This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [darwin] unwind context question



On Monday, July 7, 2003, at 01:16 PM, Andreas Tobler wrote:


Geoffrey Keating wrote:

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

Well, not from my experience. I tried, but not success. Maybe I run a kernel which is to old? But I don't think so.


#include <stdio.h>
int main(int argc, char *argv[]) {
    printf("%d",*((int*)0));
    return 0;
}

[titanium:~/gcc-work/exception] andreast% ./print
Bus error

That's some kind of bug, I've noticed it with GCC. The signal that is thrown really is SIGSEGV, but either (a) it gets named 'Bus error' or (b) it gets passed to the handler as SIGBUS. If you try to catch SIGSEGV, you will get that error.


(In any case, you could always just catch SIGBUS as well.)

I write to a protected mem area.

[titanium:~/gcc-work/exception] andreast% gdb print
Program received signal EXC_BAD_ACCESS, Could not access memory.
0x00001db0 in main ()
(gdb)

So, these kind of errors end up in KERN_PROTECTION_FAILURE. And a SIGSEGV does not help. At least I didn't manage it to catch the failure.
It would be much easier to handle a SEGV than incorporate a mach msg handler.



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.

What do you need to see?

The instructions just before the ones you listed would be interesting. You could check this much more easily by just writing a signal handler that does return and seeing where it returns to...


--
Geoff Keating <geoffk@apple.com>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]