Script to add Rust specific pretty-printing to the LLDB debugger.
With the recent removal of Rust specific pretty printing from CodeLLDB, debugging Rust, especially enums, has become quite painful.
This script is meant as a temporary fix until the situation of the ecosystem improves, see Compatability.
To load the script into your lldb debugger instance, execute the following lldb command:
command script import <path to rust_prettifier_for_lldb.py>
rust_prettifier_for_lldb.py
is the only file from this Repository
that you actually need. You can download it separately from the
Releases section.
To use this script with VSCode debug adapters you have to instruct them to execute the same lldb command as above before the actual debugging session.
Don't forget to replace <path to rust_prettifier_for_lldb.py>
with the actual path on your local machine in the examples below.
If you dislike linking to an absolute path on your machine I recommend
placing (or symlinking) rust_prettifier_for_lldb.py
into the
.vscode
folder of your repository, so you can use
"${workspaceFolder}/.vscode/rust_prettifier_for_lldb.py"
as the path.
For the CodeLLDB extension, add the preRunCommands
json tag to your launch configuration(s).
It is also recommended to set "expressions": "simple"
to fix an issue with
the array subscript operator ([..]
) in the Debug Watch Window.
Here's an example configuration for your .vscode/launch.json
:
{
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug",
"cargo": {
"args": [
"build",
],
"filter": {
"name": "<your binary name here>",
"kind": "bin"
}
},
"expressions": "simple",
"preRunCommands": [
"command script import <path to rust_prettifier_for_lldb.py>"
],
"args": [],
},
]
}
For the lldb-dap extension, add the initCommands
JSON tag to your .vscode/launch.json
configuration(s), as shown in the example below:
{
"version": "0.2.0",
"configurations": [
{
"type": "lldb-dap",
"request": "launch",
"name": "Debug",
"program": "<binary name here>",
"args": [],
"cwd": "${workspaceFolder}",
"initCommands": [
"command script import <path to rust_prettifier_for_lldb.py>"
],
}
]
}
This script was developed for LLDB Version 19.0.0
, aswell as 19.1.0-codelldb
(version currently bundled by CodeLLDB).
At the time of writing, it is known to work well with the latest stable version Rust (1.82.0
).
Initially this did not support Windows, although @jesnor was able to get it partially working. Any improvements on that front would of course be welcomed.
If you are using older versions of Rust or LLDB this script might not work for you.
Due to the changing nature of the Rust Standard Library internals aswell as the LLDB representation of them, this will never be more than a temporary hack that's constantly in danger of becoming outdated. The hope is that Rust's own Pretty Printers will eventually ship in a functional state, superseeding this temporary bandaid.
The plan for this script is to live at head, and hopefully get retired sooner rather than later.
I'm happy to accept pull requests to improve this script or even add support for commonly used collection types of third party crates, as long as you supply testcases to make sure your additions can be maintained.
Thank you to Vadim Chugunov (@vadimcn) for the wonderful CodeLLDB and the starting point for this script.
If this script has helped you out a a Github Star ✨ would make me very happy, and maybe help demonstrate to the Rust Project Maintainers that a solid solution for debugging Rust is something that many people desire.