如何使用gdb分析程序的核心转储文件? [英] How to analyze a program's core dump file with gdb?

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

问题描述

我的程序运行如下:

exe -p param1 -i param2 -o param3

它崩溃并生成了一个核心转储文件 core.pid

It crashed and generated a core dump file core.pid

我想通过

gdb ./exe -p param1 -i param2 -o param3 core.pid 

但是,gdb会识别 exe 作为gdb的输入。

but the gdb recognize the paramters of exe as gdb's input.

在这种情况下如何分析核心转储文件?

How to analyze core dump file in this situation?

推荐答案

您可以通过多种方式将核心与gdb配合使用,但传递给gdb的可执行文件的参数不是使用核心文件的方式。这也可能是您得到该错误的原因。您可以使用以下方式使用核心文件:

gdb< executable> < core-file> gdb< executable> -c< core-file>

You can use the core with gdb in many ways, but passing parameters which is to be passed to executable to gdb is not the way to use core file. This could also be the reason you got that error. You can use the core file in following ways:
gdb <executable> <core-file> or gdb <executable> -c <core-file> or

gdb <executable>
...
(gdb) core <core-file>

使用核心文件时,您不必传递参数。崩溃情况显示在gdb中(在Ubuntu上使用gdb版本7.1进行检查)。
例如:

When using core file you don't have to pass arguments. The crash scenario is shown in gdb (checked with gdb Version 7.1 on Ubuntu) . For example:

$ ./crash -p param1 -o param2
Segmentation fault (core dumped)
$ gdb ./crash core
GNU gdb (GDB) 7.1-ubuntu
...
Core was generated by `./crash -p param1 -o param2'. <<<<< See this line shows crash scenario
Program terminated with signal 11, Segmentation fault.
#0  __strlen_ia32 () at ../sysdeps/i386/i686/multiarch/../../i586/strlen.S:99
99  ../sysdeps/i386/i686/multiarch/../../i586/strlen.S: No such file or directory.
    in ../sysdeps/i386/i686/multiarch/../../i586/strlen.S
(gdb) 

如果要将参数传递给要在gdb中调试的可执行文件,请使用 - args

例如:

If you want to pass parameters to the executable to be debugged in gdb use --args.
For example:

$ gdb --args ./crash -p param1 -o param2
GNU gdb (GDB) 7.1-ubuntu
...
(gdb) r
Starting program: /home/@@@@/crash -p param1 -o param2

Program received signal SIGSEGV, Segmentation fault.
__strlen_ia32 () at ../sysdeps/i386/i686/multiarch/../../i586/strlen.S:99
99  ../sysdeps/i386/i686/multiarch/../../i586/strlen.S: No such file or directory.
    in ../sysdeps/i386/i686/multiarch/../../i586/strlen.S
(gdb) 

手册页将有助于查看其他gdb选项。

Man pages will be helpful to see other gdb options.

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

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