[darwin] unwind context question

Geoffrey Keating geoffk@apple.com
Mon Jul 7 18:47:00 GMT 2003


On Monday, July 7, 2003, at 11:13  AM, Andreas Tobler wrote:

> Hi,
>
> I'm still trying to implement the MD_FALLBACK_FRAME_STATE_FOR macro 
> for darwin. While doing so I get a bit confused about the context I 
> find during debugging.
>
> First, some words on how I do it.
> In libgcj we need this macro to catch NullPointerExceptions and 
> friends.
> To catch a EXC_BAD_ACCESS under darwin we have to install a mach 
> message handler to catch the exception, then we can modify the 
> threadstate and call a forwarding function to call a SIGSEGV.

Won't Darwin do this for you?  All you should need to do is catch 
SIGSEGV.

> After that the MAKE_THROW_FRAME from libjava/include/*signal.h gets 
> invoked.
>
> The mechanism is not finished yet but for prototyping it should work.
>
> Now I can run the Throw_2 testcase from libjava.lang and catch the 
> EXC_BAD_ACCESS. Then I modify the threadstate to call a > raise(SIGSEGV).
> I end up in the MAKE_THROW_FRAME and there it should start with 
> unwinding. Here I have my problems in understanding.
>
> I enter the MD_FALLBACK_FRAME_STATE_FOR and see a context->ra which is 
> in the middle of sigtramp and not as I would expect at the beginning 
> of sigreturn.
>
> Below the disass.
> I would expect context->ra at 0x9000fae0 and not at 0x9000fa9c.

Maybe.  It's hard to tell without seeing how the return address got 
set.  You'll note that the code there does eventually wind up in 
sigreturn.

> Now where does this context come from? I see the init here:
>
> unwind-dw2.c:1184#define uw_init_context(CONTEXT)

Yes, it starts there.

> But I don't follow, do we have a __builtin_unwind_init on darwin?

No, we don't.

> And what about __builtin_return_address ? There are some comments from 
> mrs in rs6000.h

Yes, we do have one of those.

> Any further readings, hints are very appreciated.
>
> Thank you in advance.
>
> Andreas
>
>
>
> (gdb) p context->ra
> $3 = (void *) 0x9000fa9c
>
> Dump of assembler code from 0x9000fa9c to 0x9000fb20:
> 0x9000fa9c <_sigtramp+92>:      addi    r11,r29,4648
> 0x9000faa0 <_sigtramp+96>:      mr      r3,r30
> 0x9000faa4 <_sigtramp+100>:     lwz     r9,0(r11)
> 0x9000faa8 <_sigtramp+104>:     addi    r9,r9,-1
> 0x9000faac <_sigtramp+108>:     stw     r9,0(r11)
> 0x9000fab0 <_sigtramp+112>:     lwz     r0,88(r1)
> 0x9000fab4 <_sigtramp+116>:     addi    r1,r1,80
> 0x9000fab8 <_sigtramp+120>:     lmw     r29,-12(r1)
> 0x9000fabc <_sigtramp+124>:     mtlr    r0
> 0x9000fac0 <_sigtramp+128>:     b       0x900cca1c 
> <dyld_stub_sigreturn>
> 0x9000fac4 <_sigtramp+132>:     .long 0x0
> 0x9000fac8 <_sigtramp+136>:     .long 0x0
> 0x9000facc <_sigtramp+140>:     .long 0x0
> 0x9000fad0 <_sigtramp+144>:     .long 0x0
> 0x9000fad4 <_sigtramp+148>:     .long 0x0
> 0x9000fad8 <_sigtramp+152>:     .long 0x0
> 0x9000fadc <_sigtramp+156>:     .long 0x0
> 0x9000fae0 <sigreturn+0>:       li      r0,103
> 0x9000fae4 <sigreturn+4>:       sc
> 0x9000fae8 <sigreturn+8>:       b       0x9000faf0 <sigreturn+16>
> 0x9000faec <sigreturn+12>:      b       0x9000fb10 <sigreturn+48>
> 0x9000faf0 <sigreturn+16>:      mflr    r0
> 0x9000faf4 <sigreturn+20>:      bl      0x9000faf8 <sigreturn+24>
> 0x9000faf8 <sigreturn+24>:      mflr    r12
> 0x9000fafc <sigreturn+28>:      mtlr    r0
> 0x9000fb00 <sigreturn+32>:      addis   r12,r12,4095
> 0x9000fb04 <sigreturn+36>:      lwz     r12,21960(r12)
> 0x9000fb08 <sigreturn+40>:      mtctr   r12
> 0x9000fb0c <sigreturn+44>:      bctr
> 0x9000fb10 <sigreturn+48>:      nop
> 0x9000fb14 <sigreturn+52>:      blr
> 0x9000fb18 <sigreturn+56>:      .long 0x0
> 0x9000fb1c <sigreturn+60>:      .long 0x0
> End of assembler dump.
>
>
>



More information about the Gcc mailing list