终止bad_alloc异常,但堆栈跟踪中没有"new"

Terminate with bad_alloc exception, but no "new" in stack trace

本文关键字:跟踪 new 堆栈 bad alloc 异常 终止      更新时间:2023-10-16

c++程序抛出这个:

抛出'St9bad_alloc'实例后终止调用what(): std::bad_alloc

似乎是从new抛出的,但是堆栈跟踪没有显示对new的任何调用:

#0  0x0000003174a330c5 in raise () from /lib64/libc.so.6
#1  0x0000003174a34a76 in abort () from /lib64/libc.so.6
#2  0x00007f93b1b7b0b4 in __gnu_cxx::__verbose_terminate_handler ()
at ../../../../gcc-4.3.4/libstdc++-v3/libsupc++/vterminate.cc:98
#3  0x00007f93b1b794f6 in __cxxabiv1::__terminate (handler=0x522b)
at ../../../../gcc-4.3.4/libstdc++-v3/libsupc++/eh_terminate.cc:43
#4  0x00007f93b1b79523 in std::terminate ()
at ../../../../gcc-4.3.4/libstdc++-v3/libsupc++/eh_terminate.cc:53
#5  0x00007f93b1b79536 in __cxxabiv1::__unexpected (handler=0x522b)
at ../../../../gcc-4.3.4/libstdc++-v3/libsupc++/eh_terminate.cc:59
#6  0x00007f93b1b78ec8 in __cxxabiv1::__cxa_call_unexpected (exc_obj_in=0x7f93b1dae770)
at ../../../../gcc-4.3.4/libstdc++-v3/libsupc++/eh_personality.cc:750
#7  0x00007f93b2c356e0 in network::HttpLoader::doLoad (this=0x7f938801ef20) at loaders/HttpLoader.cxx:1071
#8  0x00007f93b2c70971 in network::Loader::load (this=0x522b) at Loader.cxx:899
#9  0x00007f93b2c74a15 in network::Loader::load2 (this=0x522b) at Loader.cxx:925
#10 0x00007f93b2c7b13a in network::LoaderThread::run() ()
#11 0x00007f93b1e60be4 in threads::Thread_startWorker (thr=0x7f938801e460) at Threads.cxx:479
#12 0x00007f93b1e60ead in threads::ThreadPool::run (this=0x1140478, thr=0x7f938801eeb0) at Threads.cxx:727
#13 0x00007f93b1e608e8 in threads::__Thread_startWorker (param=<value optimized out>) at Threads.cxx:520
#14 0x0000003175206ccb in start_thread () from /lib64/libpthread.so.0
#15 0x0000003174ae0c2d in clone () from /lib64/libc.so.6

在dolad()开头添加了调试语句,但它永远不会到达那个点。

难住了!

任何想法吗?

new调用可能不在堆栈中,因为它在应用程序终止时已经展开。我尝试在抛出异常的那一刻设置一个断点(例如,在gdb下使用catch throw)——此时您将在堆栈中看到异常的原因

可能由于优化而内联了new调用。尝试禁用优化,至少在loaders/HttpLoader.cxx中。