3

I'm trying to log all the crashes that are occurring in my app. I've written a signalHandler and an exceptionHandler. I'm registering the signalHandler for all the signals that are defined in sys/signal.h file. And I'm getting my signalHandler method invoked on SIGABRT, SIGUSR1, etc..

The problem is that, I'm getting some weird signals at times, that are not invoking my signalHandler. One example is EXC_BAD_ACCESS (code=1 or 2, address='some memory address'). I've registered SIGSEGV with the signalHandler; in fact I've registered all the defined signals in sys/signal.h file.

If you want to create this EXC_BAD_ACCESS (code=1, address=0x00XXXXXX)signal, just write the following line of code in your app,

NSLog(@"Stupid Log %@ %@");

Can someone please help me, to catch such signals?

Thanks in advance,

Suraj

Suran
  • 1,209
  • 1
  • 17
  • 21
  • 1
    I don't think you can catch a segmentation fault. When it occurs, your program has messed up something in the memory so seriously that it doesn't have a chance to be resumed, the only thing can be done is that the OS kills the process. Try writing good code without memory management mistakes instead, that's way more powerful and elegant. –  Apr 23 '13 at 05:08
  • You should use crashlytics. It is an awesome tool for tracking and then debugging crashes. – HalR Apr 23 '13 at 05:10
  • 1
    @H2CO3, I understand that, the best thing to do is to write good code without memory management mistakes. But, as you know, everyone makes some mistakes; in my case, I make a hell lot of mistakes. It'll be really good, to have a back up plan like, logging all the crashes, in case we make some terrible memory management mistakes. So is this signal coming because of segmentation fault? – Suran Apr 23 '13 at 05:17
  • @Suran Yes, it does. And if you make a lot of mistakes, then you should use a debugger instead of trying to do magic in the code itself. I get segfaults sometimes, me too, don't think I don't. But then I just fire up GDB. –  Apr 23 '13 at 05:19
  • @H2CO3, The signal SIGSEGV means segmentation fault right?, And we can handle SIGSEGV signals. But, only EXC_BAD_ACCESS with this 'code' in parentheses are not getting caught. Any idea, why is that? Can you please help me understand it properly? – Suran Apr 23 '13 at 05:29
  • @Suran "we can handle SIGSEGV signals" - for the reasons I just explained, you can't. And `EXC_BAD_ACCESS` is not a signal, it's the name of the error code your process (or rather the OS) throws when the segfault occurs. –  Apr 23 '13 at 05:32
  • @H2CO3, What I meant is that, we can invoke a method/signalHandler on EXC_BAD_ACCESS error aka SIGSEGV signal. And we can do that. The problem I was having was because, the device was connected to GDB. When I run the app, disconnected from XCode/Mac, the signalHandler is working fine and is giving me logs. Anyway, thanks for the help...:-) – Suran Apr 23 '13 at 06:09
  • @Suran I understood what you meant, and **you can't, because `EXC_BAD_ACESS` is not a signal name.** –  Apr 23 '13 at 06:11
  • @H2CO3 I never said that EXC_BAD_ACCESS is a signal. Sorry, if I caused you any confusion. – Suran Apr 23 '13 at 09:22
  • possible duplicate of [NSSetUncaughtExceptionHandler not catch all errors on iPhone](http://stackoverflow.com/questions/1128539/nssetuncaughtexceptionhandler-not-catch-all-errors-on-iphone) – Rachel Gallen Apr 24 '13 at 00:26

1 Answers1

5

You can refer the following links :

EXC_BAD_ACCESS automatic handling

Also look into this :

How to prevent EXC_BAD_ACCESS from crashing an app?

Community
  • 1
  • 1
V-Xtreme
  • 7,230
  • 9
  • 39
  • 79
  • Actually, I'm trying to find a way to handle the EXC_BAD_ACCESS (code=1,...) crash. The NSLog I provided is just to create such a crash. – Suran Apr 23 '13 at 05:20
  • 1
    @Suran:Sorry , I misread the question. Have referred this :http://stackoverflow.com/questions/10315526/exc-bad-access-automatic-handling and http://stackoverflow.com/questions/15513864/how-to-prevent-exc-bad-access-from-crashing-an-app – V-Xtreme Apr 23 '13 at 05:28
  • Thanks, The first link helped. The signalHandler is getting called when I'm running the app, after disconnecting the device from XCode/Mac. Please edit your answer to include the links, I'll accept the answer. – Suran Apr 23 '13 at 05:57
  • @Suran:its nice to hear that it helped you . – V-Xtreme Apr 23 '13 at 06:04