Crash Reporter for iPhone Applications (Part 2)

crashDuck.png

In part one I describe how to set up an Exception Handler, Uli discovered as first one that this handles not all cases. The missing part is a signal handler to get information of SIGSEGV, SIGBUS, … signals.

I thought the hard part of this is getting the backtrace inside a signal handler. I already found code for this, but I couldn’t use it because it was GPL. I tried the easy way, offering the author money to release it under public domain, oh boy this was a waste of time. But now that I found my own solution for this I’m happy that I didn’t spend money on this. (1 line versus 20 lines of code)

Let’s start with setting up a signal handler, the good old man page helps.

  1. int main(int argc, char *argv[]) {
  2.         struct sigaction mySigAction;
  3.         mySigAction.sa_sigaction = mysighandler;
  4.         mySigAction.sa_flags = SA_SIGINFO;
  5.         sigemptyset(&mySigAction.sa_mask);
  6.         sigaction(SIGQUIT, &mySigAction, NULL);
  7.         sigaction(SIGILL, &mySigAction, NULL);
  8.         sigaction(SIGTRAP, &mySigAction, NULL);
  9.         sigaction(SIGABRT, &mySigAction, NULL);
  10.         sigaction(SIGEMT, &mySigAction, NULL);
  11.         sigaction(SIGFPE, &mySigAction, NULL);
  12.         sigaction(SIGBUS, &mySigAction, NULL);
  13.         sigaction(SIGSEGV, &mySigAction, NULL);
  14.         sigaction(SIGSYS, &mySigAction, NULL);
  15.         sigaction(SIGPIPE, &mySigAction, NULL);
  16.         sigaction(SIGALRM, &mySigAction, NULL);
  17.         sigaction(SIGXCPU, &mySigAction, NULL);
  18.         sigaction(SIGXFSZ, &mySigAction, NULL);
  19.        
  20.         NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
  21.         int retVal = UIApplicationMain(argc, argv, nil, nil);
  22.         [pool release];
  23.         return retVal;
  24. }

And here the line of code I was searching for over two days: backtrace(3). You don’t find this little bastard if you search in Xcode Help with iPhone OS Library selected (there goes my two days)

  1. void mysighandler(int sig, siginfo_t *info, void *context) {
  2.         void *backtraceFrames[128];
  3.         int frameCount = backtrace(backtraceFrames, 128);
  4.  
  5.         // report the error
  6. }

Like in the Exception Handler you now just use backtrace_symbols(3). (Example)

Good luck with working down the crash reports you will get now :)

Crash Reporter for iPhone Applications (Part 1)
Crash Reporter for iPhone Applications (Part 2)


1
 
del.icio.us digg

[...] restoroot.com » Blog » Crash Reporter for iPhone Applications (Part 2) (tags: iphone osx programming fuckingnda) [...]

ys raoli.com » Blog Archiv
   
Says raoli.com » Blog Archive » links for 2008-10-21 on

Leave a Reply