Debugging with GDB v8.3.1 Notes

1 A Simple GDB Session

区分nextstep:

  • next 用在执行整个程序
  • step 用在进入到一个函数的内部程序

continue应该是使暂停的程序继续运行.

2 Getting In and Out of GDB

The command-line options described here are designed to cover a variety of situations.

You can start with both an executeble program and a core file specified:

1
gdb program core

第二个 argument 可以改为 process ID, 以此 debug a running process:

1
gdb program 1234

2.1.1 Choosing Files

If you prefer, you can flag option arguments with ‘–’ rather than ‘-‘.

2.1.2 Choosing Modes

2.1.3 What GDB Does During Startup

The GDB init file are normally called .gdbinit.

2.2 Quitting GDB

2.3 Shell Commands

Using shell command during debugging:

1
!command-string

可直接使用make:

1
make make-args

2.4 Logging Output

保存 the output of GDB commands to a file.

3 GDB Commands

3.1 Command Syntax

A blank line as input to GDB means to repeat the previous command. User-defined commands can disable this feature.

3.2 Command Completion

M-?和按两次TAB作用相同.

3.3 Getting Help

Using help.

help class, 输入help后出现的是class, help class 会显示这个class中的命令.

apropos args, the apropos command searches through all of the GDB commands, and their documentation, for the regular expression specified in args.

complete args, the complete args command lists all the possible completions for the beginning of a command.

除了help, infoshow 都能够给出 the state of your program, or the state of GDB itself.

  • list, 用于 describing the state of your program, 如info args, info registers, info breakpoints.
  • set, 用于 assign an environment variable.
  • show, 用于 describing the state of GDB itself. To display all the settable parameters and their current values, you can use show with no argument or info set.

4 Running Programs Under GDB

4.1 Compiling for Debugging

在编译时使用-g选项.

Some compilers are unable to handle the -g and -O options together.

Always use -g whenever you compile a program is recommended.

DWARF is currently the most expressive and best supported debugging format in GDB.

4.2 Starting your Program

  • start, this command does the equivalent of setting a temporary breakpoint at the beginning of the main procedure and then invoking the run command.

4.3 Your Program’s Arguments

The arguments to your program can be specified by the arguments of the run command.


Debugging with GDB v8.3.1 Notes
http://example.com/2022/08/07/Debugging-with-GDB-v8-3-1-Notes/
作者
Jie
发布于
2022年8月7日
许可协议