C/C++ 调试器无法使用 VSCode 在 WSL 中创建和写入 raise.c

C/C++ debugger failing to create and write to raise.c in WSL using VSCode

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

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

当运行进入assert时,调试器出错,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 问题和 Whosebug 问题的答案,但没有任何效果。

我有理由相信这与 VSC 对 write/create 文件没有某种权限有关,因为如果我按 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,为什么我仍然需要它?

看到这个过程,类似的错误,但在不同的环境。

在我的例子中,我使用 try{}catch{} 来打印错误并查看错误,与 raise.c

无关

根据GDB skip函数: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”命令也在网上找,目前(January 27, 2019)不知道还有什么办法。但是这个问题下还有其他的解决方法,不需要编译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//rootfsusr/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 launching an instance of 'std:: logic_error'这是空指针导致的。这个问题的可能原因之一是我忘记在Launch.json.

中的“Configurations”中的“Args”列表中添加一个运行程序所需的参数。

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