Join the AI Workshop and learn to build real-world apps with AI. A hands-on, practical program to level up your skills.
VS Code has a powerful built-in debugger that works with many languages.
General Debugging
To start debugging:
- Click the Debug icon in the sidebar (or press
F5). - VS Code will prompt you to create a debug configuration if one doesn’t exist.
- Set breakpoints by clicking in the gutter next to line numbers.
- Start debugging.
The debugger provides:
- Variables inspection (local and global)
- Watch expressions for specific variables
- Call stack visualization
- Breakpoint management
Debugging Go with Delve
For Go debugging, you need Delve.
Setup
- Install the official Go VS Code extension
- Make sure
$GOPATHis configured - On Linux/Windows: Run the command
Go: Install/Update Tools - On macOS: Install Delve via Homebrew:
brew install go-delve/delve/delve
Configuration
Press F5 to start debugging. VS Code creates a .vscode/launch.json file automatically:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${fileDirname}",
"env": {},
"args": [],
"showLog": true
}
]
}
Debug Modes
The mode parameter can be set to:
| Mode | Description |
|---|---|
debug | Compile and debug the current program |
test | Debug tests (use -test.run and test name in args for single tests) |
exec | Run a pre-built binary (specify path in program) |
remote | Debug remotely |
Tips
- Step into library calls to learn how the standard library works.
- The Go standard library is well documented and readable.
- Debugging helps you understand the internal workings of packages you use.
Check the official documentation for more details and troubleshooting tips.