gdbgui icon indicating copy to clipboard operation
gdbgui copied to clipboard

Attach to a running process from command line.

Open Veritasosrb opened this issue 4 years ago • 22 comments

Describe the bug I am not sure if this can be treated as a bug. But it would be great to have the capability to attach to a running process from the command line. eg : gdbgui --attach_process 3434 where 3434 is the PID of the process.

To Reproduce Steps to reproduce the behavior: We do not have a way to do so.

Expected behavior Launch browser with the process attached.

Screenshots None.

Please complete the following information:

  • OS:
  • gdbgui version (gdbgui -v):
  • gdb version (gdb -v):
  • browser [e.g. chrome, safari]:
  • python packages (pip freeze):

Additional context Add any other context about the problem here.

Veritasosrb avatar Aug 31 '19 18:08 Veritasosrb

gdbgui --gdb-args "-p 3434" should work.

bjorn3 avatar Aug 31 '19 18:08 bjorn3

I was able to attach to an already running process but i am unable to debug it. After applying the breakpoint on any line when ever I press the continue button i see the below error.

Screen1: Attached to a process and applied breakpoint. image

Screen2: Error and nothing happen further. No gdb response received after 10 seconds. Possible reasons include:

  1. gdbgui, gdb, or the debugged process is not running.
  2. gdb or the inferior process is busy running and needs to be interrupted (press the pause button up top).
  3. Something is just taking a long time to finish and respond back to this browser window, in which case you can just keep waiting.
image

gkaushal avatar Sep 20 '19 07:09 gkaushal

Did you try interrupting the inferior process? If that doesn't help, you may try running as sudo since sometimes the OS restricts you from debugging running processes.

cs01 avatar Sep 20 '19 16:09 cs01

yes, i did try with sudo and interrupting the process but that did not help. Though if i run gdbgui by giving the process name like 'gdbgui test', I am able to debug it.

But my requirement is to attach to the already running process, and i a struck. Is there some kind of logging for troubleshooting the issue.

Please advice.

gkaushal avatar Sep 20 '19 18:09 gkaushal

You might want to try this using gdb in the terminal first to confirm it works, then try with gdbgui.

cs01 avatar Sep 20 '19 19:09 cs01

gdb terminal is running fine. image

I am also able to debug when i launch the gdbgui with the program name "gbdgui test"

The problem is only with attach to process. once the process is attached the gdb does not talk with the frontend. I am able to see this on multiple machines. LinuxRHEL, MAC and CentOS.

I am really in a bind here.

Even If i send gdb commands from the command windows in the gdbgui after attaching. The browser shows the error.

image

I found the below call stack on the terminal running gbgui image

gkaushal avatar Sep 23 '19 11:09 gkaushal

Any suggestions anyone? This blocker is preventing me to use this amazing debugging tool.

gkaushal avatar Sep 26 '19 10:09 gkaushal

Anyone Anywhere?

gkaushal avatar Sep 30 '19 12:09 gkaushal

Here are some things to try:

  • Confirm gdb can debug the process by attaching to it (not by running the test binary since that already works in gdbgui and therefore doesn't provide any additional information)
  • Run gdbgui with the --debug flag and see if anything else relevant is printed to the terminal before that stack trace shows up

cs01 avatar Sep 30 '19 15:09 cs01

I confirmed the things asked.

  1. gdb can debug the attached process. image

  2. I tried launching gdb with --debug mode. image

After that i went to the browser and tried to attach the process and debug it. image

The break-point gets hit but everytime i press the continue button the browser takes me to assembly view. Though the gdbgui did not hang this time.

image

gkaushal avatar Oct 01 '19 18:10 gkaushal

So you're good?

cs01 avatar Oct 01 '19 18:10 cs01

Not Exactly. :) How to get rid of the assembly view. I just want to debug my code line by line, but everytime i press continue button., GUI changes to assembly view and code is not visible. This is a problem while debugging the code.

gkaushal avatar Oct 01 '19 18:10 gkaushal

If you press continue a second time, does it jump to your breakpoint?

cs01 avatar Oct 01 '19 18:10 cs01

no. just momentarily the code flashes and again goes back to assembly screen.

gkaushal avatar Oct 01 '19 19:10 gkaushal

I'm struggling with this on my Ubuntu 18.04 VM running on a Mac with OS High Sierra.

I'm using Firefox, and the various versions are at the bottom of this comment.

My problem is to debug an ncurses application, so I want to attach gdbgui to a running process.

I've tried numerous command-lines, the most recent being:

gdbgui --gdb-args='-p 30847'

where 30847 is the PID of the program but none gets me into the already-running program. I usually get a ptrace error.

parallels@parallels-Parallels-Virtual-Platform:~$ gdbgui -v 0.13.2.0 parallels@parallels-Parallels-Virtual-Platform:~$ gdb -v GNU gdb (Ubuntu 8.1-0ubuntu3.2) 8.1.0.20180409-git Copyright (C) 2018 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-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: http://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". parallels@parallels-Parallels-Virtual-Platform:~$ pip freeze asn1crypto==0.24.0 cryptography==2.1.4 enum34==1.1.6 idna==2.6 ipaddress==1.0.17 keyring==10.6.0 keyrings.alt==3.0 pycrypto==2.6.1 pygobject==3.26.1 pyxdg==0.25 SecretStorage==2.3.1 six==1.11.0 parallels@parallels-Parallels-Virtual-Platform:~$ ^C

MichaelHendry avatar Apr 15 '20 17:04 MichaelHendry

Does gdb -p <pid> work, or does it have the same error? If it has the same error, please post the error itself.

bjorn3 avatar Apr 15 '20 17:04 bjorn3

GNU gdb (Ubuntu 8.1-0ubuntu3.2) 8.1.0.20180409-git Copyright (C) 2018 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-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: http://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". Attaching to process 30847 Could not attach to process. If your uid matches the uid of the target process, check the setting of /proc/sys/kernel/yama/ptrace_scope, or try again as the root user. For more details, see /etc/sysctl.d/10-ptrace.conf ptrace: Operation not permitted.

MichaelHendry avatar Apr 15 '20 17:04 MichaelHendry

Your system is configured in a way to only allow debugging processes spawned by the debugger. What is the output of cat /proc/sys/kernel/yama/ptrace_scope? If it isn't 0, try echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope to disable this restriction until a reboot.

bjorn3 avatar Apr 15 '20 17:04 bjorn3

This is looking more promising, thanks!

I'm getting stuck now on a missing file - will need to pursue this later.

Attaching to process 30847 Reading symbols from /usr/local/bin/llines...done. Reading symbols from /lib/x86_64-linux-gnu/libncursesw.so.5...(no debugging symbols found)...done. Reading symbols from /lib/x86_64-linux-gnu/libtinfo.so.5...(no debugging symbols found)...done. Reading symbols from /lib/x86_64-linux-gnu/libm.so.6...Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/libm-2.27.so...done. done. Reading symbols from /lib/x86_64-linux-gnu/libc.so.6...Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/libc-2.27.so...done. done. Reading symbols from /lib/x86_64-linux-gnu/libdl.so.2...Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/libdl-2.27.so...done. done. Reading symbols from /lib64/ld-linux-x86-64.so.2...Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/ld-2.27.so...done. done. 0x00007ff07f0a5081 in __GI___libc_read (fd=0, buf=0x7ffc86ed3f7f, nbytes=1) at ../sysdeps/unix/sysv/linux/read.c:27 27 ../sysdeps/unix/sysv/linux/read.c: No such file or directory.

MichaelHendry avatar Apr 15 '20 18:04 MichaelHendry

It should work despite that error. It just says that it couldn't find the source of libc.

bjorn3 avatar Apr 15 '20 18:04 bjorn3

Thanks, Bjorn, that's got me on the road again! Michael

MichaelHendry avatar Apr 16 '20 10:04 MichaelHendry

Hi!

I would like also to be able to attach to a running process like I do it with ddd and gdb.

I can't get it fully working right now gdbgui...

When I launch ddd or gdb from my program (via execvp), I give the following arguments:

gdb path_to_exe pid

and it works like a charm.

I tried many thing to launch gdbgui but it never gave me the gdbgui launched at execution point with the executable symbols loaded...

I tried:

gdbgui --gdb-args='path_to_exec pid'
gdbgui --gdb-args='-p pid path_to_exec'

It opens up, but there is no stack... no symbols...

Looking at what is running, I can see:

ericc   10360 10358 17 22:41 ?        00:00:02 /usr/bin/python3 /usr/bin/gdbgui --gdb-args='-p 10372 /home/mefpp_ericc/GIREF/bin/Test.MEF++.dev'
ericc    10505 10360  0 22:41 pts/23   00:00:00 gdb -iex=new-ui mi2 /dev/pts/22 -iex=set inferior-tty /dev/pts/21 -iex=set pagination off

And here is what i get into the windows of gdbgui:

image

Where am I wrong?

Thanks, Eric

ericch1 avatar Feb 24 '22 03:02 ericch1