当前位置:网站首页>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
- Is it safe to open a stock account by mobile phone?
- Finally, someone explained the cloud native architecture
- Interviewer: what is the internal implementation of strings in redis?
- [matlab] function definition and use
- 第五章 虚拟存储器 练习
- Cs5463 code module analysis (including download link)
- Leetcode 324 Swing sort II [tri double pointeur] le chemin du leetcode pour l'héroding
- 机器学习4-降维技术
- 一张能卖上千万,商家扩张比玩家还快:球星卡的江湖你不懂
猜你喜欢
随机推荐
One card can sell tens of millions, and the business expansion is faster than that of players: you don't understand the Jianghu of star cards
Chapter II Classic synchronous exercises
大三,不简单啊!
Counting sorting and stability of sorting
2022-06-28:以下golang代码输出什么?A:true;B:false;C:panic;D:编译失败。 package main import “fm
Flowable boundary timer
直击产业落地 | 飞桨重磅推出业界首个模型选型工具
When dialogfragment's onstop is completely invisible, call disass to exit the interface and report an error. Solution
Progress of dbnn experiment
Three communication skills in software testing
note
Small sample sharp weapon 2 Text confrontation + semi supervised FGSM & VAT & FGM code implementation
Is it difficult to register stocks and open accounts online? Is it safe to open an account online?
What is the difference between WMS warehouse management system and ERP
Is it safe and reliable for changtou school to help open a securities account? How to drive
Undefined symbol main (referred from entry9a.o).
笔记
Complex nested object pool (4) -- manage the object pool of multi class instances and multi-stage instances
老家出资,俞敏洪设立两支基金
数学知识:求组合数 I—求组合数


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






