Debugging and Errors¶
This page is inspired by CS161 Proj2 @ UC Berkeley
Full Tutorial of VSCode Debugging is listed here
Debug Toolbar¶
You can use mouse to grab this bar to anywhere you want
Commands¶
Continue / Pause
Continue
: Resume normal program/script execution (up to the next breakpoint / end).Pause
: Inspect code executing at the current line and debug line-by-line.
Step Over
- Execute the next method as a single command without inspecting or following its component steps.
Step Into
- Enter the next method to follow its execution line-by-line.
Step Out
- When inside a method or subroutine, return to the earlier execution context by completing remaining lines of the current method as though it were a single command.
Restart
- Terminate the current program execution and start debugging again using the current run configuration.
Stop
- Terminate the current program execution.
Example¶
Go | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Go | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
-
If I stand in breakpoint-1, and use
continue
, I will arrive at breakpoint-2. -
At breakpoint-1, if I use
step over
, I will arrive atif !ok {
. -
At breakpoint-1, if I use
step into
, I will enteruserlib.DatastoreGet(storageKey)
and inspect its execution line-by-line. -
And in
userlib.DatastoreGet(storageKey)
, if I get toArrive Point
, and usestep out
, I will return to breakpoint-1dataJSON, ok := userlib.DatastoreGet(storageKey)
like this function finished within a single command.
Breakpoints and Logpoints¶
BreakPoint
LogPoint
A Logpoint is a variant of a breakpoint that does not "break" into the debugger but instead logs a message to the debug console.
Logpoints enable you to inject logging while debugging without modifying the source code. They are especially useful when you're debugging production servers that cannot be paused or stopped.
Logpoints can also help you save time by not having to add or remove logging statements in your code.
Data Inspection¶
Look at the left side bar, and you can see the VARIABLES
/ WATCH
section.
VARIABLES
WATCH