From owner-freebsd-hackers Wed Sep 8 17:33:45 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from bingnet2.cc.binghamton.edu (bingnet2.cc.binghamton.edu [128.226.1.18]) by hub.freebsd.org (Postfix) with ESMTP id C770915D7F for ; Wed, 8 Sep 1999 17:33:35 -0700 (PDT) (envelope-from zzhang@cs.binghamton.edu) Received: from sol.cs.binghamton.edu (cs1-gw.cs.binghamton.edu [128.226.171.72]) by bingnet2.cc.binghamton.edu (8.9.3/8.9.3) with SMTP id UAA23224; Wed, 8 Sep 1999 20:33:22 -0400 (EDT) Date: Wed, 8 Sep 1999 20:19:32 -0400 (EDT) From: Zhihui Zhang To: Kip Macy Cc: freebsd-hackers@freebsd.org Subject: How to follow child process in gdb In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Wed, 8 Sep 1999, Kip Macy wrote: > You need to detach from your current process and attach to the spawned > process. It might make it easier to attach in a timely fashion if you put > a 3 second sleep in right after the fork. This would all be easiest using > something like DDD where DDD will tell you what other processes are > running with the same name, and allow you to attach to them through the > GUI. In dbx on a Sun workstation, all I need to do to follow a child process after fork() is to use the following command in advance: (dbx)dbxenv follow_fork_mode child Your response suggests that I can not achieve the same result simply by using (I am using gdb 4.18): (gdb)set follow-fork-mode child I have to use attach and dettach to do so. Does that mean I have to display the pid of the new process in order to follow it. And I have to modify the child process so that it can wait until I can attach to it. That will not be as easy. -Zhihui > > > > On Wed, 8 Sep 1999, Zhihui Zhang wrote: > > > > > I am using gdb 4.18 on FreeBSD-current. The program being debugged > > consists of two small files: test1.c and test2.c. The main() in test1.c > > has a call to fork() and for the child process case, it will call a > > routine, say test(), in test2.c. > > > > I use "set follow-fork-mode child", "break fork", "step" command trying to > > access the source in test2.c without success. The program is compiled > > with "cc -g test1.c test2.c" and I run gdb with "gdb a.out". > > > > If there is no fork(), a call from test1.c to a routine in test2.c will > > bring up the source of test2.c if I step that routine. Why it does not > > work with fork()? Am I missing something? > > To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message