dbg无法在带有WSL2的VScode上运行-无法解析不存在的文件“ vscode-remote://wsl+ubuntu-20.04 ..”

问题描述

我已经安装了WSL2和构建工具,并且在Linux控制台上一切正常(包括我可以使用dbg调试的测试c ++程序)。 我现在正在尝试通过安装VSCode和几个扩展(c / c ++和Remote 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)时,我都会得到一个新的弹出式窗口,并且出现相同的错误

screenshot of error and dev environment

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

在我的launch.json文件之后

    {
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more @R_722_4045@ion,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
                }
            ]
        }
    ]
}

和我的task.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和插件)。

预先感谢任何帮助的人。

解决方法

添加

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

launch.json 为我解决了问题。