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

时间:2022-06-14 16:38:38

My program operates like this:

我的程序是这样运作的:

exe -p param1 -i param2 -o param3

It crashed and generated a core dump file core.pid

它崩溃了,生成了一个核心转储文件。

I want to analyze the core dump file by

我想分析一下核心转储文件。

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

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

但gdb承认exe的参数为gdb的输入。

How to analyze core dump file in this situation?

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

8 个解决方案

#1


121  

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的核心,但是传递的参数将被传递到可执行文件到gdb,这不是使用核心文件的方式。这也可能是你得到那个错误的原因。您可以使用以下方式使用核心文件:gdb <可执行的> 或gdb <可执行> -c 或。

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

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:

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

$ ./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) 

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

如果您想要将参数传递给在gdb使用中调试的可执行文件—args。例如:

$ 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) 

Man pages will be helpful to see other gdb options.

Man页面将有助于查看其他gdb选项。

#2


20  

Just skip the params, gdb doesn't need them:

跳过这些参数,gdb不需要它们:

gdb ./exe core.pid

#3


18  

Simple usage of GDB, to debug coredump files:

简单使用GDB,调试coredump文件:

gdb <executable_path> <coredump_file_path>

Coredump file for a "process" gets created, as "core.pid" file. After you get inside the gdb-prompt, (on execution of the above command), type;

“进程”的Coredump文件被创建为“核心”。pid”文件。进入gdb-prompt(执行上述命令)之后,键入;

...
(gdb) where

This will get you with the information, of the stack, where you can analayze the cause of crash/fault. Other command, for same purposes is;

这将使您了解堆栈的信息,您可以在其中找到崩溃/错误的原因。其他命令,出于相同目的;

...
(gdb) bt full

This is same as above. By convention, it lists the whole stack info (which ultimately leads to the crash location).

这和上面一样。按照惯例,它列出了整个堆栈信息(最终导致崩溃位置)。

#4


10  

From RMS's gdb Debugger Tutorial:

来自RMS的gdb调试器教程:

prompt > myprogram
Segmentation fault (core dumped)
prompt > gdb myprogram
...
(gdb) core core.pid
...

Make sure your file really is a core image -- check it using file.

确保您的文件确实是一个核心映像——使用文件检查它。

#5


8  

A slightly different approach will allow you to skip GDB entirely. If all you want is a backtrace, the linux-specific utility 'catchsegv' will catch SIGSEGV and display a backtrace.

稍微不同的方法可以让您完全跳过GDB。如果您想要的只是一个回溯,那么特定于linux的实用工具“catchsegv”将会捕获SIGSEGV并显示一个回溯。

#6


2  

It doesn't matter executable have arguments or not, To run GDB on any binary with a generated core file Syntax is below.

无论可执行文件是否有参数,在任何二进制文件中运行GDB,生成的核心文件语法都在下面。

Syntax: 
gdb <binary name> <generated core file>    
Eg: 
gdb l3_entity 6290-corefile    

let me take the below example for more understanding.

让我以下面的例子来理解。

bash-4.1$**gdb l3_entity 6290-corefile**

**Core was generated** by `/dir1/dir2/dir3/l3_entity **Program terminated with signal SIGABRT, Aborted.**
#0
#1
#2
#3
#4
#5
#6  
#7  
#8  
#9  
#10 
(gdb)

From the above output, you can guess something about core whether it is a NULL access or SIGABORT etc..

从上面的输出中,您可以猜到一些关于核心的东西,不管它是空访问还是SIGABORT等。

These numbers #0 to #10 are the stack frames of GDB. These stack frames are not of your binary. in the above 0 - 10 frames if you suspect anything wrong select that frame

这些数字#0到#10是GDB的堆栈帧。这些堆栈帧不是二进制的。在上述0 - 10帧中,如果您怀疑有任何错误选择该帧。

(gdb) frame 8 

Now to see more details about it:

现在来看看更多的细节:

(gdb) list + 

To investigate issue further you can print the suspected variable values here at this point of time.

为了进一步研究问题,您可以在此时打印可疑的变量值。

(gdb) print thread_name 

#7


1  

You can analyze the core dump file using "gdb" command.

您可以使用“gdb”命令来分析核心转储文件。

 gdb - The GNU Debugger

 syntax:

 # gdb executable-file core-file

 ex: # gdb out.txt core.xxx 

Thanks.

谢谢。

#8


0  

Simply type command

只需输入命令

$ gdb <Binary> <codeDump>

or

$ gdb <binary>

$ gdb) core <coreDump>

No need to provide any command line arguement. The code dump generated due to earlier exercise.

不需要提供任何命令行争论。由于早期的练习而生成的代码转储。

#1


121  

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的核心,但是传递的参数将被传递到可执行文件到gdb,这不是使用核心文件的方式。这也可能是你得到那个错误的原因。您可以使用以下方式使用核心文件:gdb <可执行的> 或gdb <可执行> -c 或。

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

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:

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

$ ./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) 

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

如果您想要将参数传递给在gdb使用中调试的可执行文件—args。例如:

$ 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) 

Man pages will be helpful to see other gdb options.

Man页面将有助于查看其他gdb选项。

#2


20  

Just skip the params, gdb doesn't need them:

跳过这些参数,gdb不需要它们:

gdb ./exe core.pid

#3


18  

Simple usage of GDB, to debug coredump files:

简单使用GDB,调试coredump文件:

gdb <executable_path> <coredump_file_path>

Coredump file for a "process" gets created, as "core.pid" file. After you get inside the gdb-prompt, (on execution of the above command), type;

“进程”的Coredump文件被创建为“核心”。pid”文件。进入gdb-prompt(执行上述命令)之后,键入;

...
(gdb) where

This will get you with the information, of the stack, where you can analayze the cause of crash/fault. Other command, for same purposes is;

这将使您了解堆栈的信息,您可以在其中找到崩溃/错误的原因。其他命令,出于相同目的;

...
(gdb) bt full

This is same as above. By convention, it lists the whole stack info (which ultimately leads to the crash location).

这和上面一样。按照惯例,它列出了整个堆栈信息(最终导致崩溃位置)。

#4


10  

From RMS's gdb Debugger Tutorial:

来自RMS的gdb调试器教程:

prompt > myprogram
Segmentation fault (core dumped)
prompt > gdb myprogram
...
(gdb) core core.pid
...

Make sure your file really is a core image -- check it using file.

确保您的文件确实是一个核心映像——使用文件检查它。

#5


8  

A slightly different approach will allow you to skip GDB entirely. If all you want is a backtrace, the linux-specific utility 'catchsegv' will catch SIGSEGV and display a backtrace.

稍微不同的方法可以让您完全跳过GDB。如果您想要的只是一个回溯,那么特定于linux的实用工具“catchsegv”将会捕获SIGSEGV并显示一个回溯。

#6


2  

It doesn't matter executable have arguments or not, To run GDB on any binary with a generated core file Syntax is below.

无论可执行文件是否有参数,在任何二进制文件中运行GDB,生成的核心文件语法都在下面。

Syntax: 
gdb <binary name> <generated core file>    
Eg: 
gdb l3_entity 6290-corefile    

let me take the below example for more understanding.

让我以下面的例子来理解。

bash-4.1$**gdb l3_entity 6290-corefile**

**Core was generated** by `/dir1/dir2/dir3/l3_entity **Program terminated with signal SIGABRT, Aborted.**
#0
#1
#2
#3
#4
#5
#6  
#7  
#8  
#9  
#10 
(gdb)

From the above output, you can guess something about core whether it is a NULL access or SIGABORT etc..

从上面的输出中,您可以猜到一些关于核心的东西,不管它是空访问还是SIGABORT等。

These numbers #0 to #10 are the stack frames of GDB. These stack frames are not of your binary. in the above 0 - 10 frames if you suspect anything wrong select that frame

这些数字#0到#10是GDB的堆栈帧。这些堆栈帧不是二进制的。在上述0 - 10帧中,如果您怀疑有任何错误选择该帧。

(gdb) frame 8 

Now to see more details about it:

现在来看看更多的细节:

(gdb) list + 

To investigate issue further you can print the suspected variable values here at this point of time.

为了进一步研究问题,您可以在此时打印可疑的变量值。

(gdb) print thread_name 

#7


1  

You can analyze the core dump file using "gdb" command.

您可以使用“gdb”命令来分析核心转储文件。

 gdb - The GNU Debugger

 syntax:

 # gdb executable-file core-file

 ex: # gdb out.txt core.xxx 

Thanks.

谢谢。

#8


0  

Simply type command

只需输入命令

$ gdb <Binary> <codeDump>

or

$ gdb <binary>

$ gdb) core <coreDump>

No need to provide any command line arguement. The code dump generated due to earlier exercise.

不需要提供任何命令行争论。由于早期的练习而生成的代码转储。