Debugging 在VSCode中使用gdbserver调试时暂停-“;启动前任务';docker gdb&x27;无法跟踪。”;
摘要 <>我试图在一个DoCKER映像(Ubuntu)中调试一个C++程序,同时在我的主机系统(OS X)上使用VSCODEL作为IDE。在对gdbserver和VSCode任务进行了各种修补之后,我现在能够成功运行调试器,但每次启动调试会话时,VSCode都会挂起10秒钟,然后报告错误消息: “无法跟踪启动前任务‘docker gdb’。” 如果我点击这个错误,我可以正常地调试,但是每次调试10秒的等待是非常令人沮丧的 详细信息 我的Docker映像是通过以下方式启动的,因此我的源代码将装载在“app”目录中。安全设置是我在Stack Overflow的其他地方找到的,允许gdbserver:Debugging 在VSCode中使用gdbserver调试时暂停-“;启动前任务';docker gdb&x27;无法跟踪。”;,debugging,docker,visual-studio-code,gdbserver,vscode-tasks,Debugging,Docker,Visual Studio Code,Gdbserver,Vscode Tasks,摘要 我试图在一个DoCKER映像(Ubuntu)中调试一个C++程序,同时在我的主机系统(OS X)上使用VSCODEL作为IDE。在对gdbserver和VSCode任务进行了各种修补之后,我现在能够成功运行调试器,但每次启动调试会话时,VSCode都会挂起10秒钟,然后报告错误消息: “无法跟踪启动前任务‘docker gdb’。” 如果我点击这个错误,我可以正常地调试,但是每次调试10秒的等待是非常令人沮丧的 详细信息 我的Docker映像是通过以下方式启动的,因此我的源代码将装载在“a
docker run --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -it -v "$(pwd):/app" -w "/app" -p 9091:9091 {imageName} /bin/bash
在主机上启动调试会话时,我使用以下启动命令,将本地gdb连接到docker gdbserver,并运行启动前任务:
{
"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"
}
]
}
这是发射前任务的定义;它使用docker exec在相关可执行文件上杀死任何现有gdbserver并启动一个新的gdbserver:
{
"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"
}
]
}
启动调试会话时,我会立即获得以下预期输出:
创建流程./tests/ConfigurationTest.cpp_TestRunner;pid=1167
监听端口9091
现在,gdbserver已经准备就绪,我希望VSCode能够启动它的gdb。但是VSCode会等待10秒钟,然后弹出一个对话框,说“无法跟踪预启动任务docker gdb”。如果单击“无论如何调试”,调试会话将按预期恢复,并且似乎表现良好
我试过什么
10秒的等待时间听起来非常类似,因此我尝试使用带有“activeOnStart:true”的problemMatcher,正如这里所建议的那样。这没有效果
我认为问题可能在于docker exec命令正在前台运行,而VSCode正在等待它返回,因此我尝试使用-d(分离模式,在后台运行)执行docker exec,或者只是在docker命令的末尾添加一个“&”。同样,没有效果
有人能建议我怎么做才能摆脱这烦人的10秒等待吗
非常感谢。我今天遇到了同样的问题,我试图用调试器运行Mocha测试,vscode正在等待调试器完成启动前任务,这与我需要的相反-任务公开调试器,因此我需要它在“后台”运行-尽管如此,此配置为我修复了它 launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Docker: Attach to Mocha",
"port": 5858,
"address": "localhost",
"localRoot": "${workspaceFolder}/server",
"remoteRoot": "/usr/src/app/server",
"protocol": "inspector",
"preLaunchTask": "mocha-docker-debug"
}
]
}
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "mocha-docker-debug",
"type": "shell",
"command": "docker exec up-ibe-server-node npm run test-debug",
"group": "test",
"isBackground": true,
"presentation": {
"reveal": "never"
},
"problemMatcher": {
"owner": "mocha",
"fileLocation": "relative",
"pattern": [
{
"regexp": "^not\\sok\\s\\d+\\s(.*)$"
},
{
"regexp": "\\s+(.*)$",
"message": 1
},
{
"regexp": "\\s+at\\s(.*):(\\d+):(\\d+)$",
"file": 1,
"line": 2,
"column": 3
}
],
"background": {
"activeOnStart": true,
"beginsPattern":{
"regexp": "mocha*"
},
"endsPattern":{
"regexp": "Debugger listening*"
}
},
}
}
]
}
tasks.json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Docker: Attach to Mocha",
"port": 5858,
"address": "localhost",
"localRoot": "${workspaceFolder}/server",
"remoteRoot": "/usr/src/app/server",
"protocol": "inspector",
"preLaunchTask": "mocha-docker-debug"
}
]
}
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "mocha-docker-debug",
"type": "shell",
"command": "docker exec up-ibe-server-node npm run test-debug",
"group": "test",
"isBackground": true,
"presentation": {
"reveal": "never"
},
"problemMatcher": {
"owner": "mocha",
"fileLocation": "relative",
"pattern": [
{
"regexp": "^not\\sok\\s\\d+\\s(.*)$"
},
{
"regexp": "\\s+(.*)$",
"message": 1
},
{
"regexp": "\\s+at\\s(.*):(\\d+):(\\d+)$",
"file": 1,
"line": 2,
"column": 3
}
],
"background": {
"activeOnStart": true,
"beginsPattern":{
"regexp": "mocha*"
},
"endsPattern":{
"regexp": "Debugger listening*"
}
},
}
}
]
}
这里要注意的主要问题是isBackground
标志、beginsPattern
和endsPattern
正则表达式,这告诉“父”启动任务,当xxx从“子”打印到控制台时,它就完成了,vscode可以继续执行实际任务
这可能不是你所说的C++应用程序的确切问题,但我想也是出于同样的原因。
< P>我已经找到了一个非常实用的解决方案。 我正在使用以下预启动任务,而不需要isBackground和regex模式(检测任务执行的开始和结束),只需将gdbserver作为后台命令/作业启动,并结合少量睡眠:{
“标签”:“启动GDB远程调试器”,
“类型”:“外壳”,
“选择”:{
“cwd”:“${workspaceRoot}/”
},
“介绍”:{
“回声”:没错,
“透露”:“始终”,
“焦点”:错误,
“面板”:“共享”,
“revealProblems”:“onProblem”
},
“命令”:“clear;/ssh.py'cd/opt/bin/;(nohup gdbserver localhost:6666 myapp&);sleep 1',
“问题匹配者”:[]
},
可以找到整个gdbserver配置
根据我的经验,即使是在通过vpn的慢速连接上,这种方法也非常稳定。将
模式
与后台
参数结合使用也非常重要,否则它将无法工作。我必须添加一个填充模式
类似的“模式”:[{“regexp”:“*”,“file”:1,“location”:2,“message”:3}],
只是为了确保使用背景
开始模式
和结束模式
。