X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fdebug%2Fbacktrace.cpp;h=f43a9edacccb2655eaaf42e094e4d5f74dd8742f;hb=d5dd704b2576f878809e87dbb8ff8591b9bdbce4;hp=c0bfd9d9ca16158e898b7ecd2625eb9375d3bc6d;hpb=d61b4678e4e4a2a3661a2472dc7349cc9fd5eaad;p=libs%2Fcore.git diff --git a/source/debug/backtrace.cpp b/source/debug/backtrace.cpp index c0bfd9d..f43a9ed 100644 --- a/source/debug/backtrace.cpp +++ b/source/debug/backtrace.cpp @@ -4,10 +4,15 @@ This file is part of libmspcore Copyright © 2007 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ -#ifndef WIN32 + +// 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; @@ -16,17 +21,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<