1 // Must include something to test for glibc
3 #if !defined(WIN32) && defined(__GLIBC__)
15 Backtrace Backtrace::create()
17 #if !defined(WIN32) && defined(__GLIBC__)
19 int count = ::backtrace(addresses, 50);
23 for(int i=0; i<count; ++i)
26 frame.address = addresses[i];
27 if(dladdr(addresses[i], &dli))
29 frame.file = dli.dli_fname;
31 frame.symbol = demangle(dli.dli_sname);
34 frame.file = "<unknown>";
35 bt.frames.push_back(frame);
44 ostream &operator<<(ostream &out, const Backtrace &bt)
46 const list<Backtrace::StackFrame> &frames = bt.get_frames();
47 for(list<Backtrace::StackFrame>::const_iterator i=frames.begin(); i!=frames.end(); ++i)
53 ostream &operator<<(ostream &out, const Backtrace::StackFrame &sf)
56 if(!sf.symbol.empty())
57 out<<" in "<<sf.symbol;
58 out<<" from "<<sf.file;