且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用gdb分析程序的核心转储文件?

更新时间:2022-12-04 20:56:32

您可以通过多种方式将核心与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.