3 This file is part of libmspcore
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 // Must include something to test for glibc
10 #if !defined(WIN32) && defined(__GLIBC__)
14 #include "backtrace.h"
22 Backtrace Backtrace::create()
24 #if !defined(WIN32) && defined(__GLIBC__)
26 int count=::backtrace(addresses, 50);
30 for(int i=0; i<count; ++i)
33 frame.address=addresses[i];
34 if(dladdr(addresses[i], &dli))
36 frame.file=dli.dli_fname;
38 frame.symbol=demangle(dli.dli_sname);
41 frame.file="<unknown>";
42 bt.frames.push_back(frame);
51 ostream &operator<<(ostream &out, const Backtrace &bt)
53 const list<Backtrace::StackFrame> &frames=bt.get_frames();
54 for(list<Backtrace::StackFrame>::const_iterator i=frames.begin(); i!=frames.end(); ++i)
60 ostream &operator<<(ostream &out, const Backtrace::StackFrame &sf)
63 if(!sf.symbol.empty())
64 out<<" in "<<sf.symbol;
65 out<<" from "<<sf.file;