microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.4k stars 29.33k forks source link

Failure to attach cppdbg #91342

Closed galvesribeiro closed 4 years ago

galvesribeiro commented 4 years ago

Hello folks!

I have the following tasks.json:

{
    "version": "2.0.0",
    "runner": "terminal",
    "options": {
        "cwd": "${workspaceRoot}/Firmware",
        "env": {
            "PATH": "${env:PATH}:${workspaceFolder}/../build-tools/bin/linux"
        }
    },
    "tasks": [
        {
            "label": "4-attach-logger",
            "type": "shell",
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "dedicated",
                "showReuseMessage": true,
                "clear": false
            },
            "isBackground": true,
            "dependsOn": "3-start-debugger",
            "command": "telnet 192.168.35.2 2342",
            "problemMatcher": []
        },
        {
            "label": "3-start-debugger",
            "type": "shell",
            "dependsOn": "2-deploy-image",
            "command": "azsphere device app start --debug --componentid 0f149356-2cb8-4aa4-9608-f41e060d82c5",
            "presentation": {
                "echo": true,
                "reveal": "always"
            }
        },
        {
            "label": "2-deploy-image",
            "type": "shell",
            "dependsOn": "1-build-firmware",
            "command": "azsphere device sideload deploy --manualstart --imagepackage out/debug/eGYM_Backbone.imagepackage",
            "presentation": {
                "echo": true,
                "reveal": "always"
            }
        },
        {
            "label": "1-build-firmware",
            "type": "shell",
            "command": "./rungn debug -p",
            "presentation": {
                "echo": true,
                "reveal": "always"
            },
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": [
                {
                    "owner": "cpp",
                    "fileLocation": [
                        "relative",
                        "${workspaceRoot}/Firmware"
                    ],
                    "pattern": {
                        "regexp": "^../../(.*):(\\d+):(\\d+):\\s+(warning|\\w*\\s?error):\\s+(.*)$",
                        "file": 1,
                        "line": 2,
                        "column": 3,
                        "severity": 4,
                        "message": 5
                    }
                },
                {
                    "owner": "cpp",
                    "fileLocation": [
                        "relative",
                        "${workspaceRoot}/Firmware"
                    ],
                    "pattern": {
                        "regexp": "^../../(.*?):(.*):\\s+(warning|\\w*\\s?error):\\s+(.*)$",
                        "file": 1,
                        "severity": 3,
                        "message": 4
                    }
                }
            ]
        }
    ]
}

And the following launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "eGYM.Backbone (gdb)",
            "type": "cppdbg",
            "request": "launch",
            "externalConsole": true,
            "miDebuggerServerAddress": "192.168.35.2:2345",
            "cwd": "${workspaceFolder}/Firmware",
            "preLaunchTask": "4-attach-logger",
            "miDebuggerPath": "/opt/azurespheresdk/Sysroots/4+Beta2001/tools/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-musleabi/arm-poky-linux-musleabi-gdb",
            "program": "${workspaceRoot}/Firmware/out/debug/exe.unstripped/eGYM_Backbone.out",
            "MIMode": "gdb",
            "sourceFileMap": {
                "${workspaceRoot}/Firmware": "Firmware"
            },
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true,
                }
            ]
        }
    ]
}

Following the numbers on the tasks array you will see that when I press F5, it build and pack the project (1), deploy it to the target device (3), ask the device to go into the debug mode (4).

The step 4 is where my problem exist. In order for the device to be able to really start the gdbserver it requires me first to connect over telnet to the port 2342. So when I run this project I see this on the terminal:

image

That means the debugger actually started, and is listening on 2345. If you see from the launch.json it should be ok and the debugger should just be able to attach to it right? Except it doesn't. Even marking the task 4 as "isBackground": true, the task still hanging and VSCode still stuck on the running progress bar:

image

The fact is that, in order to debug, I need to follow the following tasks:

  1. Build the C/C++ code
  2. Pack the device image
  3. Deploy to the device
  4. Tell the device to enter debug mode
  5. Telnet to 2342 and keep the telnet running while at the same time let VSCode proceed
  6. Attach gdb to 2345
  7. When the debugger session is over, both gdb and telnet must be killed
  8. reboot

The current configs hand on 5.

This issue is basically "how can I run a background task that is used as preLaunchTask and that must keep the process running while the debugging session is running without block the debugger to actually run?".

So, can anyone point me what am I doing wrong with those configs in order to support that scenario?

PS: Please ignore the fact that it is an Azure Sphere MCU device as you may figure out by some usages of azsphere CLI over the tasks.json and that it has its own extension on VSCode marketplace. We don't want to use CMake and since it is a regular linux device with a public SDK/toolchain, it should work with regular C/C++ extension as well. We are using gn with ninja and everything works well (I can keep the telnet running on another terminal but that is far from ideal), except the F5 experience.

Thank you! I really appreciate any help!

vscodebot[bot] commented 4 years ago

This issue is caused by an extension, please file it with the repository (or contact) the extension has linked in its overview in VS Code or the marketplace for VS Code. See also our issue reporting guidelines.

Happy Coding!

weinand commented 4 years ago

Please file against the C++ extension.

galvesribeiro commented 4 years ago

@weinand it is not a CPP extension problem. It is the fact the VSCode isn't allowing me to run a task in back ground as it should. That is why I've opened the issue here...

galvesribeiro commented 4 years ago

@weinand I've opened it there but they said tasks.json problems are VSCode team problem... So, you say it is their problem, they said it is yours... Who can we finally hope for support?

pieandcakes commented 4 years ago

@weinand The title is misleading. @galvesribeiro is trying to call a task that he wants to leave running in the background and then to start debugging but the problem is he calls this task and it hangs there, never getting to the actual debugging step. If this is something in the extension that we need to fix, can you point me on where to look?

alexr00 commented 4 years ago

I think we actually fixed this already with https://github.com/microsoft/vscode/issues/66561 @galvesribeiro can you please see if your issue occurs in the latest release of VS Code?

galvesribeiro commented 4 years ago

Hello @alexr00!

It was fixed with that PR indeed. The problem was timing. Just like on the PR repro case you linked.

Thank you!