Debugging in VSCode
This is a short guide on how to use the debugger in Visual Studio Code (VSCode). The debugger allows you to stop the execution of your program at a breakpoint you choose, and then go through the code line-by-line to investigate the behavior of your program in detail. This is very beneficial for locating bugs (errors).
- Add breakpoint: F9 (not on empty line)
- Start: F5
- Into: F11 (go into functions)
- Over: F10 (go over functions)
- Out: Shift+F11 (continue until current function is finished)
Continue: F5 (to next breakpoint)
Write the following code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
def f(a,b): a += 2 b += 2 g(a,b) def g(a,b): a += 1 b += 1 a = 0 b = 0 f(a,b) f(a,b) f(a,b) f(a,b) f(a,b) print(a,b)
Add breakpoint on line 11
Experiment with stepping into, over and out
Notice that the “Variables” window show the current values of all variables
Open the debug console with Ctrl+Shift+Y
Try writing e.g.
- It also stops at errors.
- Breakpoints can be made conditional (right click on it in list or by line number)