Home Download Change log

Description

This demo show how to create a stacktrace including source file name, function and line number information in C and C++ by using the GNU C library backtrace()-function and libbfd (binutils).

Requirements

Compile

Sorry, there is no makefile, but it is very simple to compile the demo. Make sure you have the libbfd and the binutil development files installed on your system. Then type in:
gcc -g -Wall -o stacktraceDemo stacktraceDemo.c -lbfd
Note: make sure the compiler is called with the -g-option. Otherwise the file and line number information is not available.

Run

When the demo is executed you see some output like:
Stack trace:
    [0x401c98] f1 (/home/torsten/projects/c/stacktrace/stacktraceDemo.c:685)
    [0x401cb5] f2 (/home/torsten/projects/c/stacktrace/stacktraceDemo.c:691)
    [0x401cc5] f3 (/home/torsten/projects/c/stacktrace/stacktraceDemo.c:696)
    [0x401d3b] main (/home/torsten/projects/c/stacktrace/stacktraceDemo.c:712)
    [0x2176d] __libc_start_main (/build/buildd/eglibc-2.15/csu/libc-start.c:258)
The strace show the call stack for the test functions f1, f2, f3 of the demo including the source file name and the line numbers.

License

The demo is under GPL.

The code is based on the original source from OpenLieroX: Debug_extended_backtrace.cpp

Download

stacktracedemo.tar.bz2

ChangeLog

2015-09-05 0.01
  * initial public release
      

    
Back to top