debugging - 配合使用带有Rust的vscode调试控制台

标签 debugging visual-studio-code rust vscode-extensions lldb

我不确定我正在使用谁的控制台。但是,假设我有以下调试配置:

{
    "version": "0.2.0",
    "inputs": [
        ...
    ],
    "configurations": [
        {
            "type": "lldb",
            "request": "attach",
            "name": "Attach to...",
            "program": "${workspaceFolder}/src/lib/${input:pickPackage}/target/debug/${input:pickPackage}"
        }
    ]
}
我的程序在MacOS终端中使用cargo run -p ...运行
vscode的调试器为我提供了lldb的调试控制台
说,我处于断点,想尝试一下...
到目前为止,我尝试过防 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
What I found in the lldb dos
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")?
最后从错误中可以看出什么:
script print ("Here is some text")
Here is some text
你好,这个词很好,但是我如何到达我的实际范围呢?
我应该为此使用lldb的script命令吗?
我在那里的语法是什么?
更新
@ForceBru感谢您关于python的提示。
我正在互动的是vscode-lldb debugger api
在将https://github.com/vadimcn/vscode-lldb/blob/v1.6.0/MANUAL.md#rust-language-support中的script debugger.evaluate("/se t[0]")添加到我的配置中之后,看来我应该能够执行类似"sourceLanguages": ["rust"]的操作
但没有运气
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

我仍然在python中
script debugger.evaluate("locals().keys()")
dict_keys([])

最佳答案

有人评论说,您的配置似乎不正确,并且正在尝试将您的源代码调试为Python。获得正确配置的最简单方法是使用提供的模板。在您的情况下,您可能可以跳到此答案的末尾,并使用其中一个“附加”配置文件,但其他配置文件可能对其他人有用。
在调试面板中,有一个下拉列表:
VS Code LLDB: add configuration
如果选择“添加配置...”,则可以选择要添加的模板:
configuration templates
选择“LLDB:调试 cargo 输出”会将其添加到您的launch.json文件中:

{
    "type": "lldb",
    "request": "launch",
    "name": "Cargo launch",
    "cargo": {
        "args": [
            "build",
            "--lib"
        ]
    },
    "program": "${cargo:program}",
    "args": []
},
如果您的箱子是二进制文件,则需要将该--lib更改为--bin并指定要运行的二进制文件:
{
    "type": "lldb",
    "request": "launch",
    "name": "Cargo launch",
    "cargo": {
        "args": [
            "build",
            "--bin=foo"
        ]
    },
    "program": "${cargo:program}",
    "args": []
},
对于测试,您可以选择“LLDB:调试 cargo 测试”。它将生成如下内容:
{
    "type": "lldb",
    "request": "launch",
    "name": "Cargo test",
    "cargo": {
        "args": [
            "test",
            "--no-run",
            "--lib"
        ]
    },
    "program": "${cargo:program}",
    "args": []
},
您可能想要删除--lib参数,以便它将运行项目中的所有测试。您可以通过将其添加为尾随参数来对其进行过滤,以仅调试感兴趣的测试。例如只运行名称包含“foo”的测试:
{
    "type": "lldb",
    "request": "launch",
    "name": "Cargo test",
    "cargo": {
        "args": [
            "test",
            "--no-run",
            "--lib"
        ]
    },
    "program": "${cargo:program}",
    "args": ["foo"]
},
要调试已经运行的程序,可以使用模板“LLDB:按名称附加”,该模板将生成:
{
    "type": "lldb",
    "request": "attach",
    "name": "Attach",
    "program": "${workspaceFolder}/foo"
},
或“LLDB:按PID附加”:
{
    "type": "lldb",
    "request": "attach",
    "name": "Attach",
    "pid": "${command:pickMyProcess}" // use ${command:pickProcess} to pick other users' processes
},
这将为您提供正在运行的进程的可过滤列表,因此您可以选择要调试的进程。
对于这最后两种配置,您可能会遇到权限问题(至少在Linux上,但在Mac上也可能)。您可以通过以其他用户身份运行可执行文件或提升VS Code的权限(例如,以sudo开头)来解决此问题。

关于debugging - 配合使用带有Rust的vscode调试控制台,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64683236/

相关文章:

java - 如何在没有 int 参数的情况下递归删除连续的重复项?

visual-studio-2010 - Visual Studio - 启动 .bat 文件作为启动项目

debugging - 如何有条件地内联 F# 中的成员,或完全关闭调试版本中的内联

html - 更漂亮的格式化配置

c++ - 在 VSCode 中使用 MSVS 编译器构建 OpenCV 应用程序

rust - 从单个元素创建迭代器

rust - 在模块中查找函数名称

wpf - 调试 WPF 事件、绑定(bind)

opengl - GLFW-RS 只显示黑色方 block 而不是旋转立方体

powershell - 在 VS 代码片段中为 Powershell 变量保留 $