2001-12-17 14:31:42 +00:00
|
|
|
|
/** NSException - Object encapsulation of a general exception handler
|
1999-04-21 20:16:25 +00:00
|
|
|
|
Copyright (C) 1993, 1994, 1996, 1997, 1999 Free Software Foundation, Inc.
|
1995-03-18 17:15:15 +00:00
|
|
|
|
|
|
|
|
|
Written by: Adam Fedor <fedor@boulder.colorado.edu>
|
|
|
|
|
Date: Mar 1995
|
|
|
|
|
|
1996-05-12 00:56:10 +00:00
|
|
|
|
This file is part of the GNUstep Base Library.
|
1995-03-18 17:15:15 +00:00
|
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
1999-04-21 20:16:25 +00:00
|
|
|
|
|
1995-03-18 17:15:15 +00:00
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
|
License along with this library; if not, write to the Free
|
2006-05-10 03:18:08 +00:00
|
|
|
|
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
|
Boston, MA 02111 USA.
|
2001-12-18 16:54:15 +00:00
|
|
|
|
|
|
|
|
|
$Date$ $Revision$
|
1995-03-18 17:15:15 +00:00
|
|
|
|
*/
|
1996-05-28 18:27:40 +00:00
|
|
|
|
|
2003-06-07 01:24:41 +00:00
|
|
|
|
#include "config.h"
|
2003-07-31 23:49:32 +00:00
|
|
|
|
#include "GNUstepBase/preface.h"
|
2006-05-10 03:18:08 +00:00
|
|
|
|
#include <Foundation/NSDebug.h>
|
|
|
|
|
#include <Foundation/NSBundle.h>
|
2003-06-07 01:24:41 +00:00
|
|
|
|
#include "Foundation/NSException.h"
|
|
|
|
|
#include "Foundation/NSString.h"
|
|
|
|
|
#include "Foundation/NSArray.h"
|
|
|
|
|
#include "Foundation/NSCoder.h"
|
2006-05-10 03:18:08 +00:00
|
|
|
|
#include "Foundation/NSNull.h"
|
2003-06-07 01:24:41 +00:00
|
|
|
|
#include "Foundation/NSThread.h"
|
|
|
|
|
#include "Foundation/NSDictionary.h"
|
2001-05-31 22:39:16 +00:00
|
|
|
|
#include <stdio.h>
|
2002-03-27 09:55:57 +00:00
|
|
|
|
|
2006-05-10 03:18:08 +00:00
|
|
|
|
/*
|
|
|
|
|
* Turn off STACKTRACE if we don't have bfd support for it.
|
|
|
|
|
*/
|
|
|
|
|
#if !(defined(HAVE_BFD_H) && defined(HAVE_LIBBFD) && defined(HAVE_LIBIBERTY))
|
|
|
|
|
#if defined(STACKTRACE)
|
|
|
|
|
#undef STACKTRACE
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if defined(STACKTRACE)
|
|
|
|
|
|
|
|
|
|
// GSStackTrace inspired by FYStackTrace.m
|
|
|
|
|
// created by Wim Oudshoorn on Mon 11-Apr-2006
|
|
|
|
|
// reworked by Lloyd Dupont @ NovaMind.com on 4-May-2006
|
|
|
|
|
|
|
|
|
|
#include <bfd.h>
|
|
|
|
|
|
|
|
|
|
@class GSBinaryFileInfo;
|
|
|
|
|
|
|
|
|
|
@interface GSFunctionInfo : NSObject
|
|
|
|
|
{
|
|
|
|
|
void *_address;
|
|
|
|
|
NSString *_fileName;
|
|
|
|
|
NSString *_functionName;
|
|
|
|
|
int _lineNo;
|
|
|
|
|
GSBinaryFileInfo *_module;
|
|
|
|
|
}
|
|
|
|
|
- (void*) address;
|
|
|
|
|
- (NSString *) fileName;
|
|
|
|
|
- (NSString *) function;
|
|
|
|
|
- (id) initWithModule: (GSBinaryFileInfo*)module
|
|
|
|
|
address: (void*)address
|
|
|
|
|
file: (NSString*)file
|
|
|
|
|
function: (NSString*)function
|
|
|
|
|
line: (int)lineNo;
|
|
|
|
|
- (int) lineNumber;
|
|
|
|
|
- (GSBinaryFileInfo*) module;
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@interface GSBinaryFileInfo : NSObject
|
|
|
|
|
{
|
|
|
|
|
NSString *_filename;
|
|
|
|
|
bfd *_abfd;
|
|
|
|
|
asymbol **_symbols;
|
|
|
|
|
long _symbolCount;
|
|
|
|
|
}
|
|
|
|
|
- (NSString *) filename;
|
|
|
|
|
- (GSFunctionInfo *) functionForAddress: (void*) address;
|
|
|
|
|
- (id) initWithBinaryFile: (NSString *)filename;
|
|
|
|
|
- (id) init; // return info for the current executing process
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@interface GSStackTrace : NSObject
|
|
|
|
|
{
|
|
|
|
|
NSMutableArray *frames;
|
|
|
|
|
}
|
|
|
|
|
+ (GSStackTrace*) currentStack;
|
|
|
|
|
/*
|
|
|
|
|
* Add some module information to the stack trace information
|
|
|
|
|
* only symbols from the current process's file, GNUstep base library,
|
|
|
|
|
* GNUstep gui library, and any bundles containing code are loaded.
|
|
|
|
|
* All other symbols should be manually added
|
|
|
|
|
*/
|
|
|
|
|
+ (BOOL) loadModule: (NSString *)filename;
|
|
|
|
|
|
|
|
|
|
- (NSString*) description;
|
|
|
|
|
- (NSEnumerator*) enumerator;
|
|
|
|
|
- (GSFunctionInfo*) frameAt: (unsigned)index;
|
|
|
|
|
- (unsigned) frameCount;
|
|
|
|
|
- (NSEnumerator*) reverseEnumerator;
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@implementation GSFunctionInfo
|
|
|
|
|
|
|
|
|
|
- (void*) address
|
|
|
|
|
{
|
|
|
|
|
return _address;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (oneway void) dealloc
|
|
|
|
|
{
|
|
|
|
|
[_module release];
|
|
|
|
|
_module = nil;
|
|
|
|
|
[_fileName release];
|
|
|
|
|
_fileName = nil;
|
|
|
|
|
[_functionName release];
|
|
|
|
|
_functionName = nil;
|
|
|
|
|
[super dealloc];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSString *) description
|
|
|
|
|
{
|
|
|
|
|
return [NSString stringWithFormat: @"(%@: %p) %@ %@: %d",
|
|
|
|
|
[_module filename], _address, _functionName, _fileName, _lineNo];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSString *) fileName
|
|
|
|
|
{
|
|
|
|
|
return _fileName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSString *) function
|
|
|
|
|
{
|
|
|
|
|
return _functionName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
|
{
|
|
|
|
|
[self release];
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) initWithModule: (GSBinaryFileInfo*)module
|
|
|
|
|
address: (void*)address
|
|
|
|
|
file: (NSString*)file
|
|
|
|
|
function: (NSString*)function
|
|
|
|
|
line: (int)lineNo
|
|
|
|
|
{
|
|
|
|
|
_module = [module retain];
|
|
|
|
|
_address = address;
|
|
|
|
|
_fileName = [file retain];
|
|
|
|
|
_functionName = [function retain];
|
|
|
|
|
_lineNo = lineNo;
|
|
|
|
|
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (int) lineNumber
|
|
|
|
|
{
|
|
|
|
|
return _lineNo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (GSBinaryFileInfo *) module
|
|
|
|
|
{
|
|
|
|
|
return _module;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@implementation GSBinaryFileInfo
|
|
|
|
|
|
|
|
|
|
+ (GSBinaryFileInfo*) infoWithBinaryFile: (NSString *)filename
|
|
|
|
|
{
|
|
|
|
|
return [[[self alloc] initWithBinaryFile: filename] autorelease];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (void) initialize
|
|
|
|
|
{
|
|
|
|
|
static BOOL first = YES;
|
|
|
|
|
|
|
|
|
|
if (first == NO)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
first = NO;
|
|
|
|
|
bfd_init ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (oneway void) dealloc
|
|
|
|
|
{
|
|
|
|
|
[_filename release];
|
|
|
|
|
_filename = nil;
|
|
|
|
|
if (_abfd)
|
|
|
|
|
{
|
|
|
|
|
bfd_close (_abfd);
|
|
|
|
|
_abfd = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (_symbols)
|
|
|
|
|
{
|
|
|
|
|
free (_symbols);
|
|
|
|
|
_symbols = NULL;
|
|
|
|
|
}
|
|
|
|
|
[super dealloc];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSString *) filename
|
|
|
|
|
{
|
|
|
|
|
return _filename;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
|
{
|
|
|
|
|
NSString *processName;
|
|
|
|
|
|
|
|
|
|
processName = [[[NSProcessInfo processInfo] arguments] objectAtIndex: 0];
|
|
|
|
|
return [self initWithBinaryFile: processName];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) initWithBinaryFile: (NSString *)filename
|
|
|
|
|
{
|
|
|
|
|
int neededSpace;
|
|
|
|
|
|
|
|
|
|
// 1st initialize the bfd
|
|
|
|
|
if ([filename length] == 0)
|
|
|
|
|
{
|
|
|
|
|
NSLog (@"GSBinaryFileInfo: No File");
|
|
|
|
|
[self release];
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
_filename = [filename copy];
|
|
|
|
|
_abfd = bfd_openr ([filename cString], NULL);
|
|
|
|
|
if (!_abfd)
|
|
|
|
|
{
|
|
|
|
|
NSLog (@"GSBinaryFileInfo: No Binary Info");
|
|
|
|
|
[self release];
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
if (!bfd_check_format_matches (_abfd, bfd_object, NULL))
|
|
|
|
|
{
|
|
|
|
|
NSLog (@"GSBinaryFileInfo: BFD format object error");
|
|
|
|
|
[self release];
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// second read the symbols from it
|
|
|
|
|
if (!(bfd_get_file_flags (_abfd) & HAS_SYMS))
|
|
|
|
|
{
|
|
|
|
|
NSLog (@"GSBinaryFileInfo: BFD does not contain any symbols");
|
|
|
|
|
[self release];
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
neededSpace = bfd_get_symtab_upper_bound (_abfd);
|
|
|
|
|
if (neededSpace < 0)
|
|
|
|
|
{
|
|
|
|
|
NSLog (@"GSBinaryFileInfo: BFD error while deducing needed space");
|
|
|
|
|
[self release];
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
if (neededSpace == 0)
|
|
|
|
|
{
|
|
|
|
|
NSLog (@"GSBinaryFileInfo: BFD no space for symbols needed");
|
|
|
|
|
[self release];
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
_symbols = malloc (neededSpace);
|
|
|
|
|
if (!_symbols)
|
|
|
|
|
{
|
|
|
|
|
NSLog (@"GSBinaryFileInfo: Can't malloc buffer");
|
|
|
|
|
[self release];
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
_symbolCount = bfd_canonicalize_symtab (_abfd, _symbols);
|
|
|
|
|
if (_symbolCount < 0)
|
|
|
|
|
{
|
|
|
|
|
NSLog (@"GSBinaryFileInfo: BFD error while reading symbols");
|
|
|
|
|
[self release];
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct SearchAddressStruct
|
|
|
|
|
{
|
|
|
|
|
void *theAddress;
|
|
|
|
|
GSBinaryFileInfo *module;
|
|
|
|
|
asymbol **symbols;
|
|
|
|
|
GSFunctionInfo *theInfo;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void find_address (bfd *abfd, asection *section,
|
|
|
|
|
struct SearchAddressStruct *info)
|
|
|
|
|
{
|
|
|
|
|
bfd_vma address;
|
|
|
|
|
bfd_vma vma;
|
|
|
|
|
unsigned size;
|
|
|
|
|
const char *fileName;
|
|
|
|
|
const char *functionName;
|
|
|
|
|
unsigned line = 0;
|
|
|
|
|
|
|
|
|
|
if (info->theInfo)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!(bfd_get_section_flags (abfd, section) & SEC_ALLOC))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
address = (bfd_vma) info->theAddress;
|
|
|
|
|
|
|
|
|
|
vma = bfd_get_section_vma (abfd, section);
|
|
|
|
|
size = bfd_get_section_size (section);
|
|
|
|
|
if (address < vma || address >= vma + size)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bfd_find_nearest_line (abfd, section, info->symbols,
|
|
|
|
|
address - vma, &fileName, &functionName, &line))
|
|
|
|
|
{
|
|
|
|
|
GSFunctionInfo *fi;
|
|
|
|
|
|
|
|
|
|
fi = [GSFunctionInfo alloc];
|
|
|
|
|
fi = [fi initWithModule: info->module
|
|
|
|
|
address: info->theAddress
|
|
|
|
|
file: [NSString stringWithCString: fileName]
|
|
|
|
|
function: [NSString stringWithCString: functionName]
|
|
|
|
|
line: line];
|
|
|
|
|
[fi autorelease];
|
|
|
|
|
info->theInfo = fi;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (GSFunctionInfo *) functionForAddress: (void*) address
|
|
|
|
|
{
|
|
|
|
|
struct SearchAddressStruct searchInfo = { address, self, _symbols, nil };
|
|
|
|
|
|
|
|
|
|
bfd_map_over_sections (_abfd,
|
|
|
|
|
(void (*) (bfd *, asection *, void *)) find_address, &searchInfo);
|
|
|
|
|
return searchInfo.theInfo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
// this method automatically load the current process + GNUstep base & gui.
|
|
|
|
|
static NSMutableDictionary *GetStackModules()
|
|
|
|
|
{
|
|
|
|
|
static NSMutableDictionary *stackModules = nil;
|
|
|
|
|
|
|
|
|
|
if (stackModules == nil)
|
|
|
|
|
{
|
|
|
|
|
NSEnumerator *enumerator;
|
|
|
|
|
NSBundle *bundle;
|
|
|
|
|
|
|
|
|
|
stackModules = [NSMutableDictionary new];
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Try to ensure we have the main, base and gui library bundles.
|
|
|
|
|
*/
|
|
|
|
|
[NSBundle mainBundle];
|
|
|
|
|
[NSBundle bundleForClass: [NSObject class]];
|
|
|
|
|
[NSBundle bundleForClass: NSClassFromString(@"NSView")];
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Add file info for all bundles with code.
|
|
|
|
|
*/
|
|
|
|
|
enumerator = [[NSBundle allBundles] objectEnumerator];
|
|
|
|
|
while ((bundle = [enumerator nextObject]) != nil)
|
|
|
|
|
{
|
|
|
|
|
if ([bundle load] == YES)
|
|
|
|
|
{
|
|
|
|
|
[GSStackTrace loadModule: [bundle executablePath]];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return stackModules;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@implementation GSStackTrace : NSObject
|
|
|
|
|
|
|
|
|
|
static NSNull *null = nil;
|
|
|
|
|
|
|
|
|
|
+ (GSStackTrace*) currentStack
|
|
|
|
|
{
|
|
|
|
|
return [[[GSStackTrace alloc] init] autorelease];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (void) initialize
|
|
|
|
|
{
|
|
|
|
|
null = RETAIN([NSNull null]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// initialize stack trace info
|
|
|
|
|
+ (BOOL) loadModule: (NSString *)filename
|
|
|
|
|
{
|
|
|
|
|
if ([filename length] > 0)
|
|
|
|
|
{
|
|
|
|
|
NSMutableDictionary *modules = GetStackModules();
|
|
|
|
|
|
|
|
|
|
if ([modules objectForKey: filename] == nil)
|
|
|
|
|
{
|
|
|
|
|
GSBinaryFileInfo *module;
|
|
|
|
|
|
|
|
|
|
module = [GSBinaryFileInfo infoWithBinaryFile: filename];
|
|
|
|
|
if (module != nil)
|
|
|
|
|
{
|
|
|
|
|
[modules setObject: module forKey: filename];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
[modules setObject: null forKey: filename];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ([modules objectForKey: filename] != null)
|
|
|
|
|
{
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (oneway void) dealloc
|
|
|
|
|
{
|
|
|
|
|
[frames release];
|
|
|
|
|
frames = nil;
|
|
|
|
|
|
|
|
|
|
[super dealloc];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSString*) description
|
|
|
|
|
{
|
|
|
|
|
NSMutableString *result = [NSMutableString string];
|
|
|
|
|
int i;
|
|
|
|
|
int n;
|
|
|
|
|
|
|
|
|
|
n = [frames count];
|
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
|
{
|
|
|
|
|
GSFunctionInfo *line = [frames objectAtIndex: i];
|
|
|
|
|
|
|
|
|
|
[result appendFormat: @"%3d: %@\n", i, line];
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSEnumerator*) enumerator
|
|
|
|
|
{
|
|
|
|
|
return [frames objectEnumerator];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (GSFunctionInfo*) frameAt: (unsigned)index
|
|
|
|
|
{
|
|
|
|
|
return [frames objectAtIndex: index];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (unsigned) frameCount
|
|
|
|
|
{
|
|
|
|
|
return [frames count];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// grab the current stack
|
|
|
|
|
// this MAX_FRAME comes from NSDebug.h which warn only 100 frames are available
|
|
|
|
|
#define MAX_FRAME 100
|
|
|
|
|
- (id) init
|
|
|
|
|
{
|
|
|
|
|
NSArray *modules;
|
|
|
|
|
int i;
|
|
|
|
|
int j;
|
|
|
|
|
int n;
|
|
|
|
|
int m;
|
|
|
|
|
|
|
|
|
|
frames = [[NSMutableArray alloc] init];
|
|
|
|
|
modules = [GetStackModules() allValues];
|
|
|
|
|
n = NSCountFrames();
|
|
|
|
|
m = [modules count];
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < n && i < MAX_FRAME; i++)
|
|
|
|
|
{
|
|
|
|
|
GSFunctionInfo *aFrame = nil;
|
|
|
|
|
void *address = NSReturnAddress(i);
|
|
|
|
|
|
|
|
|
|
for (j = 0; j < m; j++)
|
|
|
|
|
{
|
|
|
|
|
GSBinaryFileInfo *bfi = [modules objectAtIndex: j];
|
|
|
|
|
|
|
|
|
|
if ((id)bfi != (id)null)
|
|
|
|
|
{
|
|
|
|
|
aFrame = [bfi functionForAddress: address];
|
|
|
|
|
if (aFrame)
|
|
|
|
|
{
|
|
|
|
|
[frames addObject: aFrame];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// not found (?!), add an 'unknown' function
|
|
|
|
|
if (!aFrame)
|
|
|
|
|
{
|
|
|
|
|
aFrame = [GSFunctionInfo alloc];
|
|
|
|
|
[aFrame initWithModule: nil
|
|
|
|
|
address: address
|
|
|
|
|
file: nil
|
|
|
|
|
function: nil
|
|
|
|
|
line: 0];
|
|
|
|
|
[aFrame autorelease];
|
|
|
|
|
[frames addObject: aFrame];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSEnumerator*) reverseEnumerator
|
|
|
|
|
{
|
|
|
|
|
return [frames reverseObjectEnumerator];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
#endif /* STACKTRACE */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-06-09 11:47:45 +00:00
|
|
|
|
NSString* const NSGenericException
|
2002-06-09 11:36:13 +00:00
|
|
|
|
= @"NSGenericException";
|
|
|
|
|
|
2002-06-09 11:47:45 +00:00
|
|
|
|
NSString* const NSInternalInconsistencyException
|
2002-06-09 11:36:13 +00:00
|
|
|
|
= @"NSInternalInconsistencyException";
|
|
|
|
|
|
2002-06-09 11:47:45 +00:00
|
|
|
|
NSString* const NSInvalidArgumentException
|
2002-06-09 11:36:13 +00:00
|
|
|
|
= @"NSInvalidArgumentException";
|
|
|
|
|
|
2002-06-09 11:47:45 +00:00
|
|
|
|
NSString* const NSMallocException
|
2002-06-09 11:36:13 +00:00
|
|
|
|
= @"NSMallocException";
|
|
|
|
|
|
2002-06-09 11:47:45 +00:00
|
|
|
|
NSString* const NSRangeException
|
2002-06-09 11:36:13 +00:00
|
|
|
|
= @"NSRangeException";
|
|
|
|
|
|
2002-06-09 11:47:45 +00:00
|
|
|
|
NSString* const NSCharacterConversionException
|
2002-06-09 11:36:13 +00:00
|
|
|
|
= @"NSCharacterConversionException";
|
|
|
|
|
|
2002-06-09 11:47:45 +00:00
|
|
|
|
NSString* const NSParseErrorException
|
2002-06-09 11:36:13 +00:00
|
|
|
|
= @"NSParseErrorException";
|
|
|
|
|
|
2002-03-27 09:55:57 +00:00
|
|
|
|
#include "GSPrivate.h"
|
2001-01-25 08:05:52 +00:00
|
|
|
|
|
2005-07-01 08:53:32 +00:00
|
|
|
|
static void _terminate()
|
1995-03-18 17:15:15 +00:00
|
|
|
|
{
|
2005-07-01 08:53:32 +00:00
|
|
|
|
BOOL shouldAbort;
|
2001-01-25 08:05:52 +00:00
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2005-07-01 08:53:32 +00:00
|
|
|
|
shouldAbort = YES; // abort() by default.
|
2001-01-25 08:05:52 +00:00
|
|
|
|
#else
|
2005-07-01 08:53:32 +00:00
|
|
|
|
shouldAbort = NO; // exit() by default.
|
2001-01-25 08:05:52 +00:00
|
|
|
|
#endif
|
2005-11-15 13:07:09 +00:00
|
|
|
|
shouldAbort = GSEnvironmentFlag("CRASH_ON_ABORT", shouldAbort);
|
2005-07-01 08:53:32 +00:00
|
|
|
|
if (shouldAbort == YES)
|
2001-01-25 08:05:52 +00:00
|
|
|
|
{
|
|
|
|
|
abort();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
1995-03-18 17:15:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-07-01 08:53:32 +00:00
|
|
|
|
static void
|
|
|
|
|
_NSFoundationUncaughtExceptionHandler (NSException *exception)
|
|
|
|
|
{
|
|
|
|
|
extern const char* GSArgZero(void);
|
|
|
|
|
|
|
|
|
|
fprintf(stderr, "%s: Uncaught exception %s, reason: %s\n", GSArgZero(),
|
|
|
|
|
[[exception name] lossyCString], [[exception reason] lossyCString]);
|
|
|
|
|
fflush(stderr); /* NEEDED UNDER MINGW */
|
|
|
|
|
|
|
|
|
|
_terminate();
|
|
|
|
|
}
|
|
|
|
|
|
1995-03-18 17:15:15 +00:00
|
|
|
|
@implementation NSException
|
|
|
|
|
|
2000-04-05 14:21:05 +00:00
|
|
|
|
+ (NSException*) exceptionWithName: (NSString*)name
|
|
|
|
|
reason: (NSString*)reason
|
|
|
|
|
userInfo: (NSDictionary*)userInfo
|
1995-03-18 17:15:15 +00:00
|
|
|
|
{
|
1999-04-21 20:16:25 +00:00
|
|
|
|
return AUTORELEASE([[self alloc] initWithName: name reason: reason
|
2002-01-03 10:01:25 +00:00
|
|
|
|
userInfo: userInfo]);
|
1995-03-18 17:15:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-05 14:21:05 +00:00
|
|
|
|
+ (void) raise: (NSString*)name
|
|
|
|
|
format: (NSString*)format,...
|
1995-03-18 17:15:15 +00:00
|
|
|
|
{
|
1999-04-21 20:16:25 +00:00
|
|
|
|
va_list args;
|
1995-03-18 17:15:15 +00:00
|
|
|
|
|
1999-04-21 20:16:25 +00:00
|
|
|
|
va_start(args, format);
|
|
|
|
|
[self raise: name format: format arguments: args];
|
2002-10-27 01:38:30 +00:00
|
|
|
|
// This probably doesn't matter, but va_end won't get called
|
1999-04-21 20:16:25 +00:00
|
|
|
|
va_end(args);
|
1995-03-18 17:15:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-05 14:21:05 +00:00
|
|
|
|
+ (void) raise: (NSString*)name
|
|
|
|
|
format: (NSString*)format
|
|
|
|
|
arguments: (va_list)argList
|
1995-03-18 17:15:15 +00:00
|
|
|
|
{
|
1999-04-21 20:16:25 +00:00
|
|
|
|
NSString *reason;
|
|
|
|
|
NSException *except;
|
|
|
|
|
|
|
|
|
|
reason = [NSString stringWithFormat: format arguments: argList];
|
|
|
|
|
except = [self exceptionWithName: name reason: reason userInfo: nil];
|
|
|
|
|
[except raise];
|
1995-03-18 17:15:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-05 14:21:05 +00:00
|
|
|
|
- (id) initWithName: (NSString*)name
|
|
|
|
|
reason: (NSString*)reason
|
|
|
|
|
userInfo: (NSDictionary*)userInfo
|
1995-03-18 17:15:15 +00:00
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
|
ASSIGN(_e_name, name);
|
|
|
|
|
ASSIGN(_e_reason, reason);
|
|
|
|
|
ASSIGN(_e_info, userInfo);
|
1999-04-21 20:16:25 +00:00
|
|
|
|
return self;
|
1995-03-18 17:15:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-05 14:21:05 +00:00
|
|
|
|
- (void) dealloc
|
1997-09-13 17:52:31 +00:00
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
|
DESTROY(_e_name);
|
|
|
|
|
DESTROY(_e_reason);
|
|
|
|
|
DESTROY(_e_info);
|
1997-09-13 17:52:31 +00:00
|
|
|
|
[super dealloc];
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-05 14:21:05 +00:00
|
|
|
|
- (void) raise
|
1995-03-18 17:15:15 +00:00
|
|
|
|
{
|
2006-05-10 03:18:08 +00:00
|
|
|
|
#ifndef _NATIVE_OBJC_EXCEPTIONS
|
1999-04-21 20:16:25 +00:00
|
|
|
|
NSThread *thread;
|
|
|
|
|
NSHandler *handler;
|
2006-05-10 03:18:08 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if defined(STACKTRACE)
|
|
|
|
|
if ([_e_info objectForKey: @"GSStackTraceKey"] == nil)
|
|
|
|
|
{
|
|
|
|
|
NSMutableDictionary *m;
|
1995-03-18 17:15:15 +00:00
|
|
|
|
|
2006-05-10 03:18:08 +00:00
|
|
|
|
if (_e_info == nil)
|
|
|
|
|
{
|
|
|
|
|
_e_info = m = [NSMutableDictionary new];
|
|
|
|
|
}
|
|
|
|
|
else if ([_e_info isKindOfClass: [NSMutableDictionary class]] == YES)
|
|
|
|
|
{
|
|
|
|
|
m = (NSMutableDictionary*)_e_info;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m = [_e_info mutableCopy];
|
|
|
|
|
RELEASE(_e_info);
|
|
|
|
|
_e_info = m;
|
|
|
|
|
}
|
|
|
|
|
[m setObject: [GSStackTrace currentStack] forKey: @"GSStackTraceKey"];
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef _NATIVE_OBJC_EXCEPTIONS
|
|
|
|
|
@throw self;
|
|
|
|
|
#else
|
1999-04-21 20:16:25 +00:00
|
|
|
|
thread = GSCurrentThread();
|
|
|
|
|
handler = thread->_exception_handler;
|
|
|
|
|
if (handler == NULL)
|
|
|
|
|
{
|
2005-07-01 08:53:32 +00:00
|
|
|
|
static BOOL recursion = NO;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Set a flag to prevent recursive uncaught exceptions.
|
|
|
|
|
*/
|
|
|
|
|
if (recursion == NO)
|
|
|
|
|
{
|
|
|
|
|
recursion = YES;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"recursion encountered handling uncaught exception\n");
|
|
|
|
|
fflush(stderr); /* NEEDED UNDER MINGW */
|
|
|
|
|
_terminate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Call the uncaught exception handler (if there is one).
|
|
|
|
|
*/
|
|
|
|
|
if (_NSUncaughtExceptionHandler != NULL)
|
|
|
|
|
{
|
|
|
|
|
(*_NSUncaughtExceptionHandler)(self);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The uncaught exception handler which is set has not
|
|
|
|
|
* exited, so we call the builtin handler, (undocumented
|
|
|
|
|
* behavior of MacOS-X).
|
|
|
|
|
* The standard handler is guaranteed to exit/abort.
|
|
|
|
|
*/
|
|
|
|
|
_NSFoundationUncaughtExceptionHandler(self);
|
1999-04-21 20:16:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
thread->_exception_handler = handler->next;
|
|
|
|
|
handler->exception = self;
|
|
|
|
|
longjmp(handler->jumpState, 1);
|
2006-05-10 03:18:08 +00:00
|
|
|
|
#endif
|
1995-03-18 17:15:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-05 14:21:05 +00:00
|
|
|
|
- (NSString*) name
|
1995-03-18 17:15:15 +00:00
|
|
|
|
{
|
2000-09-07 16:53:14 +00:00
|
|
|
|
if (_e_name != nil)
|
|
|
|
|
{
|
|
|
|
|
return _e_name;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return NSStringFromClass([self class]);
|
|
|
|
|
}
|
1995-03-18 17:15:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-05 14:21:05 +00:00
|
|
|
|
- (NSString*) reason
|
1995-03-18 17:15:15 +00:00
|
|
|
|
{
|
2000-09-07 16:53:14 +00:00
|
|
|
|
if (_e_reason != nil)
|
|
|
|
|
{
|
|
|
|
|
return _e_reason;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return @"unspecified reason";
|
|
|
|
|
}
|
1995-03-18 17:15:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-05 14:21:05 +00:00
|
|
|
|
- (NSDictionary*) userInfo
|
1995-03-18 17:15:15 +00:00
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
|
return _e_info;
|
1995-03-18 17:15:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-10-17 18:56:49 +00:00
|
|
|
|
- (Class) classForPortCoder
|
|
|
|
|
{
|
|
|
|
|
return [self class];
|
|
|
|
|
}
|
|
|
|
|
|
1999-04-21 20:16:25 +00:00
|
|
|
|
- (id) replacementObjectForPortCoder: (NSPortCoder*)aCoder
|
1998-10-17 18:56:49 +00:00
|
|
|
|
{
|
1999-04-21 20:16:25 +00:00
|
|
|
|
return self;
|
1998-10-17 18:56:49 +00:00
|
|
|
|
}
|
1995-03-18 17:15:15 +00:00
|
|
|
|
|
1999-04-21 20:16:25 +00:00
|
|
|
|
- (void) encodeWithCoder: (NSCoder*)aCoder
|
1995-03-18 17:15:15 +00:00
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(id) at: &_e_name];
|
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(id) at: &_e_reason];
|
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(id) at: &_e_info];
|
1995-03-18 17:15:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-04-21 20:16:25 +00:00
|
|
|
|
- (id) initWithCoder: (NSCoder*)aDecoder
|
1995-03-18 17:15:15 +00:00
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(id) at: &_e_name];
|
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(id) at: &_e_reason];
|
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(id) at: &_e_info];
|
1999-04-21 20:16:25 +00:00
|
|
|
|
return self;
|
1995-03-18 17:15:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-04-21 20:16:25 +00:00
|
|
|
|
- (id) deepen
|
1995-03-18 17:15:15 +00:00
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
|
_e_name = [_e_name copyWithZone: [self zone]];
|
|
|
|
|
_e_reason = [_e_reason copyWithZone: [self zone]];
|
|
|
|
|
_e_info = [_e_info copyWithZone: [self zone]];
|
1999-04-21 20:16:25 +00:00
|
|
|
|
return self;
|
1995-03-18 17:15:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-05 14:21:05 +00:00
|
|
|
|
- (id) copyWithZone: (NSZone*)zone
|
1995-03-18 17:15:15 +00:00
|
|
|
|
{
|
1999-04-21 20:16:25 +00:00
|
|
|
|
if (NSShouldRetainWithZone(self, zone))
|
|
|
|
|
return RETAIN(self);
|
|
|
|
|
else
|
|
|
|
|
return [(NSException*)NSCopyObject(self, 0, zone) deepen];
|
1995-03-18 17:15:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-04-21 20:16:25 +00:00
|
|
|
|
- (NSString*) description
|
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
|
if (_e_info)
|
1999-05-11 09:43:04 +00:00
|
|
|
|
return [NSString stringWithFormat: @"%@ NAME:%@ REASON:%@ INFO:%@",
|
1999-09-16 07:21:34 +00:00
|
|
|
|
[super description], _e_name, _e_reason, _e_info];
|
1999-04-21 20:16:25 +00:00
|
|
|
|
else
|
1999-05-11 09:43:04 +00:00
|
|
|
|
return [NSString stringWithFormat: @"%@ NAME:%@ REASON:%@",
|
1999-09-16 07:21:34 +00:00
|
|
|
|
[super description], _e_name, _e_reason];
|
1999-04-21 20:16:25 +00:00
|
|
|
|
}
|
1995-03-18 17:15:15 +00:00
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
1999-04-21 20:16:25 +00:00
|
|
|
|
void
|
2000-04-05 14:21:05 +00:00
|
|
|
|
_NSAddHandler (NSHandler* handler)
|
1995-03-18 17:15:15 +00:00
|
|
|
|
{
|
1999-04-19 14:29:52 +00:00
|
|
|
|
NSThread *thread;
|
1995-03-18 17:15:15 +00:00
|
|
|
|
|
1999-04-19 14:29:52 +00:00
|
|
|
|
thread = GSCurrentThread();
|
2006-04-09 16:16:07 +00:00
|
|
|
|
#if defined(__MINGW32__) && defined(DEBUG)
|
2005-10-23 15:11:19 +00:00
|
|
|
|
if (thread->_exception_handler
|
|
|
|
|
&& IsBadReadPtr(thread->_exception_handler, sizeof(NSHandler)))
|
|
|
|
|
{
|
2005-10-23 21:30:24 +00:00
|
|
|
|
fprintf(stderr, "ERROR: Current exception handler is bogus.\n");
|
2005-10-23 15:11:19 +00:00
|
|
|
|
}
|
|
|
|
|
#endif
|
1999-04-19 14:29:52 +00:00
|
|
|
|
handler->next = thread->_exception_handler;
|
|
|
|
|
thread->_exception_handler = handler;
|
1995-03-18 17:15:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-04-21 20:16:25 +00:00
|
|
|
|
void
|
2000-04-05 14:21:05 +00:00
|
|
|
|
_NSRemoveHandler (NSHandler* handler)
|
1995-03-18 17:15:15 +00:00
|
|
|
|
{
|
1999-04-19 14:29:52 +00:00
|
|
|
|
NSThread *thread;
|
1995-03-18 17:15:15 +00:00
|
|
|
|
|
1999-04-19 14:29:52 +00:00
|
|
|
|
thread = GSCurrentThread();
|
2005-10-23 15:11:19 +00:00
|
|
|
|
#if defined(DEBUG)
|
|
|
|
|
if (thread->_exception_handler != handler)
|
|
|
|
|
{
|
2005-10-23 15:14:35 +00:00
|
|
|
|
fprintf(stderr, "ERROR: Removing exception handler that is not on top "
|
2005-10-23 21:30:24 +00:00
|
|
|
|
"of the stack. (You probably called return in an NS_DURING block.)\n");
|
2005-10-23 15:11:19 +00:00
|
|
|
|
}
|
2006-04-09 16:16:07 +00:00
|
|
|
|
#if defined(__MINGW32__)
|
2005-10-23 15:11:19 +00:00
|
|
|
|
if (IsBadReadPtr(handler, sizeof(NSHandler)))
|
|
|
|
|
{
|
2005-10-23 15:14:35 +00:00
|
|
|
|
fprintf(stderr, "ERROR: Could not remove exception handler, "
|
2005-10-23 21:30:24 +00:00
|
|
|
|
"handler is bad pointer.\n");
|
2005-10-23 15:11:19 +00:00
|
|
|
|
thread->_exception_handler = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (handler->next && IsBadReadPtr(handler->next, sizeof(NSHandler)))
|
|
|
|
|
{
|
2005-10-23 15:14:35 +00:00
|
|
|
|
fprintf(stderr, "ERROR: Could not restore exception handler, "
|
2005-10-23 21:30:24 +00:00
|
|
|
|
"handler->next is bad pointer.\n");
|
2005-10-23 15:11:19 +00:00
|
|
|
|
thread->_exception_handler = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
thread->_exception_handler = handler->next;
|
1997-03-03 19:51:04 +00:00
|
|
|
|
}
|