• 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: William Squires <email@hidden>
  • Date: Mon, 28 Nov 2011 19:39:59 -0600


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

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);

This should give a booboo - You have 6 % specifiers, but only three arguments being passed to conform. This'll almost assuredly screw the pooch (stack pointer)!

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

  • Prev by Date: Re: (SOLVED) MainWindow.xib required or not? (Philip McIntosh)
  • Next by Date: Re: Question about the C++ backtrace
  • Previous by thread: Re: Question about the C++ backtrace
  • Next by thread: Re: Question about the C++ backtrace
  • Index(es):
    • Date
    • Thread