* utils.c (strcmp_iw): Add a hack to allow "FOO(ARGS)" to
[deliverable/binutils-gdb.git] / gdb / procfs.c
index 4af048b3706eee1ae8eb79a63678ce7e31253e80..b4b1201175e25ff2f6928d7020d4ad21cafbf70c 100644 (file)
@@ -1,5 +1,5 @@
 /* Machine independent support for SVR4 /proc (process file system) for GDB.
-   Copyright (C) 1991 Free Software Foundation, Inc.
+   Copyright 1991, 1992 Free Software Foundation, Inc.
    Written by Fred Fish at Cygnus Support.
 
 This file is part of GDB.
@@ -362,7 +362,7 @@ static int
 proc_address_to_fd PARAMS ((CORE_ADDR, int));
 
 static int
-open_proc_file PARAMS ((int, struct procinfo *));
+open_proc_file PARAMS ((int, struct procinfo *, int));
 
 static void
 close_proc_file PARAMS ((struct procinfo *));
@@ -514,7 +514,7 @@ lookupname (transp, val, prefix)
          free (locbuf);
        }
       locbuf = xmalloc (strlen (prefix) + 16);
-      (void) sprintf (locbuf, "%s %u", prefix, val);
+      sprintf (locbuf, "%s %u", prefix, val);
       name = locbuf;
     }
   return (name);
@@ -539,7 +539,7 @@ sigcodename (sip)
     }
   if (name == NULL)
     {
-      (void) sprintf (locbuf, "sigcode %u", sip -> si_signo);
+      sprintf (locbuf, "sigcode %u", sip -> si_signo);
       name = locbuf;
     }
   return (name);
@@ -597,7 +597,7 @@ syscallname (syscallnum)
     }
   else
     {
-      (void) sprintf (locbuf, "syscall %u", syscallnum);
+      sprintf (locbuf, "syscall %u", syscallnum);
       rtnval = locbuf;
     }
   return (rtnval);
@@ -1123,7 +1123,7 @@ unconditionally_kill_inferior ()
   int signo;
   
   signo = SIGKILL;
-  (void) ioctl (pi.fd, PIOCKILL, &signo);
+  ioctl (pi.fd, PIOCKILL, &signo);
   close_proc_file (&pi);
   wait ((int *) 0);
 }
@@ -1228,10 +1228,10 @@ store_inferior_registers (regno)
 {
   if (regno != -1)
     {
-      (void) ioctl (pi.fd, PIOCGREG, &pi.gregset);
+      ioctl (pi.fd, PIOCGREG, &pi.gregset);
     }
   fill_gregset (&pi.gregset, regno);
-  (void) ioctl (pi.fd, PIOCSREG, &pi.gregset);
+  ioctl (pi.fd, PIOCSREG, &pi.gregset);
 
 #if defined (FP0_REGNUM)
 
@@ -1241,10 +1241,10 @@ store_inferior_registers (regno)
 
   if (regno != -1)
     {
-      (void) ioctl (pi.fd, PIOCGFPREG, &pi.fpregset);
+      ioctl (pi.fd, PIOCGFPREG, &pi.fpregset);
     }
   fill_fpregset (&pi.fpregset, regno);
-  (void) ioctl (pi.fd, PIOCSFPREG, &pi.fpregset);
+  ioctl (pi.fd, PIOCSFPREG, &pi.fpregset);
 
 #endif /* FP0_REGNUM */
 
@@ -1279,13 +1279,13 @@ void
 inferior_proc_init (pid)
      int pid;
 {
-  if (!open_proc_file (pid, &pi))
+  if (!open_proc_file (pid, &pi, O_RDWR))
     {
       proc_init_failed ("can't open process file");
     }
   else
     {
-      (void) memset ((char *) &pi.prrun, 0, sizeof (pi.prrun));
+      memset ((char *) &pi.prrun, 0, sizeof (pi.prrun));
       prfillset (&pi.prrun.pr_trace);
       proc_signal_handling_change ();
       prfillset (&pi.prrun.pr_fault);
@@ -1391,7 +1391,7 @@ proc_set_exec_trap ()
   auto char procname[32];
   int fd;
   
-  (void) sprintf (procname, PROC_NAME_FMT, getpid ());
+  sprintf (procname, PROC_NAME_FMT, getpid ());
   if ((fd = open (procname, O_RDWR)) < 0)
     {
       perror (procname);
@@ -1429,11 +1429,26 @@ proc_set_exec_trap ()
   {
       long pr_flags;
       pr_flags = PR_FORK;
-      (void) ioctl (fd, PIOCRESET, &pr_flags);
+      ioctl (fd, PIOCRESET, &pr_flags);
   }
 #else
 #if defined (PIOCRFORK)        /* Original method */
-  (void) ioctl (fd, PIOCRFORK, NULL);
+  ioctl (fd, PIOCRFORK, NULL);
+#endif
+#endif
+
+  /* Turn on run-on-last-close flag so that this process will not hang
+     if GDB goes away for some reason.  */
+
+#if defined (PIOCSET)  /* New method */
+  {
+      long pr_flags;
+      pr_flags = PR_RLC;
+      (void) ioctl (fd, PIOCSET, &pr_flags);
+  }
+#else
+#if defined (PIOCSRLC) /* Original method */
+  (void) ioctl (fd, PIOCSRLC, 0);
 #endif
 #endif
 }
@@ -1601,7 +1616,8 @@ NOTES
 
        The option of stopping at attach time is specific to the /proc
        versions of gdb.  Versions using ptrace force the attachee
-       to stop.
+       to stop.  (I have changed this version to do so, too.  All you
+       have to do is "continue" to make it go on. -- gnu@cygnus.com)
 
 */
 
@@ -1609,7 +1625,9 @@ int
 attach (pid)
      int pid;
 {
-  if (!open_proc_file (pid, &pi))
+  int result;
+
+  if (!open_proc_file (pid, &pi, O_RDWR))
     {
       perror_with_name (pi.pathname);
       /* NOTREACHED */
@@ -1632,8 +1650,26 @@ attach (pid)
   else
     {
       pi.was_stopped = 0;
-      if (query ("Process is currently running, stop it? "))
+      if (1 || query ("Process is currently running, stop it? "))
        {
+         /* Make it run again when we close it.  */
+#if defined (PIOCSET)  /* New method */
+         {
+             long pr_flags;
+             pr_flags = PR_RLC;
+             result = ioctl (pi.fd, PIOCSET, &pr_flags);
+         }
+#else
+#if defined (PIOCSRLC) /* Original method */
+         result = ioctl (pi.fd, PIOCSRLC, 0);
+#endif
+#endif
+         if (result < 0)
+           {
+             print_sys_errmsg (pi.pathname, errno);
+             close_proc_file (&pi);
+             error ("PIOCSRLC or PIOCSET failed");
+           }
          if (ioctl (pi.fd, PIOCSTOP, &pi.prstatus) < 0)
            {
              print_sys_errmsg (pi.pathname, errno);
@@ -1647,19 +1683,19 @@ attach (pid)
          printf ("Ok, gdb will wait for process %u to stop.\n", pid);
        }
     }
-  
+
   /*  Remember some things about the inferior that we will, or might, change
       so that we can restore them when we detach. */
   
-  (void) ioctl (pi.fd, PIOCGTRACE, &pi.saved_trace);
-  (void) ioctl (pi.fd, PIOCGHOLD, &pi.saved_sighold);
-  (void) ioctl (pi.fd, PIOCGFAULT, &pi.saved_fltset);
-  (void) ioctl (pi.fd, PIOCGENTRY, &pi.saved_entryset);
-  (void) ioctl (pi.fd, PIOCGEXIT, &pi.saved_exitset);
+  ioctl (pi.fd, PIOCGTRACE, &pi.saved_trace);
+  ioctl (pi.fd, PIOCGHOLD, &pi.saved_sighold);
+  ioctl (pi.fd, PIOCGFAULT, &pi.saved_fltset);
+  ioctl (pi.fd, PIOCGENTRY, &pi.saved_entryset);
+  ioctl (pi.fd, PIOCGEXIT, &pi.saved_exitset);
   
   /* Set up trace and fault sets, as gdb expects them. */
   
-  (void) memset (&pi.prrun, 0, sizeof (pi.prrun));
+  memset (&pi.prrun, 0, sizeof (pi.prrun));
   prfillset (&pi.prrun.pr_trace);
   proc_signal_handling_change ();
   prfillset (&pi.prrun.pr_fault);
@@ -1709,6 +1745,8 @@ void
 detach (signal)
      int signal;
 {
+  int result;
+
   if (signal)
     {
       set_proc_siginfo (&pi, signal);
@@ -1750,12 +1788,29 @@ detach (signal)
          if (signal || !pi.was_stopped ||
              query ("Was stopped when attached, make it runnable again? "))
            {
-             (void) memset (&pi.prrun, 0, sizeof (pi.prrun));
-             pi.prrun.pr_flags = PRCFAULT;
-             if (ioctl (pi.fd, PIOCRUN, &pi.prrun))
+             /* Clear any fault that might have stopped it.  */
+             if (ioctl (pi.fd, PIOCCFAULT, 0))
+               {
+                 print_sys_errmsg (pi.pathname, errno);
+                 printf ("PIOCCFAULT failed.\n");
+               }
+
+             /* Make it run again when we close it.  */
+#if defined (PIOCSET)  /* New method */
+             {
+                 long pr_flags;
+                 pr_flags = PR_RLC;
+                 result = ioctl (pi.fd, PIOCSET, &pr_flags);
+             }
+#else
+#if defined (PIOCSRLC) /* Original method */
+             result = ioctl (pi.fd, PIOCSRLC, 0);
+#endif
+#endif
+             if (result)
                {
                  print_sys_errmsg (pi.pathname, errno);
-                 printf ("PIOCRUN failed.\n");
+                 printf ("PIOCSRLC or PIOCSET failed.\n");
                }
            }
        }
@@ -1980,7 +2035,7 @@ set_proc_siginfo (pip, signo)
        }
       else
        {
-         (void) memset ((char *) &newsiginfo, 0, sizeof (newsiginfo));
+         memset ((char *) &newsiginfo, 0, sizeof (newsiginfo));
          sip = &newsiginfo;
          sip -> si_signo = signo;
          sip -> si_code = 0;
@@ -2144,8 +2199,7 @@ fetch_core_registers (core_reg_sect, core_reg_size, which, reg_addr)
        }
       else
        {
-         (void) memcpy ((char *) &pi.gregset, core_reg_sect,
-                        sizeof (pi.gregset));
+         memcpy ((char *) &pi.gregset, core_reg_sect, sizeof (pi.gregset));
          supply_gregset (&pi.gregset);
        }
     }
@@ -2157,8 +2211,7 @@ fetch_core_registers (core_reg_sect, core_reg_size, which, reg_addr)
        }
       else
        {
-         (void) memcpy ((char *) &pi.fpregset, core_reg_sect,
-                        sizeof (pi.fpregset));
+         memcpy ((char *) &pi.fpregset, core_reg_sect, sizeof (pi.fpregset));
 #if defined (FP0_REGNUM)
          supply_fpregset (&pi.fpregset);
 #endif
@@ -2189,7 +2242,7 @@ proc_init_failed (why)
      char *why;
 {
   print_sys_errmsg (pi.pathname, errno);
-  (void) kill (pi.pid, SIGKILL);
+  kill (pi.pid, SIGKILL);
   close_proc_file (&pi);
   error (why);
   /* NOTREACHED */
@@ -2221,7 +2274,7 @@ close_proc_file (pip)
   pip -> pid = 0;
   if (pip -> valid)
     {
-      (void) close (pip -> fd);
+      close (pip -> fd);
     }
   pip -> fd = -1;
   if (pip -> pathname)
@@ -2240,15 +2293,16 @@ LOCAL FUNCTION
 
 SYNOPSIS
 
-       static int open_proc_file (pid, struct procinfo *pip)
+       static int open_proc_file (int pid, struct procinfo *pip, int mode)
 
 DESCRIPTION
 
-       Given a process id, close the existing open /proc entry (if any)
-       and open one for the new process id.  Once it is open, then
-       mark the local process information structure as valid, which
-       guarantees that the pid, fd, and pathname fields match an open
-       /proc entry.  Returns zero if the open fails, nonzero otherwise.
+       Given a process id and a mode, close the existing open /proc
+       entry (if any) and open one for the new process id, in the
+       specified mode.  Once it is open, then mark the local process
+       information structure as valid, which guarantees that the pid,
+       fd, and pathname fields match an open /proc entry.  Returns
+       zero if the open fails, nonzero otherwise.
 
        Note that the pathname is left intact, even when the open fails,
        so that callers can use it to construct meaningful error messages
@@ -2256,21 +2310,22 @@ DESCRIPTION
  */
 
 static int
-open_proc_file (pid, pip)
+open_proc_file (pid, pip, mode)
      int pid;
      struct procinfo *pip;
+     int mode;
 {
-  pip -> valid = 0;
+  pip -> valid = 0;            /* FIXME, what is this? ?!  */
   if (pip -> valid)
     {
-      (void) close (pip -> fd);
+      close (pip -> fd);
     }
   if (pip -> pathname == NULL)
     {
       pip -> pathname = xmalloc (32);
     }
   sprintf (pip -> pathname, PROC_NAME_FMT, pid);
-  if ((pip -> fd = open (pip -> pathname, O_RDWR)) >= 0)
+  if ((pip -> fd = open (pip -> pathname, mode)) >= 0)
     {
       pip -> valid = 1;
       pip -> pid = pid;
@@ -2844,8 +2899,8 @@ info_proc (args, from_tty)
            {
              pid = pii.pid;
              pip = &pii;
-             (void) memset (&pii, 0, sizeof (pii));
-             if (!open_proc_file (pid, pip))
+             memset (&pii, 0, sizeof (pii));
+             if (!open_proc_file (pid, pip, O_RDONLY))
                {
                  perror_with_name (pip -> pathname);
                  /* NOTREACHED */
This page took 0.029358 seconds and 4 git commands to generate.