
On Oct 20, 2010, at 3:47 PM, Artyom wrote:
Hello,
Is there any interest in getting portable stack trace to boost - get something similar to Java's printStackTrace.
Basics:
1. Getting stack trace of return pointers 2. Converting this pointers to human readable trace
Extras:
1. Create exception classes that capture stack trace on throw (only pointers) 2. Print a trace on catch
Supported Platforms: Linux, Mac OS X, Solaris and Windows >= XP using MSVC.
Tested on:
Linux x86_64, GCC, Linux x86, GCC Linux x86_64, Intel Windows XP 32bit, MSVC 2008
How implemented:
Linux/Mac/Solaris with GCC:
Capture trace using backtrace Convert trace using dladdr + with demangling Requires: compilation with -rdynamic for fetching symbols
Linux/Mac/Solaris with Other compilers:
Capture trace using backtrace Convert trace using backtrace_symbols (no demangling) Requires: compilation with -rdynamic for fetching symbols
Windows/MSVC
Capture trace using RtlCaptureStackBackTrace (XP and Above) Convert trace using dbghelp.lib using SymFromAddr Requires: debug info (PDB files) for fetching symbols
All other:
Create an empty trace
For example:
#include <boost/backtrace.hpp> #include <iostream>
int foo() { throw boost::runtime_error("My Error"); return 10; }
int bar() { return foo()+20; }
int main() { try { std::cout << bar() << std::endl; } catch(std::exception const &e) { std::cerr << e.what() << std::endl; std::cerr << boost::trace(e); } }
Prints:
My Error 0x403fe1: boost::stack_trace::trace(void**, int) + 0x1b in ./test_backtrace 0x405451: boost::backtrace::backtrace(unsigned long) + 0x65 in ./test_backtrace 0x4054d2: boost::runtime_error::runtime_error(std::string const&) + 0x32 in ./test_backtrace 0x40417e: foo() + 0x44 in ./test_backtrace 0x40425c: bar() + 0x9 in ./test_backtrace 0x404271: main + 0x10 in ./test_backtrace 0x7fd612ecd1a6: __libc_start_main + 0xe6 in /lib/libc.so.6 0x403b39: __gxx_personality_v0 + 0x99 in ./test_backtrace
Initial Source Code:
http://art-blog.no-ip.info/files/backtrace.tar.gz
Any interest? Artyom
I am very interested, but when I attempted to link your code I got the following error: Undefined symbols: "boost::stack_trace::write_symbols(void* const*, int, std::basic_ostream<char, std::char_traits<char> >&)", referenced from: boost::backtrace::trace(std::basic_ostream<char, std::char_traits<char> >&) const in libfl_scheduler-1.a(scheduler.cpp.o) In the code you provided I saw backtrace.hpp and backtrace.cpp, neither one provides an implementation for boost::track_trace::write_symbols, what am I missing? Dan
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost