The remote protocol, and consequently GDBserver, does not support following forks. Multi-process remote debugging usefulness is quite limited on GNU/Linux due to this.
I plan to take this on.
Luis handed this off to me early this year. I've just posted a patch series implementing fork events: https://sourceware.org/ml/gdb-patches/2014-08/msg00145.html.
This work looks very interesting and very complete. What is the status of this work, is there a chance it could get into GDB mainline anytime soon ? Thanks!
This work has been merged already, and is present in 7.10. In mainline you'll find support for following execs as well.
Created attachment 8782 [details] Testcase Still I am not able to follow the fork and debug the child process with gdbserver, while without using gdbserver(running gdb alone) i am easily able to debug the Child Process. Steps to reproduce: $ ./gdbserver :12345 final-fork & Process final-fork created; pid = 13460 Listening on port 12345 $ ./gdb final-fork GNU gdb (GDB) 7.10.50.20151115-cvs Copyright (C) 2015 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This GDB was configured as "x86_64-pc-linux-gnu". Reading symbols from final-fork...done. [?1034h(gdb) target remote :12345 Remote debugging using :12345 Reading /lib64/ld-linux-x86-64.so.2 from remote target... Reading /lib64/ld-linux-x86-64.so.2 from remote target... Reading symbols from target:/lib64/ld-linux-x86-64.so.2...Reading /lib64/ld-2.18.so.debug from remote target... Reading /lib64/.debug/ld-2.18.so.debug from remote target... (no debugging symbols found)...done. 0x0000003b1f6011f0 in _start () from target:/lib64/ld-linux-x86-64.so.2 (gdb) b main Breakpoint 1 at 0x4006a8: file final-fork.c, line 13. (gdb) c Continuing. Reading /lib64/libc.so.6 from remote target... Reading /lib64/libc-2.18.so.debug from remote target... Reading /lib64/.debug/libc-2.18.so.debug from remote target... Breakpoint 1, main () at final-fork.c:13 13 pid = fork(); (gdb) set follow-fork-mode child (gdb) b ChildProcess Breakpoint 2 at 0x40072c: file final-fork.c, line 35. (gdb) c Continuing. pid of process :13468 pid of process :0 Parent Process invoking Invoking Child Process This line is from parent, value = 1 This line is from parent, value = 2 This line is from parent, value = 3 This line is from parent, value = 4 This line is from parent, value = 5 This line is from parent, value = 6 This line is from parent, value = 7 This line is from parent, value = 8 This line is from parent, value = 9 This line is from parent, value = 10 This line is from parent, value = 11 This line is from parent, value = 12 This line is from parent, value = 13 This line is from parent, value = 14 This line is from parent, value = 15 This line is from parent, value = 16 This line is from parent, value = 17 This line is from parent, value = 18 This line is from parent, value = 19 This line is from parent, value = 20 *** Parent is done *** Child exited with status 23 GDBserver exiting [Inferior 1 (process 13460) exited with code 027] [8]+ Stopped ./gdb final-fork NOTE:- Here I am not able to debug Child Process. Update me if I am doing anything wrong. Also Find the attached test-case. However When I run gdb alone I am getting the expected output as below: $ ./gdb final-fork GNU gdb (GDB) 7.10.50.20151115-cvs Copyright (C) 2015 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This GDB was configured as "x86_64-pc-linux-gnu". Reading symbols from final-fork...done. [?1034h(gdb) b main Breakpoint 1 at 0x4006a8: file final-fork.c, line 13. (gdb) r Starting program: /home/kpit/ran44/35-JIRA/gdb/i-gdb/bin/final-fork Breakpoint 1, main () at final-fork.c:13 13 pid = fork(); (gdb) set follow-fork-mode child (gdb) b ChildProcess Breakpoint 2 at 0x40072c: file final-fork.c, line 35. (gdb) c Continuing. [New process 13519] [Switching to process 13519] Breakpoint 2, ChildProcess () at final-fork.c:35 35 asm("nop"); (gdb) c Continuing. pid of process :0 Invoking Child Process This line is from child, value = 1 This line is from child, value = 2 This line is from child, value = 3 This line is from child, value = 4 This line is from child, value = 5 This line is from child, value = 6 This line is from child, value = 7 This line is from child, value = 8 This line is from child, value = 9 This line is from child, value = 10 This line is from child, value = 11 This line is from child, value = 12 This line is from child, value = 13 This line is from child, value = 14 This line is from child, value = 15 This line is from child, value = 16 This line is from child, value = 17 This line is from child, value = 18 This line is from child, value = 19 This line is from child, value = 20 *** Child process is done *** [Inferior 2 (process 13519) exited with code 041] (gdb) pid of process :13519 Parent Process invoking This line is from parent, value = 1 This line is from parent, value = 2 This line is from parent, value = 3 This line is from parent, value = 4 This line is from parent, value = 5 This line is from parent, value = 6 This line is from parent, value = 7 This line is from parent, value = 8 This line is from parent, value = 9 This line is from parent, value = 10 This line is from parent, value = 11 This line is from parent, value = 12 This line is from parent, value = 13 This line is from parent, value = 14 This line is from parent, value = 15 This line is from parent, value = 16 This line is from parent, value = 17 This line is from parent, value = 18 This line is from parent, value = 19 This line is from parent, value = 20 *** Parent is done *** (gdb) q
Just an idea, you might need gdbserver --multi such that the host GDB can attach to the forked child ? IMHO, if that is the case, there should be better error reporting eg the "set follow-fork-mode child" should report that the gdbserver hasn't been started with --multi.
Close. You need to connect with "target extended-remote" instead of "target remote". I just saw that Don recently posted patches to make this work with "target remote" too though: https://sourceware.org/ml/gdb-patches/2015-11/msg00209.html
This is now complete for both target extended-remote and target remote.