当前位置:网站首页>使用gdb添加断点的几种方式
使用gdb添加断点的几种方式
2022-06-29 02:40:00 【Hello,C++!】
1. 普通断点
根据代码行数设置断点是最常见的一种方式,在debug程序运行前就可以进行断点的配置。如:
(gdb) b src/main.cpp:127
当程序执行到main.cpp文件的第127行时就会触发断点。
2. 条件断点
顾名思义,这种断点是当满足一定条件时才会触发,比较适合进行异常排查。设置方式(gdb)break line-or-function if (condition), 如:
(gdb) b src/main.cpp:127 if cnt==10
3. 数据断点
就是根据地址来进行设置断点,只能是在debug程序运行之后设置,因为只有运行后,你才能很方便地获知变量的地址。当该地址上的内容发生改变时就会触发断点。设置数据断点有两种方式,一种是直接指出地址值,如:
(gdb) b *0x400522
注意必须加*号。而获取地址值的方法是,先设置普通断点,在断点处print &变量名 就能获取该变量的地址。另一种当然就是直接设置变量名了,如:
(gdb) b &变量名
4. 函数断点
这种断点是当程序执行到某个程序时就会触发断点。设置方式如:
(gdb) b funcName
但是函数断点并不是对所有函数都有效,比如优化后的静态函数和inline函数等,可能就无法触发断点。
5. 监视
设置监视也必须是在程序运行后才行。如:
(gdb) watch *地址 # 当地址所指内容发送变化时断点
(gdb) watch var #当var值变化时,断点
(gdb) watch (condition) #当条件符合时,断点
监视也被称为硬件断点。可以监测栈变量和堆变量值的变化,当被监测变量值发生变化时,程序被停住。
边栏推荐
- String method exercise
- [Algèbre linéaire] 1.1 déterminant du deuxième et du troisième ordre
- String segment combination
- Download and installation of MySQL
- China's flexible employment has reached 200million
- Deploy redis high availability cluster
- PHP system function
- [sans titre]
- Why should the pointer be null after delete
- Prepare for the Blue Bridge Cup - double pointer, BFS
猜你喜欢
随机推荐
Mipi d-phy -- contents of HS and LP agreements
fsockopen函数的应用
What is a thread pool?
Oracle Recovery Tools实战批量坏块修复
PWN attack and defense world level2
字符串方法练习
How does sound amplify weak sounds
Use photoshop2022 to create a wonderful gradient effect for pictures
Troubleshooting of pyinstaller failed to pack pikepdf
线程池是什么老鸡?
“内窥镜第一股”二闯IPO,去年亏损5个亿,核心产品商业化仍存疑 | IPO速递
Sysbench Pressure Test Oracle (installation and use examples)
认证培训|StreamNative Certification 培训第2期
The thinkphp5.1 runtime file has been changed to 777 permission, but cannot be written
安装mysql5.7 并修改密码
PHP的system函数
mark
Some tests on complementary wasm environment
MySQL的下载和安装
Target detection - ADAS practice









