当前位置:网站首页>使用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) #当条件符合时,断点
监视也被称为硬件断点。可以监测栈变量和堆变量值的变化,当被监测变量值发生变化时,程序被停住。
边栏推荐
- Programmers whose monthly salary is less than 30K must recite the interview stereotype. I'll eat it first
- EMC、EMI、EMS的關系
- PWN attack and defense world level2
- chrome浏览器关闭更新弹窗
- Relations EMC, EMI, EMS
- Pvcreate ASM disk causes abnormal recovery of ASM disk group - sparing separation
- Target detection - ADAS practice
- Talk about the copyonwritearraylist of JUC
- Leetcode counts the logarithm of points that cannot reach each other in an undirected graph
- Today's sleep quality record 82 points
猜你喜欢

Lanbao sensor technology rushes to the scientific innovation board: annual revenue of 350million yuan xuyongtong family has a strong color

Overview of PMP project management
![[Algèbre linéaire] 1.1 déterminant du deuxième et du troisième ordre](/img/ea/70b59c64d3287a887e371a9181fe45.png)
[Algèbre linéaire] 1.1 déterminant du deuxième et du troisième ordre

Deploy redis high availability cluster

China's flexible employment has reached 200million

EMC、EMI、EMS的關系

Install kibana

Chrome browser close update Popup

Ctfhub web password default password

CTFHub-Web-SQL注入-整数型注入
随机推荐
"The first share of endoscope" broke into IPO two times. Last year, it lost 500million yuan. The commercialization of core products is still in doubt | IPO Express
chrome浏览器关闭更新弹窗
The linkedhashset set makes the elements orderly without repetition
双击事件与单击事件的那些事
Relations EMC, EMI, EMS
What is a thread pool?
手机开户股票开户安全吗?开户很难么?
【無標題】
Some tests on complementary wasm environment
18. `bs對象.節點名.next_sibling` 獲取兄弟節點
MySQL的下载和安装
String method exercise
Mipi d-phy -- contents of HS and LP agreements
leetcode 统计无向图中无法互相到达点对数
Application of fsockopen function
String segment combination
[untitled]
How to optimize databases and tables
Only in the past four years, Microsoft finally gave it up!
Why should the pointer be null after delete