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.