-
Notifications
You must be signed in to change notification settings - Fork 3
/
ExceptionHelper.m
executable file
·40 lines (35 loc) · 1.45 KB
/
ExceptionHelper.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//
// ExceptionHelper.m
// Enormego Helpers
//
// Created by Shaun Harrison on 3/13/09.
// Copyright 2009 enormego. All rights reserved.
//
#import "ExceptionHelper.h"
#ifdef ENABLE_EXCEPTIONS
@implementation ExceptionHelper
+ (void)generateStackTraceForException:(NSException*)exception {
NSString* processIdentifier = [[NSNumber numberWithInt:[[NSProcessInfo processInfo] processIdentifier]] stringValue];
NSString* stackAddresses = [[exception callStackReturnAddresses] componentsJoinedByString:@" "];
NSMutableString* debugInfo = [NSMutableString string];
[debugInfo appendString:@"\n"];
[debugInfo appendString:@"================================\n"];
[debugInfo appendString:@"Exception Caught:\n"];
[debugInfo appendString:@"--------------------------------\n"];
[debugInfo appendFormat:@"Name: %@\n", exception.name];
[debugInfo appendFormat:@"Reason: %@\n", exception.reason];
if(exception.userInfo) {
[debugInfo appendFormat:@"Additional Info: %@\n", exception.userInfo];
} else {
[debugInfo appendString:@"No additional information available..\n"];
}
[debugInfo appendString:@"--------------------------------\n"];
[debugInfo appendFormat:@"Run the following command in GDB to view a full stack trace:\n\nshell atos -p %@ %@\n\n", processIdentifier, stackAddresses];
[debugInfo appendString:@"================================\n"];
NSLog(@"%@", debugInfo);
while(1) {
// Keeps the process alive while you run the command.
}
}
@end
#endif