当程序具有命令行参数时,如何使用 GDB 分析程序的核心转储文件? [英] How do I analyze a program's core dump file with GDB when it has command-line parameters?

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

问题描述

我的程序是这样运行的:

My program operates like this:

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 GDB recognizes the parameters of the EXE file as GDB's input.

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

How do I analyze a core dump file in this situation?

推荐答案

你可以通过多种方式将核心与GDB一起使用,但是将要传递给可执行文件的参数传递给GDB并不是使用核心文件的方式.这也可能是您收到该错误的原因.您可以通过以下方式使用核心文件:

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

gdb <可执行文件><core-file>gdb <executable>-c <core-file>

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

使用核心文件时,您不必传递参数.崩溃场景显示在 GDB 中(在 Ubuntu 上使用 GDB 7.1 版进行检查).

When using the core file you don't have to pass arguments. The crash scenario is shown in GDB (checked with GDB version 7.1 on Ubuntu).

例如:

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

例如:

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

最有用的命令是:

  • bt(回溯)
  • info locals(显示局部变量的值)
  • info registers(显示CPU寄存器的值)
  • frame X(更改为堆栈帧X)
  • updown(在堆栈帧(调用链)中导航)
  • bt (backtrace)
  • info locals (show values of local variables)
  • info registers (show values of CPU registers)
  • frame X (change to stack frame X)
  • up and down (navigate in the stack frame (call chain))

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

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