mr-edd.co.uk :: horsing around with the C++ programming language

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

(optional)
(optional)
(required, hint)

Links can be added like [this one -> http://www.mr-edd.co.uk], to my homepage.
Phrases and blocks of code can be enclosed in {{{triple braces}}}.
Any HTML markup will be escaped.