【问题标题】:C/C++ debugger failing to create and write to raise.c in WSL using VSCodeC/C++ 调试器无法使用 VSCode 在 WSL 中创建并写入 raise.c
【发布时间】:2021-08-03 21:01:24
【问题描述】:

我正在尝试在 WSL(2)(使用 Ubuntu)上使用 C 语言开发大学课程,但在使用 VSCode 中的 C/C++ 内置调试​​器(通过 C/C++ 扩展安装)时遇到问题。 对于我的测试,我正在运行以下代码:

#include <assert.h>
int main() {
    assert(1==0); 
    return 0;
}

运行到断言时,调试器出错,VSC 在右下角显示以下消息:

Unable to open 'raise.c': Unable to read file 'vscode-remote://wsl+ubuntu/build/glibc-eX1tMB/glibc-2.31/sysdeps/unix/sysv/linux/raise.c' (Error: Unable to resolve non-existing file 'vscode-remote://wsl+ubuntu/build/glibc-eX1tMB/glibc-2.31/sysdeps/unix/sysv/linux/raise.c').

我已经尝试了每一个教程、github 问题和 stackoverflow 问题的答案,但没有任何效果。

我有理由相信这与 VSC 没有某种写入/创建文件的权限有关,因为如果我按下 Create File(在消息中提示),它会说:

Unable to write file 'vscode-remote://wsl+ubuntu/build/glibc-eX1tMB/glibc-2.31/sysdeps/unix/sysv/linux/raise.c' (NoPermissions (FileSystemError): Error: EACCES: permission denied, mkdir '/build')

但是,如果我创建文件夹/buildchmod 777 它,它可以创建文件,但不能向其中写入任何内容。

谁有办法解决这个问题?

另外,raise.c 是什么,我为什么还需要它?

【问题讨论】:

    标签: visual-studio-code windows-subsystem-for-linux visual-studio-debugging


    【解决方案1】:

    根据GDB跳过功能:https://sourceware.org/gdb/onlinedocs/gdb/Skipping-Over-Functions-and-Files.html#Skipping-Over-Functions-and-FilesPuede将其添加到Launch.json中“configurations”下的“SetupCommands”中:

    {
    "description": "Skip glibc files",
    "text": "-interpreter-exec console \"skip -gfi build/glibc-YYA7BZ/glibc-2.31//**/*\""
    }
    

    但是没问题,添加WSL+Ubuntu/或者VSL+ubuntu,会忽略路径,不解决问题,其他环境可能有效,但是VSCode使用远程连接无效。根据文章编号811:Disable "Unable to open file" during debug 开发者说"Skip"命令也在网上找,目前(2019年1月27日)不知道有什么其他办法。但是这个问题下还有其他解决方案,不需要编译Glibc库:

    执行这个:

    $ sudo apt install glibc-source
    $ cd /usr/src/glibc
    $ sudo tar xvf glibc-2.31.tar.xz
    

    “2.31”要改成实际版本号Source,可以通过“LS”命令看到。然后将其添加到 Launch.json 的“设置”中

    "sourceFileMap": {
        "/build/glibc-YYA7BZ": "/usr/src/glibc"
    }
    

    “YYA7BZ”改成GLIBC后缀出现在错误信息中。如果这个方法无效,可以把路径改成:c:/users//AppData///local packages canonicalGroupLimited.ubuntuonWindows_79RHKP1FNDGSC//localstate//rootfs usr/src/glibc,其中79RHKP1FNDGSC应该改文件夹名上你自己的系统。

    现在搜索终端错误信息:

    Done "/usr/bin/gdb" --interpreter=mi --tty=${DbgTerm} 0<"/tmp/Microsoft-MIEngine-In-p3q623bu.gbr" 1>"/tmp/Microsoft-MIEngine-Out-s4xm3p6g.lqk"
    

    根据执行时的错误:ends Call After launch an instance of 'std :: logic_error',这是空指针造成的。这个问题的可能原因之一是我忘记在Launch.json的“Configurations”中的“Args”列表中添加必要的参数来添加运行程序。

    来源:https://programmerclick.com/article/54012533450/

    【讨论】:

      【解决方案2】:

      看到这个过程,类似的错误但在不同的环境中。 https://stackoverflow.com/a/48287761/16842210

      在我的例子中,我使用 try{}catch{} 来打印错误并看到了与 raise.c 无关的内容

      【讨论】:

        猜你喜欢
        • 2022-11-04
        • 1970-01-01
        • 1970-01-01
        • 2021-10-28
        • 2020-03-20
        • 2019-01-23
        • 2020-04-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多