当前位置:网站首页>使用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) #当条件符合时,断点
监视也被称为硬件断点。可以监测栈变量和堆变量值的变化,当被监测变量值发生变化时,程序被停住。
边栏推荐
- PHP system function
- Deploy redis high availability cluster
- Have you learned the common SQL interview questions on the short video platform?
- Summary of several days
- On the fact that lambda expressions cannot handle recursion
- [線性代數] 1.1 二階與三階行列式
- Learning Tai Chi Maker - mqtt Chapter II (IX) test of this chapter
- 字符串输出
- chrome浏览器关闭更新弹窗
- 字符串方法练习
猜你喜欢

OpenResty 使用介绍

Ctfhub web SQL injection - integer injection

PWN attack and defense world guess_ num

SQL training 01

“内窥镜第一股”二闯IPO,去年亏损5个亿,核心产品商业化仍存疑 | IPO速递

18. `bs对象.节点名.next_sibling` 获取兄弟节点

EMC、EMI、EMS的關系

China's flexible employment has reached 200million

干货丨微服务架构是什么?有哪些优点和不足?

What is the dry goods microservice architecture? What are the advantages and disadvantages?
随机推荐
短视频平台常见SQL面试题,你学会了吗?
Handling method of occasional error reporting on overseas equipment
Which securities company is the largest and safest? Which securities company has good service
Talk about SQL optimization
矩阵特征值和特征向量求解——特征值分解(EVD)
ArrayList basic operation and add element source code
centos7 安装php7.2
PHP system function
Apache does not parse PHP files, but directly displays the source code
Relations EMC, EMI, EMS
PWN attack and defense world level2
Calculate rectangular area
Temperature conversion II
线程池是什么老鸡?
高并发的理解与设计方案
After today, I look forward to the new year's eve of the year of the rabbit
哪个证券公司最大最安全 哪家券商服务好
Sysbench Pressure Test Oracle (installation and use examples)
Oracle Recovery Tools实战批量坏块修复
Method overload summary