使用cpp中的回溯调试分段错误

时间:2018-01-01 09:35:37

标签: c++ linux segmentation-fault backtrace

在我的代码中(用cpp编写)我遇到了一个带有以下backtrace的分段错误:

Got signal 11
==== start backtrace ====
/lib/x86_64-linux-gnu/libpthread.so.0(+0x13150)[0x7ff25eb6f150]
./build/debug/lock_free_list_test(+0xa053)[0x55614154e053]
./build/debug/lock_free_list_test(+0x9159)[0x55614154d159]
./build/debug/lock_free_list_test(+0x49bf)[0x5561415489bf]
./build/debug/lock_free_list_test(+0x4789)[0x556141548789]
./build/debug/lock_free_list_test(+0x7c5f)[0x55614154bc5f]
./build/debug/lock_free_list_test(+0xca51)[0x556141550a51]
./build/debug/lock_free_list_test(+0xffa8)[0x556141553fa8]
./build/debug/lock_free_list_test(+0x10ba7)[0x556141554ba7]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x77fc)[0x7ff25eb637fc]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x3f)[0x7ff25e2f3b0f]
==== end backtrace ====
==== start backtrace ====
/lib/x86_64-linux-gnu/libpthread.so.0(+0x13150)[0x7ff25eb6f150]
./build/debug/lock_free_list_test(+0xa05e)[0x55614154e05e]
./build/debug/lock_free_list_test(+0x9159)[0x55614154d159]
./build/debug/lock_free_list_test(+0x49bf)[0x5561415489bf]
./build/debug/lock_free_list_test(+0x4789)[0x556141548789]
./build/debug/lock_free_list_test(+0x7c5f)[0x55614154bc5f]
./build/debug/lock_free_list_test(+0xca51)[0x556141550a51]
./build/debug/lock_free_list_test(+0xffa8)[0x556141553fa8]
./build/debug/lock_free_list_test(+0x10ba7)[0x556141554ba7]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x77fc)[0x7ff25eb637fc]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x3f)[0x7ff25e2f3b0f]
==== end backtrace ====
==== start backtrace ====
/lib/x86_64-linux-gnu/libpthread.so.0(+0x13150)[0x7ff25eb6f150]
./build/debug/lock_free_list_test(+0x9fad)[0x55614154dfad]
./build/debug/lock_free_list_test(+0x9159)[0x55614154d159]
./build/debug/lock_free_list_test(+0x49bf)[0x5561415489bf]
./build/debug/lock_free_list_test(+0x4789)[0x556141548789]
./build/debug/lock_free_list_test(+0x7c5f)[0x55614154bc5f]
./build/debug/lock_free_list_test(+0xca51)[0x556141550a51]
./build/debug/lock_free_list_test(+0xffa8)[0x556141553fa8]
./build/debug/lock_free_list_test(+0x10ba7)[0x556141554ba7]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x77fc)[0x7ff25eb637fc]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x3f)[0x7ff25e2f3b0f]
==== end backtrace ====
==== start backtrace ====
/lib/x86_64-linux-gnu/libpthread.so.0(+0x13150)[0x7ff25eb6f150]
./build/debug/lock_free_list_test(+0x9fc9)[0x55614154dfc9]
./build/debug/lock_free_list_test(+0x9159)[0x55614154d159]
./build/debug/lock_free_list_test(+0x49bf)[0x5561415489bf]
./build/debug/lock_free_list_test(+0x4789)[0x556141548789]
./build/debug/lock_free_list_test(+0x7c5f)[0x55614154bc5f]
./build/debug/lock_free_list_test(+0xca51)[0x556141550a51]
./build/debug/lock_free_list_test(+0xffa8)[0x556141553fa8]
./build/debug/lock_free_list_test(+0x10ba7)[0x556141554ba7]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x77fc)[0x7ff25eb637fc]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x3f)[0x7ff25e2f3b0f]
==== end backtrace ====
==== start backtrace ====
/lib/x86_64-linux-gnu/libpthread.so.0(+0x13150)[0x7ff25eb6f150]
./build/debug/lock_free_list_test(+0x9fb5)[0x55614154dfb5]
./build/debug/lock_free_list_test(+0x9159)[0x55614154d159]
./build/debug/lock_free_list_test(+0x49bf)[0x5561415489bf]
./build/debug/lock_free_list_test(+0x4789)[0x556141548789]
./build/debug/lock_free_list_test(+0x7c5f)[0x55614154bc5f]
./build/debug/lock_free_list_test(+0xca51)[0x556141550a51]
./build/debug/lock_free_list_test(+0xffa8)[0x556141553fa8]
./build/debug/lock_free_list_test(+0x10ba7)[0x556141554ba7]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x77fc)[0x7ff25eb637fc]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x3f)[0x7ff25e2f3b0f]
==== end backtrace ====
==== start backtrace ====
/lib/x86_64-linux-gnu/libpthread.so.0(+0x13150)[0x7ff25eb6f150]
./build/debug/lock_free_list_test(+0xa022)[0x55614154e022]
./build/debug/lock_free_list_test(+0x90bf)[0x55614154d0bf]
./build/debug/lock_free_list_test(+0x498c)[0x55614154898c]
./build/debug/lock_free_list_test(+0x4789)[0x556141548789]
./build/debug/lock_free_list_test(+0x7c5f)[0x55614154bc5f]
./build/debug/lock_free_list_test(+0xca51)[0x556141550a51]
./build/debug/lock_free_list_test(+0xffa8)[0x556141553fa8]
./build/debug/lock_free_list_test(+0x10ba7)[0x556141554ba7]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x77fc)[0x7ff25eb637fc]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x3f)[0x7ff25e2f3b0f]
==== end backtrace ====
==== start backtrace ====
/lib/x86_64-linux-gnu/libpthread.so.0(+0x13150)[0x7ff25eb6f150]
./build/debug/lock_free_list_test(+0x9fb5)[0x55614154dfb5]
./build/debug/lock_free_list_test(+0x90bf)[0x55614154d0bf]
./build/debug/lock_free_list_test(+0x498c)[0x55614154898c]
./build/debug/lock_free_list_test(+0x4789)[0x556141548789]
./build/debug/lock_free_list_test(+0x7c5f)[0x55614154bc5f]
./build/debug/lock_free_list_test(+0xca51)[0x556141550a51]
./build/debug/lock_free_list_test(+0xffa8)[0x556141553fa8]
./build/debug/lock_free_list_test(+0x10ba7)[0x556141554ba7]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x77fc)[0x7ff25eb637fc]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x3f)[0x7ff25e2f3b0f]
==== end backtrace ====
==== start backtrace ====
/lib/x86_64-linux-gnu/libpthread.so.0(+0x13150)[0x7ff25eb6f150]
./build/debug/lock_free_list_test(+0x9fb1)[0x55614154dfb1]
./build/debug/lock_free_list_test(+0x90bf)[0x55614154d0bf]
./build/debug/lock_free_list_test(+0x498c)[0x55614154898c]
./build/debug/lock_free_list_test(+0x4789)[0x556141548789]
./build/debug/lock_free_list_test(+0x7c5f)[0x55614154bc5f]
./build/debug/lock_free_list_test(+0xca51)[0x556141550a51]
./build/debug/lock_free_list_test(+0xffa8)[0x556141553fa8]
./build/debug/lock_free_list_test(+0x10ba7)[0x556141554ba7]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x77fc)[0x7ff25eb637fc]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x3f)[0x7ff25e2f3b0f]
==== end backtrace ====
==== start backtrace ====
/lib/x86_64-linux-gnu/libpthread.so.0(+0x13150)[0x7ff25eb6f150]
./build/debug/lock_free_list_test(+0x9ca5)[0x55614154dca5]
./build/debug/lock_free_list_test(+0x9fc9)[0x55614154dfc9]
./build/debug/lock_free_list_test(+0x90bf)[0x55614154d0bf]
./build/debug/lock_free_list_test(+0x498c)[0x55614154898c]
./build/debug/lock_free_list_test(+0x4789)[0x556141548789]
./build/debug/lock_free_list_test(+0x7c5f)[0x55614154bc5f]
./build/debug/lock_free_list_test(+0xca51)[0x556141550a51]
./build/debug/lock_free_list_test(+0xffa8)[0x556141553fa8]
./build/debug/lock_free_list_test(+0x10ba7)[0x556141554ba7]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x77fc)[0x7ff25eb637fc]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x3f)[0x7ff25e2f3b0f]
==== end backtrace ====
==== start backtrace ====
/lib/x86_64-linux-gnu/libpthread.so.0(+0x13150)[0x7ff25eb6f150]
./build/debug/lock_free_list_test(+0x9fb5)[0x55614154dfb5]
./build/debug/lock_free_list_test(+0x90bf)[0x55614154d0bf]
./build/debug/lock_free_list_test(+0x498c)[0x55614154898c]
./build/debug/lock_free_list_test(+0x4789)[0x556141548789]
./build/debug/lock_free_list_test(+0x7c5f)[0x55614154bc5f]
./build/debug/lock_free_list_test(+0xca51)[0x556141550a51]
./build/debug/lock_free_list_test(+0xffa8)[0x556141553fa8]
./build/debug/lock_free_list_test(+0x10ba7)[0x556141554ba7]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x77fc)[0x7ff25eb637fc]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x3f)[0x7ff25e2f3b0f]
==== end backtrace ====
==== start backtrace ====
/lib/x86_64-linux-gnu/libpthread.so.0(+0x13150)[0x7ff25eb6f150]
./build/debug/lock_free_list_test(+0x9fc1)[0x55614154dfc1]
./build/debug/lock_free_list_test(+0x90bf)[0x55614154d0bf]
./build/debug/lock_free_list_test(+0x498c)[0x55614154898c]
./build/debug/lock_free_list_test(+0x4789)[0x556141548789]
./build/debug/lock_free_list_test(+0x7c5f)[0x55614154bc5f]
./build/debug/lock_free_list_test(+0xca51)[0x556141550a51]
./build/debug/lock_free_list_test(+0xffa8)[0x556141553fa8]
./build/debug/lock_free_list_test(+0x10ba7)[0x556141554ba7]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x77fc)[0x7ff25eb637fc]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x3f)[0x7ff25e2f3b0f]
==== end backtrace ====
==== start backtrace ====
/lib/x86_64-linux-gnu/libpthread.so.0(+0x13150)[0x7ff25eb6f150]
./build/debug/lock_free_list_test(+0x9fb5)[0x55614154dfb5]
./build/debug/lock_free_list_test(+0x9159)[0x55614154d159]
./build/debug/lock_free_list_test(+0x49bf)[0x5561415489bf]
./build/debug/lock_free_list_test(+0x4789)[0x556141548789]
./build/debug/lock_free_list_test(+0x7c5f)[0x55614154bc5f]
./build/debug/lock_free_list_test(+0xca51)[0x556141550a51]
./build/debug/lock_free_list_test(+0xffa8)[0x556141553fa8]
./build/debug/lock_free_list_test(+0x10ba7)[0x556141554ba7]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x77fc)[0x7ff25eb637fc]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x3f)[0x7ff25e2f3b0f]
==== end backtrace ====
Got signal 11
==== start backtrace ====
/lib/x86_64-linux-gnu/libpthread.so.0(+0x13150)[0x7ff25eb6f150]
./build/debug/lock_free_list_test(+0xa053)[0x55614154e053]
./build/debug/lock_free_list_test(+0x9159)[0x55614154d159]
./build/debug/lock_free_list_test(+0x49bf)[0x5561415489bf]
./build/debug/lock_free_list_test(+0x4789)[0x556141548789]
./build/debug/lock_free_list_test(+0x7c5f)[0x55614154bc5f]
./build/debug/lock_free_list_test(+0xca51)[0x556141550a51]
./build/debug/lock_free_list_test(+0xffa8)[0x556141553fa8]
./build/debug/lock_free_list_test(+0x10ba7)[0x556141554ba7]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x77fc)[0x7ff25eb637fc]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x3f)[0x7ff25e2f3b0f]
==== end backtrace ====
==== start backtrace ====
/lib/x86_64-linux-gnu/libpthread.so.0(+0x13150)[0x7ff25eb6f150]
./build/debug/lock_free_list_test==== start backtrace ====
(+0x9fb5)[0x55614154dfb5]
/lib/x86_64-linux-gnu/libpthread.so.0./build/debug/lock_free_list_test(+0x9fc9)[0x55614154dfc9]
./build/debug/lock_free_list_test(+0x9159)[0x55614154d159]
(./build/debug/lock_free_list_test+0x(13150+0x)49bf[0x)7ff25eb6f150[0x]
5561415489bf./build/debug/lock_free_list_test]
./build/debug/lock_free_list_test(+0x(9ca2+0x)4789[0x)55614154dca2[0x]
556141548789./build/debug/lock_free_list_test]
(./build/debug/lock_free_list_test+0x9fc9()+0x[0x7c5f55614154dfc9)]
[0x./build/debug/lock_free_list_test55614154bc5f]
(./build/debug/lock_free_list_test+0x9159()+0x[0xca5155614154d159)]
[0x./build/debug/lock_free_list_test556141550a51]
(./build/debug/lock_free_list_test+0x(49bf+0x)ffa8[0x)5561415489bf[0x]
556141553fa8./build/debug/lock_free_list_test]
(./build/debug/lock_free_list_test+0x4789()+0x[0x10ba7556141548789)]
[0x556141554ba7]
/lib/x86_64-linux-gnu/libpthread.so.0./build/debug/lock_free_list_test((+0x+0x77fc7c5f))[0x[0x7ff25eb637fc55614154bc5f]
]
==== end backtrace ====
./build/debug/lock_free_list_test(+0xca51)[0x556141550a51]
./build/debug/lock_free_list_test(+0xffa8)[0x556141553fa8]
./build/debug/lock_free_list_test(+0x10ba7)[0x556141554ba7]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x77fc)[0x7ff25eb637fc]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x3f)[0x7ff25e2f3b0f]
==== end backtrace ====
==== start backtrace ====
/lib/x86_64-linux-gnu/libpthread.so.0(+0x13150)[0x7ff25eb6f150]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x10f96)[0x7ff25eb6cf96]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x11054)[0x7ff25eb6d054]
/lib/x86_64-linux-gnu/libpthread.so.0(sem_wait+0x64)[0x7ff25eb6d144]
./build/debug/lock_free_list_test(+0x101d9)[0x5561415541d9]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x13150)[0x7ff25eb6f150]
./build/debug/lock_free_list_test(+0xa053)[0x55614154e053]
./build/debug/lock_free_list_test(+0x9159)[0x55614154d159]
./build/debug/lock_free_list_test(+0x49bf)[0x5561415489bf]
./build/debug/lock_free_list_test(+0x4789)[0x556141548789]
./build/debug/lock_free_list_test(+0x7c5f)[0x55614154bc5f]
./build/debug/lock_free_list_test(+0xca51)[0x556141550a51]
./build/debug/lock_free_list_test(+0xffa8)[0x556141553fa8]
./build/debug/lock_free_list_test(+0x10ba7)[0x556141554ba7]
==== end backtrace ====
==== start backtrace ====
/lib/x86_64-linux-gnu/libpthread.so.0(+0x13150)[0x7ff25eb6f150]
./build/debug/lock_free_list_test(+0x9fb5)[0x55614154dfb5]
./build/debug/lock_free_list_test(+0x90bf)[0x55614154d0bf]
./build/debug/lock_free_list_test(+0x498c)[0x55614154898c]
./build/debug/lock_free_list_test(+0x4789)[0x556141548789]
./build/debug/lock_free_list_test(+0x7c5f)[0x55614154bc5f]
./build/debug/lock_free_list_test(+0xca51)[0x556141550a51]
./build/debug/lock_free_list_test(+0xffa8)[0x556141553fa8]
./build/debug/lock_free_list_test(+0x10ba7)[0x==== start backtrace ====
556141554ba7]
==== start backtrace ====
/lib/x86_64-linux-gnu/libpthread.so.0/lib/x86_64-linux-gnu/libpthread.so.0/lib/x86_64-linux-gnu/libpthread.so.0((+0x+0x77fc13150))[0x[0x7ff25eb637fc(7ff25eb6f150]
+0x]
./build/debug/lock_free_list_test13150)[0x7ff25eb6f150(]
+0x./build/debug/lock_free_list_test9fb5)([0x+0x/lib/x86_64-linux-gnu/libc.so.69fb555614154dfb5]
)./build/debug/lock_free_list_test[0x55614154dfb5]
(+0x./build/debug/lock_free_list_test90bf)[0x55614154d0bf(]
+0x./build/debug/lock_free_list_test90bf)([0x+0x55614154d0bf498c]
)./build/debug/lock_free_list_test[0x(55614154898c(]
+0xclone./build/debug/lock_free_list_test498c+0x)3f[0x)(55614154898c[0x+0x]
7ff25e2f3b0f4789./build/debug/lock_free_list_test]
)(==== end backtrace ====
[0x+0x5561415487894789]
)./build/debug/lock_free_list_test[0x556141548789Segmentation fault (core dumped)

那么有没有办法调试这个并获得哪个行发生段错误? (我在这里找不到这样的帖子,如果它重复,我会删除它)。 代码本身非常大,所以在这里键入它是不正确的我猜,我只是想知道我是否可以使用backtrace调试代码。

2 个答案:

答案 0 :(得分:1)

  

在我的代码中(用cpp编写)我遇到了一个带有以下backtrace的分段错误:

这显然是从您的测试框架输出的。

虽然它包含了相当多的有用信息,但您将从调试器获得很多更多有用的信息(假设您已使用-g标志编译了测试以进行调试)

gdb build/debug/lock_free_list_test
(gdb) run
... wait for SIGSEGV
(gdb) where        ## should print file and line info leading to the crash
(gdb) info locals  ## should print values of local variables and parameters

如果出于某种原因你不能或不想使用调试器,你至少可以从现有的崩溃中获取函数,文件和行信息(再次假设你使用{{1}构建了测试} flag:

-g

答案 1 :(得分:0)

考虑运行valgrind,它记录任何与内存相关的错误的反向跟踪,它可以在C和C ++上使用。设置LD_LIBRARY_PATH会给出确切的问题。尝试一次运行一个测试,因为valgrind有时会耗费时间,如果构建是调试/发布则无关紧要。我可以看到你在Linux 64bit上遇到问题,但是如果你有使用Windows的选项,那么Dr. memory也会有很好的帮助。