'During remote debugging, gdbserver is unable to connect to gdb client when debug session is invoked for the second time
For debugging an application which is already running on remote target (architecture: arm-linux-gnueabihf), I am using gdb from Linaro toolchain: GNU gdb (Linaro_GDB-2017.05) 7.12.1.20170417-git and on the target, gdbserver(GNU gdbserver (GDB) 7.12.1.20170417-git). I have ran the gdbserver on the remote target side in a multi mode as: 'gdbserver --multi :. The commands used for debugging the application (myApp) remotely, which is already running on remote target are highlighted in the gdb traces below. After the debug is complete, I want to detach my application (myApp) from gdb, because my application (myApp) should be running indefinitely. I tried the commands: detach, detach inferior id, but got the response that "Cannot execute this command while the target is running. Use the "interrupt" command to stop the target and then try again". I then tried to give interrupt command, keyboard interrupt. After this, I got back the gdb control, then I tried to quit the gdb session using "q" command. I response I got after this is: "A debugging session is active. Inferior 1 [process 12910] will be detached. Quit anyway? (y or n)". I entered "y" as my response which gave the response as: "Cannot execute this command while the target is running. Use the "interrupt" command to stop the target and then try again". This completed my gdb client session. At the remote target side, gdbserver responded to this quit as: "client connection closed". This debug session was successful. But as my gdbserver was in multi mode, when I try to start a new debug session and attach my running application (myApp) again to gdbserver which is already running in multi mode on the same port number, my gdb client at host is unable to connect to gdbserver at target side. This command is not executed: "target extended-remote 192.168.2.2:5000" Earlier with gdb 7.8 and gdbserver 7.8, I was able to successfully detach my running application (myApp). And the above scenario of attaching a process again to the same gdbserver used to work. But gdbserver 7.8 did not support debugging child process, hence i needed to move to gdb client and server 7.12, which supports child process debug. Detailed gdb traces are as follows:
> C:\Users\abc>arm-linux-gnueabihf-gdb
> GNU gdb (Linaro_GDB-2017.05) 7.12.1.20170417-git
Copyright (C) 2017 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 "--host=i686-w64-mingw32 --target=arm-linux-gnueabihf".
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".
(gdb) target extended-remote 192.168.2.2:5000
Remote debugging using 192.168.2.2:5000
(gdb) set detach-on-fork off
(gdb) set follow-fork-mode child
(gdb) attach 12910
Attaching to process 12910
Reading /home/root/myApp from remote target...
warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead.
Reading /home/root/myApp from remote target...
Reading symbols from target:/home/root/myApp...done.
Reading /lib/libdl.so.2 from remote target...
Reading /usr/lib/libffi.so.6 from remote target...
Reading /lib/libpthread.so.0 from remote target...
Reading /usr/lib/libstdc++.so.6 from remote target...
Reading /lib/libm.so.6 from remote target...
Reading /lib/libgcc_s.so.1 from remote target...
Reading /lib/libc.so.6 from remote target...
Reading /lib/ld-linux-armhf.so.3 from remote target...
Reading symbols from target:/lib/libdl.so.2...Reading /lib/libdl-2.22.so from remote target...
Reading /lib/.debug/libdl-2.22.so from remote target...
(no debugging symbols found)...done.
Reading symbols from target:/usr/lib/libffi.so.6...Reading /usr/lib/libffi.so.6.0.4 from remote target...
Reading /usr/lib/.debug/libffi.so.6.0.4 from remote target...
(no debugging symbols found)...done.
Reading symbols from target:/lib/libpthread.so.0...Reading /lib/libpthread-2.22.so from remote target...
Reading /lib/.debug/libpthread-2.22.so from remote target...
(no debugging symbols found)...done.
Reading symbols from target:/usr/lib/libstdc++.so.6...Reading /usr/lib/libstdc++.so.6.0.21 from remote target...
Reading /usr/lib/.debug/libstdc++.so.6.0.21 from remote target...
(no debugging symbols found)...done.
Reading symbols from target:/lib/libm.so.6...Reading /lib/libm-2.22.so from remote target...
Reading /lib/.debug/libm-2.22.so from remote target...
(no debugging symbols found)...done.
Reading symbols from target:/lib/libgcc_s.so.1...Reading /lib/.debug/libgcc_s.so.1 from remote target...
(no debugging symbols found)...done.
Reading symbols from target:/lib/libc.so.6...Reading /lib/libc-2.22.so from remote target...
Reading /lib/.debug/libc-2.22.so from remote target...
(no debugging symbols found)...done.
Reading symbols from target:/lib/ld-linux-armhf.so.3...Reading /lib/ld-2.22.so from remote target...
Reading /lib/.debug/ld-2.22.so from remote target...
(no debugging symbols found)...done.
Reading /lib/ld-linux-armhf.so.3 from remote target...
[New Thread 12910.12912]
[New Thread 12910.12913]
[New Thread 12910.12914]
[New Thread 12910.12915]
[New Thread 12910.12916]
[New Thread 12910.12917]
[New Thread 12910.12919]
[New Thread 12910.12920]
[New Thread 12910.12921]
[New Thread 12910.12922]
[New Thread 12910.12923]
[New Thread 12910.12924]
[New Thread 12910.12925]
[New Thread 12910.12926]
[New Thread 12910.12927]
[New Thread 12910.12928]
[New Thread 12910.13024]
[New Thread 12910.13025]
[New Thread 12910.13026]
[New Thread 12910.13027]
[New Thread 12910.13028]
[New Thread 12910.13029]
[New Thread 12910.13030]
[New Thread 12910.13031]
[New Thread 12910.13032]
[New Thread 12910.13033]
[New Thread 12910.13034]
[New Thread 12910.13041]
0x76885924 in nanosleep () from target:/lib/libc.so.6
(gdb) b printWithArgs1
Function "printWithArgs1" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (printWithArgs1) pending.
(gdb) c
Continuing.
Reading /home/root/libdebugTest.so from remote target...
[Switching to Thread 12910.13041]
Thread 29 "myApp" hit Breakpoint 1, printWithArgs1 (a=0x621011b0 " esha", b=12, c=45.6699982) at ..\debugTest.c:9
9 printf("\n\n a: %s, b: %d, c: %f\n\n", a, b, c);
(gdb) c
Continuing.
warning: Temporarily disabling breakpoints for unloaded shared library "target:/home/root/libdebugTest.so"
The target is not responding to interrupt requests.
Stop debugging it? (y or n) deQuit (expect signal SIGINT when the program is resumed)
(gdb) detach
Cannot execute this command while the target is running.
Use the "interrupt" command to stop the target
and then try again.
(gdb) i inferiors
Num Description Executable
* 1 process 12910 target:/home/root/myApp
(gdb) detach inferior 1
Cannot execute this command while the target is running.
Use the "interrupt" command to stop the target
and then try again.
(gdb) help detach inferior
Detach from inferior ID (or list of IDS).
(gdb) detach inferior 1
Cannot execute this command while the target is running.
Use the "interrupt" command to stop the target
and then try again.
(gdb) Quit (expect signal SIGINT when the program is resumed)
(gdb) detach inferior 1
Cannot execute this command while the target is running.
Use the "interrupt" command to stop the target
and then try again.
(gdb) detach
Cannot execute this command while the target is running.
Use the "interrupt" command to stop the target
and then try again.
(gdb) q
A debugging session is active.
Inferior 1 [process 12910] will be detached.
Quit anyway? (y or n) y
Cannot execute this command while the target is running.
Use the "interrupt" command to stop the target
and then try again.
At gdbserver side (Remote target), this message is displayed:
root@user:~# gdbserver --multi :5000
Listening on port 5000
Remote debugging from host 192.168.2.23
Attached; pid = 12910
client connection closed
Solution 1:[1]
Try to kill all the running task and remove and terminate the server and reconnect it his happining because some task is already running on your port
Go to command line and try to see for /f %p (path) do taskkill /f /pid %p
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | harsh dixit |
