X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fdebug%2Fbacktrace.cpp;h=f9057dce833d95b9231917bd763a489f7a856fb1;hp=2078996c41d234bb138f8cb29c4805e7894cd9ab;hb=5a32939eb6e576c223e1be5f80226d9e628a2398;hpb=521cf1db00f8ce2d9f9494dca503d6c17d89ac2f diff --git a/source/debug/backtrace.cpp b/source/debug/backtrace.cpp index 2078996..f9057dc 100644 --- a/source/debug/backtrace.cpp +++ b/source/debug/backtrace.cpp @@ -1,11 +1,11 @@ -/* $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 +#if !defined(_WIN32) && defined(__GLIBC__) +#include #include +#endif #include "backtrace.h" +#include "demangle.h" using namespace std; @@ -14,17 +14,26 @@ namespace Debug { Backtrace Backtrace::create() { -#ifndef WIN32 +#if !defined(_WIN32) && defined(__GLIBC__) void *addresses[50]; - int count=::backtrace(addresses, 50); - - char **symbols=backtrace_symbols(addresses, count); + int count = ::backtrace(addresses, 50); Backtrace bt; + Dl_info dli; for(int i=0; iaddress<<" in "<symbol<<'\n'; + const list &frames = bt.get_frames(); + for(list::const_iterator i=frames.begin(); i!=frames.end(); ++i) + out<<*i<<'\n'; + + return out; +} + +ostream &operator<<(ostream &out, const Backtrace::StackFrame &sf) +{ + out<