I've just read
How to generate a stacktrace when my gcc C++ app crashes
which is pretty old by now (5 years). Some answers suggest solutions allowing you to get, for every stack frame, the name of the function and an offset (within the stack I guess). But what I (and may others) really need is the source filename and line number where the call was made (assuming the code was compiled with debug information). One of the answers linked to a part of glibc which does this (libSegfault; see files in this directory - segfault.c
, backtracesyms.c
, backtracesymsfd.c
) - so it is possible.
My questions are:
- Can this information be extracted in a platform-independent fashion, or one that conforms to some standard (POSIX??)
- Why doesn't libunwind support this? (I think it doesn't, after looking through ther website)
- Does this necessarily depend on your compiler's C/C++ standard library (for C/C++ apps, at least)?
Notes:
- You may assume the binary has debugging info, so in the case of C/C++ it was compiled with
-g
; of course, in a proper library we would check whether debug info is available or not.
gdb
(or any of its' relatives, likeddd
) 1) the C program or C++ program must have been compiled with the-g
option otherwise the stack trace information, with file names and line numbers is not available. Even then when debugging the problem, the original source code files must be available to the debugger. Also, the executable must not have beenstripped
of the debug information. Such debug information is related to the C and C++ compiler and linker, not to the environment./OS – Neckwear