* docs: add more hints to observability docs; add database intellij docs * localize images
2.1 KiB
How to debug live code
How to debug a program with Visual Studio Code. Instructions for debugging Go code with Goland/IntelliJ here
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/IntelliJ 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:52to set a breakpoint on a line (bplists all,clearalldeletes all)cto continue execution of the programCtrl-Cpause the program to bring back the command promptnto step over the next statementsto step into the next function callstepoutto step out of the current function callCtrl-Dto 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).