microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.53k stars 1.56k forks source link

[gdbserver] Tasks.json task stuck even when isBackground = true #5005

Closed galvesribeiro closed 3 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!

pieandcakes commented 4 years ago

@galvesribeiro I don't have as much experience with task.json as that is a feature wholly owned by the actual VS Code team (https://github.com/microsoft/vscode) but it looks like that task isn't completing so its hung on step 5 and you are wondering what can be done to get around it.

I think the way tasks.json is supposed to work is that it is sequential and that each task is meant to complete before the next "task" (or debug) is supposed to be kicked off. You may want to reach out to that team first to see if what you are attempting is supposed to work or not.

galvesribeiro commented 4 years ago

@pieandcakes Thanks for the reply. The problem is that they told it is an extension problem and they told me to open the issue here (https://github.com/microsoft/vscode/issues/91342#issuecomment-590777355).

So, who would be the one that can help us? o.O

github-actions[bot] commented 3 years ago

This issue has been closed automatically because it's labeled as 'external'.