Reputation: 2963
How do I add conditional breakpoints for python debugging, similar to the conditional breakpoints in Visual Studio?
Upvotes: 41
Views: 59640
Reputation: 16119
Right click on an existing breakpoint and select "Edit Breakpoint…", or right click on the breakpoint margin and select "Add Conditional Breakpoint…".
See the VS Code Debugging docs for details.
Upvotes: 52
Reputation: 1280
if for some reason you cannot make conditional breakpoint to work follow below approach. write if statements in your code and put breakpoint inside it.
if(condition): # condition when you want to program to stop
print("pause execution here") # put a breakpoint on this line.
Upvotes: 6
Reputation: 1328342
With VSCode 1.52 (Nov. 2020), you also have:
Breakpoints View: Conditions for exception breakpoints
We now support editing conditions for Exception breakpoints from the BREAKPOINTS view using the "
Edit Condition
" context menu action.For now, only the Mock Debug extension has a (fake) Exception Breakpoint condition support, but soon other debug extensions will follow - such as the Javascript debugger.
That applies to Node debugger in VSCode 1.53 (Jan. 2021): see issue 104453
It is now possible to edit conditions for exception breakpoints and function breakpoints using the inline Edit Condition action or the new context menu actions.
Using conditions it is possible for the user to specify that the program should break on an exception only when a particular condition is met.
Currently the Javascript debug extension support conditions for exception or function breakpoints and soon other debug extensions will support it as well.
VSCode 1.55 (March 2021) will add:
Inline menu to edit condition and hit count
We now show an inline menu for editing conditions and hit counts for function breakpoints.
Previously the inline edit button would choose automatically what condition to edit, now the menu should make the flow easier and give more control to the user.Access types of data breakpoints
Data breakpoints now support more access types to break on:
- Break on Read: breakpoint will be hit every time a variable gets read.
- Break on Access: breakpoint will be hit every time a variable is accessed.
As a reminder, data breakpoints can be added from a context menu in the VARIABLES view and we already supported Break on Value Change.
For now, only the Mock Debug extension has (fake) Data Breakpoint support for all three access types, but soon other debug extensions will follow - such as the Java extension.
Upvotes: 13
Reputation: 1102
You can use c++ functions.
I used this to partially match a string in a variable for conditional breakpoint with an expression:
variable.find("string")"
Upvotes: 0