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
- Windows:
start chrome.exe –remote-debugging-port=9222
- Linux:
chromium-browser --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
Install Delve:
xcode-select --install pushd /tmp go get github.com/go-delve/delve/cmd/dlv popd /tmp
Then install pgrep
:
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:52
to set a breakpoint on a line (bp
lists all,clearall
deletes all)c
to continue execution of the programCtrl-C
pause the program to bring back the command promptn
to step over the next statements
to step into the next function callstepout
to step out of the current function callCtrl-D
to exit
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).