Digamos que eu escrevi um programa C++ simples
#include <stdexcept>
int main(int argc, char *argv[])
{
throw std::logic_error("Error");
return 0;
}
Este programa (compilado com g++ -O0 -ggdb -o test test.cpp
) lança previsivelmente uma exceção capturada pelo gdb:
> gdb test
Reading symbols from test...
(gdb) r
Starting program: /home/christoph/test/gdb/test
terminate called after throwing an instance of 'std::logic_error'
what(): Error
Program received signal SIGABRT, Aborted.
0x00007ffff7abace5 in raise () from /usr/lib/libc.so.6
(gdb) bt
#0 0x00007ffff7abace5 in raise () from /usr/lib/libc.so.6
#1 0x00007ffff7aa4857 in abort () from /usr/lib/libc.so.6
#2 0x00007ffff7e3b81d in __gnu_cxx::__verbose_terminate_handler () at /build/gcc/src/gcc/libstdc++-v3/libsupc++/vterminate.cc:95
#3 0x00007ffff7e482ea in __cxxabiv1::__terminate (handler=<optimized out>) at /build/gcc/src/gcc/libstdc++-v3/libsupc++/eh_terminate.cc:48
#4 0x00007ffff7e48357 in std::terminate () at /build/gcc/src/gcc/libstdc++-v3/libsupc++/eh_terminate.cc:58
#5 0x00007ffff7e485be in __cxxabiv1::__cxa_throw (obj=<optimized out>, tinfo=0x555555557da8 <typeinfo for std::logic_error@@GLIBCXX_3.4>, dest=0x7ffff7e5e660 <std::logic_error::~logic_error()>) at /build/gcc/src/gcc/libstdc++-v3/libsupc++/eh_throw.cc:95
#6 0x00005555555551c0 in main (argc=1, argv=0x7fffffffdf08) at test.cpp:5
Digamos que eu tenha uma Makefile
compilação do programa, que executo a partir do gdb após touch
acessar a fonte durante uma sessão contínua do gdb:
(gdb) make
g++ -O0 -ggdb -o test test.cpp
A compilação foi bem-sucedida, mas quando executo o programa novamente, acontece o seguinte:
(gdb) r
The program being debugged has been started already.
Start it from the beginning? (y or n) y
`/dir/to/test' has changed; re-reading symbols.
Starting program: /dir/to/test
terminate called after throwing an instance of 'std::logic_error'
what(): Error
Program received signal SIGABRT, Aborted.
0x00007ffff7abace5 in ?? ()
(gdb) bt
#0 0x00007ffff7abace5 in ?? ()
#1 0x0000000000000000 in ?? ()
Aparentemente, os símbolos não foram relidos corretamente e o stack trace é inútil. Se eu reler a tabela de símbolos, tudo funcionará conforme o esperado:
(gdb) symbol-file /dir/to/test
Reading symbols from /dir/to/test...
Reading symbols from /usr/lib/libstdc++.so.6...
Reading symbols from /usr/lib/libm.so.6...
(No debugging symbols found in /usr/lib/libm.so.6)
Reading symbols from /usr/lib/libgcc_s.so.1...
Reading symbols from /usr/lib/libc.so.6...
(No debugging symbols found in /usr/lib/libc.so.6)
Reading symbols from /lib64/ld-linux-x86-64.so.2...
(No debugging symbols found in /lib64/ld-linux-x86-64.so.2)
(gdb) bt
#0 0x00007ffff7abace5 in raise () from /usr/lib/libc.so.6
#1 0x00007ffff7aa4857 in abort () from /usr/lib/libc.so.6
#2 0x00007ffff7e3b81d in __gnu_cxx::__verbose_terminate_handler () at /build/gcc/src/gcc/libstdc++-v3/libsupc++/vterminate.cc:95
#3 0x00007ffff7e482ea in __cxxabiv1::__terminate (handler=<optimized out>) at /build/gcc/src/gcc/libstdc++-v3/libsupc++/eh_terminate.cc:48
#4 0x00007ffff7e48357 in std::terminate () at /build/gcc/src/gcc/libstdc++-v3/libsupc++/eh_terminate.cc:58
#5 0x00007ffff7e485be in __cxxabiv1::__cxa_throw (obj=<optimized out>, tinfo=0x555555557da8 <typeinfo for std::logic_error@@GLIBCXX_3.4>, dest=0x7ffff7e5e660 <std::logic_error::~logic_error()>) at /build/gcc/src/gcc/libstdc++-v3/libsupc++/eh_throw.cc:95
#6 0x00005555555551c0 in main (argc=1, argv=0x7fffffffdf08) at test.cpp:5
Isso é um bug no gdb ou no comportamento pretendido? Existe alguma opção para permitir o recarregamento automático da tabela de símbolos?
Nota: O comportamento ocorre com gdb 9.1 e g++ 9.2.1