|
Boost : |
From: Neal D. Becker (nbecker_at_[hidden])
Date: 2002-08-21 11:58:55
Another useful function for glibc systems is the "backtrace()". If I
could just figure out how to demangle the output, we'd be in business.
Here is an example:
---------------
#include <execinfo.h>
#include <iostream>
#include <cstdlib>
using namespace std;
/* Obtain a backtrace and print it to `stdout'. */
void
print_trace (void)
{
void *array[10];
size_t size;
char **strings;
size_t i;
size = backtrace (array, 10);
strings = backtrace_symbols (array, size);
for (i = 0; i < size; i++)
cout << strings[i] << '\n';
free (strings);
}
/* A dummy function to make the backtrace more interesting. */
void
dummy_function (void)
{
print_trace ();
}
int
main (void)
{
dummy_function ();
return 0;
}
----------------------
Here's the output:
g++3 -g -o Hello Hello.cc -rdynamic
./Hello
Hello
Hello(_Z11print_tracev+0x14) [0x804882c]
Hello(_Z14dummy_functionv+0xb) [0x80488a9]
Hello(main+0x15) [0x80488c1]
Hello(__libc_start_main+0x95) [0x42017589]
Hello(__gxx_personality_v0+0x31) [0x8048789]
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk