我的功能 f 会抛出异常,我的程序无法处理它。在gdb中,我可以得到如下的回溯
#0 0x00007ffff722ec59 in raise () from /lib64/libc.so.6
#1 0x00007ffff7230368 in abort () from /lib64/libc.so.6
#2 0x00007ffff7b35f85 in __gnu_cxx::__verbose_terminate_handler() () from /lib64/libstdc++.so.6
#3 0x00007ffff7b33ee6 in ?? () from /lib64/libstdc++.so.6
#4 0x00007ffff7b33f13 in std::terminate() () from /lib64/libstdc++.so.6
#5 0x00007ffff7b3413f in __cxa_throw () from /lib64/libstdc++.so.6
#6 0x00000000004006e6 in g () at x.cc:2
#7 0x00000000004006ef in f () at x.cc:6
#8 0x00000000004006fa in main () at x.cc:10
但如果我将其更改为多线程,
std::thread t(f);
t.join();
这是回溯。
#0 0x00007ffff7011c59 in raise () from /lib64/libc.so.6
#1 0x00007ffff7013368 in abort () from /lib64/libc.so.6
#2 0x00007ffff7b35f85 in __gnu_cxx::__verbose_terminate_handler() () from /lib64/libstdc++.so.6
#3 0x00007ffff7b33ee6 in ?? () from /lib64/libstdc++.so.6
#4 0x00007ffff7b33f13 in std::terminate() () from /lib64/libstdc++.so.6
#5 0x00007ffff7b8a345 in ?? () from /lib64/libstdc++.so.6
#6 0x00007ffff73a2f33 in start_thread () from /lib64/libpthread.so.0
#7 0x00007ffff70d0ead in clone () from /lib64/libc.so.6
这是测试代码:
void g() {
throw 1;
}
void f() {
g();
}
int main() {
f();
return 0;
}
我的工具版本是:
GNU gdb(GDB)Fedora 7.6.50.20130731-16.fc20
gcc版本4.8.2 20131212(红帽4.8.2-7)(GCC)
我编译它:
g++ x.cc -o x -ggdb -O0 -pthred -std=c++11
我的问题是如何才能获得案例2的完整回溯?