GDB无法使用:无法插入断点1。无法访问地址[...]的内存。

6

我正在尝试使用WSL的gdb在vscode上调试C++程序。但是我在我的WSL 1(Ubuntu 22.04 LTS)上遇到了问题。每当我尝试设置断点并运行程序时,都会出现以下错误:

Starting program: /mnt/d/Informatics/vscode/test/a.out
warning: opening /proc/PID/mem file for lwp 7674.7674 failed: No such file or directory (2)
Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0x10e0

程序内容无关紧要,总是出现错误。代码使用以下行编译:

g++ -Wall -pedantic-errors -O2 -std=c++23 -ggdb3 -fdiagnostics-color=always /mnt/d/Informatics/vscode/test/*.cpp

gdb版本: GNU gdb (Ubuntu 12.0.90-0ubuntu1) 12.0.90
g++版本: 12.0.1 (也尝试过 11.2.0 - 没有区别)

在Windows上,使用MinGW提供的g++和gdb时,问题不存在,这应该意味着我没有错误地使用gdb调试器。


编辑:按照评论中的建议尝试了从源代码编译gdb 11.2,但未能解决问题。唯一的区别是现在不显示/proc/PID/mem警告。

Starting program: /mnt/d/Informatics/vscode/test/a.out
Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0x10e0

编辑2:从源代码编译gdb 10.2并且它能正常工作,问题没有出现。我不知道为什么任何高于10.2版本的都无法使用。这是gdb的bug还是WSL的bug?


你试过 Ubuntu 20.04 LTS 吗? - Philippe
@Philippe 不,我升级到了 Ubuntu 22.04,没有20.04版本。 - Lassie
1
好的,我刚在 Debian 上尝试过,它可以运行,所以问题可能是特定于操作系统或 GDB 版本。Debian 使用的是 GDB 10.1,Arch Linux 使用的是 GDB 12.1。现在我认为这个问题也涉及到版本号。 - Spundun
1
更新:不起作用:使用Arch软件包脚本本地构建和安装了gdb,出现相同的错误。 - Spundun
1
可以在ChromeOS上的Arch Linux上确认。 - Michaël
显示剩余14条评论
1个回答

0
在较新的版本中修复:在Ubuntu 23.04(WSL)上,使用gdb 13.1似乎一切正常运行。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接