带有 WSL 的 VSCode C++:GDB:无法设置控制终端:不允许操作

问题描述 投票:0回答:1

我想在我的 Windows 10 计算机上使用 WSL2 运行 C++ 代码。

到目前为止,我一步步遵循本指南:https://code.visualstudio.com/docs/cpp/config-wsl#_run-helloworldcpp

单击

Run C/C++ File
会显示错误消息:

&"warning: GDB: Failed to set controlling terminal: Operation not permitted\n"
[1] + Done                       "/usr/bin/gdb" --interpreter=mi --tty=${DbgTerm} 0<"/tmp/Microsoft-MIEngine-In-o2o5gmaj.nup" 1>"/tmp/Microsoft-MIEngine-Out-y3zvkit4.33t"

如果我点击

Debug C/C++ File
我会得到以下信息:

ERROR: Unable to start debugging. Unexpected GDB output from command "-exec-run". Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0x8002509
Cannot insert breakpoint 2.
Cannot access memory at address 0x800279c

The program '/mnt/d/workspace/cpp_tut/hello' has exited with code 42 (0x0000002a).

(请注意,我在 IDE 中只设置了一个断点,我不确定第二个断点来自哪里)

我在网上找到的唯一信息是,这应该已在 WSL2 中修复,但显然没有。为了理智起见,我检查了 g++ 是否是问题所在,但

g++ ./hello.cpp -o hello
似乎工作正常,所以我怀疑它是。

我有:

OS: Ubuntu 22.04.4 LTS on Windows 10 x86_64 
Kernel: 4.4.0-19041-Microsoft
g++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
GNU gdb (Ubuntu 12.1-0ubuntu1~22.04) 12.1
VSCode 1.86.2

不确定我应该提供哪些其他信息,提前谢谢。


编辑: 又做了一些实验。如果我自己在 g++ 输出文件上运行 gdb,我会得到以下结果:

$ gdb ./hello
(gdb) b main
Breakpoint 1 at 0x251d: file /mnt/d/workspace/cpp_tut/hello.cpp, line 8.
(gdb) r
Starting program: /mnt/d/workspace/cpp_tut/hello 
warning: opening /proc/PID/mem file for lwp 1887.1887 failed: No such file or directory (2)
Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0x8002509

如果我查看

/proc/
则没有
PID
目录。

c++ visual-studio-code gdb windows-subsystem-for-linux wsl-2
1个回答
0
投票

我通过降级到 GDB 10.2“修复”了这个问题(从源代码安装)

© www.soinside.com 2019 - 2024. All rights reserved.