Search code examples
c++visual-studio-codegdbg++windows-subsystem-for-linux

GDB doesn't work: Cannot insert breakpoint 1. Cannot access memory at address [...]


I'm trying to setup my vscode to debug C++ programs using gdb from WSL. But I faced problem with gdb on my WSL 1 (Ubuntu 22.04 LTS). Whenever I try set a breakpoint and run a program, I get the following error:

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

The contents of the program don't matter, always getting the error. Code is compiled using the following line:

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

gdb version: GNU gdb (Ubuntu 12.0.90-0ubuntu1) 12.0.90
g++ version: 12.0.1 (also tried with 11.2.0 - no difference)

On windows with g++ and gdb from MinGW the problem doesn't exist, so this should mean I'm not using the gdb debugger wrong.


Edit: tried compiling gdb 11.2 from source as suggested in comments, but this did not fix the problem. Only difference is that it's not showing /proc/PID/mem warning now.

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

Edit 2: Compiled gdb 10.2 from source and it works, the problem does not appear. I don't know why it doesn't work with any version above 10.2. Is it gdb bug or WSL bug?


Solution

  • Fixed in newer versions: everything seems to work fine in gdb 13.1 on Ubuntu 23.04 (WSL).