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
The backtrace library is compatible with QNX Neutrino 6.3.0 SP2 or later.
Note the following:
The following notes apply only to PowerPC targets:
- Backtrace's second entry on PowerPC (PPC) isn't guaranteed to be
accurate because of how the PPC handles the lr (link register).
- In the specific case of backtracing BT_SELF, the
second entry of a backtrace will be accurate.
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.