How to debug live code
How to debug a program with Visual Studio Code:
Debug TypeScript code
Requires "Debugger for Chrome" extension.
- Quit Chrome
- Launch Chrome (Canary) from the command line with a remote debugging port:
- Mac OS:
/Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary --remote-debugging-port=9222
start chrome.exe –remote-debugging-port=9222
- Mac OS:
- Go to http://localhost:3080
- Open the Debugger in VSCode: "View" > "Debug"
- Launch the
(ui) http://localhost:3080/*debug configuration
- Set breakpoints, enjoy
Debug Go code
Instructions for attaching with Goland here
xcode-select --install pushd /tmp go get github.com/go-delve/delve/cmd/dlv popd /tmp
brew install proctools
Make sure to run
env DELVE=true sg start to disable optimizations during compilation, otherwise Delve will have difficulty stepping through optimized functions (line numbers will be off, you won't be able to print local variables, etc.).
Now you can attach a debugger to any Go process (e.g. frontend, searcher, go-langserver) in 1 command:
dlv attach $(pgrep frontend)
Delve will pause the process once it attaches the debugger. Most used commands:
b internal/db/access_tokens.go:52to set a breakpoint on a line (
cto continue execution of the program
Ctrl-Cpause the program to bring back the command prompt
nto step over the next statement
sto step into the next function call
stepoutto step out of the current function call
Attaching via Goland
After running with
env DELVE=true sg start you may use Run | Attach to Process in Goland to debug a running Go binary (⌥⇧F5 on macOS).