rust/docs/dev/debugging.md

87 lines
3.1 KiB
Markdown
Raw Normal View History

2020-02-16 15:52:41 -06:00
# Debugging VSCode plugin and the language server
## Prerequisites
2020-02-16 15:52:41 -06:00
- Install [LLDB](https://lldb.llvm.org/) and the [LLDB Extension](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb).
- Open the root folder in VSCode. Here you can access the preconfigured debug setups.
<img height=150px src="https://user-images.githubusercontent.com/36276403/74611090-92ec5380-5101-11ea-8a41-598f51f3f3e3.png" alt="Debug options view">
- Install all TypeScript dependencies
```bash
cd editors/code
npm install
```
## Common knowledge
2020-02-16 15:52:41 -06:00
* All debug configurations open a new `[Extension Development Host]` VSCode instance
where **only** the `rust-analyzer` extension being debugged is enabled.
* To activate the extension you need to open any Rust project folder in `[Extension Development Host]`.
## Debug TypeScript VSCode extension
2020-02-18 05:33:16 -06:00
- `Run Extension` - runs the extension with the globally installed `rust-analyzer` binary.
- `Run Extension (Dev Server)` - runs extension with the locally built LSP server (`target/debug/rust-analyzer`).
TypeScript debugging is configured to watch your source edits and recompile.
To apply changes to an already running debug process press <kbd>Ctrl+Shift+P</kbd> and run the following command in your `[Extension Development Host]`
```
> Developer: Reload Window
```
## Debug Rust LSP server
- When attaching a debugger to an already running `rust-analyzer` server on Linux you might need to enable `ptrace` for 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`:
```toml
[profile.dev]
debug = 2
```
2020-02-18 05:33:16 -06:00
- Select `Run Extension (Dev Server)` to run your locally built `target/debug/rust-analyzer`.
- In the original VSCode window once again select the `Attach To Server` debug configuration.
2020-02-18 05:33:16 -06:00
- A list of running processes should appear. Select the `rust-analyzer` from this repo.
2020-02-18 05:33:16 -06:00
- Navigate to `crates/rust-analyzer/src/main_loop.rs` and add a breakpoint to the `on_task` function.
- Go back to the `[Extension Development Host]` instance and hover over a Rust variable and your breakpoint should hit.
## Demo
- [Debugging TypeScript VScode extension](https://www.youtube.com/watch?v=T-hvpK6s4wM).
- [Debugging Rust LSP server](https://www.youtube.com/watch?v=EaNb5rg4E0M).
## Troubleshooting
2020-02-18 05:33:16 -06:00
### Can't find the `rust-analyzer` process
It could be a case of just jumping the gun.
2020-02-18 05:33:16 -06:00
The `rust-analyzer` is only started once the `onLanguage:rust` activation.
Make sure you open a rust file in the `[Extension Development Host]` and try again.
2020-02-18 05:33:16 -06:00
### Can't connect to `rust-analyzer`
Make sure you have run `echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope`.
By default this should reset back to 1 everytime 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`.