* fork debugging : back to parent.
@ 2006-08-07 20:21 Richard (sent by Nabble.com)
2006-08-07 21:07 ` Daniel Jacobowitz
2006-08-10 21:06 ` Richard
0 siblings, 2 replies; 11+ messages in thread
From: Richard (sent by Nabble.com) @ 2006-08-07 20:21 UTC (permalink / raw)
To: gdb
Below is the code from "Advanced programming in the Unix environment". if I
set follow-fork to child, I can step ok to the exclp line. But how do I get
back to debugging the parent process? Is it possible? I tried setting
follow-fork back to "parent" and then "c"ontinuing but no joy. or do I have
to specifically save process ids and reattach to the parent process?
=======
#include "apue.h"
#include <sys/wait.h>
int
main(void)
{
char buf[MAXLINE]; /* from apue.h */
pid_t pid;
int status;
printf("%% "); /* print prompt (printf requires %% to print %) */
while (fgets(buf, MAXLINE, stdin) != NULL) {
if (buf[strlen(buf) - 1] == '\n')
buf[strlen(buf) - 1] = 0; /* replace newline with null */
if ((pid = fork()) < 0) {
err_sys("fork error");
} else if (pid == 0) { /* child */
execlp(buf, buf, (char *)0);
err_ret("couldn't execute: %s", buf);
exit(127);
}
/* parent */
if ((pid = waitpid(pid, &status, 0)) < 0)
err_sys("waitpid error");
printf("%% ");
}
exit(0);
}
--
View this message in context: http://www.nabble.com/fork-debugging-%3A-back-to-parent.-tf2067795.html#a5693501
Sent from the gdb - General forum at Nabble.com.
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: fork debugging : back to parent. 2006-08-07 20:21 fork debugging : back to parent Richard (sent by Nabble.com) @ 2006-08-07 21:07 ` Daniel Jacobowitz 2006-08-07 21:47 ` Richard 2006-08-10 21:06 ` Richard 1 sibling, 1 reply; 11+ messages in thread From: Daniel Jacobowitz @ 2006-08-07 21:07 UTC (permalink / raw) To: Richard; +Cc: gdb On Mon, Aug 07, 2006 at 01:21:02PM -0700, Richard (sent by Nabble.com) wrote: > > Below is the code from "Advanced programming in the Unix environment". if I > set follow-fork to child, I can step ok to the exclp line. But how do I get > back to debugging the parent process? Is it possible? I tried setting > follow-fork back to "parent" and then "c"ontinuing but no joy. or do I have > to specifically save process ids and reattach to the parent process? Try using a recent version of GDB, and set follow-fork-mode to "both". This was added in GDB 6.5. -- Daniel Jacobowitz CodeSourcery ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: fork debugging : back to parent. 2006-08-07 21:07 ` Daniel Jacobowitz @ 2006-08-07 21:47 ` Richard 2006-08-08 0:04 ` Daniel Jacobowitz 0 siblings, 1 reply; 11+ messages in thread From: Richard @ 2006-08-07 21:47 UTC (permalink / raw) To: Richard; +Cc: gdb I have version 6.5.5 just build and confirmed with "show version" ,---- | show version | GNU gdb 6.5.50.20060806 | Copyright (C) 2006 Free Software Foundation, Inc. | GDB is free software, covered by the GNU General Public License, and you are | welcome to change it and/or distribute copies of it under certain conditions. | Type "show copying" to see the conditions. | There is absolutely no warranty for GDB. Type "show warranty" for details. | This GDB was configured as "i686-pc-linux-gnu". | > `---- set follow-fork-mode to both is not supported: ,---- | >help set follow | Set debugger response to a program call of fork or vfork. | A fork or vfork creates a new process. follow-fork-mode can be: | parent - the original process is debugged after a fork | child - the new process is debugged after a fork | The unfollowed process will continue to run. | By default, the debugger will follow the parent process. | >set follow-fork-mode both | Undefined item: "both". | >set follow-fork-mode child | > `---- Sorry, if I'm missing something obvious. How owuld I browse "recent features" in CVS? Daniel Jacobowitz <drow@false.org> writes: > On Mon, Aug 07, 2006 at 01:21:02PM -0700, Richard (sent by Nabble.com) wrote: >> >> Below is the code from "Advanced programming in the Unix environment". if I >> set follow-fork to child, I can step ok to the exclp line. But how do I get >> back to debugging the parent process? Is it possible? I tried setting >> follow-fork back to "parent" and then "c"ontinuing but no joy. or do I have >> to specifically save process ids and reattach to the parent process? > > Try using a recent version of GDB, and set follow-fork-mode to "both". > This was added in GDB 6.5. > > -- > Daniel Jacobowitz > CodeSourcery > -- ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: fork debugging : back to parent. 2006-08-07 21:47 ` Richard @ 2006-08-08 0:04 ` Daniel Jacobowitz 2006-08-08 7:27 ` Richard 2006-08-08 8:49 ` Richard 0 siblings, 2 replies; 11+ messages in thread From: Daniel Jacobowitz @ 2006-08-08 0:04 UTC (permalink / raw) To: Richard; +Cc: Richard, gdb On Mon, Aug 07, 2006 at 11:47:03PM +0200, Richard wrote: > set follow-fork-mode to both is not supported: Sorry, try turning off detach-on-fork. See "help set". > Sorry, if I'm missing something obvious. How owuld I browse "recent > features" in CVS? Take a look at the NEWS file. -- Daniel Jacobowitz CodeSourcery ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: fork debugging : back to parent. 2006-08-08 0:04 ` Daniel Jacobowitz @ 2006-08-08 7:27 ` Richard 2006-08-08 8:49 ` Richard 1 sibling, 0 replies; 11+ messages in thread From: Richard @ 2006-08-08 7:27 UTC (permalink / raw) To: Richard; +Cc: Richard, gdb Daniel Jacobowitz <drow@false.org> writes: > On Mon, Aug 07, 2006 at 11:47:03PM +0200, Richard wrote: >> set follow-fork-mode to both is not supported: > > Sorry, try turning off detach-on-fork. See "help set". > >> Sorry, if I'm missing something obvious. How owuld I browse "recent >> features" in CVS? > > Take a look at the NEWS file. > > -- > Daniel Jacobowitz > CodeSourcery > I tried setting detach-on-fork to off and follow-fork to "child" and it all just froze. Possibly I'm misunderstanding its use? Could you advise on its intended use and how it integrates with follow-fork-mode or catch fork? I set follow to "child", detach to "off" and then "info fork" reported no forks after the fork() call while in the childs code. "both" is now removed for "follow-fork"? ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: fork debugging : back to parent. 2006-08-08 0:04 ` Daniel Jacobowitz 2006-08-08 7:27 ` Richard @ 2006-08-08 8:49 ` Richard 2006-08-08 13:16 ` Daniel Jacobowitz 1 sibling, 1 reply; 11+ messages in thread From: Richard @ 2006-08-08 8:49 UTC (permalink / raw) To: Richard; +Cc: Richard, gdb Daniel Jacobowitz <drow@false.org> writes: > On Mon, Aug 07, 2006 at 11:47:03PM +0200, Richard wrote: >> set follow-fork-mode to both is not supported: > > Sorry, try turning off detach-on-fork. See "help set". > >> Sorry, if I'm missing something obvious. How owuld I browse "recent >> features" in CVS? > > Take a look at the NEWS file. > > -- > Daniel Jacobowitz > CodeSourcery > I think I answered my own question: By setting follow to parent and detach to off, one can use info fork in the parent thread in order to switch to the child thread. If follow is set to child and detach is off, then there is no fork info in the child for some reason so you cant switch back to the parent. Is this a bug? (1) follow parent and then switch to the child fork - we end up at our childs breakpoint "pit_t par=" etc... ,---- | >set follow parent | >set detach off | >c | Continuing. | % date | Breakpoint 3, main () at forkcmd.c:31 | 31 if ((pid = waitpid(pid, &status, 0)) < 0) | >info fork | 1 process 11319 at 0xffffe410, <__kernel_vsyscall> | * 0 process 11308 (main process) at 0x80487e6, file forkcmd.c, line 31 | >fork 1 | Reading in symbols for ../sysdeps/i386/elf/start.S...done. | Switching to process 11319 | #0 __kernel_vsyscall () | >c | Continuing. | | Breakpoint 2, main () at forkcmd.c:23 | 23 pid_t par = getppid(); | > `---- (2) try to follow child to a break and switch back to parent fork : not possible. ,---- | >set follow child | >run | The program being debugged has been started already. | Start it from the beginning? (y or n) y | Starting program: etc | Reading symbols from system-supplied DSO at 0xffffe000...done. | Reading symbols from /lib/tls/i686/cmov/libc.so.6...done. | Reading symbols from /lib/ld-linux.so.2...done. | | Breakpoint 1, main () at forkcmd.c:11 | 11 printf("%% "); /* print prompt (printf requires %% to print %) */ | >c | Continuing. | % date | [New process 11385] | | Program received signal SIGINT, Interrupt. | __kernel_vsyscall () | >c | Continuing. | c | | Program received signal SIGINT, Interrupt. | __kernel_vsyscall () | >info fork | * 2 process 11385 at 0xffffe410, <__kernel_vsyscall> `---- Am I misunderstandong something? Thanks for any help. -- ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: fork debugging : back to parent. 2006-08-08 8:49 ` Richard @ 2006-08-08 13:16 ` Daniel Jacobowitz 0 siblings, 0 replies; 11+ messages in thread From: Daniel Jacobowitz @ 2006-08-08 13:16 UTC (permalink / raw) To: Richard; +Cc: Richard, gdb On Tue, Aug 08, 2006 at 10:49:41AM +0200, Richard wrote: > By setting follow to parent and detach to off, one can use info fork in > the parent thread in order to switch to the child thread. > > If follow is set to child and detach is off, then there is no fork info > in the child for some reason so you cant switch back to the parent. Is > this a bug? Yes, this does sound like a bug. -- Daniel Jacobowitz CodeSourcery ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: fork debugging : back to parent. 2006-08-07 20:21 fork debugging : back to parent Richard (sent by Nabble.com) 2006-08-07 21:07 ` Daniel Jacobowitz @ 2006-08-10 21:06 ` Richard 2006-08-10 21:39 ` Daniel Jacobowitz 1 sibling, 1 reply; 11+ messages in thread From: Richard @ 2006-08-10 21:06 UTC (permalink / raw) To: gdb Incidentally, I also tried "set $tmp=parent_id" (I made an api call to get the parent proc id in the child fork), and in the child I tried to "attach $tmp", but it said there was no such process. Is it not possible to use convenience variables for things like "attach"? "attach parent_id" worked fine. Richard wrote: > > Below is the code from "Advanced programming in the Unix environment". if > I set follow-fork to child, I can step ok to the exclp line. But how do I > get back to debugging the parent process? Is it possible? I tried setting > follow-fork back to "parent" and then "c"ontinuing but no joy. or do I > have to specifically save process ids and reattach to the parent process? > > ======= > #include "apue.h" > #include <sys/wait.h> > > int > main(void) > { > char buf[MAXLINE]; /* from apue.h */ > pid_t pid; > int status; > > printf("%% "); /* print prompt (printf requires %% to print %) */ > while (fgets(buf, MAXLINE, stdin) != NULL) { > if (buf[strlen(buf) - 1] == '\n') > buf[strlen(buf) - 1] = 0; /* replace newline with null */ > > if ((pid = fork()) < 0) { > err_sys("fork error"); > } else if (pid == 0) { /* child */ > execlp(buf, buf, (char *)0); > err_ret("couldn't execute: %s", buf); > exit(127); > } > > /* parent */ > if ((pid = waitpid(pid, &status, 0)) < 0) > err_sys("waitpid error"); > printf("%% "); > } > exit(0); > } > -- View this message in context: http://www.nabble.com/fork-debugging-%3A-back-to-parent.-tf2067795.html#a5752608 Sent from the gdb - General forum at Nabble.com. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: fork debugging : back to parent. 2006-08-10 21:06 ` Richard @ 2006-08-10 21:39 ` Daniel Jacobowitz 2006-08-10 22:06 ` Richard 0 siblings, 1 reply; 11+ messages in thread From: Daniel Jacobowitz @ 2006-08-10 21:39 UTC (permalink / raw) To: Richard; +Cc: gdb On Thu, Aug 10, 2006 at 02:06:38PM -0700, Richard wrote: > > > Incidentally, I also tried "set $tmp=parent_id" (I made an api call to get > the parent proc id in the child fork), and in the child I tried to "attach > $tmp", but it said there was no such process. Is it not possible to use > convenience variables for things like "attach"? "attach parent_id" worked > fine. Yes, I don't think convenience variables are supported there - some targets may not use numbers for these identifiers, in theory. -- Daniel Jacobowitz CodeSourcery ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: fork debugging : back to parent. 2006-08-10 21:39 ` Daniel Jacobowitz @ 2006-08-10 22:06 ` Richard 2006-08-10 22:10 ` Daniel Jacobowitz 0 siblings, 1 reply; 11+ messages in thread From: Richard @ 2006-08-10 22:06 UTC (permalink / raw) To: Richard; +Cc: gdb Daniel Jacobowitz <drow@false.org> writes: > On Thu, Aug 10, 2006 at 02:06:38PM -0700, Richard wrote: >> >> >> Incidentally, I also tried "set $tmp=parent_id" (I made an api call to get >> the parent proc id in the child fork), and in the child I tried to "attach >> $tmp", but it said there was no such process. Is it not possible to use >> convenience variables for things like "attach"? "attach parent_id" worked >> fine. > > Yes, I don't think convenience variables are supported there - some > targets may not use numbers for these identifiers, in theory. > Seems strange. Is there a design reason behind that? It was the first time I ever used a convenience variable and *bang* it doesnt work :( I'm jinxed - whatever I seem to want to do is either not supported or buggy ... Mind you I do like the gdb-ui interface a lot - functional and certainly better than the previous GUD interface. > -- > Daniel Jacobowitz > CodeSourcery > -- ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: fork debugging : back to parent. 2006-08-10 22:06 ` Richard @ 2006-08-10 22:10 ` Daniel Jacobowitz 0 siblings, 0 replies; 11+ messages in thread From: Daniel Jacobowitz @ 2006-08-10 22:10 UTC (permalink / raw) To: Richard; +Cc: Richard, gdb On Fri, Aug 11, 2006 at 12:06:19AM +0200, Richard wrote: > Seems strange. Is there a design reason behind that? Sort of, sort of not. It could be a string, e.g. "attach foothread", on some platform other than a Unix workalike. But that probably doesn't justify not honoring variables for PIDs; it could be fixed. -- Daniel Jacobowitz CodeSourcery ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2006-08-10 22:10 UTC | newest] Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2006-08-07 20:21 fork debugging : back to parent Richard (sent by Nabble.com) 2006-08-07 21:07 ` Daniel Jacobowitz 2006-08-07 21:47 ` Richard 2006-08-08 0:04 ` Daniel Jacobowitz 2006-08-08 7:27 ` Richard 2006-08-08 8:49 ` Richard 2006-08-08 13:16 ` Daniel Jacobowitz 2006-08-10 21:06 ` Richard 2006-08-10 21:39 ` Daniel Jacobowitz 2006-08-10 22:06 ` Richard 2006-08-10 22:10 ` Daniel Jacobowitz
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox