当前位置:网站首页>使用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) #当条件符合时,断点
监视也被称为硬件断点。可以监测栈变量和堆变量值的变化,当被监测变量值发生变化时,程序被停住。
边栏推荐
猜你喜欢

Deploy redis high availability cluster

Relations EMC, EMI, EMS

leetcode 统计放置房子的方式数

thinkphp5.1 runtime文件改成777权限了, 还是无法写入

Leetcode counts the logarithm of points that cannot reach each other in an undirected graph

Handling method of occasional error reporting on overseas equipment

Oracle Recovery Tools实战批量坏块修复

Trigonometric function calculation

Ctfhub web SQL injection - integer injection

Some tests on complementary wasm environment
随机推荐
Ctfhub web password default password
arraylist基操和添加元素源码
Day10 enumeration class and annotation
对补wasm环境的一些测试
99乘法表
CTFHub-Web-SQL注入-整数型注入
What is the Valentine's Day gift given by the operator to the product?
Some tests on complementary wasm environment
Pytoch Learning Series: Introduction
【一起上水硕系列】最简单的字幕配置
认证培训|StreamNative Certification 培训第2期
There is a time delay for the click event on the mobile terminal. What is the delay time? How to solve it?
Talk about SQL optimization
目标检测——ADAS实战
Install kibana
Leetcode counts the number of ways to place houses
EMC、EMI、EMS的关系
[sans titre]
What is Mipi
PHP SimpleXML