- 
                Notifications
    You must be signed in to change notification settings 
- Fork 505
OSX unwind workaround #2166
OSX unwind workaround #2166
Conversation
| Hi @christianscheuer, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution! TTYL, DNFBOT; | 
| @christianscheuer, Thanks for signing the contribution license agreement so quickly! Actual humans will now validate the agreement and then evaluate the PR. | 
| 
 @janvorli Apparently, there is number of places where we expect to have pointers to registers. Could you please take a look and see whether it is worth it to try to fix all of them as a workaround, instead of just fixing the unwinder? | 
| @jkotas Let me know if there is anything I can do to help push this. Right now this issue is blocking a lot of progress for me personally, hence my interest in seeking to resolve it before the March milestone. I'll be happy to invest considerable time in it, but I would need some guidance to get started :) | 
| @jkotas, @christianscheuer what could work as a temporary workaround for now is to revert the change that @christianscheuer made and then: 
 | 
| Great, thank you @janvorli. I'll give that a shot asap. | 
| @janvorli PTLA.  | 
| @christianscheuer - does this mean you were not getting the stack trace? The abort is expected to happen at the end, since unhandled exception is supposed to fail fast. | 
| 
 This is expected. You should also see message with exception type and message on the console. The stacktrace printing on unhandled exceptions does not work yet. | 
| @janvorli Yes this is an exception that when compiled in CoreCLR is caught by a catch block and logged to console so the program can continue. With these bits in CoreRT it aborts the program. So it seems the catch handler is not called, making the exception bubble up. | 
| @jkotas All I get in the console is:  | 
|  | ||
| #else // !UNIX_AMD64_ABI | ||
|  | ||
| #if defined(__APPLE__) | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Could you please change the define to something like UNWIND_WORKAROUND that is defined for __APPLE__ so that all places related to this are easy to find?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! Which header file would be the appropriate place to make this define?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src\Native\CMakeLists.txt may be a good place
| Hmm, we may need to set the register pointers in the UnwindCursorToRegDisplay little bit differently. There seem to be cases when the pointers were actually pointing to some location and we want to preserve that. E.g. the pRBP is set in the StackFrameIterator::InternalInit to point to a member in the TransitionFrame or the others pointing to the initial PAL_LIMITED_CONTEXT. Or we set them to values from thisFuncletPtrs at some point. #define GET_CONTEXT_POINTER(unwReg, rdReg) GetContextPointer(cursor, unwContext, unwReg, ®Display->p##rdReg);
    GET_CONTEXT_POINTERS
#undef GET_CONTEXT_POINTERHmm, actually, now that I think about it, I've just realized that the context pointers are always initialized at the beginning of the stack walk to point inside the initial PAL_LIMITED_CONTEXT (or the TransitionFrame). | 
| Also, you can try setting breaking at RhpThrowEx and RhpRethrow, and check whether you see good stacktrace under debugger. There is a bug in generation of unwind info on Unix: #1461 - the exception handling won't work through methods affected by this bug. | 
        
          
                src/Native/CMakeLists.txt
              
                Outdated
          
        
      | add_compile_options(-fPIC) | ||
| add_compile_options(-fvisibility=hidden) | ||
|  | ||
| if(CLR_CMAKE_PLATFORM_DARWIN) | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the workaround is limited to a single place now, it is not very valueable to have it controlled via special define...
| @christianscheuer Is this still WIP? Are the crashes that you have been running into before fixed now? | 
| @jkotas I am currently getting a new error which relates to this code using an await statement in a try block. I am trying to isolate it to see if this works as expected when not combined with the Task async/await pattern. | 
| I removed the Task pattern complexity from my code. It seems now that the stack's backtrace show correctly, but that it somehow resumes from the wrong address? I am now getting an error here: This virtualcall is the argument Element.UIElement (a property call) in the following code: result.Require(...) is the throwing method. Any ideas? | 
| @christianscheuer Thank you for the confirmation. @janvorli is working on the full fix for this problem (statically link a custom version of the unwinder with the runtime), but it does not hurt to have this workaround in master until that comes online. | 
Work in progress.
I have done a workaround for the missing OSX unwind as you suggested, @jkotas (see #1867).
I might be in a little deep here though, so forgive me if I have misunderstood anything.
Now when I run a real-world OSX app on this, it stops in
RhpCallCatchFunclet:frame #0: 0x000000010005fad2 cptsbackendRhpCallCatchFunclet + 63`At this point:
Where the value of rax is 0x0.
It seems to be this code in
RhpCallCatchFuncletWhere the RegDisplay's pRbx is 0x0.
I don't know if that happens due to a misalignment of offsets, if I did something wrong in other parts of the code, or if this is related to the original todo-item.