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 for(const Backtrace::StackFrame &f: bt.get_frames())
52 ostream &operator<<(ostream &out, const Backtrace::StackFrame &sf)
55 if(!sf.symbol.empty())
56 out << " in " << sf.symbol;
57 out << " from " << sf.file;