gdb调试命令-1

1.启动命令

gdb program
gdb program core
#would attach GDB to process 1234. With option -p you can omit the program filename.
gdb program 1234
gdb -p 1234
#This will cause gdb to debug gcc, and to set gcc’s command-line arguments (see Arguments) to ‘-O2 -c foo.c’.
gdb --args gcc -O2 -c foo.c

2.gdb调试过程中输入命令

#If you need to execute occasional shell commands during your debugging session, there is no need to leave or suspend GDB; you can just use the shell command.

shell command-string

3.gdb调试过程中记录日志

set logging on
#Enable logging.

set logging off
#Disable logging.

set logging file file
#Change the name of the current logfile. The default logfile is gdb.txt.

set logging overwrite [on|off]
#By default, GDB will append to the logfile. Set overwrite if you want set logging on to #overwrite the logfile instead.

4.run直接设置参数

(gdb) set args one two three
(gdb) b main
Breakpoint 1 at 0x4005d3: file test.c, line 29.
(gdb) r
Starting program: /mnt/hgfs/windoc/test_prj/gdb_prj/shell_cmd/test one two three

Breakpoint 1, main (argc=4, args=0x7fffffffe4a8) at test.c:29

5.进程间的调试, 可以用来调试tcp 收发或者多进程

(gdb) info inferiors
  Num  Description       Executable
  2    process 2307      hello
* 1    process 3401      goodbye

#To switch focus between inferiors, use the inferior command:
inferior infno

add-inferior [ -copies n ] [ -exec executable ]
(gdb) info inferiors
  Num  Description       Executable
* 1    process 29964     helloworld
(gdb) clone-inferior
Added inferior 2.
1 inferiors added.
(gdb) info inferiors
  Num  Description       Executable
  2    <null>            helloworld
* 1    process 29964     helloworld

6.调试线程

#automatic notification of new threads
thread thread-id 
#a command to switch among threads

info threads 
#a command to inquire about existing threads

thread apply [thread-id-list | all] args 
#a command to apply a command to a list of threads thread-specific breakpoints

set print thread-events
#which controls printing of messages on thread start and exit.

set libthread-db-search-path path
#which lets the user specify which libthread_db to use if the default choice isn’t compatible with the program.

7.调试进程

By default, when a program forks, GDB will continue to debug the parent process and the child process will run unimpeded.

If you want to follow the child process instead of the parent process, use the command set follow-fork-mode.

set follow-fork-mode mode
Set the debugger response to a program call of fork or vfork. A call to fork or vfork creates a new process. The mode argument can be:

parent
The original process is debugged after a fork. The child process runs unimpeded. This is the default.

child
The new process is debugged after a fork. The parent process runs unimpeded.

show follow-fork-mode
Display the current debugger response to a fork or vfork call.

On Linux, if you want to debug both the parent and child processes, use the command set detach-on-fork.

set detach-on-fork mode
Tells gdb whether to detach one of the processes after a fork, or retain debugger control over them both.

on
The child process (or parent process, depending on the value of follow-fork-mode) will be detached and allowed to run independently. This is the default.

off
Both processes will be held under the control of GDB. One process (child or parent, depending on the value of follow-fork-mode) is debugged as usual, while the other is held suspended.

show detach-on-fork
Show whether detach-on-fork mode is on/off.

8.设置checkpoint,保留当前断点信息

info checkpoints
#List the checkpoints that have been saved in the current debugging session. For each #checkpoint, the following information will be listed:

Checkpoint ID
Process ID
Code Address
Source lin
restart checkpoint-id
Restore the program state that was saved as checkpoint number checkpoint-id. All program variables, registers, stack frames etc. will be returned to the values that they had when the checkpoint was saved. In essence, gdb will “wind back the clock” to the point in time when the checkpoint was saved.

Note that breakpoints, GDB variables, command history etc. are not affected by restoring a checkpoint. In general, a checkpoint only restores things that reside in the program being debugged, not in the debugger.

delete checkpoint checkpoint-id
Delete the previously-saved checkpoint identified by checkpoint-id.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值