microsoft / vscode-cmake-tools

CMake integration in Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=vector-of-bool.cmake-tools
MIT License
1.47k stars 453 forks source link

Simplify debug configuration for ctest debug launch #3153

Open PrimeMinisterOfGreed opened 1 year ago

PrimeMinisterOfGreed commented 1 year ago

Brief Issue Summary

it's not clear how to write a configuration in launch.json that can debug a single test, since the default configuration launch all tests.

CMake Tools Diagnostics

No response

Debug Log

No response

Additional Information

No response

PrimeMinisterOfGreed commented 1 year ago

i'll explain that confuse issue over there. When using TestMate c++ this extension provide a debug configuration that work by default without writing a new one in launch.json. The new cmake tools ask for a launch configuration when try to use a debugger, but after days of searching i did not encounter any tutorial that provide a way to , for example, pass the name of the selected test to the args in launch.json, this mean that also if i selected a test, all tests will be launched. If there is a way to pass such argument, this information should be provided by the extension itself or by a default launch.json configuration that indicate the presence of this argument.

xisui-MSFT commented 1 year ago

@IlVirtuoso Can you provide the launch.json you are using?

gcampbell-msft commented 1 year ago

@IlVirtuoso Does the launch.json under ctest within the "debug-launch.md" file work for you?

If not, does a launch.json that looks similar to the following:

{
        "name": "CTest Launch",
        "type": "cppdbg",
        "request": "launch",
        "program": "${cmake.testProgram} ",
        "args": [ "${cmake.testArgs}" ],
    }

allow you to then debug tests from the Test Explorer?

gcampbell-msft commented 1 year ago

@IlVirtuoso Following up on this, does the above launch.json work for you? Thanks

PrimeMinisterOfGreed commented 1 year ago

@gcampbell-msft Sorry i saw the message just now, my previous json was that

 {
            "name": "LaunchTest",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/build/DistributedCrack_test",
            "args": [
                "--gtest_filter= ${relativeFile} "
            ],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Abilita la riformattazione per gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "Imposta Versione Disassembly su Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ]
        },

i tried to catch the name of the entry and filter it in relativeFile with a custom action, but it failed. Trying to launch the .json you provide (in debug obliviously) i obtain the error launch property 'cwd' is missing.

gcampbell-msft commented 1 year ago

If you provide the same cwd from your example you sent, what happens then?

xisui-MSFT commented 1 year ago

@IlVirtuoso Are you using the test explorer? If so, my suggestion is to start debugging the test you want to debug in the test explorer. The main advantage is, using this method, ${cmake.testProgram} and ${cmake.testArgs} are expanded automatically, and you don't need to specify the details manually. Notice that, you'll have to start debugging from the test explorer, and F5 may not work.

If you are not using the test explorer, you'll need to make sure the program and args match the test item you would like to debug.

Either way, you'll need to double check that fields like fileDirname and relativeFile would be auto expanded as expected.

diablodale commented 1 year ago

after following @xisui-MSFT instructions to add testProgram and testArgs, I am able to ctest debug individual tests. 👍 However, this requires me to manually select wit my mouse the launch configuration for the selected test. I see no setting in debug-launch.md or cmake-settings.md to set the default.

This is worse when I click the Debug Tests at the top of the test explorer UI. This starts ctest for each test (22 in my project). I then have to manually wait for each test to be run by vscode and manually select the launch configuration 22 times as each test completes and the next test starts. 👎 I see no setting in debug-launch.md or cmake-settings.md to set the default.

gcampbell-msft commented 1 year ago

@diablodale I'm glad you're able to ctest debug individual tests!

Thanks for your feedback regarding the usage of the Test Explorer, we will continue to use your feedback into consideration as we plan our backlog and plan for future features and work items.

@xisui-MSFT FYI