我使用带有选项-O0 -g3
的GCC编译了所有源文件,然后在GDB中运行了相应的二进制文件。收到SIGABRT后,我进行了回溯。
以下是GDB中运行的“崩溃”输出:
terminate called recursively
terminate called recursively
terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check
terminate called recursively
Program received signal SIGABRT, Aborted.
[Switching to Thread 0x7ffff5baf700 (LWP 6434)]
0x00007ffff6be9037 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
56 ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.
这是GDB回溯(紧跟上面显示的输出):
(gdb) bt
#0 0x00007ffff6be9037 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
#1 0x00007ffff6bec698 in __GI_abort () at abort.c:90
#2 0x00007ffff7921e8d in __gnu_cxx::__verbose_terminate_handler() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#3 0x00007ffff791ff76 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#4 0x00007ffff791f089 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#5 0x00007ffff791fbc1 in __gxx_personality_v0 () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#6 0x00007ffff71a615b in ?? () from /lib/x86_64-linux-gnu/libgcc_s.so.1
#7 0x00007ffff71a65b8 in _Unwind_Resume () from /lib/x86_64-linux-gnu/libgcc_s.so.1
#8 0x0000000000445b5d in simulate4_NEJMdisutilities (P=..., NNSmode=true, NNScontrol=false) at ../simulation4.cpp:1846
#9 0x0000000000420f97 in Policy::evaluate (this=0x8ad368) at ../globals.cpp:686
#10 0x000000000041201b in OCBA_SC(std::vector<Policy, std::allocator<Policy> >&, double, int, int, int, double) [clone ._omp_fn.1] () at ../OCBA.cpp:616
#11 0x00007ffff73b586a in ?? () from /usr/lib/x86_64-linux-gnu/libgomp.so.1
#12 0x00007ffff6f81f8e in start_thread (arg=0x7ffff5baf700) at pthread_create.c:311
#13 0x00007ffff6cabe1d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:113
(gdb)
从第8帧开始,GDB似乎声称问题来自源文件simulation4.cpp
中的第1846行。
然而,这里是第1846行(和周围的行):
1835 if(NORMAL && VALIDATION) {
1836 P.hist_PSAtest.print();
1837 P.hist_biopsy.print();
1838 P.hist_treatment.print();
1839 P.hist_getCancer.print();
1840 P.hist_getMetastasis.print();
1841 P.hist_death.print();
1842 P.hist_deathOther.print();
1843 P.hist_deathPCa.print();
1844
1845 prevalence.print();
1846 }
1847
1848 /* ------------ TESTING ------------ */
1849 #if SIMULATION4_DEBUG > 1
1850 cout << "After single execution of simulate4_NEJMdisutilities(Policy&,bool,bool):\n";
1851 cout << " Policy::QALY::sum() = " << P.QALYs.sum() << "\n";
1852 cout << " Policy::Year::sum() = " << P.Years.sum() << "\n";
1853 cout << "\n";
1854 #endif
1855 /* --------------------------------- */
1856
1857
1858 } //simulate4_NEJMdisutilities()
什么可以解释行号之间的差异?
作为背景,我应该注意到我在std::vector::at()
而不是simulation4.cpp
运算符中使用[]
次调用,特别是因为我怀疑某处可能存在内存损坏。在切换到at()
方法之前,我收到了一个seg错误。
我还应该在运行中注意VALIDATION=false
,所以1836--1845行上没有任何代码被执行。
答案 0 :(得分:1)
代码中有很多宏吗?如果您有许多多行预编译器扩展(例如多行宏),那么您的“代码”将被修改为在链接发生之前由预处理器包含。这些都算作代码行,所以可以抛弃你的调试器。