Backtraces

QNX SDP8.0TechnotesDeveloperUser

The libbacktrace library gives you a way to programmatically backtrace a running process from within itself. You can use backtracing for debugging, as well as for diagnostics or logging. Most of the time, you should use gdb for debugging.

The backtrace library lets you:

  • backtrace the calling thread
  • backtrace a thread within the same process
  • backtrace a thread in another process
  • backtrace C code
  • backtrace C++ code

Note the following:

  • Backtracing is a best effort, and may at times be inaccurate due to the nature of backtracing (e.g. optimized code can confuse the backtracer).
  • Backtracing a corrupt stack could cause a fatal SIGSEGV.
  • The backtrace library needs to trap SIGSEGV and SIGBUS, but gdb normally catches these signals. If you're using gdb on a program that uses libbacktrace, you need to tell gdb to pass these signals to the program for correct operation:
    handle SIGSEGV pass
    handle SIGBUS pass
      
Note:
The backtrace library is an unsupported feature, due to its fragility. The functionality it offers is available via gdb in a safer and more stable way; gdb uses debugging information to unwind, while backtrace uses guessing — it decodes instructions/stack/registers to figure out the return address, and this is prone to errors. GDB uses such guessing only as a fallback when symbols aren't available.

Due to multiple gcc versions that can be used, and in each of them probable different optimizations, backtrace accuracy is directly affected; it is almost certain the backtrace won't work in many cases.

Page updated: