Table of contents
Premise: The program must be written by yourself! ! !
gdb ./xxx.out
basic instruction
-g
Compile the executable file with this parameter to get the debug table.
list
List source code.
list 1
or
l 1
b
Set breakpoints.
b 行号
b 20 //在20行设置断点
Set a conditional breakpoint.
b 行号 条件
b 20 if i=5
run or r
Run the program to find the location of the segment fault.
run
or
r
Set the parameters passed to the main function.
run 参数值
run abc 123
next or n
The next line of code skips the function.
next
or
n
step or s
The next line of code, will enter the function.
step
or
s
print or p
View the value of a variable.
print 变量名
print i
or
p 变量名
p i
continue
Continue to execute the code following the breakpoint.
quit
Exit gdb current debugging.
other instructions
finish
End the current function call.
finish
set args
Set the parameters passed to the main function.
set args 参数值
set args abc 123
info b
See the breakpoint information table.
info b
ptype
View variable types.
ptype 变量名
ptype i
bt
List the stack frames that exist in the current program, and you can view the stack frame number.
bt
frame
Switch stack frames.
frame 栈帧编号
frame 1
display
Set up tracking variables.
display 变量名
display i
undisplay
Unset the tracking variable.
undisplay 变量的编号
undisplay 2
process related
When debugging with gdb, gdb can only track one process. Set the gdb debugging tool to track the parent process or track the child process through the command. By default the parent process is traced. It must be set before the fork function call to be valid.
set trace child process
set follow-fork-mode child
set trace parent process
set follow-fork-mode parent