How to analyze a program's core dump file with

2019-01-01 12:18发布

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.

How to analyze core dump file in this situation?

8条回答
冷夜・残月
2楼-- · 2019-01-01 12:46

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>

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) 

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) 

Man pages will be helpful to see other gdb options.

查看更多
浅入江南
3楼-- · 2019-01-01 12:46

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.

查看更多
裙下三千臣
4楼-- · 2019-01-01 12:48

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

 gdb - The GNU Debugger

 syntax:

 # gdb executable-file core-file

 ex: # gdb out.txt core.xxx 

Thanks.

查看更多
怪性笑人.
5楼-- · 2019-01-01 12:49

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.

查看更多
闭嘴吧你
6楼-- · 2019-01-01 12:52

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

gdb ./exe core.pid
查看更多
心情的温度
7楼-- · 2019-01-01 12:55

Simple usage of GDB, to debug coredump files:

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;

...
(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).

查看更多
登录 后发表回答