Implement native stack unwinding for Linux#282
Conversation
|
@jkotas Could you please take a look? |
|
@kangaroo This is what works on Linux with the libunwind from http://www.nongnu.org/libunwind. It seems that what we need to change for OSX is the WinContextToUnwindContext function in seh-unwind.cpp. We should be able to use unw_set_reg on OSX for all registers with the OSX libunwind (provided it works the same way as the libunwind in LLVM), while with the other libunwind, e.g. the RSP is considered read only. |
|
@kangaroo This unix_issue177 branch is the branch that I've created for you and me to work on the unwinder. |
|
@janvorli Awesome! I'll try to take a look tonight. For #5 see: https://github.com/dotnet/coreclr/issues/141 |
|
Also, what (if any) tests are you validating against right now? |
|
@kangaroo No tests yet. I've just created a simple C# app that dumps managed stack trace. Like this (needs to be compiled with optimizations off so that the compiler preserves all the methods and the dump doesn't contain just main): class Program
{
static void A()
{
B();
}
static void B()
{
C();
}
static void C()
{
D();
}
static void D()
{
Console.WriteLine(System.Environment.StackTrace);
}
static void Main(string[] args)
{
A();
}
} |
There was a problem hiding this comment.
Maybe call it PAL_VirtualUnwind to make it clear that it is not a regular Win32 API?
|
I'll try to address my review comments with a patch after dinner. |
|
Initial PR to clean up OS X here: #284 It still needs a bit of work, since its not actually displaying the stack trace yet, but it doesn't break build or crash anymore. |
GC currently relies on having these context pointers so that when it moves an object to which a register stored somewhere on the stack points, it can update the value of the register on the stack. So what we are trying to do there is to get a pointer to the stack location that we can keep and GC can update it later. |
|
@dotnet-bot test this please |
Yes, pointer to an object managed by GC would be stored in a register stored in one of the native frames.
If the unwind on Mac does not support context pointers, I would not worry about it right now. It will become a problem only once we start enabling GC - I would do it as part of enabling GC.
It would require: keeping track of unavailable register context pointers in REGDISPLAY - it may be as simple as storing NULL as register context pointer when it is not available, and then using that information to pin the values that cannot be updated in EECodeManager::EnumGcRefs. |
Refactor libunwind to work on osx
Rename VirtualUnwind in PAL to PAL_VirtualUnwind Move .cfi annotation inside macros and update PROLOG_WITH_TRANSITION_BLOCK to use these macros. I've verified that the annotation is correct by stepping through the asm code and verifying that the stack trace is correct at every instruction.
|
@kangaroo Our changes are now in the master branch. |
|
@janvorli excellent, I've been looking at the existing machinery around exception handling expecting thats up next ;) |
|
@kangaroo Regarding the exception handling. I've started to work on a plan for it and I've figured that most of the stuff in PAL like the PAL_TryExcept and all the related stuff will go away. Only the exception raising stuff will stay (RtlpRaiseException, SEHRaiseException, RaiseException). We will use plain C++ exceptions instead of this low level simulation of SEH. So hopefully there should be no platform specific stuff for that. |
|
@janvorli Do you have a timeline for the PAL changes? |
|
@janvorli Yes, a lot of the existing stuff looked overly complicated. I think C++ exceptions are the right way to go. |
|
@janvorli can you keep us informed as the EH plans evolve? |
|
@pgavlin @AndyAyersMS @kangaroo Let's move further discussion to #192 which @sergiy-k has created for the exception handling work. |
|
@pgavlin I have already made the changes in PAL and the related PAL_TRY, PAL_EXCEPT, ... macros locally and I'd like to send out a PR for these today. |
|
@AndyAyersMS I hope I'll be able to share all the plan details tomorrow. |
This change implements native stack unwinding using the libunwind on
Linux. I have also fixed bunch of issues / details in the related code:
LEAF_ENTRY / LEAF_END macros.
.L to see the CallDescrWorkerInternal in the stack trace
parameters unaligned