Linux:如何调试 SIGSEGV?如何追踪错误来源? [英] Linux: How to debug a SIGSEGV? How do I trace the error source?

查看:25
本文介绍了Linux:如何调试 SIGSEGV?如何追踪错误来源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Firefox 从今天开始崩溃.我没有更改系统或 firefox 配置上的任何内容.

我用
strace -ff -o dumpfile.txt firefox
来追踪问题.帮助不大.

我在两个生成的进程转储中看到了段错误,但是我如何追查他们的原因?

运行 10 秒后崩溃,22MB 数据由 strace 生成.

这是输出的片段,您可以在其中看到实际的 SIGSEGV.:

<上一页>读取(19,372",1)= 1gettimeofday({1245590019, 542231}, NULL) = 0读(3, "6[Qmy2631Y20023233A3233(201", 4096) = 32read(3, 0xf5c55058, 4096) = -1 EAGAIN(资源暂时不可用)gettimeofday({1245590019, 542813}, NULL) = 0轮询([{fd=4,事件=POLLIN},{fd=3,事件=POLLIN},{fd=8,事件=POLLIN|POLLPRI},{fd=12,事件=POLLIN|POLLPRI},{fd=13,事件=POLLIN|POLLPRI},{fd=14,事件=POLread(3, 0xf5c55058, 4096) = -1 EAGAIN(资源暂时不可用)gettimeofday({1245590019, 543161}, NULL) = 0gettimeofday({1245590019, 546672}, NULL) = 0gettimeofday({1245590019, 546761}, NULL) = 0read(3, 0xf5c55058, 4096) = -1 EAGAIN(资源暂时不可用)gettimeofday({1245590019, 546936}, NULL) = 0轮询([{fd=4,事件=POLLIN},{fd=3,事件=POLLIN},{fd=8,事件=POLLIN|POLLPRI},{fd=12,事件=POLLIN|POLLPRI},{fd=13,事件=POLLIN|POLLPRI},{fd=14,事件=POL轮询([{fd=3, 事件=POLLIN|POLLOUT}], 1, 4294967295) = 1 ([{fd=3, revents=POLLOUT}])writev(3, [{"5304006212002266 200217]32304500721200026212002317"..., 1624}, {NULL, 0}, {"", 0}], 3) = 1624民意调查([{fd=3, 事件=POLLIN}], 1, 4294967295) = 1 ([{fd=3, revents=POLLIN}])读(3,130224Q1717000235273o264Q"..., 4096) = 4096读(3, "375240f376242j377261200271a+271a+377261200376252w376250s"..., 11356) = 11356read(3, 0xf5c55058, 4096) = -1 EAGAIN(资源暂时不可用)轮询([{fd=3, 事件=POLLIN|POLLOUT}], 1, 4294967295) = 1 ([{fd=3, revents=POLLOUT}])writev(3, [{"2303271212002?212002377377377377377377377377171015104"..., 956}, {NULL, 0}, {"", 0}], 3) = 956民意调查([{fd=3, 事件=POLLIN}], 1, 4294967295) = 1 ([{fd=3, revents=POLLIN}])读(3, "130256Q1717000235273o264Q"..., 4096) = 4096读(3, "375240f376242j377261200271a+271a+377261200376252w376250s"..., 11356) = 11356read(3, 0xf5c55058, 4096) = -1 EAGAIN(资源暂时不可用)--- SIGSEGV(分段错误)@ 0 (0) ---unlink("/home/userrrr/.mozilla/firefox/mvbnkitl.default/lock") = 0rt_sigaction(SIGSEGV, {SIG_DFL, ~[HUP INT QUIT ABRT BUS FPE KILL PIPE CHLD CONT TTOU URG XCPU WINCH RT_1 RT_2 RT_3 RT_4 RT_8 RT_11 RT_14 RT_17 RT_22], SA_NOCLDSTOP},rt_sigprocmask(SIG_BLOCK, ~[ILL ABRT BUS FPE SEGV RTMIN RT_1], ~[KILL STOP RTMIN RT_1], 8) = 0打开(/home/userrrr/.mozilla/firefox/mvbnkitl.default/minidumps/56b30367-5ee2-0495-32646b7f-59dc87e9.dmp",O_WRONLY|O_CREAT|O_EXCL,0600)= 63克隆(child_stack=0xf5bfffe4,标志=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_UNTRACED)= 18929waitpid(18929, NULL, __WALL) = 18929打开(/proc/18913/task",O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC)= 64fstat64(64, {st_mode=S_IFDIR|0555, st_size=0, ...}) = 0getdents64(64,/* 12 个条目 */, 1024) = 368ptrace(PTRACE_DETACH, 18913, 0, SIG_0) = -1 ESRCH (没有这样的过程)关闭(64)= 0ftruncate(63, 91256) = 0关闭(63)= 0rt_sigprocmask(SIG_SETMASK, ~[KILL STOP RTMIN RT_1], ~[KILL STOP RTMIN RT_1], 8) = 0时间(NULL)= 1245590020open("/home/userrrr/.mozilla/firefox/Crash Reports/LastCrash", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 63写(63,1245590020",10)= 10

解决方案

Ivan,你真正的问题是如何调试 SIGSEGV?"

strace 在这里很少有很好的帮助.SIGSEGV 表示应用程序试图取消引用(访问)内存中尚未分配的位置(或由于各种其他原因不允许取消引用).它与 strace 正在捕获的系统调用活动无关的可能性很高.为了发现崩溃的原因,首先要了解取消引用的地址以及尝试执行此操作的函数.调试器是完成这项任务的正确工具.

这是你需要做的:

 gdb <your_app_name><你的核心转储文件>

在那里,分析最后执行的指令并使用信息寄存器",您将看到有问题的地址.使用bt"命令,您将看到调用堆栈.通过向上遍历调用堆栈,您会发现如何计算不正确的地址.此地址计算中涉及的步骤之一是您的问题的原因.

调试很有趣,这是深入研究它的好机会.一本好书或一些在线文章可以帮助你.谷歌离开,祝你好运!

My firefox started crashing since today. I haven't changed anything on the system or on firefox config.

I use
strace -ff -o dumpfile.txt firefox
to trace the problem. It's not a big help.

I see the segfault, in two of the generated process dumps, but how I can trace them to their cause?

After running for 10 seconds and crashing, 22MB of data is generated by strace.

This is a snippet of the output, where you can see actual SIGSEGV in the middle.:

read(19, "372", 1)                     = 1
gettimeofday({1245590019, 542231}, NULL) = 0
read(3, "6[Qmy2631Y20023233A3233(201", 4096) = 32
read(3, 0xf5c55058, 4096)               = -1 EAGAIN (Resource temporarily unavailable)
gettimeofday({1245590019, 542813}, NULL) = 0
poll([{fd=4, events=POLLIN}, {fd=3, events=POLLIN}, {fd=8, events=POLLIN|POLLPRI}, {fd=12, events=POLLIN|POLLPRI}, {fd=13, events=POLLIN|POLLPRI}, {fd=14, events=POL
read(3, 0xf5c55058, 4096)               = -1 EAGAIN (Resource temporarily unavailable)
gettimeofday({1245590019, 543161}, NULL) = 0
gettimeofday({1245590019, 546672}, NULL) = 0
gettimeofday({1245590019, 546761}, NULL) = 0
read(3, 0xf5c55058, 4096)               = -1 EAGAIN (Resource temporarily unavailable)
gettimeofday({1245590019, 546936}, NULL) = 0
poll([{fd=4, events=POLLIN}, {fd=3, events=POLLIN}, {fd=8, events=POLLIN|POLLPRI}, {fd=12, events=POLLIN|POLLPRI}, {fd=13, events=POLLIN|POLLPRI}, {fd=14, events=POL
poll([{fd=3, events=POLLIN|POLLOUT}], 1, 4294967295) = 1 ([{fd=3, revents=POLLOUT}])
writev(3, [{"5304006212002266
200217]32304500721200026212002317"..., 1624}, {NULL, 0}, {"", 0}], 3) = 1624
poll([{fd=3, events=POLLIN}], 1, 4294967295) = 1 ([{fd=3, revents=POLLIN}])
read(3, "130224Q1717000235273o264Q"..., 4096) = 4096
read(3, "375240f376242j377261200271a+271a+377261200376252w376250s"..., 11356) = 11356
read(3, 0xf5c55058, 4096)               = -1 EAGAIN (Resource temporarily unavailable)
poll([{fd=3, events=POLLIN|POLLOUT}], 1, 4294967295) = 1 ([{fd=3, revents=POLLOUT}])
writev(3, [{"2303271212002?212002377377377377377377377377171015104"..., 956}, {NULL, 0}, {"", 0}], 3) = 956
poll([{fd=3, events=POLLIN}], 1, 4294967295) = 1 ([{fd=3, revents=POLLIN}])
read(3, "130256Q1717000235273o264Q"..., 4096) = 4096
read(3, "375240f376242j377261200271a+271a+377261200376252w376250s"..., 11356) = 11356
read(3, 0xf5c55058, 4096)               = -1 EAGAIN (Resource temporarily unavailable)
--- SIGSEGV (Segmentation fault) @ 0 (0) ---
unlink("/home/userrrr/.mozilla/firefox/mvbnkitl.default/lock") = 0
rt_sigaction(SIGSEGV, {SIG_DFL, ~[HUP INT QUIT ABRT BUS FPE KILL PIPE CHLD CONT TTOU URG XCPU WINCH RT_1 RT_2 RT_3 RT_4 RT_8 RT_11 RT_14 RT_17 RT_22], SA_NOCLDSTOP},
rt_sigprocmask(SIG_BLOCK, ~[ILL ABRT BUS FPE SEGV RTMIN RT_1], ~[KILL STOP RTMIN RT_1], 8) = 0
open("/home/userrrr/.mozilla/firefox/mvbnkitl.default/minidumps/56b30367-5ee2-0495-32646b7f-59dc87e9.dmp", O_WRONLY|O_CREAT|O_EXCL, 0600) = 63
clone(child_stack=0xf5bfffe4, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_UNTRACED) = 18929
waitpid(18929, NULL, __WALL) = 18929
open("/proc/18913/task", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC) = 64
fstat64(64, {st_mode=S_IFDIR|0555, st_size=0, ...}) = 0
getdents64(64, /* 12 entries */, 1024)  = 368
ptrace(PTRACE_DETACH, 18913, 0, SIG_0)  = -1 ESRCH (No such process)
close(64)                               = 0
ftruncate(63, 91256)                    = 0
close(63)                               = 0
rt_sigprocmask(SIG_SETMASK, ~[KILL STOP RTMIN RT_1], ~[KILL STOP RTMIN RT_1], 8) = 0
time(NULL)                              = 1245590020
open("/home/userrrr/.mozilla/firefox/Crash Reports/LastCrash", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 63
write(63, "1245590020", 10)             = 10

解决方案

Ivan, your real question is "how do I debug a SIGSEGV?"

strace is rarely a good help here. SIGSEGV means that the application tried to dereference (access) a location in memory which which hasn't been allocated (or not allowed to be dereferenced for various other reasons). Chances are high that it is not related to the system calls activity which strace is capturing. In order to discover the cause of your crash, start by understanding what address is being dereferenced and what function tries to do that. Debugger is the right tool for this task.

Here's what you need to do:

 gdb <your_app_name> <your_coredump_file>

in there, analyzing the last executed instruction and using "info registers" you'll see the address in question. Using the "bt" command you'll see the callstack. By walking the callstack up, you'll discover how the incorrect address is being calculated. One of the steps involved in this address calculation is the cause of your problem.

Debugging is fun and this is a good opportunity to delve into it. A good book or some online articles can help you there. Google away and good luck!

这篇关于Linux:如何调试 SIGSEGV?如何追踪错误来源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆