当前位置:网站首页>GDB常用指令
GDB常用指令
2022-07-16 00:43:00 【大囚长】
摘抄整合,勿喷
GDB
r:run,执行程序n:next,下一步,不进入函数s:step,下一步,会进入函数b:breakponit,设置断点l:list,查看源码c:continue,继续执行到下一断点bt:backtrace,查看当前调用栈p:print,打印查看变量q:quit,退出 GDBwhatis:查看对象类型info breakpoints:查看所有的断点info locals:查看局部变量info args:查看函数的参数值及要返回的变量值info frame:堆栈帧信息info goroutines:查看 goroutines 信息。在使用前 ,需要注意先执行 source /usr/local/go/src/runtime/runtime-gdb.pygoroutine 1 bt:查看指定序号的 goroutine 调用堆栈回车:重复执行上一次操作
其中有几个指令的使用比较灵活
比如 l - list,查看代码
# 查看指定行数上下5行
(gdb) l 8
# 查看指定范围的行数
(gdb) l 5:8
# 查看指定文件的行数上下5行
l demo.go:8
# 可以查看函数,记得加包名
l main.main
把上面的 l 换成 b ,大多数也同样适用
# 在指定行打断点
(gdb) b 8
# 在指定指定文件的行打断点
b demo.go:8
# 在指定函数打断点,记得加包名
b main.main
还有 p - print,打印变量
# 查看变量
(gdb) p var
# 查看对象长度或容量
(gdb) p $len(var)
(gdb) p $cap(var)
# 查看对象的动态类型
(gdb) p $dtype(var)
(gdb) iface var
# 举例如下
(gdb) p i
$4 = {
str = "cbb"}
(gdb) whatis i
type = regexp.input
(gdb) p $dtype(i)
$26 = (struct regexp.inputBytes *) 0xf8400b4930
(gdb) iface i
regexp.input: struct regexp.inputBytes *
变量的查看
基本的命令 p
使用这个命令,还可以查看结构体的各元素值。
例:p \*pstData;
复杂的命令
使用 dislpaly 命令,自动显示变量的值。
使用 command 命令,执行更复杂的操作,可以执行条件判断。
使用 call 命令,调用打印输出函数。
查看数组变量
格式控制
p /x Val
/c
/f
查看内存变量
x
查看局部变量
info local
设置程序入口参数
set args
程序变量的修改
set var=value
GDB变量的使用
历史变量的使用:$1, $2, …
方便变量(convenience variable)的使用
例:
set @q =0
p a\[@q++\]
调试输入参数
gdb 运行程序
例子程序名为prog,则在终端输入 gdb prog
gdb 设置参数
set args 可指定运行时参数。(如:set args 10 20 30 40 50)show args 命令可以查看设置好的运行参数。
若要再次修改参数,可再执行一遍 set args
运行
输入 r 运行
出错后,输入 bt 查看运行堆栈
退出
输入 quit
边栏推荐
- UDS之0x22、0x2E服务
- Wireless communication safety operation 4
- Getting started with redis
- Memory management: memory allocation and recycling
- 【Pygame闯关游戏】手残勿入,最新虐心游戏《见缝插针》——不得不玩的一款游戏。
- 【MySql项目实战优化】通过执行计划分析追加索引
- Pendingintent details
- Redis profile
- Complete process of invention patent application (from application to authorization)
- 面试官:怎么不用定时任务实现关闭订单?
猜你喜欢

Wireless communication safety operation 2

Mid platform construction sharp weapon SPI plug-in mechanism
![[C language] dynamic address book](/img/3e/6cf7ad1a0e5c697a57ab2d55231270.png)
[C language] dynamic address book

Take you to brush (niuke.com) C language hundred questions (the next day)

Matlab_插值与抽取

Matlab_ Interpolation and extraction

第1章:初识数据库与MySQL----MySQL安装

为什么说大公司不是天堂,里面有哪些坑?

Free SSL certificate application and deployment practice

单元测试界的高富帅,Pytest框架 (完) 测试报告篇
随机推荐
免费SSL证书申请及部署实践
[C language] implementation of static address book
JSD-2204-MVC-微博项目-Day15
网络安全服务国家战略需要
redis数据类型
Wireless communication safety operation 3
【Pygame闯关游戏】手残勿入,最新虐心游戏《见缝插针》——不得不玩的一款游戏。
[es practice] spark writes es support
JSON data parsing of Scala
Getting started with redis
无线通信安全作业4
Summary of commonly used tricks in torch
Solve the nail alarm notification in the Intranet Environment -- the road of building a dream
Basic functions commonly used in unity
DDD领域驱动设计
采取哪些行之有效的措施可以提高讨论研究问题的效率?
Vertical/Column text select in PyCharm
UDS之0x22、0x2E服务
删除.idea目录后,svn菜单恢复操作
Redis overview, installation and visual access