To use breakpoints and conditional debugging with VSCode, follow these steps:
Install VSCode: Download and install Visual Studio Code from the official website.
Open your project: Open your project folder by selecting "Open Folder" from the "File" menu.
Set breakpoints: In your source code, click on the line number where you want to set a breakpoint. A red circle will appear, indicating the breakpoint is set. You can set multiple breakpoints in different locations.
Configure conditional breakpoints (optional): Right-click on the breakpoint icon and select "Edit Breakpoint." Provide a condition that should be evaluated when the execution reaches that breakpoint. The breakpoint will be hit only if the condition is true.
Start debugging: Click on the debug icon in the activity bar on the side, or use the F5 keyboard shortcut. This will open the debug view.
Configure the debugger: On the debug view, you'll find a dropdown menu with launch configurations. Select the desired configuration or create a new one if it doesn't exist. A launch configuration specifies how the debugger should run and what files to debug.
Start debugging session: Click the green "Start Debugging" button or press F5. This will start the debugging session, and your breakpoints will be hit when the code execution reaches them.
Debug controls: Once the debugger is running, you can use various controls such as "Continue" to resume code execution, "Step Over" to execute the next line, "Step Into" to dive into a function, and "Step Out" to return to the caller. Use these controls to navigate and interact with the code during debugging.
Inspect variables and values: While debugging, you can inspect the values of variables by hovering over them or using the "Watch" panel. You can add expressions and watch their values as well.
Conditional debugging: If you have set a conditional breakpoint, the debugger will only break when the condition is met. You can check the condition's evaluation in the debugger console.
End debugging: To stop the debugging session, click the red "Stop Debugging" icon or press Shift+F5.
By utilizing breakpoints and conditional debugging, you can pause the execution at specific points in your code and analyze variables and values, making it easier to diagnose and fix issues.