4

Lets say I have written a simple C++ program

#include <stdexcept>

int main(int argc, char *argv[])
{
  throw std::logic_error("Error");
  return 0;
}

This program (compiled with g++ -O0 -ggdb -o test test.cpp) predictably throws an exception caught by 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

Lets say I have a Makefile compiling the program, which I execute from gdb after touching the source during a continuing gdb session:

(gdb) make
g++ -O0 -ggdb -o test test.cpp

The compilation succeeds, but when I run the program again, the following happens:

(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 ?? ()

Apparently, the symbols have not been reread properly and the stack trace is useless. If I reread the symbol table, then everything works as expected:

(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

Is this a bug in gdb or intended behavior? Is there some switch to enable reloading the symbol table automatically?

Note: The behavior occurs with gdb 9.1 and g++ 9.2.1

0

You must log in to answer this question.

Browse other questions tagged .