gdb not able to debug
Version
Microsoft Windows [版本 10.0.19042.1706]
WSL Version
- [ ] WSL 2
- [X] WSL 1
Kernel Version
Ubuntu-22.04 default version: 2
Distro Version
Ubuntu-22.04
Other Software
gdb --version GNU gdb (Ubuntu 12.0.90-0ubuntu1) 12.0.90 gcc --version gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0
Repro Steps
- write a simple test.c to output hello world
- run 'gcc -g test.c'
- gdb a.out
- in gdb , input "l main" , "b main", "run"
- it will report error : Starting program: /mnt/c/junk/a.out warning: opening /proc/PID/mem file for lwp 92.92 failed: No such file or directory (2) Warning: Cannot insert breakpoint 1. Cannot access memory at address 0x8001149
Expected Behavior
gdb is expecting to work.
Actual Behavior
as above input, you can find, gdb not able to work.
Diagnostic Logs
No response
The same here.
I've found a fix to the gdb binaries you can see in:
#8356
In brief, the new gdb doesn't have the fallback of using ptrace if /proc/[pid]/mem fails. It can be restored be modifying two byte of the gdb binary, as:
echo -ne '\x90\x90' | sudo dd of=/usr/bin/gdb seek=$((0x335bad)) bs=1 count=2 conv=notrunc
But this is just a "ugly" patch means the /proc/[pid]/mem is fix in WSL.
Regards
Thanks a lot for your reply. I tested the patch, it can work well.
Also this not happened on WSL-2
Regards
I am not sure I understand. You closed this bug because a hack has been found? The fundamental issue is still occurring, any plans to fix it?
This is happening on WSL2. Please reopen.
warning: opening /proc/PID/mem file for lwp 15355.15355 failed: No such file or directory (2)
Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0x8001150
$ wsl.exe --status
Default Distribution: Ubuntu-22.04
Default Version: 2
I am not sure I understand. You closed this bug because a hack has been found? The fundamental issue is still occurring, any plans to fix it?
yes, the hack has been verified and the hack can work. since it is a hack patch, not fix fundamental issue. Sorry, I am not a developer of this project. I will look at this issue further.
I will reopen this issue since you found it reopen. what are gdb/gcc version? I guess that information may help the real developer to address the issue.
BTW: I am not the developer of this project. ^_^
The same here. I've found a fix to the gdb binaries you can see in: #8356 In brief, the new gdb doesn't have the fallback of using ptrace if /proc/[pid]/mem fails. It can be restored be modifying two byte of the gdb binary, as:
echo -ne '\x90\x90' | sudo dd of=/usr/bin/gdb seek=$((0x335bad)) bs=1 count=2 conv=notruncBut this is just a "ugly" patch means the /proc/[pid]/mem is fix in WSL.
Regards
not work for me. This is crazy, halt hundreds of thousands people using gdb just because of some engineer's preference. I call this arrogance.
The same here. I've found a fix to the gdb binaries you can see in: #8356 In brief, the new gdb doesn't have the fallback of using ptrace if /proc/[pid]/mem fails. It can be restored be modifying two byte of the gdb binary, as:
echo -ne '\x90\x90' | sudo dd of=/usr/bin/gdb seek=$((0x335bad)) bs=1 count=2 conv=notruncBut this is just a "ugly" patch means the /proc/[pid]/mem is fix in WSL. Regardsnot work for me. This is crazy, halt hundreds of thousands people using gdb just because of some engineer's preference. I call this arrogance.
Life is quite sad, isn't it? The wrong people get to make decisions. Imagine how messed up life will become if random stupid AI get to make decisions like that.
I am not sure I understand. You closed this bug because a hack has been found? The fundamental issue is still occurring, any plans to fix it?
yes, the hack has been verified and the hack can work. since it is a hack patch, not fix fundamental issue. Sorry, I am not a developer of this project. I will look at this issue further.
Ah ok. I understand why you closed it. It's nice that some hack has been found but this shows a fundamental bug in the way WSL handles debugging traps. Thus I would indeed leave a WSL developer work on it properly and close it when the issue has been fixed.
Hey, guys, any updates on this? This bug is likely blocker for anyone which has to use any fresh versions of debuggers or any another software which wants to read /proc/pid/memory
@benhillis , may you add the /proc/ tag and take a look this bug, please (sorry for mention).
Thanks in advance.
upd.: Related bugs: #8356 #547
I built gdb 13.1 from source (released 2/19/23) and I am able to debug with it on WSL2 (Ubuntu 22.04.2 LTS) though I still get the warnings:
warning: opening /proc/self/mem file failed: No such file or directory (2)
warning: opening /proc/PID/mem file for lwp 31679.31679 failed: No such file or directory (2)
It is unclear to me whether building from source or using 13.1 was the (partial?) fix.
this "patch" didn't work for me, I don't remember having this issue back with ubuntu 18.04, maybe there's something there. I would switch back to that version, but I can't install valgrind in that version because of the libc6 issue.
- Download the GDB source code and compile under WSL
- Remove the pre-installed GDB
- install the new build GDB, it can work.
- Download the GDB source code and compile under WSL
- Remove the pre-installed GDB
- install the new build GDB, it can work.
not work for me, which gdb version you are using?
The version is : 13.1 Package : https://ftp.gnu.org/gnu/gdb/gdb-13.1.tar.xz
The version is : 13.1 Package : https://ftp.gnu.org/gnu/gdb/gdb-13.1.tar.xz
Yes it worked, although warnings are still there but not a show stopper anymore. Thanks man!
The version is : 13.1 Package : https://ftp.gnu.org/gnu/gdb/gdb-13.1.tar.xz
Thank you! This is the answer. Other solutions talk about going back to gdb 9.2, but you can not easily do that with Ubuntu 22.04.
The version is : 13.1 Package : https://ftp.gnu.org/gnu/gdb/gdb-13.1.tar.xz
Yes it worked, although warnings are still there but not a show stopper anymore. Thanks man!
Unfortunately this still not worked for me. Even a hello world can not access breakpoint. My enviroment is as below
NAME STATE VERSION
* Ubuntu-22.04 Running 2
docker-desktop Running 2
docker-desktop-data Running 2
GNU gdb (GDB) 13.1
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Here is the gdb information.
This is gdb ./hello
GNU gdb (GDB) 13.1
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./hello...
(gdb) b main
Breakpoint 1 at 0x1175: file hello.c, line 3.
e(gdb) run
Starting program: /d/Software/develop/VSCode/tools/example/vscode_c/hello
Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0x1169
(gdb) disassemble main
Dump of assembler code for function main:
0x0000000000001169 <+0>:
Cannot access memory at address 0x1169
This is through sudo gdb ./hello
GNU gdb (GDB) 13.1
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./hello...
(gdb) run
Starting program: /d/Software/develop/VSCode/tools/example/vscode_c/hello
process 3265 is executing new program: /usr/bin/bash
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
process 3265 is executing new program: /d/Software/develop/VSCode/tools/example/vscode_c/hello
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
5, sizeof(p)=8
hello world
[Inferior 1 (process 3265) exited normally]
(gdb) b main
Breakpoint 1 at 0x55c65d2d0175: file hello.c, line 3.
(gdb) run
Starting program: /d/Software/develop/VSCode/tools/example/vscode_c/hello
Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0x55c65d2d0169
The version is : 13.1 Package : https://ftp.gnu.org/gnu/gdb/gdb-13.1.tar.xz
Yes it worked, although warnings are still there but not a show stopper anymore. Thanks man!
Unfortunately this still not worked for me. Even a hello world can not access breakpoint. My enviroment is as below
NAME STATE VERSION * Ubuntu-22.04 Running 2 docker-desktop Running 2 docker-desktop-data Running 2 GNU gdb (GDB) 13.1 Copyright (C) 2023 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.Here is the gdb information.
This is
gdb ./helloGNU gdb (GDB) 13.1 Copyright (C) 2023 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-pc-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: <https://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from ./hello... (gdb) b main Breakpoint 1 at 0x1175: file hello.c, line 3. e(gdb) run Starting program: /d/Software/develop/VSCode/tools/example/vscode_c/hello Warning: Cannot insert breakpoint 1. Cannot access memory at address 0x1169 (gdb) disassemble main Dump of assembler code for function main: 0x0000000000001169 <+0>: Cannot access memory at address 0x1169This is through
sudo gdb ./helloGNU gdb (GDB) 13.1 Copyright (C) 2023 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-pc-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: <https://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from ./hello... (gdb) run Starting program: /d/Software/develop/VSCode/tools/example/vscode_c/hello process 3265 is executing new program: /usr/bin/bash [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". process 3265 is executing new program: /d/Software/develop/VSCode/tools/example/vscode_c/hello [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". 5, sizeof(p)=8 hello world [Inferior 1 (process 3265) exited normally] (gdb) b main Breakpoint 1 at 0x55c65d2d0175: file hello.c, line 3. (gdb) run Starting program: /d/Software/develop/VSCode/tools/example/vscode_c/hello Warning: Cannot insert breakpoint 1. Cannot access memory at address 0x55c65d2d0169
How did you get the 'gdb' program ? compile by yourself?
If you compiled by yourself, please also make sure the old installed version GDB is removed first, then install the version that you compiled by yourself.
The version is : 13.1 Package : https://ftp.gnu.org/gnu/gdb/gdb-13.1.tar.xz
Yes it worked, although warnings are still there but not a show stopper anymore. Thanks man!
Unfortunately this still not worked for me. Even a hello world can not access breakpoint. My enviroment is as below
NAME STATE VERSION * Ubuntu-22.04 Running 2 docker-desktop Running 2 docker-desktop-data Running 2 GNU gdb (GDB) 13.1 Copyright (C) 2023 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.Here is the gdb information. This is
gdb ./helloGNU gdb (GDB) 13.1 Copyright (C) 2023 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-pc-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: <https://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from ./hello... (gdb) b main Breakpoint 1 at 0x1175: file hello.c, line 3. e(gdb) run Starting program: /d/Software/develop/VSCode/tools/example/vscode_c/hello Warning: Cannot insert breakpoint 1. Cannot access memory at address 0x1169 (gdb) disassemble main Dump of assembler code for function main: 0x0000000000001169 <+0>: Cannot access memory at address 0x1169This is through
sudo gdb ./helloGNU gdb (GDB) 13.1 Copyright (C) 2023 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-pc-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: <https://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from ./hello... (gdb) run Starting program: /d/Software/develop/VSCode/tools/example/vscode_c/hello process 3265 is executing new program: /usr/bin/bash [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". process 3265 is executing new program: /d/Software/develop/VSCode/tools/example/vscode_c/hello [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". 5, sizeof(p)=8 hello world [Inferior 1 (process 3265) exited normally] (gdb) b main Breakpoint 1 at 0x55c65d2d0175: file hello.c, line 3. (gdb) run Starting program: /d/Software/develop/VSCode/tools/example/vscode_c/hello Warning: Cannot insert breakpoint 1. Cannot access memory at address 0x55c65d2d0169How did you get the 'gdb' program ? compile by yourself? If you compiled by yourself, please also make sure the old installed version GDB is removed first, then install the version that you compiled by yourself.
Yes, I compiled from the souce. I uninstalled the old version of gdb. And the gdb version shows that it is v13.1.
I think you need to double check your environment. you can see the main function address is different in your two cases (sudo, or no sudo). they should be the same function address as one program.
I think you need to double check your environment. you can see the main function address is different in your two cases (sudo, or no sudo). they should be the same function address as one program.
Beginner CS student here The gdb-13.1 directory has multiple directories and sub-directories, how can I compile them all, and after I compile the gdb source locally, what should I do next?
Beginner CS student here The gdb-13.1 directory has multiple directories and sub-directories, how can I compile them all, and after I compile the gdb source locally, what should I do next?
cd gdb-13.1
./configure
make
make install
After installing, confirm:
❯ gdb --version
GNU gdb (GDB) 13.1
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
I found out that WSL 2 does not have the issue. Since WSL 1 still seems to be supported, I think the bug should remain open but I believe an upgrade to WSL 2 would be a good recommendation.
I agree with this solution if WSL2 work fine. BTW: I don't verify the solution at my environment.
- Download the GDB source code and compile under WSL
- Remove the pre-installed GDB
- install the new build GDB, it can work.
This worked for me. Thanks @vingocheng !
for ubuntu 22.04 I did:
sudo apt remove gdb
sudo apt install libgmp-dev
wget https://ftp.gnu.org/gnu/gdb/gdb-13.1.tar.xz
tar -xf gdb-13.1.tar.xz
cd gdb-13.1/
./configure
make -j8
sudo make install
Thanks @stewpend0us , that worked for me!
I can confirm that the bug still occurs on WSL 1 (and I need WSL 1 because it's faster with NTFS interop). I'd prefer not to build my own GDB but... Erg. Guess I'll have to do that.
for ubuntu 22.04 I did:
sudo apt remove gdb sudo apt install libgmp-dev wget https://ftp.gnu.org/gnu/gdb/gdb-13.1.tar.xz tar -xf gdb-13.1.tar.xz cd gdb-13.1/ ./configure make -j8 sudo make install
That works for me, too! Besides, if someone wants tui, the following commands are needed:
sudo apt install libncurses5-dev
./configure --enable-tui=yes
then the "layout" command can be used in gdb
You can install GDB from Ubuntu Support Team PPA if you don't want to rebuild GDB yourself.