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

Question about the C++ backtrace


  • Subject: Question about the C++ backtrace
  • From: 成 嘉伟 <email@hidden>
  • Date: Sat, 26 Nov 2011 21:17:15 +0800

Hi, all:

I got a problem while wants to trace some information on program catches exceptions.

I used the function below:

extern "C" void log_backtrace()
{
// Dump the callstack
int callstack[128];
int  frames = backtrace((void**) callstack, 128);
char** strs = backtrace_symbols((void**) callstack, frames);


for (int i = 1; i < frames; ++i)
{
char functionSymbol[64*1024];
char moduleName    [64*1024];
int  offset        = 0;
sscanf(strs[i], "%*d %s %*s %s %*s %d", &moduleName,
  &functionSymbol, &offset);
int addr = callstack[i];
int   validCppName;
char* functionName = abi::__cxa_demangle(functionSymbol, NULL, 0,
&validCppName);
if (validCppName == 0)
printf(   "\t%8.8x — %s + %d\t\t(%s)\n",
  addr, functionName, offset, moduleName);
else
printf(   "\t%8.8x — %s + %d\t\t(%s)\n",
  addr, functionSymbol, offset, moduleName);
if (functionName)
free(functionName);
}
free(strs);
}

And the output is like this:
20:48:44 [ERROR]tcp_client::connect() failed. error:Connection refused
00000001 — latte::Log::out_error(std::string const&) + 151 (valhalla)
001a6637 — latte::tcp_client::connect(boost::asio::ip::basic_endpoint<boost::asio::ip::tcp> const&) + 307 (valhalla)
00000001 — valhalla::hall::start() + 388 (valhalla)
00204803 — main + 388 (valhalla)
00000001 — start + 52 (valhalla)
00143ae4 — 0x0 + 1 (???)

All the informations(the namespaces, class names and the method names) are good. But the only problem is the line numbers are wrong.

Is there any idea to fix the line numbers in the backtrace?

Thanks very much!

Best Regards!
 

Sends from my Mac







发自我的Mac




 _______________________________________________
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: William Squires <email@hidden>
    • Re: Question about the C++ backtrace
      • From: Fritz Anderson <email@hidden>
  • Prev by Date: Re: Lexical or Preprocessor Issue 'Cocoa/Cocoa.h file not found
  • Next by Date: Re: Question about the C++ backtrace
  • Previous by thread: Re: Lexical or Preprocessor Issue 'Cocoa/Cocoa.h file not found
  • Next by thread: Re: Question about the C++ backtrace
  • Index(es):
    • Date
    • Thread