visual-studio-code - VSCode、WSL 和 Docker - 使用 gdbserver 进行调试
问题描述
我想用 VSCode 调试 C++ 应用程序,在 WSL 内部的 docker 容器中运行。
我目前的设置:
- VSCode 在宿主 Windows 机器上运行。远程安装的“Native Debug”扩展(应该在本地安装?)
- 源代码在 WSL Ubuntu 发行版中,VScode 与 WSL-Remote 连接。
- 该应用程序可以从安装了 gdbserver 的 docker 容器中执行。容器具有固定 IP (172.17.0.2)。
我已经在容器上运行了 gdbserver:
gdbserver 172.17.0.2:9999 /path/to/app
如何将 VScode 附加到 gdbserver,在 WSL 上的容器中运行?
这是我已经尝试过的方法以及结果:
-
{ "name": "Simple Native Plugin", "type": "gdb", "request": "attach", "executable": "./app", "target": "172.17.0.2:9999", "cwd": "${workspaceRoot}", "remote": true },
结果:
Could not start debugger process, does the program exist in filesystem?
Error: spawn gdb ENOENT
-
{ "name": "(gdb) Attach - WSL - Native Plugin", "type": "gdb", "request": "attach", "target" : "172.17.0.2:9999", "remote" : true, "executable": "${workspaceFolder}/app", "gdbpath": "/usr/bin/gdbserver", "cwd": "${workspaceRoot}", },
结果:
undefined/bin/bash: line 0: exec: -q: invalid option
exec: usage: exec [-cl] [-a name] [command [arguments ...]] [redirection ...]
During startup program exited with code 2.
Exiting
-
{ "name": "(gdb) Launch - WSL - CPPdbg Plugin", "type": "cppdbg", "request": "launch", "remote" : true, "miDebuggerServerAddress": "172.17.0.2:9999", "miDebuggerPath": "/usr/bin/gdbserver", "program": "${workspaceFolder}/app", "args": [], "stopAtEntry": false, "cwd": "${workspaceRoot}", "externalConsole": true, "linux": { "MIMode": "gdb", }, "windows": { "MIMode": "gdb" } }
结果:
Starting: "/usr/bin/gdbserver" --interpreter=mi
Unknown argument: --interpreter=mi
"/usr/bin/gdbserver" exited with code 1 (0x1).
解决方案
你的第二次尝试几乎是正确的。尝试输入路径 togdb
而不是gdbserver
in gdbpath
。
推荐阅读
- git - 如何使用 Sourcetree 从 git 中卸载中间提交?
- php - Google OAuth 2.0:刷新 access_token
- typescript - 无法理解呼叫签名
- c - 为什么我的 NAPI 轮询函数会导致 CPU 使用率过高?
- ruby-on-rails - 在 Ruby on Rails 上正确安装 Google Analytics
- azure - 具有 ADLS Gen 2 安全访问的 Azure Databricks
- c++ - 该程序接收数字输入并存储,当输入为 42 时,它停止接收输入并打印存储的接收输入
- laravel - Laravel eloquent 比较两个 withCount 值
- tfs - 如何解决以下 xmlns MSBuild 错误?
- android - Android:Finsky 强制停止我的应用程序