--- /dev/null
+/* $Id$
+
+This file is part of libmspcore
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+#include <execinfo.h>
+#include "backtrace.h"
+
+using namespace std;
+
+namespace Msp {
+namespace Debug {
+
+Backtrace Backtrace::create()
+{
+#ifndef WIN32
+ void *addresses[50];
+ int count=::backtrace(addresses, 50);
+
+ char **symbols=backtrace_symbols(addresses, count);
+
+ Backtrace bt;
+ for(int i=0; i<count; ++i)
+ bt.frames.push_back(StackFrame(addresses[i], symbols[i]));
+
+ free(symbols);
+
+ return bt;
+#else
+ return Backtrace();
+#endif
+}
+
+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->address<<" in "<<i->symbol<<'\n';
+
+ return out;
+}
+
+} // namespace Debug
+} // namespace Msp