如何使用 VSCode + cppdbg 调试 Rust 集成测试

问题描述 投票:0回答:1

我想使用 gdb(比 lldb 更好的枚举支持)在 VSCode 中调试 Rust 集成测试。 我曾经使用 lldb 使用很棒的

CodeLLDB
插件,我在
launch.json
中的配置如下所示:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "lldb",
            "request": "launch",
            "name": "run integration test",
            "sourceLanguages": ["rust"],
            "cargo": {
                "args": [
                    "test",
                    "--package=name_of_my_package",
                    "--no-run",
                    "--tests",
                ],
                "filter": {
                    "kind": "test"
                }
            },
            "args": [
                "--exact",
                "--nocapture",
                "name_of_my_test",
            ],
            "cwd": "${workspaceFolder}",
        },
    ],
}

对于使用 gdb,我假设我必须使用

cpptools
扩展(调试类型
"cppdbg"
),它不支持
"cargo"
指令。

如何为

cpptools
创建与上述配置等效的配置?

(或其他支持 gdb 的扩展)

主要问题似乎是获取测试二进制文件的正确路径,其中包含不确定的哈希值。 我发现没有什么比this question更好的了,这个问题很老了,特定于Windows,并且没有任何令人满意的答案。现在有更好的解决方案吗?

最坏的情况,我什至不会反对使用

tasks.json
将二进制文件移动/符号链接到确定性位置的某种黑客行为。

linux visual-studio-code debugging rust gdb
1个回答
0
投票

我想出了一种使用我提到的

tasks.json
机制来做到这一点的巧妙方法。这需要
jq
上的
xargs
PATH

如果有人有更好的方法,我很乐意接受他们的回答。

my_package_name
my_test_name
显然需要调整。


tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build_integration_test",
            "type": "shell",
            "command": "cargo test --package=my_package_name --no-run --tests --message-format=json | jq -r 'first(select(.executable != null and .target.kind == [\"test\"])) | .executable' | xargs -I@ ln -fs @ ${workspaceFolder}/target/debug/integration_test_bin",
            "group": "build",
            "presentation": {
                "reveal": "silent"
            },
            "options": {
                "cwd": "${workspaceFolder}"
            },
        }
    ]
}


launch.json

{
    "version": "0.2.0",
    "configurations": [
     {
            "type": "cppdbg",
            "request": "launch",
            "name": "debug integration test (cppdbg)",
            "preLaunchTask": "build_integration_test",
            "program": "${workspaceFolder}/target/debug/integration_test_bin",
            "args": [
                "--test-threads=1",
                "--exact",
                "--nocapture",
                "my_test_name"
            ],
            "cwd": "${workspaceFolder}",
        },
    ],
}

© www.soinside.com 2019 - 2024. All rights reserved.