std::thread 中的异常会丢失调用栈
(金庆的专栏 2019.9)
主函数中的异常生成core文件能看到调用栈,
但是 std::thread 子线程中的异常生成 core 文件的调用栈如下:
Program received signal SIGABRT, Aborted.
[Switching to Thread 0x7f18f00ab700 (LWP 32340)]
0x00007f19007335f7 in raise () from /lib64/libc.so.6
(gdb) bt
#0 0x00007f19007335f7 in raise () from /lib64/libc.so.6
#1 0x00007f1900734ce8 in abort () from /lib64/libc.so.6
#2 0x00007f19010379d5 in __gnu_cxx::__verbose_terminate_handler() () from /lib64/libstdc++.so.6
#3 0x00007f1901035946 in ?? () from /lib64/libstdc++.so.6
#4 0x00007f1901035973 in std::terminate() () from /lib64/libstdc++.so.6
#5 0x00007f190108c2b5 in ?? () from /lib64/libstdc++.so.6
#6 0x00007f19012e7dc5 in start_thread () from /lib64/libpthread.so.0
#7 0x00007f19007f41cd in clone () from /lib64/libc.so.6
(gdb)
调用栈丢失使调试无法找到问题点。
据说 GCC 8 修正了该问题。
参考:
- C++ uncaught exception in worker thread
- Bug 55917 - Impossible to find/debug unhandled exceptions in an std::thread
转载:https://blog.csdn.net/jq0123/article/details/101455415
查看评论