GDB
帮助
shell
gdb -h启动
shell
gdb program_name
gdb program_name core
gdb program_name pid
gdb -p pid
gdb --args parogram_name args
# 读符号表
-symbols file
-s file
# 增加源码搜索路径
-directory directory
-d directory
# 指定core文件
-core file
-c file退出
shell
exit
#或
Ctrl+d运行时设置
shell
# gui与命令行切换
ctrl+x+a
# 切换窗口
crtl+x+o
# 打印数组
set print array on/num
set print array off
# 屏蔽信号
handle SIGPIPE nostop
#跟踪子进程
set follow-fork-mode child
#跟踪父进程
set follow-fork-mode parent
#子进程也不 detach
set detach-on-fork off运行时命令
gdb里可以用TAB键补全
| 命令 | 缩写 | 作用 | 示例 |
|---|---|---|---|
| info | 查看信息 | ||
| break | b | 增加断点 | b file:line b fun break locspec thread thread-id break locspec thread thread-id if … |
| clear | 清除断点 | ||
| delete | 删除断点 | ||
| enable/disable breakpoints | |||
| run | r | 开始执行 | |
| continue | c | 继续执行 | |
| p | 打印变量 | p var | |
| watch | 监视变量 | ||
| rwatch | 变量被写时暂停 | ||
| awatch | 变量被读或者被写时暂停 | ||
| bt | 查看堆栈信息 |
多线程调试
| 命令 | 说明 |
|---|---|
| info threads | 查询当前线程ID |
| thread id | 切换线程 |
| thread apply [thread-id-list] [all] args | 在线程上执行命令 |
| set print thread-events | 控制打印线程启动或结束是的信息 |
| set scheduler-locking off/on/step | off:不锁定任何线程,也就是所有的线程都执行,这是默认值。 on:只有当前被调试的线程能够执行。 step:阻止其他线程在当前线程单步调试时,抢占当前线程。只有当next、continue、util以及finish的时候,其他线程才会获得重新运行的机会。 |
日志输出
shell
#Enable logging.
set logging on
#Disable logging.
set logging off
#Show the current values of the logging settings.
show logging宏信息
shell
gcc -ggdb3
info macro MCRO_NAME
macro expand MCRO_NAME
p MCRO_NAME