WSL icon indicating copy to clipboard operation
WSL copied to clipboard

gdb not able to debug

Open vingocheng opened this issue 3 years ago • 41 comments

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

  1. write a simple test.c to output hello world
  2. run 'gcc -g test.c'
  3. gdb a.out
  4. in gdb , input "l main" , "b main", "run"
  5. 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

vingocheng avatar Jun 16 '22 06:06 vingocheng

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

fazaldegui avatar Aug 10 '22 11:08 fazaldegui

Thanks a lot for your reply. I tested the patch, it can work well.

Also this not happened on WSL-2

Regards

vingocheng avatar Aug 11 '22 02:08 vingocheng

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?

wsourdeau avatar Dec 06 '22 23:12 wsourdeau

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

jdknox avatar Dec 23 '22 07:12 jdknox

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.

vingocheng avatar Dec 26 '22 02:12 vingocheng

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. ^_^

vingocheng avatar Dec 26 '22 02:12 vingocheng

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

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.

etorth avatar Dec 29 '22 05:12 etorth

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

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.

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.

quiret avatar Jan 04 '23 13:01 quiret

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.

wsourdeau avatar Jan 04 '23 14:01 wsourdeau

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

leha-bot avatar Feb 17 '23 16:02 leha-bot

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.

orodri avatar Feb 23 '23 22:02 orodri

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.

aaron-jencks avatar Feb 26 '23 05:02 aaron-jencks

  1. Download the GDB source code and compile under WSL
  2. Remove the pre-installed GDB
  3. install the new build GDB, it can work.

vingocheng avatar Feb 28 '23 02:02 vingocheng

  1. Download the GDB source code and compile under WSL
  2. Remove the pre-installed GDB
  3. install the new build GDB, it can work.

not work for me, which gdb version you are using?

etorth avatar Feb 28 '23 02:02 etorth

The version is : 13.1 Package : https://ftp.gnu.org/gnu/gdb/gdb-13.1.tar.xz

vingocheng avatar Feb 28 '23 06:02 vingocheng

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!

etorth avatar Feb 28 '23 09:02 etorth

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.

mikecancilla avatar Mar 02 '23 04:03 mikecancilla

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

YuriSizuku avatar Mar 22 '23 16:03 YuriSizuku

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

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.

vingocheng avatar Apr 03 '23 07:04 vingocheng

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

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.

Yes, I compiled from the souce. I uninstalled the old version of gdb. And the gdb version shows that it is v13.1.

YuriSizuku avatar Apr 03 '23 08:04 YuriSizuku

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.

vingocheng avatar Apr 03 '23 08:04 vingocheng

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?

chandan22140 avatar Apr 15 '23 13:04 chandan22140

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.

orodri avatar Apr 15 '23 16:04 orodri

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.

wsourdeau avatar Apr 16 '23 18:04 wsourdeau

I agree with this solution if WSL2 work fine. BTW: I don't verify the solution at my environment.

vingocheng avatar Apr 17 '23 02:04 vingocheng

  1. Download the GDB source code and compile under WSL
  2. Remove the pre-installed GDB
  3. 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

stewpend0us avatar Apr 27 '23 19:04 stewpend0us

Thanks @stewpend0us , that worked for me!

ademyankov avatar May 05 '23 01:05 ademyankov

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.

ethindp avatar May 19 '23 18:05 ethindp

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

fengjixiong avatar Jun 07 '23 03:06 fengjixiong

You can install GDB from Ubuntu Support Team PPA if you don't want to rebuild GDB yourself.

tienntr avatar Jun 08 '23 03:06 tienntr