Native debugging and mono_jit_runtime_invoke

rjmrjm CAMember ✭✭

Is there a way to debug native code reasonably?

I can start my XamMac app (using a bound native library), load the native library in XCode and attach lldb. It works - breakpoints are hit, I can step through code, etc...

However it's virtually unusable because it constantly breaks on mono_jit_runtime_invoke.

Any way to stop that happening? Thanks!

Posts

  • adamkempadamkemp USInsider, Developer Group Leader mod

    By default the native debugger will stop any time it gets certain Unix signals, and mono uses SIGUSR1 to trigger JITs. You can tell the debugger to ignore those signals. For lldb this link explains how:
    http://stackoverflow.com/questions/11984051/how-to-tell-lldb-debugger-not-to-handle-sigbus

    For gdb this link has similar instructions:
    http://sourceware.org/gdb/onlinedocs/gdb/Signals.html

    In either case the signal to ignore is SIGUSR1 I think that's the only one, but if you hit others then just use the same instructions. You can also put that in your .gdbinit (or equivalent lldb init file) in your home directory to make it default.

  • rjmrjm CAMember ✭✭

    Thanks! This looks like just what I was looking for.

    Can I just enter the command on a running debugging session? I tried to block SIGUSR1, SIGUSR2 and SIGSEGV but I'm still breaking on mono_jit_runtime_invoke...

  • rjmrjm CAMember ✭✭

    Maybe it's the wrong signal? When XCode is stopped on "EXC_BAD_ACCESS", how can I see the signal that caused it?

    Thanks again

  • adamkempadamkemp USInsider, Developer Group Leader mod
    edited December 2013

    EXC_BAD_ACCESS means you crashed. That's totally different. You shouldn't disable stopping on SIGSEGV because that's the signal that happens when you crash.

    I have had trouble having both a native debugger and a mono debugger (i.e., Xamarin Studio) attached at the same time. Maybe that's the problem here?

  • rjmrjm CAMember ✭✭

    Yes, ordinarily, but I'm not crashing. I can 'Continue' in the XCode debugger, and if I continue enough times I will eventually hit my breakpoint.

    So the app is not crashing. But it's constantly stopping on mono_jit_runtime_invoke with EXC_BAD_ACCESS. Which realistically makes debugging impossible.

    I tried without the mono debugger attached (i.e. "Start without debugging" on a debug build in XS), but now the XCode debugger doesn't break at all (not even on my breakpoints).

    Thanks for you help.

  • adamkempadamkemp USInsider, Developer Group Leader mod

    Maybe you're not really attached (or it doesn't have the symbols it need?) in the case where you're not using the mono debugger. I would focus on that use case. I've never been able to use both debuggers at once, and I no longer even bother trying.

  • rjmrjm CAMember ✭✭
    edited December 2013

    I stand corrected. I'm not sure what I did wrong before, but I just tried this again:

    In XS > "Start without debugging"

    In XCode > Attach to process

    Set a breakpoint in my native code

    Cause that code to execute

    And my breakpoint is hit!

    I think the only difference was that I set the breakpoint before I caused that code to execute (and probably before the native framework was actually loaded).

    Anyway, it works great. Thanks again!

  • JeffreyStedfastJeffreyStedfast USXamarin Team Xamurai

    This documentation may be useful:

    http://www.mono-project.com/Debugging

  • rjmrjm CAMember ✭✭

    @jstedfast thanks for the link!

Sign In or Register to comment.