GDB使用总结

1. GDB概述

GNU发布的调试器,可以查看程序如何运行或崩溃时的状态。

主要功能:

  • 启动程序,可以按照自定义的要求运行程序。 
  • 可让被调试的程序在你所指定的断点处停住。
  • 当程序被停住时,可以检查此时程序中所发生的事。 
  • 动态的改变程序的执行环境。 

GDB启动程序
//通过GDB启动/attach一个可程序或打开一个core文件
gdb [options] [executable-file [core-file or process-id]]
//为可执行程序指定执行参数
gdb [options] --args executable-file [inferior-arguments ...]
//为GDB启动指定扩展脚本
gdb [options] [--python|-P] script-file [script-arguments ...]

其他启动参数:
-tui Text User Interface
-s file read symbol table from file
--silent do not print version number

GDB命令特点:
命令别名
自动完成(命令/符号名)
帮助强大:
help class
help all
help command

2. 运行控制类命令:
run(r)
step(s) [count]
next(n) [count]
contine(c) [ignore-count]
finish(fin)
until(u) line
skip file|func
stepi(si)
nexti(ni)
多线程控制命令:
info thread
thread thread-id
thread apply ID1 ID2 command
thread apply all command 
set scheduler-locking off|on|step 
break location thread thread-id

break location thread thread-id if ...

3. 程序停止点

3.1 断点
break(b) [line]|[function][address]
break(b) [line]|[function][address] if …
condition break-num
command break-num
tbreak(tb) [line]|[function][address]
rbreak(rb) regex
info break [break-num]
delete(d) break-num
disable(dis) break-num [count]
enable(ena) break-num
ignore break-num count

3.2 观察点

watch [-l|-location] expr [thread thread-id]
rwatch [-l|-location] expr [thread thread-id]
awatch [-l|-location] expr [thread thread-id]
info watchpoints
delete(d) watch-num
disable(dis) watch-num
enable(ena) watch-num
condition watch-num
command watch-num
3.3 扑捉点
catch event [exception][exec][fork][syscall][signal][throw]
tcatch event

清除停止点 clear / delete
保存停止点 save breakpoints [file]


4. 状态查看类命令:
list(l) /-tui(Ctrl+x+a切换)
search/forward-search(fo)/reverse-search(rev)
print(p) /format expr
print(p) *array@len
x/nfu addr
set print pretty
set print array on
set print elements unlimited
info [locals][variables][float][vtbl][registers]
whatis / ptype
display
4.1 堆栈查看命令
backtrace(bt)
info frame(f)
frame frame-num
up [frame-num]
down [frame-num]

5. 改变程序运行类命令:
set [var] expr
jump location
return [expression]
call expression

6.内存转储
dump [format] memory filename start_addr end_addr 转储内存某地址范围内容到指定文件
dump [format] value filename expr  转储变量值到指定文件
append [binary] memory filename start_addr end_addr
append [binary] value filename expr
restore filename [binary] bias start end

generate-core-file(gcore) [file]  生成core文件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值