• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: printing a stack trace to the console
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: printing a stack trace to the console


  • Subject: Re: printing a stack trace to the console
  • From: Allan Odgaard <email@hidden>
  • Date: Wed, 31 Mar 2004 11:07:27 +0200

On 31. Mar 2004, at 10:44, Jonathan Sand wrote:

I've looked into "defaults write NSGlobalDomain NSExceptionHandlingMask
63" but defaults apparently doesn't work quite that way anymore.

I do this in code:
[[NSExceptionHandler defaultExceptionHandler]
setExceptionHandlingMask:NSLogAndHandleEveryExceptionMask];

If it did, I could write the following objective-C method:

- (void)printStackTrace {
NS_DURING
[NSException raise:0 format:@"stack trace requested!"];
NS_HANDLER
NSLog(@"%@", [localException userInfo]);
NS_ENDHANDLER
}

That's pretty much what I do, except that I use 'atos' to convert the address to symbols and 'c++filt' to demangle the C++ symbols (and then 'tail' to cut the first few lines and 'cat' to enumerate the listing), all in all my NS_HANDLER ends up being:

fprintf(stderr, "------ STACK TRACE ------\n");
if(id trace = [[localException userInfo] objectForKey:NSStackTraceKey])
{
NSString* str = [NSString stringWithFormat:@"/usr/bin/atos -p %d %@ | tail -n +4 | c++filt3 | cat -n", getpid(), trace];
if(FILE* fp = popen([str UTF8String], "r"))
{
unsigned char resBuf[512];
while(size_t len = fread(resBuf, 1, sizeof(resBuf), fp))
fwrite(resBuf, 1, len, stderr);
pclose(fp);
}
}
fprintf(stderr, "-------------------------\n");




** Cocoa FAQ: <http://www.alastairs-place.net/cocoa/faq.txt> **
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: printing a stack trace to the console
      • From: Nick Zitzmann <email@hidden>
References: 
 >printing a stack trace to the console (From: Jonathan Sand <email@hidden>)

  • Prev by Date: Re: printing a stack trace to the console
  • Next by Date: Re: Distributed Objects pitfalls and strategies (SOLUTION (?))
  • Previous by thread: Re: printing a stack trace to the console
  • Next by thread: Re: printing a stack trace to the console
  • Index(es):
    • Date
    • Thread