1 /*****************************************************************************
2 * VLCExceptionHandler.m: VLCExceptionHandler implementation
3 *****************************************************************************
4 * Copyright (C) 2007 Pierre d'Herbemont
5 * Copyright (C) 2007 the VideoLAN team
8 * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 #import "VLCExceptionHandler.h"
26 #import <ExceptionHandling/ExceptionHandling.h>
29 @implementation VLCExceptionHandler
32 [[NSExceptionHandler defaultExceptionHandler] setDelegate:[[VLCExceptionHandler alloc] init]];
34 [[NSExceptionHandler defaultExceptionHandler] setExceptionHandlingMask:
35 0xffff /* Catch all */ ];
37 [[NSExceptionHandler defaultExceptionHandler] setExceptionHangingMask:
38 NSHangOnUncaughtExceptionMask|
39 NSHangOnUncaughtSystemExceptionMask|
40 NSHangOnUncaughtRuntimeErrorMask|
41 NSHangOnTopLevelExceptionMask|
42 NSHangOnOtherExceptionMask];
45 /* From Apple's guide on exception */
46 - (BOOL)exceptionHandler:(NSExceptionHandler *)sender shouldLogException:(NSException *)exception mask:(unsigned int)aMask
48 [self printStackTrace:exception];
49 NSLog(@"*** Exception Handled! %@: %@", [exception name], [exception reason]);
50 int ret = NSRunCriticalAlertPanel(@"Exception not handled!",
51 [NSString stringWithFormat:@"%@: %@\n\nBack trace has been printed to Console.\n\nWe will now wait for debugger connection...\n",
52 [exception name], [exception reason]],
53 @"Quit", @"Wait Debugger", nil);
54 if( ret == NSOKButton )
56 [NSApp terminate:self];
61 - (void)printStackTrace:(NSException *)e
63 NSString *stack = [[e userInfo] objectForKey:NSStackTraceKey];
66 NSLog(@"No stack trace available.");
70 NSTask *ls = [[NSTask alloc] init];
71 NSString *pid = [[NSNumber numberWithInt:[[NSProcessInfo processInfo] processIdentifier]] stringValue];
72 NSMutableArray *args = [NSMutableArray arrayWithCapacity:20];
74 [args addObject:@"-p"];
76 [args addObjectsFromArray:[stack componentsSeparatedByString:@" "]];
77 /* Note: function addresses are separated by double spaces, not a single space. */
79 [ls setLaunchPath:@"/usr/bin/atos"];
80 [ls setArguments:args];