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!
|