生成调试信息
gcc -g test.c -o test
g++ -g test.cpp -o test
启动
gdb test
gdb pro PID
程序运行参数
set args [argu1 argu2 ...]
show args
run/r [argu1 argu2 ...]
断点
info b
b/breakpoint [lineno]
b/breakpoint [functionname]
b/break filename:lineno
b/break filename:function
b/break class::function
b/break namespace::class::function
观察点
watch EXPR
watch -l/location EXPR
awatch EXPR
rwatch EXPR
info watchpoints
条件断点
b/break lineno if val == num
condition breakpoint num EXPR
ignore N count
维护断点
clear
clear functionbreakpoint
clear lineno
clear filename:lineno
delete/d
delete/d [num1-num2]
disable [breakpoints] [range]
enable [breakpoints] [range]
enable ]breakpoints] once [range]
enable [breakpoints] delete [range]
command命令
break fun if x > 0
commands
>printf "x is %d" ,x
>c
>end
调试
run/r
start
step/s
next/n
finish
until/u
continie/c
si/ni
info program
查看运行时的数据
print/p COUNT
print/p cnt1+cnt2+cnt3
print/p EXPR
程序变量
print/p 'file'::var
print/p arr[0]@len
自动显示
display EXPR
disalbe display lineno
enable display lineno
打补丁
set x=4
set var x=4
跳转执行
jump lineno
jump file:lineno
jump +num
强制函数操作
return [EXPR]
call EXPR
print/p EXPR
源代码显示
set listsize n
show listsize
list
list funciton/lineno
list -
调试以运行的进程
gdb PID process-id
多线程调试
break/b lineno thread threadno
栈操作
breaktrace/bt
breaktrace/bt n
breaktrace/bt -n
frame/f n
up/down [n]