首页 > 解决方案 > dbg 无法使用 WSL2 处理 VScode - 无法解析不存在的文件“vscode-remote://wsl+ubuntu-20.04..”

问题描述

我已经安装了 WSL2 和构建工具,一切都在 linux 控制台上运行良好(包括我能够使用 dbg 调试的测试 c++ 程序)。我现在正试图通过安装 VSCode 和几个扩展(c/c++ 和远程 WSL)在我的 windows10 机器上建立一个工作开发环境。

构建工作得很好,但是当我尝试调试时,在执行(F10)几行后我得到了错误:

Unable to open 'libc-start.c': Unable to read file 'vscode-remote://wsl+ubuntu-20.04/build/glibc-YYA7BZ/glibc-2.31/csu/libc-start.c' (Error: Unable to resolve non-existing file 'vscode-remote://wsl+ubuntu-20.04/build/glibc-YYA7BZ/glibc-2.31/csu/libc-start.c').

从那时起,调试器基本上不再工作了,每次按 F10(或 F11)时,我都会收到一个带有相同错误的新弹出窗口

错误和开发环境的屏幕截图

按下“创建文件”按钮会导致“无法写入文件 'vscode-remote://wsl+ubuntu-20.04....”(与上述相同的文件)。

在我的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": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": true,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

和我的tasks.json:

{
// See https://go.microsoft.com/fwlink/?LinkId=733558 
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
    {
        "type": "shell",
        "label": "C++ Compile",
        "command": "/usr/bin/g++",
        "args": ["-g","*.cpp","-o","${fileDirname}/${fileBasenameNoExtension}"],
        "options": {"cwd": "${workspaceFolder}"},
        "problemMatcher": ["$gcc"],
        "group": {"kind": "build","isDefault": true}
    }
]

}

在发布之前我已经搜索了很多。其他人在较早的帖子中也遇到过类似的问题,但他们中的大多数人声称这是一个老错误,他们说问题已通过升级解决。我正在运行我正在使用的所有东西的最新版本(包括 VSCode 和插件)。

提前感谢任何提供帮助的人。

标签: c++visual-studio-codewindows-subsystem-for-linuxvscode-debugger

解决方案


添加

"sourceFileMap": { "//wsl$/Ubuntu-20.04" : "/" }

到launch.json 为我解决了这个问题。


推荐阅读