当前位置:网站首页>Use conditional breakpoints in vscode (based on GDB)
Use conditional breakpoints in vscode (based on GDB)
2022-06-28 23:15:00 【Love is patience】
This article tells VSCode How to use conditional breakpoints in , Generally, the breakpoints we use are regular breakpoints , The program stops when it runs , But sometimes you want to trigger a breakpoint only under certain conditions , This requires setting the normal breakpoint to a conditional breakpoint .
Use it directly gdb The instructions of can be found in debug console Set in the , about VSCode, It will be easier to set up .
One Example program
First, prepare an example program , as follows ,
#include <iostream>
#include <cstdint>
int main(int, char**) {
std::cout << "Hello, world!\n";
uint32_t index = 0;
for (; index < 100; ++index)
{
std::cout << "aaa\n";
}
return 0;
}
Then printing “aaa” Add a regular breakpoint where , See the red dot in the figure below ,
Two Conditional breakpoints
Conditional breakpoints are divided into expressions and Hit Count Two kinds of , Here are the introduction ,
1. Expression breakpoint
Suppose we want the variable index The value is greater than 20 Trigger breakpoints when , Right click the red breakpoint , choice Edit Breakpoint,
The following interface appears ,
Then enter... On the right “index > 20”, This is the expression ,
Then return , Press enter to save the settings , Otherwise, conditional breakpoints will not work , Finally, as follows ,
Then start debugging , Finally, run the program until the breakpoint is triggered , You can see in the local variables window on the left index The value of is 21,
Description of successful operation .
Expressions can be various , As long as the result of the expression is True, Then the breakpoint will be triggered , If there are multiple conditions , Then you can use it && and || Symbol to connect , as follows ,
hope index The value of the 20 and 25 Between , Remember to press enter to save after modification .
2. Hit Count The breakpoint
Hit Count The number of times the program reaches the line where the breakpoint is located , So this breakpoint means how many times it is triggered when the line is run .
Also right-click the breakpoint , And then choose Edit Breakpoint, At this point, you need to clear out the contents of the expression breakpoint , Then press enter to save it .
Because of this 2 If all configurations are set , Then it won't work , So first clear the contents of the expression breakpoint . as follows , Remember to press enter to save ,
Then right-click the breakpoint again , choice Edit Breakpoint, Then click on “Expression” The arrow on the right expands , as follows ,
choice Hit Count, Then enter a number on the right , Input here 10, as follows ,
Indicates that you want to run the line 10 Trigger after times , Then press enter to save .
Finally, start debugging , And let the program run until the breakpoint is triggered ,
Variable available index The value of proves indirectly whether it has been run so many times , The local variables window on the left is shown below ,
There may be a little doubt here : perform 10 Time ,index The value of should not be 9 Do you , Why 10? Because it is to execute 10 Time , That's what we need 10 The breakpoint is triggered only after the execution is completed , So when the break point is triggered , Is ready to execute the 11 Time , That's why index The value of is 10, instead of 9
3、 ... and summary
This article tells you how to VSCode Use conditional breakpoint debugging in C/C++ Program , It is very convenient and easy to use . For other languages , It's the same thing .
边栏推荐
- 他原来是这么刷题的!
- Code example of hiredis
- 老家出资,俞敏洪设立两支基金
- 收藏 | VLOOKUP函数的这些妙用你都知道吗?
- [API packet capturing in selenium automation] installation and configuration of browsermobproxy
- 长投学堂帮忙开证券账户是安全靠谱的吗?个人如何开
- Design e-commerce seckill system
- TDD案例实战
- IDC: Alibaba cloud ranks first in the market share of China's data governance platform in 2021
- Is it safe to open a stock account online?
猜你喜欢

At the end of June, how many people in Kangkang are ready to change jobs

keil工程,程序写多后,RTT不能打印

C# 面试题目_20220627记录一下

Interviewer: what is the internal implementation of strings in redis?

Keil project, RTT cannot print after too many programs are written

WEB API学习笔记1

lock4j--分布式锁中间件--使用/实例

Go language - reflect
![[stm32 HAL库] 串口通信](/img/2c/23a2ecf75141b8f38ab99ac6b2eaef.png)
[stm32 HAL库] 串口通信

Linq连表查询
随机推荐
他原来是这么刷题的!
The Best of Many Worlds_ Dual Mirror Descent for Online Allocation Problems
CPU、GPU、TPU、NPU区别
在线文本过滤小于指定长度工具
一文读懂,WMS仓储管理系统与ERP有什么区别
TDD和自动化测试
Class extension and optional type extension of dart
[API packet capturing in selenium automation] installation and configuration of browsermobproxy
Keil project, RTT cannot print after too many programs are written
全面掌握const的用法《一》
【深度学习】(3) Transformer 中的 Encoder 机制,附Pytorch完整代码
笔记
【Word 教程系列第 2 篇】Word 中如何设置每页的表格都有表头
运维排查-使用hcache插件排查Buffer/cache占用过高
LeetCode 324 摆动排序 II[排序 双指针] HERODING的LeetCode之路
[sword finger offer] 50 First character that appears only once
C# 面试题目_20220627记录一下
Flowable boundary timer
直击产业落地 | 飞桨重磅推出业界首个模型选型工具
MATLAB 学习笔记(6)MATLAB 的 upsample 函数和 downsample 函数