When in an std::unexpected_handler, backtrace_symbols returns a trace with functions not even called at all. I noticed strange functions to appear on the trace, and missed functions that should be there. I reproduced it with the following minimal code: #include <exception> #include <execinfo.h> extern "C" void my_unexpected_handler() { void* trace[100]; int size = backtrace(trace, 100); backtrace_symbols_fd(trace, size, 2); } void throw_0() throw() { throw 0; } extern "C" void not_called_at_all_but_appearing_on_the_backtrace() { } extern "C" int main(int, char*[]) { std::set_unexpected(my_unexpected_handler); throw_0(); return 0; } I compile this with: g++ -g -rdynamic <filename> It then produces: ./a.out(my_unexpected_handler+0x1f)[0x8048973] /usr/lib/libstdc++.so.6(+0xbd465)[0xb7853465] /usr/lib/libstdc++.so.6(__cxa_call_unexpected+0x45)[0xb78528b5] ./a.out(not_called_at_all_but_appearing_on_the_backtrace+0x0)[0x80489dc] ./a.out(main+0x1a)[0x80489fb] /lib/i686/cmov/libc.so.6(__libc_start_main+0xe6)[0xb7621c76] ./a.out[0x80488c1] terminate called after throwing an instance of 'int' Aborted As you can see, "not_called_at_all_but_appearing_on_the_backtrace" is not called anywhere, but yet it is on the stack trace. The function throw_0 however is missing. I believe this is a bug. If not, what is going on here? Best regards Erik Groeneveld
backtrace is part of libc and not GCC.
(In reply to comment #1) > backtrace is part of libc and not GCC. Thank you, I'll post it there too. Could it also have to do something with exception handling code in the c++ runtime that calls unexpected_handler? I think it somehow leaves the stack in a state that backtrace does not expect. That still leaves open the question where the bug is, if any.
The backtrace is mostly right. The issue is that the function after _Z7throw_0v is not_called_at_all_but_appearing_on_the_backtrace. The debugging info is correct. The call return place is really not_called_at_all_but_appearing_on_the_backtrace.