• 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: Question about the C++ backtrace
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question about the C++ backtrace


  • Subject: Re: Question about the C++ backtrace
  • From: Fritz Anderson <email@hidden>
  • Date: Sat, 26 Nov 2011 09:59:54 -0600

On 26 Nov 2011, at 7:17 AM, 成 嘉伟 wrote:

int callstack[128];
int  frames = backtrace((void**) callstack, 128);
char** strs = backtrace_symbols((void**) callstack, frames);

My examination of your code ought to end here. The first parameter to backtrace() and backtrace_symbols() is a pointer to an array of void pointers. You are passing a pointer to an array of ints. Casting the pointers does not change the size or type of the actual contents. That your code works on the architecture you're running on is a happy coincidence.

sscanf(strs[i], "%*d %s %*s %s %*s %d", &moduleName,
   &functionSymbol, &offset);

You assume that the offset reported by backtrace_symbols() is a line offset, which would require that the function know and care about the debugging data for your code. On Darwin, the function is documented to use dladdr(), which returns a struct that has no field for line numbers. I see that on other platforms, if you pass -g to gcc, you can get line numbers, but apparently not in Darwin.

I'm pretty sure it's a byte offset into the function, though the odd offsets in your last two frames disturb me.

— F

 _______________________________________________
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: Question about the C++ backtrace
      • From: 成 嘉伟 <email@hidden>
References: 
 >Question about the C++ backtrace (From: 成 嘉伟 <email@hidden>)

  • Prev by Date: Question about the C++ backtrace
  • Next by Date: Debugging ARC app on Snow Leopard
  • Previous by thread: Question about the C++ backtrace
  • Next by thread: Re: Question about the C++ backtrace
  • Index(es):
    • Date
    • Thread