如何在 WSL 上获取 VS Code 来调试我的 C++ 代码?
How do I get VS Code on WSL to debug my C++ code?
我已经在 Windows 10 系统上安装了 Ubuntu 20.04。在我第一次从 Ubuntu 中 运行 VS Code 之前,VS Code 在 Windows 中运行良好。现在,我可以在那里构建我的 C++ 应用程序,但无法对其进行调试。我收到一个警告框,上面写着 "Cannot find runtime 'node' on PATH. Is 'node' installed?"
每当我启动 VS Code 时,一个名为 'node' 的后台进程也会启动,所以我认为 VS Code 会启动它。我的 Ubuntu 安装在 ~/.vscode-server.
的各个子目录中有大约八个版本的 node.js
这是我的 launch.json:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/gametest",
"skipFiles": [
"<node_internals>/**"
]
},
]
}
我尝试安装最新的 nodejs。我不再收到带有未找到消息的警告框,但 VS Code 中的调试控制台现在显示:
/usr/bin/node /home/jon/projects/KSolve/gametest
Debugger listening on ws://127..... (can't copy from debug console window)
For help, ...
/home/jon/projects/KSolve/gametest:1
ELF(three squares)
^
SyntaxError: Invalid or unexpected token
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
...
...
Process exited with code 1
前段时间对我来说 运行 在 WSL Ubuntu 下的 VS Code 上调试器也很棘手。经过多次尝试,我得到了下一个 .vscode/launch.json
文件:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "test tree",
"type": "cppdbg",
"request": "launch",
"program": "enter program name, for example ${workspaceFolder}/tests/ttree",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/tests",
"environment": [],
"externalConsole": false,
"targetArchitecture": "x86_64",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
我已经在 Windows 10 系统上安装了 Ubuntu 20.04。在我第一次从 Ubuntu 中 运行 VS Code 之前,VS Code 在 Windows 中运行良好。现在,我可以在那里构建我的 C++ 应用程序,但无法对其进行调试。我收到一个警告框,上面写着 "Cannot find runtime 'node' on PATH. Is 'node' installed?"
每当我启动 VS Code 时,一个名为 'node' 的后台进程也会启动,所以我认为 VS Code 会启动它。我的 Ubuntu 安装在 ~/.vscode-server.
的各个子目录中有大约八个版本的 node.js这是我的 launch.json:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/gametest",
"skipFiles": [
"<node_internals>/**"
]
},
]
}
我尝试安装最新的 nodejs。我不再收到带有未找到消息的警告框,但 VS Code 中的调试控制台现在显示:
/usr/bin/node /home/jon/projects/KSolve/gametest
Debugger listening on ws://127..... (can't copy from debug console window)
For help, ...
/home/jon/projects/KSolve/gametest:1
ELF(three squares)
^
SyntaxError: Invalid or unexpected token
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
...
...
Process exited with code 1
前段时间对我来说 运行 在 WSL Ubuntu 下的 VS Code 上调试器也很棘手。经过多次尝试,我得到了下一个 .vscode/launch.json
文件:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "test tree",
"type": "cppdbg",
"request": "launch",
"program": "enter program name, for example ${workspaceFolder}/tests/ttree",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/tests",
"environment": [],
"externalConsole": false,
"targetArchitecture": "x86_64",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}