Permalink
Browse files

Get callstack

  • Loading branch information...
1 parent e7c8a1d commit 687f064cb37dac593be7d1f32ec5c30860a283eb @kaler committed Aug 3, 2010
Showing with 24 additions and 1 deletion.
  1. +1 −0 Classes/CrashController.h
  2. +23 −1 Classes/CrashController.m
@@ -15,4 +15,5 @@
+ (CrashController*)sharedInstance;
+- (NSArray*)callstackAsArray;
@end
View
@@ -8,13 +8,17 @@
#import "CrashController.h"
#include <signal.h>
+#include <execinfo.h>
static CrashController *sharedInstance = nil;
#pragma mark C Functions
void sighandler(int signal)
{
- NSLog(@"sighandler");
+ NSArray *arr = [[CrashController sharedInstance] callstackAsArray];
+ NSLog(@"Callstack: %@", arr);
+
+ exit(signal);
}
@implementation CrashController
@@ -97,4 +101,22 @@ - (void)dealloc
[super dealloc];
}
+#pragma mark methods
+- (NSArray*)callstackAsArray
+{
+ void* callstack[128];
+ const int numFrames = backtrace(callstack, 128);
+ char **symbols = backtrace_symbols(callstack, numFrames);
+
+ NSMutableArray *arr = [NSMutableArray arrayWithCapacity:numFrames];
+ for (int i = 0; i < numFrames; ++i)
+ {
+ [arr addObject:[NSString stringWithUTF8String:symbols[i]]];
+ }
+
+ free(symbols);
+
+ return arr;
+}
+
@end

0 comments on commit 687f064

Please sign in to comment.