* config/m68k/nm-hp300bsd.h: Correctly identify 4.3BSD vs 4.4BSD.
[deliverable/binutils-gdb.git] / gdb / procfs.c
index a18cc1814303c71757fbf400c5fdba6f9844dd83..844f8122361c52d4b7aeb07c5d88b0be2d42d7d8 100644 (file)
@@ -581,6 +581,7 @@ wait_fd ()
       print_sys_errmsg (pi->pathname, errno);
       error ("PIOCWSTOP failed");
     }
+  pi->had_event = 1;
 #endif  
   
   if (attach_flag)
@@ -1258,11 +1259,6 @@ NOTES
 static void
 procfs_kill_inferior ()
 {
-  struct procinfo *pi;
-
-  for (pi = procinfo_list; pi; pi = pi->next)
-    unconditionally_kill_inferior (pi);
-
   target_mourn_inferior ();
 }
 
@@ -1527,6 +1523,9 @@ procfs_init_inferior (pid)
 
   create_procinfo (pid);
   add_thread (pid);            /* Setup initial thread */
+
+  /* One trap to exec the shell, one to exec the program being debugged.  */
+  startup_inferior (2);
 }
 
 /*
@@ -1617,6 +1616,7 @@ static void
 proc_set_exec_trap ()
 {
   sysset_t exitset;
+  sysset_t entryset;
   auto char procname[32];
   int fd;
   
@@ -1624,10 +1624,11 @@ proc_set_exec_trap ()
   if ((fd = open (procname, O_RDWR)) < 0)
     {
       perror (procname);
-      fflush (stderr);
+      gdb_flush (gdb_stderr);
       _exit (127);
     }
   premptyset (&exitset);
+  premptyset (&entryset);
 
   /* GW: Rationale...
      Not all systems with /proc have all the exec* syscalls with the same
@@ -1641,16 +1642,25 @@ proc_set_exec_trap ()
   praddset (&exitset, SYS_execve);
 #endif
 #ifdef SYS_execv
-  praddset(&exitset, SYS_execv);
+  praddset (&exitset, SYS_execv);
 #endif
 
   if (ioctl (fd, PIOCSEXIT, &exitset) < 0)
     {
       perror (procname);
-      fflush (stderr);
+      gdb_flush (gdb_stderr);
       _exit (127);
     }
 
+  praddset (&entryset, SYS_exit);
+
+  if (ioctl (fd, PIOCSENTRY, &entryset) < 0)
+    {
+      perror (procname);
+      gdb_flush (gdb_stderr);
+      _exit (126);
+    }
+
   /* Turn off inherit-on-fork flag so that all grand-children of gdb
      start with tracing flags cleared. */
 
@@ -1849,11 +1859,11 @@ procfs_attach (args, from_tty)
       exec_file = (char *) get_exec_file (0);
 
       if (exec_file)
-       printf ("Attaching to program `%s', %s\n", exec_file, target_pid_to_str (pid));
+       printf_unfiltered ("Attaching to program `%s', %s\n", exec_file, target_pid_to_str (pid));
       else
-       printf ("Attaching to %s\n", target_pid_to_str (pid));
+       printf_unfiltered ("Attaching to %s\n", target_pid_to_str (pid));
 
-      fflush (stdout);
+      gdb_flush (gdb_stdout);
     }
 
   do_attach (pid);
@@ -1882,9 +1892,9 @@ procfs_detach (args, from_tty)
       char *exec_file = get_exec_file (0);
       if (exec_file == 0)
        exec_file = "";
-      printf ("Detaching from program: %s %s\n",
+      printf_unfiltered ("Detaching from program: %s %s\n",
              exec_file, target_pid_to_str (inferior_pid));
-      fflush (stdout);
+      gdb_flush (gdb_stdout);
     }
   if (args)
     siggnal = atoi (args);
@@ -1914,7 +1924,7 @@ static void
 procfs_files_info (ignore)
      struct target_ops *ignore;
 {
-  printf ("\tUsing the running image of %s %s via /proc.\n",
+  printf_unfiltered ("\tUsing the running image of %s %s via /proc.\n",
          attach_flag? "attached": "child", target_pid_to_str (inferior_pid));
 }
 
@@ -2022,7 +2032,7 @@ do_attach (pid)
        }
       else
        {
-         printf ("Ok, gdb will wait for %s to stop.\n", target_pid_to_str (pid));
+         printf_unfiltered ("Ok, gdb will wait for %s to stop.\n", target_pid_to_str (pid));
        }
     }
 
@@ -2099,32 +2109,32 @@ do_detach (signal)
   if (ioctl (pi->fd, PIOCSEXIT, &pi->saved_exitset) < 0)
     {
       print_sys_errmsg (pi->pathname, errno);
-      printf ("PIOCSEXIT failed.\n");
+      printf_unfiltered ("PIOCSEXIT failed.\n");
     }
   if (ioctl (pi->fd, PIOCSENTRY, &pi->saved_entryset) < 0)
     {
       print_sys_errmsg (pi->pathname, errno);
-      printf ("PIOCSENTRY failed.\n");
+      printf_unfiltered ("PIOCSENTRY failed.\n");
     }
   if (ioctl (pi->fd, PIOCSTRACE, &pi->saved_trace) < 0)
     {
       print_sys_errmsg (pi->pathname, errno);
-      printf ("PIOCSTRACE failed.\n");
+      printf_unfiltered ("PIOCSTRACE failed.\n");
     }
   if (ioctl (pi->fd, PIOCSHOLD, &pi->saved_sighold) < 0)
     {
       print_sys_errmsg (pi->pathname, errno);
-      printf ("PIOSCHOLD failed.\n");
+      printf_unfiltered ("PIOSCHOLD failed.\n");
     }
   if (ioctl (pi->fd, PIOCSFAULT, &pi->saved_fltset) < 0)
     {
       print_sys_errmsg (pi->pathname, errno);
-      printf ("PIOCSFAULT failed.\n");
+      printf_unfiltered ("PIOCSFAULT failed.\n");
     }
   if (ioctl (pi->fd, PIOCSTATUS, &pi->prstatus) < 0)
     {
       print_sys_errmsg (pi->pathname, errno);
-      printf ("PIOCSTATUS failed.\n");
+      printf_unfiltered ("PIOCSTATUS failed.\n");
     }
   else
     {
@@ -2137,7 +2147,7 @@ do_detach (signal)
              if (ioctl (pi->fd, PIOCCFAULT, 0))
                {
                  print_sys_errmsg (pi->pathname, errno);
-                 printf ("PIOCCFAULT failed.\n");
+                 printf_unfiltered ("PIOCCFAULT failed.\n");
                }
 
              /* Make it run again when we close it.  */
@@ -2155,7 +2165,7 @@ do_detach (signal)
              if (result)
                {
                  print_sys_errmsg (pi->pathname, errno);
-                 printf ("PIOCSRLC or PIOCSET failed.\n");
+                 printf_unfiltered ("PIOCSRLC or PIOCSET failed.\n");
                }
            }
        }
@@ -2272,6 +2282,18 @@ wait_again:
        {
        case PR_SIGNALLED:
          statval = (what << 8) | 0177;
+         break;
+       case PR_SYSENTRY:
+         if (what != SYS_exit)
+           error ("PR_SYSENTRY, unknown system call %d", what);
+
+         pi->prrun.pr_flags = PRCFAULT;
+
+         if (ioctl (pi->fd, PIOCRUN, &pi->prrun) != 0)
+           perror_with_name (pi->pathname);
+
+         rtnval = wait (&statval);
+
          break;
        case PR_SYSEXIT:
          switch (what)
@@ -2387,7 +2409,7 @@ wait_again:
 
   if (rtnval == -1)            /* No more children to wait for */
     {
-      fprintf (stderr, "Child process unexpectedly missing.\n");
+      fprintf_unfiltered (gdb_stderr, "Child process unexpectedly missing.\n");
       *statloc = 42;   /* Claim it exited with signal 42 */
       return rtnval;
     }
@@ -2571,7 +2593,7 @@ procfs_resume (pid, step, signo)
              {
                if (ioctl (procinfo->fd, PIOCSTATUS, &procinfo->prstatus) < 0)
                  {
-                   fprintf(stderr, "PIOCSTATUS failed, errno=%d\n", errno);
+                   fprintf_unfiltered(gdb_stderr, "PIOCSTATUS failed, errno=%d\n", errno);
                  }
                print_sys_errmsg (procinfo->pathname, errno);
                error ("PIOCRUN failed");
@@ -3461,6 +3483,11 @@ procfs_create_inferior (exec_file, allargs, env)
 static void
 procfs_mourn_inferior ()
 {
+  struct procinfo *pi;
+
+  for (pi = procinfo_list; pi; pi = pi->next)
+    unconditionally_kill_inferior (pi);
+
   unpush_target (&procfs_ops);
   generic_mourn_inferior ();
 }
@@ -3513,23 +3540,6 @@ struct target_ops procfs_ops = {
   OPS_MAGIC                    /* to_magic */
 };
 
-/*
-
-GLOBAL FUNCTION
-
-       _initialize_procfs -- initialize the process file system stuff
-
-SYNOPSIS
-
-       void _initialize_procfs (void)
-
-DESCRIPTION
-
-       Do required initializations during gdb startup for using the
-       /proc file system interface.
-
-*/
-
 void
 _initialize_procfs ()
 {
This page took 0.027661 seconds and 4 git commands to generate.