Fix -Werror -Wuninitialized warnings.
[deliverable/binutils-gdb.git] / gdb / fork-child.c
index 754367b705efd3bf1f6f19be812cde68d9e93ee5..a32ab8eb1fd47f6e240c1be1e91c9b44bd63b8d5 100644 (file)
@@ -1,5 +1,6 @@
 /* Fork a Unix child process, and set up to debug it, for GDB.
-   Copyright 1990, 91, 92, 93, 94, 1996, 1999 Free Software Foundation, Inc.
+   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000,
+   2001 Free Software Foundation, Inc.
    Contributed by Cygnus Support.
 
    This file is part of GDB.
 #include "frame.h"             /* required by inferior.h */
 #include "inferior.h"
 #include "target.h"
-#include "wait.h"
+#include "gdb_wait.h"
+#include "gdb_vfork.h"
 #include "gdbcore.h"
 #include "terminal.h"
 #include "gdbthread.h"
+#include "command.h" /* for dont_repeat () */
 
 #include <signal.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
 
 /* This just gets used as a default if we can't find SHELL */
 #ifndef SHELL_FILE
@@ -48,11 +48,7 @@ extern char **environ;
  * the four arguments "a", "b", "c", "d".
  */
 static void
-breakup_args (
-              scratch,
-              argv)
-     char *scratch;
-     char **argv;
+breakup_args (char *scratch, char **argv)
 {
   char *cp = scratch;
 
@@ -99,16 +95,13 @@ breakup_args (
    ENV is the environment vector to pass.  SHELL_FILE is the shell file,
    or NULL if we should pick one.  Errors reported with error().  */
 
+/* This function is NOT-REENTRANT.  Some of the variables have been
+   made static to ensure that they survive the vfork() call.  */
+
 void
-fork_inferior (exec_file, allargs, env, traceme_fun, init_trace_fun,
-              pre_trace_fun, shell_file)
-     char *exec_file;
-     char *allargs;
-     char **env;
-     void (*traceme_fun) PARAMS ((void));
-     void (*init_trace_fun) PARAMS ((int));
-     void (*pre_trace_fun) PARAMS ((void));
-     char *shell_file;
+fork_inferior (char *exec_file_arg, char *allargs, char **env,
+              void (*traceme_fun) (void), void (*init_trace_fun) (int),
+              void (*pre_trace_fun) (void), char *shell_file_arg)
 {
   int pid;
   char *shell_command;
@@ -119,12 +112,15 @@ fork_inferior (exec_file, allargs, env, traceme_fun, init_trace_fun,
   /* This is set to the result of setpgrp, which if vforked, will be visible
      to you in the parent process.  It's only used by humans for debugging.  */
   static int debug_setpgrp = 657473;
+  static char *shell_file;
+  static char *exec_file;
   char **save_our_env;
   int shell = 0;
-  char **argv;
+  static char **argv;
 
   /* If no exec file handed to us, get it from the exec-file command -- with
      a good, common error message if none is specified.  */
+  exec_file = exec_file_arg;
   if (exec_file == 0)
     exec_file = get_exec_file (1);
 
@@ -132,6 +128,7 @@ fork_inferior (exec_file, allargs, env, traceme_fun, init_trace_fun,
    * If 0, we'll just do a fork/exec, no shell, so don't
    * bother figuring out what shell.
    */
+  shell_file = shell_file_arg;
   if (STARTUP_WITH_SHELL)
     {
       /* Figure out what shell to start up the user program under. */
@@ -256,14 +253,10 @@ fork_inferior (exec_file, allargs, env, traceme_fun, init_trace_fun,
   if (pre_trace_fun != NULL)
     (*pre_trace_fun) ();
 
-#if defined(USG) && !defined(HAVE_VFORK)
-  pid = fork ();
-#else
   if (debug_fork)
     pid = fork ();
   else
     pid = vfork ();
-#endif
 
   if (pid < 0)
     perror_with_name ("vfork");
@@ -370,7 +363,7 @@ fork_inferior (exec_file, allargs, env, traceme_fun, init_trace_fun,
      correct program, and are poised at the first instruction of the
      new program.  */
 
-  /* Allow target dependant code to play with the new process.  This might be
+  /* Allow target dependent code to play with the new process.  This might be
      used to have target-specific code initialize a variable in the new process
      prior to executing the first instruction.  */
   TARGET_CREATE_INFERIOR_HOOK (pid);
@@ -390,9 +383,7 @@ fork_inferior (exec_file, allargs, env, traceme_fun, init_trace_fun,
    clone will set it TRUE.
  */
 void
-clone_and_follow_inferior (child_pid, followed_child)
-     int child_pid;
-     int *followed_child;
+clone_and_follow_inferior (int child_pid, int *followed_child)
 {
   extern int auto_solib_add;
 
@@ -430,13 +421,13 @@ clone_and_follow_inferior (child_pid, followed_child)
     error ("error getting pipe for handoff semaphore");
 
   /* Clone the debugger. */
-#if defined(USG) && !defined(HAVE_VFORK)
-  debugger_pid = fork ();
-#else
+#ifdef HAVE_VFORK
   if (debug_fork)
     debugger_pid = fork ();
   else
     debugger_pid = vfork ();
+#else
+  debugger_pid = fork ();
 #endif
 
   if (debugger_pid < 0)
@@ -514,8 +505,7 @@ clone_and_follow_inferior (child_pid, followed_child)
 /* Accept NTRAPS traps from the inferior.  */
 
 void
-startup_inferior (ntraps)
-     int ntraps;
+startup_inferior (int ntraps)
 {
   int pending_execs = ntraps;
   int terminal_initted;
This page took 0.027314 seconds and 4 git commands to generate.