如何使用GDB分析故障转储文件 [英] How to analyse a crash dump file using GDB

查看:69
本文介绍了如何使用GDB分析故障转储文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在Cent OS下运行的服务器应用程序.服务器每秒响应许多请求,但是大约每隔一个小时左右就反复崩溃,并创建一个故障转储文件.情况真的很糟糕,我需要尽快找出崩溃原因.

I have a server application running under Cent OS. The server answers many requests per second but it repeatedly crashes after each hour or so and creates a crash dump file. The situation is really bad and I need to find out the crash cause as soon as possible.

我怀疑该问题是并发问题,但不确定.我可以访问源代码和故障转储文件,但是我不知道如何使用故障转储来查明问题所在.

I suspect that the problem is a concurrency problem but I'm not sure. I have access to the source code and crash dump files but I don't know how to use the crash dumps to pin point the problem.

任何建议都值得赞赏.

推荐答案

要查找的第一件事是程序崩溃时收到的错误消息.这通常会告诉您发生了哪种错误.例如,分段错误" "SIGSEGV" 几乎可以肯定意味着您的程序已取消引用NULL或无效的指针.如果程序是用C ++编写的,则错误消息通常会告诉您任何未捕获的异常的名称.

The first thing to look for is the error message that you get when the program crashes. This will often tell you what kind of error occurred. For example "segmentation fault" or "SIGSEGV" almost certainly mean that your program has de-referenced a NULL or otherwise invalid pointer. If the program is written in C++, then the error message will often tell you the name of any uncaught exception.

如果没有看到错误消息,请从命令行运行该程序,或将其输出通过管道传输到文件中.

If you aren't seeing the error message, then run the program from the command line, or pipe its output into a file.

为了使核心文件真正有用,您需要在不进行优化且包含调试信息的情况下编译程序.GCC需要以下选项: -g -O0 .(确保您的构建没有其他 -O 选项.)

In order for a core file to be really useful, you need to compile your program without optimisation and with debugging information. GCC needs the following options: -g -O0. (Make sure your build doesn't have any other -O options.)

拥有核心文件后,请使用以下命令在gdb中打开文件:

Once you have the core file, then open it in gdb with:

gdb YOUR-APP COREFILE

键入 where 以查看崩溃发生的位置.您基本上处于正常的调试会话中-您可以检查变量,在堆栈中上下移动,在线程之间进行切换以及其他操作.

Type where to see the point where the crash occurred. You are basically in a normal debugging session - you can examine variables, move up and down the stack, switch between threads and whatever.

如果程序崩溃,则可能是无效的内存访问-因此,您需要查找具有零值或指向不良数据的指针.您可能找不到堆栈最底部的问题,可能必须先将堆栈上移几层,然后才能找到问题.

If your program has crashed, then it's probably an invalid memory access - so you need to look for a pointer that has zero-value, or that points to bad looking data. You might not find the problem at the very bottom of the stack, you might have to move up the stack a few levels before you find the problem.

祝你好运!

这篇关于如何使用GDB分析故障转储文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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