간단한 C++ 프로그램을 작성했다고 가정해 보겠습니다.
#include <stdexcept>
int main(int argc, char *argv[])
{
throw std::logic_error("Error");
return 0;
}
이 프로그램( 으로 컴파일됨 g++ -O0 -ggdb -o test test.cpp
)은 예상대로 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
계속되는 gdb 세션 동안 소스를 입력한 Makefile
후 gdb에서 실행하는 프로그램을 컴파일 한다고 가정해 보겠습니다 .touch
(gdb) make
g++ -O0 -ggdb -o test test.cpp
컴파일은 성공했지만 프로그램을 다시 실행하면 다음과 같은 일이 발생합니다.
(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 ?? ()
분명히 기호는 제대로 다시 읽히지 않았으며 스택 추적은 쓸모가 없습니다. 기호 테이블을 다시 읽으면 모든 것이 예상대로 작동합니다.
(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
이것은 gdb의 버그입니까, 아니면 의도된 동작입니까? 기호 테이블을 자동으로 다시 로드할 수 있는 스위치가 있습니까?
참고: 이 동작은 gdb 9.1 및 g++ 9.2.1에서 발생합니다.