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

make

Note: make sure the compiler is called with the -g-option. Otherwise the file and line number information will not be 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 trace 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

stacktrace_demo.tar.bz2

ChangeLog

2023-05-04 0.02
  * added Makefile file
  * support libbfd 2.30+2.3x
  * fixed compiling with libiberty

2015-09-05 0.01
  * initial public release
      

    
Back to top