For the example given, the backtrace command of gdb-8.3 already displays 80% of the requested information for code compiled by g++-9.3.1 using -g.
The request: > If compiled with -g, the debug output will display > (1) C/C++ names down into the standard library > (2) source code names and signatures > (3) including template instantiations > (4) file names > (5) line numbers (gdb) backtrace #0 __GI_raise (sig=sig@entry=0x6) at ../sysdeps/unix/sysv/linux/raise.c:50 #1 0x00007ffff7aac895 in __GI_abort () at abort.c:79 #2 0x0000000000401144 in bar () at traceback-test.c:6 #3 0x0000000000401154 in foo<int> () at traceback-test.c:12 #4 0x0000000000401134 in main () at traceback-test.c:17 valgrind-3.17.0: ==16820== Process terminating with default action of signal 6 (SIGABRT): dumping core ==16820== at 0x4BFCE35: raise (raise.c:51) ==16820== by 0x4BE7894: abort (abort.c:79) ==16820== by 0x401143: bar() (traceback-test.c:6) ==16820== by 0x401153: void foo<int>(int) (traceback-test.c:12) ==16820== by 0x401133: main (traceback-test.c:17) In this example, item (3) is the only essential difference. valgrind: void foo<int>(int) (traceback-test.c:12) contains result type and argument type, while gdb: in foo<int> () at traceback-test.c:12 lacks "void" and "(int)". For items (1), (2), (4), and (5) the gdb output contains the same information as the valgrind output. In addition, gdb gives more information for (1): the complete internal path for standard library code ../sysdeps/unix/sysv/linux/raise.c:50 in contrast to valgrind's (raise.c:51) So, any request for a better backtrace should be much more explicit than what was posted originally. On 5/26/21, Martin Licht via Valgrind-users wrote:
Addressing the first point: what Valgrind's tracer does better than others is fetching more source code information and semantics. This can shown immediately with the following example: ``` #include <assert.h> #include <stdlib.h> inline void bar() { abort(); } template<typename T> inline void foo(T) { bar(); } int main() { foo(5); return 0; } ``` If compiled with -g, the debug output will display (1) C/C++ names down into the standard library (2) source code names and signatures (3) including template instantiations (4) file names (5) line numbers, among other things. I would be great to have a stack tracer like that. The prettiest alternatives without Valgrind go along the lines of https://eli.thegreenplace.net/2015/programmatic-access-to-the-call-stack-in-c/ using libunwind and cxxabi. This still is not as close to the source as Valgrind's output.
_______________________________________________ Valgrind-users mailing list Valgrind-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/valgrind-users