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