stack_trace
This is a tiny library that allows you to obtain a stack trace in C++ code.
Though I will likely keep the repository around for the foreseeable future, I probably won't be actively maintaining this code for much longer, as I consider it to be superseded by my dbg library, which does not have any GPL or LGPL dependencies for MinGW targets.
Recent activity
Code
Clone the repository using mercurial:
> hg clone http://bitbucket.org/edd/stack_trace
Or get a zip file of the code.
Quick start
Mac OS X (Intel and PowerPC GCC 4) and Win32 (MSVC and MinGW) are supported.
#include <algorithm>
#include <iostream>
#include <iterator>
#include <dbg/stack.hpp>
void e()
{
dbg::stack s;
std::copy(s.begin(), s.end(), std::ostream_iterator<dbg::stack_frame>(std::cout, "\n"));
}
void d() { e(); }
void c() { d(); }
void b() { c(); }
void a() { b(); }
int main()
{
a();
return 0;
}
Output:
0x4014b5: e() in P:\software\dbg\example\obj\mingw\debug\example.exe 0x4015bf: d() in P:\software\dbg\example\obj\mingw\debug\example.exe 0x4015cc: c() in P:\software\dbg\example\obj\mingw\debug\example.exe 0x4015d9: b() in P:\software\dbg\example\obj\mingw\debug\example.exe 0x4015e6: a() in P:\software\dbg\example\obj\mingw\debug\example.exe 0x401632: main in P:\software\dbg\example\obj\mingw\debug\example.exe 0x40124b: [unknown function] in P:\software\dbg\example\obj\mingw\debug\example.exe 0x401298: [unknown function] in P:\software\dbg\example\obj\mingw\debug\example.exe 0x7c817067: RegisterWaitForInputIdle in C:\WINDOWS\system32\kernel32.dll
Further reading
Comments
All original content copyright© Edd Dawson.
Any opinions expressed by Edd are his own and are not necessarily shared by his employer. Or by anyone else, in fact.
All source code appearing on this website that was written by Edd Dawson is made available under the terms of the Boost software license version 1.0 unless otherwise stated or implied by the license associated with the work from which the code is derived.
