• 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: Help on Stack trace
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help on Stack trace


  • Subject: Re: Help on Stack trace
  • From: Steve Checkoway <email@hidden>
  • Date: Sun, 8 Feb 2009 15:35:48 -0800


On Feb 6, 2009, at 9:18 AM, Peter O'Gorman wrote:

dladdr will give you the name and address of "the nearest run-time
symbol with a value less than or equal to addr". Where run-time symbol,
means exported global symbol.


Interestingly enough, using some of your code, you can do a lot better.

Given

static void foo( int *p ) { ++*p; }
int bar() { return 0; }

the code snippet (full code listing attached, assuming the list allows it)

Dl_info info;
if( dladdr(foo, &info) )
printf( "foo: %s %s %p\n", info.dli_fname, info.dli_sname, info.dli_saddr );
if( dladdr(bar, &info) )
printf( "bar: %s %s %p\n", info.dli_fname, info.dli_sname, info.dli_saddr );
FromAddr( foo );
if( Symbol )
printf( "foo: %s %s %#tx\n", File, Symbol, (ptrdiff_t)Address );
Symbol = NULL;
FromAddr( bar );
if( Symbol )
printf( "bar: %s %s %#tx\n", File, Symbol, (ptrdiff_t)Address );


prints out
foo: /Users/steve/temp/./a.out FromAddr 0x19fc
bar: /Users/steve/temp/./a.out bar 0x1d70
foo: /Users/steve/temp/./a.out _foo 0x1d40
bar: /Users/steve/temp/./a.out _bar 0x1d70

In particular, the FromAddr() function finds foo even though it is not an exported global symbol.

The attached file is very slightly adapted from <http://svn.stepmania.com/viewvc/bin/cgi/viewvc.cgi/trunk/stepmania/src/archutils/Unix/BacktraceNames.cpp?view=markup >. In particular converted from c++ to c, hence the global variables.

Attachment: a.c
Description: Binary data


-- Steve Checkoway

    "Anyone who says that the solution is to educate the users
    hasn't ever met an actual user." -- Bruce Schneier




Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Help on Stack trace
      • From: Rick Altherr <email@hidden>
    • Re: Help on Stack trace
      • From: Peter O'Gorman <email@hidden>
References: 
 >Help on Stack trace (From: Arnab Ganguly <email@hidden>)
 >Re: Help on Stack trace (From: Rick Altherr <email@hidden>)
 >Re: Help on Stack trace (From: Arnab Ganguly <email@hidden>)
 >Re: Help on Stack trace (From: Peter O'Gorman <email@hidden>)

  • Prev by Date: Re: Carbon vs. Cocoa
  • Next by Date: Re: Booleans not being set
  • Previous by thread: Re: Help on Stack trace
  • Next by thread: Re: Help on Stack trace
  • Index(es):
    • Date
    • Thread