Summary
I'm trying to debug a C++ program within a docker image (Ubuntu), while using VSCode as an IDE on my host system (OS X). After various tinkering with gdbserver and VSCode tasks, I'm now able to successfully run the debugger, but each time I launch a debugging session, VSCode hangs for 10 seconds, then reports the error message:
"The preLaunchTask 'docker gdb' cannot be tracked."
If I click through this error, I'm able to debug perfectly normally, but this 10 second wait each time I debug is massively frustrating.
Details
My Docker image is started via the following, so my source code is mounted in the 'app' directory. The security settings are ones I found elsewhere on Stack Overflow, required to allow gdbserver:
docker run --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -it -v "$(pwd):/app" -w "/app" -p 9091:9091 {imageName} /bin/bash
And when I launch a debugging session on the host, I use this launch command, connecting local gdb to the docker gdbserver, and running a pre-launch task:
{
"version": "0.2.0",
"configurations": [
{
"name": "Remote unit test",
"type": "cppdbg",
"request": "launch",
"program": "./tests/ConfigurationTest.cpp_TestRunner",
"miDebuggerServerAddress": "localhost:9091",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"preLaunchTask": "docker gdb"
}
]
}
This is the definition of the pre-launch task; it uses docker exec to kill any existing gdbserver and start a new one, on the relevant executable:
{
"version": "2.0.0",
"tasks": [
{
"label":"docker gdb",
"command": "docker exec {containerName} /bin/bash -c \"pkill gdbserver; gdbserver localhost:9091 ./tests/ConfigurationTest.cpp_TestRunner\"",
"isBackground": true,
"type": "shell"
}
]
}
When I launch a debugging session, I get the following output immediately, which is expected:
Process ./tests/ConfigurationTest.cpp_TestRunner created; pid = 1167
Listening on port 9091
At this point, gdbserver is ready to go, and I'd love VSCode to start up its gdb. But instead VSCode waits for 10 seconds before popping up a dialog saying '"The preLaunchTask 'docker gdb' cannot be tracked."'. If I click 'Debug Anyway', the debugging session resumes as expected, and seems to behave fine.
What have I tried
The 10 second wait time sounds very similar to https://github.com/Microsoft/vscode/issues/37997, so I've tried using a problemMatcher with 'activeOnStart:true', as suggested there. This had no effect.
I thought that maybe the problem was that the docker exec command was running in the foreground, and VSCode was waiting for it to return, so I've tried executing docker exec with -d (detached mode, runs in the background), or just adding a '&' to the end of the docker command. Again, no effect.
Can anyone suggest what I can do to get rid of this annoying 10 second wait?
Many thanks.