I'm a little uncertain who's console I'm using. But let's say I have following debug configuration:
{
"version": "0.2.0",
"inputs": [
...
],
"configurations": [
{
"type": "lldb",
"request": "attach",
"name": "Attach to...",
"program": "${workspaceFolder}/src/lib/${input:pickPackage}/target/debug/${input:pickPackage}"
}
]
}
my program is running in macos terminal with cargo run -p ...
vscode's debugger provides me with debug console to lldb
say, I'm in a breakpoint and want to try things out...
I so far tried rust
script println!("{:?}", &t[op_end_index..])
File "<input>", line 1
println!("{:?}", &t[op_end_index..])
^
SyntaxError: invalid syntax
script &t[op_end_index..]
File "<input>", line 1
&t[op_end_index..]
^
SyntaxError: invalid syntax
script fn main () {println!("{:?}", &t[op_end_index..])}
File "<input>", line 1
fn main () {println!("{:?}", &t[op_end_index..])}
^
SyntaxError: invalid syntax
script print "Here is some text"
File "<input>", line 1
print "Here is some text"
^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print("Here is some text")?
and finally what it suggest from the error:
script print ("Here is some text")
Here is some text
Hello word is nice but how do I get to my actual scope?
Am I supposed to use lldb's script
command for that?
What's my syntax there?
@ForceBru thanks for the hint about python.
What I'm interacting with is vscode-lldb debugger api
It seems I should be able to do something like script debugger.evaluate("/se t[0]")
after adding "sourceLanguages": ["rust"]
from https://github.com/vadimcn/vscode-lldb/blob/v1.6.0/MANUAL.md#rust-language-support to my configuration
but no luck
script debugger.evaluate("/se t[0]")
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/Users/anvlkv/.vscode/extensions/vadimcn.vscode-lldb-1.6.0/adapter/debugger.py", line 8, in evaluate
value = codelldb.evaluate_in_context(expr, True, exec_context)
File "/Users/anvlkv/.vscode/extensions/vadimcn.vscode-lldb-1.6.0/adapter/codelldb.py", line 276, in evaluate_in_context
return eval(code, eval_globals, eval_locals)
File "<string>", line 1
/se t[0]
^
SyntaxError: invalid syntax
I'm still in python
script debugger.evaluate("locals().keys()")
dict_keys([])
As someone commented, it looks like your configuration is not correct and it is trying to debug your source code as Python. The easiest way to get the right configuration is to use the provided templates. In your case, you can probably skip to the end of this answer and use one of the "attach" profiles, but the rest might be useful to someone else.
In the debug panel, there is a dropdown:
If you choose "Add Configuration...", you'll get a choice of templates to add:
Choosing "LLDB: Debug Cargo Output" will add this to your launch.json
file:
{
"type": "lldb",
"request": "launch",
"name": "Cargo launch",
"cargo": {
"args": [
"build",
"--lib"
]
},
"program": "${cargo:program}",
"args": []
},
If your crate is a binary, you'll want to change that --lib
to --bin
and specify which binary to run:
{
"type": "lldb",
"request": "launch",
"name": "Cargo launch",
"cargo": {
"args": [
"build",
"--bin=foo"
]
},
"program": "${cargo:program}",
"args": []
},
For tests, you can choose "LLDB: Debug Cargo Tests". It will generate something like this:
{
"type": "lldb",
"request": "launch",
"name": "Cargo test",
"cargo": {
"args": [
"test",
"--no-run",
"--lib"
]
},
"program": "${cargo:program}",
"args": []
},
You probably want to delete the --lib
argument so that it will run all of the tests in your project. You can filter it to just debug the tests that you are interested in by adding that as a trailing argument. eg to only run tests whose names contain "foo":
{
"type": "lldb",
"request": "launch",
"name": "Cargo test",
"cargo": {
"args": [
"test",
"--no-run",
"--lib"
]
},
"program": "${cargo:program}",
"args": ["foo"]
},
To debug a program that is already running, you can use the template "LLDB: Attach by Name", which generates:
{
"type": "lldb",
"request": "attach",
"name": "Attach",
"program": "${workspaceFolder}/foo"
},
or "LLDB: Attach by PID":
{
"type": "lldb",
"request": "attach",
"name": "Attach",
"pid": "${command:pickMyProcess}" // use ${command:pickProcess} to pick other users' processes
},
This will give you a filterable list of processes that are running, so you can pick the one you want to debug.
For these last two configurations, you may run into permissions issues (on Linux at least, but probably Mac too). You can address that by running the executables as a different user or by elevating the permissions of VS Code (eg by starting it with sudo
).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.