ddd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question regarding forked processes


From: Andreas Zeller
Subject: Re: Question regarding forked processes
Date: 28 Nov 2000 08:24:21 +0100
User-agent: Gnus/5.0807 (Gnus v5.8.7) XEmacs/21.1 (Channel Islands)

Hi!

address@hidden writes:

> I have a large piece of software that does a fork exec to run a second
> program that deals with a separate function, data is then piped between the
> two.
> 
> When debugging this main program, I want to be able to jump to functions in
> the forked process and setup breakpoints etc etc. At the moment, I am
> unable to as the symbol table does not contain any information on this
> other process (obviously) .. so,

Here's a piece of information from the GDB documentation.  In DDD, you
can access the `set follow-fork-mode' command via `Edit->GDB
Settings', and the `attach' command via the `File' menu.

Let me know if this helps,

Andreas

Debugging programs with multiple processes
==========================================

   On most systems, GDB has no special support for debugging programs
which create additional processes using the `fork' function.  When a
program forks, GDB will continue to debug the parent process and the
child process will run unimpeded.  If you have set a breakpoint in any
code which the child then executes, the child will get a `SIGTRAP'
signal which (unless it catches the signal) will cause it to terminate.

   However, if you want to debug the child process there is a workaround
which isn't too painful.  Put a call to `sleep' in the code which the
child process executes after the fork.  It may be useful to sleep only
if a certain environment variable is set, or a certain file exists, so
that the delay need not occur when you don't want to run GDB on the
child.  While the child is sleeping, use the `ps' program to get its
process ID.  Then tell GDB (a new invocation of GDB if you are also
debugging the parent process) to attach to the child process (*note
Attach::.).  From that point on you can debug the child process just
like any other process which you attached to.

   On HP-UX (11.x and later only?), GDB provides support for debugging
programs that create additional processes using the `fork' or `vfork'
function.

   By default, when a program forks, GDB will continue to debug the
parent process and the child process will run unimpeded.

   If you want to follow the child process instead of the parent
process, use the command `set follow-fork-mode'.

`set follow-fork-mode MODE'
     Set the debugger response to a program call of `fork' or `vfork'.
     A call to `fork' or `vfork' creates a new process.  The MODE can
     be:

    `parent'
          The original process is debugged after a fork.  The child
          process runs unimpeded.

    `child'
          The new process is debugged after a fork.  The parent process
          runs unimpeded.

    `ask'
          The debugger will ask for one of the above choices.

`show follow-fork-mode'
     Display the current debugger response to a fork or vfork call.

   If you ask to debug a child process and a `vfork' is followed by an
`exec', GDB executes the new target up to the first breakpoint in the
new target.  If you have a breakpoint set on `main' in your original
program, the breakpoint will also be set on the child process's `main'.

   When a child process is spawned by `vfork', you cannot debug the
child or parent until an `exec' call completes.

   If you issue a `run' command to GDB after an `exec' call executes,
the new target restarts.  To restart the parent process, use the `file'
command with the parent executable name as its argument.

   You can use the `catch' command to make GDB stop whenever a `fork',
`vfork', or `exec' call is made.  *Note Setting catchpoints: Set
Catchpoints.


-- 
Andreas Zeller     Universitaet Passau
                   http://www.fmi.uni-passau.de/st/staff/zeller/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]