Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode debugger conditional breakpoints

I am currently debugging a python project, and I would like to add conditional breakpoints similar to the conditional breakpoints in Visual Studio. Is this feature supported and if so, how do I create one?

like image 265
Preston Martin Avatar asked Apr 09 '17 19:04

Preston Martin


People also ask

How do I add a conditional breakpoint in VS code?

Click in the far left margin next to a line of code. You can also select the line and press F9, select Debug > Toggle Breakpoint, or right-click and select Breakpoint > Insert breakpoint. The breakpoint appears as a red dot in the left margin.

How do you set a conditional breakpoint?

To set a conditional breakpoint, activate the context menu in the source pane, on the line where you want the breakpoint, and select “Add Conditional Breakpoint”. You'll then see a textbox where you can enter the expression. Press Return to finish.

How do you set a conditional breakpoint in WinDbg?

Conditional Breakpoints in WinDbg In WinDbg, you can create a conditional breakpoint by clicking Breakpoints from the Edit menu, entering a new breakpoint address into the Command box, and entering a condition into the Condition box.

What are conditional breakpoints?

Conditional breakpoints allow you to break inside a code block when a defined expression evaluates to true. Conditional breakpoints highlight as orange instead of blue. Add a conditional breakpoint by right clicking a line number, selecting Add Conditional Breakpoint , and entering an expression.


2 Answers

Yes, this is described in detail in the VS Code Debugging docs

In short, right click on an existing breakpoint and select "Edit breakpoint", or right click on the breakpoint margin and select "Add conditional breakpoint".

like image 102
Rob Lourens Avatar answered Oct 04 '22 02:10

Rob Lourens


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.

Edit Condition -- https://media.githubusercontent.com/media/microsoft/vscode-docs/vnext/release-notes/images/1_52/edit-condition.png

Exception Condition -- https://media.githubusercontent.com/media/microsoft/vscode-docs/vnext/release-notes/images/1_52/exception-condition.png


That applies to Node debugger in VSCode 1.53 (Jan. 2021): see issue 104453

conditional breakpoint

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.

Breakpoint zone widget colored -- https://media.githubusercontent.com/media/microsoft/vscode-docs/56b62268c9df79ae72305b364eb18f4f4b4cc9bb/release-notes/images/1_53/breakpoints.gif


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.

breakpoint condition menu

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.

break on access types

like image 45
VonC Avatar answered Oct 04 '22 02:10

VonC