Digamos que he escrito un programa simple en C++.
#include <stdexcept>
int main(int argc, char *argv[])
{
throw std::logic_error("Error");
return 0;
}
Este programa (compilado con g++ -O0 -ggdb -o test test.cpp
) como era de esperar arroja una excepción detectada por 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 estoy Makefile
compilando el programa, que ejecuto desde gdb después de touch
ingresar la fuente durante una sesión continua de gdb:
(gdb) make
g++ -O0 -ggdb -o test test.cpp
La compilación se realiza correctamente, pero cuando ejecuto el programa nuevamente sucede lo siguiente:
(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, los símbolos no se han releído correctamente y el seguimiento de la pila es inútil. Si vuelvo a leer la tabla de símbolos, todo funciona como se esperaba:
(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
¿Es esto un error en gdb o un comportamiento previsto? ¿Existe algún interruptor para permitir la recarga automática de la tabla de símbolos?
Nota: El comportamiento ocurre con gdb 9.1 y g++ 9.2.1.