简体   繁体   中英

How do I get VS Code on WSL to debug my C++ code?

I have installed Ubuntu 20.04 on my Windows 10 system. Before I first ran VS Code from within Ubuntu, VS Code worked fine in Windows. Now, I can build my C++ app there, but cannot debug it. I get an alert box saying "Cannot find runtime 'node' on PATH. Is 'node' installed?"

Whenever I start VS Code, a background process called 'node' also starts, so I presume VS Code starts it. My Ubuntu installation has about eight versions of node.js in various subdirectories of ~/.vscode-server.

Here is my 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>/**"
            ]
        },
    ]
}

I tried installing the newest nodejs. I no longer get the alert box with the not found message, but the debug console in VS Code now shows:

/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

Some time ago for me also was tricky to run debugger on VS Code under WSL Ubuntu. With a lot of attempts I have got next .vscode/launch.json file:

{
    // 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
                }
            ]
        }
    ]
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM