microsoft / vscode-cmake-tools

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

Cannot start CMake debugger in (Conan-)bootstrapped environments #4022

Closed rschuurmanbench closed 2 months ago

rschuurmanbench commented 2 months ago

Brief Issue Summary

I am using Conan and CMake, and Conan will start CMake in the def build(), as shown here:

class MyProject(ConanFile):
    #... Lots of  stuff

    def build(self):
        # Pre-build actions

        cmake = CMake(self)
        cli_args = []

        if debugging:
            cli_args += ["--debugger", "--debugger-pipe",
                         r'\\.\pipe\MyCmakeDebugger']

        cmake.configure(cli_args=cli_args)
        if self.should_build:
            cmake.build()  # This calls CMake

As I understand, this means that if I want to use the CMake debugger for this, I need to set vscode debug type to external and provide --debugger --debugger-pipe \\.\pipe\MyCmakeDebugger as arguments to CMake. The conanfile looks like this:

Now I have this launch configuration:

{
    "name": "Create build with CMake",
    "type": "cmake",
    "request": "launch",
    "pipeName": "\\\\.\\pipe\\MyCmakeDebugger",
    "preLaunchTask": "MyTaskThatBootstrapsTheBuild", // <-- Note that this does not work because VSCode will wait for the task to complete
    "cmakeDebugType": "external"
},

Now if I run this, the preLaunchTask will block, waiting for a debugger to connect.

It would be much better if VSCode just waits for the preLaunchTask to open the pipeName, and then connect to that. If I seperate the 2 calls (run the task manually, then start the debugger), then it works perfectly fine.

CMake Tools Diagnostics

No response

Debug Log

No response

Additional Information

No response

gcampbell-msft commented 2 months ago

Thanks for posting the issue! To help us understand the issue and prioritize it, could you tell us what version of the extension is this on?

rschuurmanbench commented 2 months ago

It's on v1.19.49, which is the latest available for me now.

gcampbell-msft commented 2 months ago

@rschuurmanbench Can you install the 1.18.44 version and let me know if it works there? Our expectation is that it still won't work there. We're trying to understand if this is a regression

rschuurmanbench commented 2 months ago

It's still there in 1.18.44. In both versions it's stuck here: image What I think is happening: Conan/Python calls CMake with --debugger -> This makes CMake blocking while waiting for a debugger to attach. Because the PreLaunchTask probably has to be exited before the debugger even tries to connect, it blocks.

v-frankwang commented 2 months ago

@gcampbell-msft Users have verified that this issue is still reproduced on CMake Tools:v1.18.44, can you give some advice?

gcampbell-msft commented 2 months ago

@v-frankwang Yes, this is a feature request.

@rschuurmanbench I actually believe this would be a possible feature request for VS Code. We don't control how the preLaunchTask runs, our task only starts to execute once this is finished. Therefore, I don't believe there is anything for us to do here.