-/* $Id$
-
-This file is part of libmspcore
-Copyright © 2007 Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
// Must include something to test for glibc
#include <cstdlib>
-#if !defined(WIN32) && defined(__GLIBC__)
+#if !defined(_WIN32) && defined(__GLIBC__)
#include <dlfcn.h>
#include <execinfo.h>
#endif
Backtrace Backtrace::create()
{
-#if !defined(WIN32) && defined(__GLIBC__)
+#if !defined(_WIN32) && defined(__GLIBC__)
void *addresses[50];
- int count=::backtrace(addresses, 50);
+ int count = ::backtrace(addresses, 50);
Backtrace bt;
Dl_info dli;
for(int i=0; i<count; ++i)
{
StackFrame frame;
- frame.address=addresses[i];
+ frame.address = addresses[i];
if(dladdr(addresses[i], &dli))
{
- frame.file=dli.dli_fname;
+ frame.file = dli.dli_fname;
if(dli.dli_sname)
- frame.symbol=demangle(dli.dli_sname);
+ frame.symbol = demangle(dli.dli_sname);
}
else
- frame.file="<unknown>";
+ frame.file = "<unknown>";
bt.frames.push_back(frame);
}
ostream &operator<<(ostream &out, const Backtrace &bt)
{
- const Backtrace::FrameSeq &frames=bt.get_frames();
- for(Backtrace::FrameSeq::const_iterator i=frames.begin(); i!=frames.end(); ++i)
- out<<*i<<'\n';
+ for(const Backtrace::StackFrame &f: bt.get_frames())
+ out << f << '\n';
return out;
}
ostream &operator<<(ostream &out, const Backtrace::StackFrame &sf)
{
- out<<sf.address;
+ out << sf.address;
if(!sf.symbol.empty())
- out<<" in "<<sf.symbol;
- out<<" from "<<sf.file;
+ out << " in " << sf.symbol;
+ out << " from " << sf.file;
return out;
}