Debugging VSCode plugin and the language server
August 27, 2023 ยท View on GitHub
Prerequisites
- You can successfully build this project from source.
- Install LLDB and the LLDB Extension.
- Open the root folder in VSCode. Press CtrlShiftD and here you can access the preconfigured debug setups.
Common knowledge
- All debug configurations open a new
[Extension Development Host]VSCode instance where only the Zeek extension being debugged is enabled. - To activate the extension you need to open any Zeek script file
(
.zeek/.bro) in[Extension Development Host].
Debug TypeScript VSCode extension
Run Extension (Debug Build)- runs extension with the locally built LSP server (target/debug/zeek-language-server).
TypeScript debugging is configured to watch your source edits and recompile. To
apply changes to an already running debug process, press
CtrlShiftP and run the following command in
your [Extension Development Host]
> Developer: Reload Window
Debug LSP server
-
When attaching a debugger to an already running
zeek-language-serverserver on Linux you might need to enableptracefor unrelated processes by running:echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope -
By default, the LSP server is built without debug information. To enable it, you'll need to change
Cargo.toml:[profile.dev] debug = 2 -
Select
Run Extension (Debug Build)to run your locally builttarget/debug/zeek-language-server. -
In the original VSCode window once again select the
Attach To Serverdebug configuration. -
A list of running processes should appear. Select the
zeek-language-serverfrom this repo. -
Navigate to
src/lsp.rsand add a breakpoint to thehoverfunction. -
Go back to the
[Extension Development Host]instance and hover over a Zeek variable and your breakpoint should hit.
Troubleshooting
Can't find the zeek-language-server process
It could be a case of just jumping the gun.
The zeek-language-server is only started once the onLanguage:zeek activation.
Make sure you open a Zeek script file in the [Extension Development Host] and
try again.
Can't connect to zeek-language-server
Make sure you have run echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope.
By default this should reset back to 1 every time you log in.
Breakpoints are never being hit
Check your version of lldb. If it's version 6 and lower, use the classic
adapter type. It's lldb.adapterType in settings file.
If you're running lldb version 7, change the lldb adapter type to bundled
or native.