proc-events.c: fix compilation on Solaris
[deliverable/binutils-gdb.git] / gdb / procfs.c
index a939dedb0093fead6028d574819086b9968b1302..3c747cd3e21eb97ebce6585e8a226ef0cb4b09fe 100644 (file)
@@ -45,7 +45,8 @@
 #include "inflow.h"
 #include "auxv.h"
 #include "procfs.h"
-#include "observer.h"
+#include "observable.h"
+#include "common/scoped_fd.h"
 
 /* This module provides the interface between GDB and the
    /proc file system, which is used on many versions of Unix
 /* This module defines the GDB target vector and its methods.  */
 
 static void procfs_attach (struct target_ops *, const char *, int);
-static void procfs_detach (struct target_ops *, const char *, int);
+static void procfs_detach (struct target_ops *, inferior *, int);
 static void procfs_resume (struct target_ops *,
                           ptid_t, int, enum gdb_signal);
-static void procfs_interrupt (struct target_ops *self, ptid_t);
 static void procfs_files_info (struct target_ops *);
 static void procfs_fetch_registers (struct target_ops *,
                                    struct regcache *, int);
@@ -172,7 +172,6 @@ procfs_target (void)
   t->to_xfer_partial = procfs_xfer_partial;
   t->to_pass_signals = procfs_pass_signals;
   t->to_files_info = procfs_files_info;
-  t->to_interrupt = procfs_interrupt;
 
   t->to_update_thread_list = procfs_update_thread_list;
   t->to_thread_alive = procfs_thread_alive;
@@ -1595,8 +1594,6 @@ proc_get_LDT_entry (procinfo *pi, int key)
 {
   static struct ssd *ldt_entry = NULL;
   char pathname[MAX_PROC_NAME_SIZE];
-  struct cleanup *old_chain = NULL;
-  int  fd;
 
   /* Allocate space for one LDT entry.
      This alloc must persist, because we return a pointer to it.  */
@@ -1605,16 +1602,16 @@ proc_get_LDT_entry (procinfo *pi, int key)
 
   /* Open the file descriptor for the LDT table.  */
   sprintf (pathname, "/proc/%d/ldt", pi->pid);
-  if ((fd = open_with_retry (pathname, O_RDONLY)) < 0)
+  scoped_fd fd (open_with_retry (pathname, O_RDONLY));
+  if (fd.get () < 0)
     {
       proc_warn (pi, "proc_get_LDT_entry (open)", __LINE__);
       return NULL;
     }
-  /* Make sure it gets closed again!  */
-  old_chain = make_cleanup_close (fd);
 
   /* Now 'read' thru the table, find a match and return it.  */
-  while (read (fd, ldt_entry, sizeof (struct ssd)) == sizeof (struct ssd))
+  while (read (fd.get (), ldt_entry, sizeof (struct ssd))
+        == sizeof (struct ssd))
     {
       if (ldt_entry->sel == 0 &&
          ldt_entry->bo  == 0 &&
@@ -1623,13 +1620,9 @@ proc_get_LDT_entry (procinfo *pi, int key)
        break;  /* end of table */
       /* If key matches, return this entry.  */
       if (ldt_entry->sel == key)
-       {
-         do_cleanups (old_chain);
-         return ldt_entry;
-       }
+       return ldt_entry;
     }
   /* Loop ended, match not found.  */
-  do_cleanups (old_chain);
   return NULL;
 }
 
@@ -1829,7 +1822,7 @@ proc_iterate_over_threads (procinfo *pi,
    friends.  */
 
 static ptid_t do_attach (ptid_t ptid);
-static void do_detach (int signo);
+static void do_detach ();
 static void proc_trace_syscalls_1 (procinfo *pi, int syscallnum,
                                   int entry_or_exit, int mode, int from_tty);
 
@@ -1924,14 +1917,10 @@ procfs_attach (struct target_ops *ops, const char *args, int from_tty)
 }
 
 static void
-procfs_detach (struct target_ops *ops, const char *args, int from_tty)
+procfs_detach (struct target_ops *ops, inferior *inf, int from_tty)
 {
-  int sig = 0;
   int pid = ptid_get_pid (inferior_ptid);
 
-  if (args)
-    sig = atoi (args);
-
   if (from_tty)
     {
       const char *exec_file;
@@ -1945,7 +1934,7 @@ procfs_detach (struct target_ops *ops, const char *args, int from_tty)
       gdb_flush (gdb_stdout);
     }
 
-  do_detach (sig);
+  do_detach ();
 
   inferior_ptid = null_ptid;
   detach_inferior (pid);
@@ -2023,16 +2012,13 @@ do_attach (ptid_t ptid)
 }
 
 static void
-do_detach (int signo)
+do_detach ()
 {
   procinfo *pi;
 
   /* Find procinfo for the main process.  */
   pi = find_procinfo_or_die (ptid_get_pid (inferior_ptid),
                             0); /* FIXME: threads */
-  if (signo)
-    if (!proc_set_current_signal (pi, signo))
-      proc_warn (pi, "do_detach, set_current_signal", __LINE__);
 
   if (!proc_set_traced_signals (pi, &pi->saved_sigset))
     proc_warn (pi, "do_detach, set_traced_signal", __LINE__);
@@ -2049,15 +2035,15 @@ do_detach (int signo)
   if (!proc_set_held_signals (pi, &pi->saved_sighold))
     proc_warn (pi, "do_detach, set_held_signals", __LINE__);
 
-  if (signo || (proc_flags (pi) & (PR_STOPPED | PR_ISTOP)))
-    if (signo || !(pi->was_stopped) ||
-       query (_("Was stopped when attached, make it runnable again? ")))
+  if (proc_flags (pi) & (PR_STOPPED | PR_ISTOP))
+    if (!(pi->was_stopped)
+       || query (_("Was stopped when attached, make it runnable again? ")))
       {
        /* Clear any pending signal.  */
        if (!proc_clear_current_fault (pi))
          proc_warn (pi, "do_detach, clear_current_fault", __LINE__);
 
-       if (signo == 0 && !proc_clear_current_signal (pi))
+       if (!proc_clear_current_signal (pi))
          proc_warn (pi, "do_detach, clear_current_signal", __LINE__);
 
        if (!proc_set_run_on_last_close (pi))
@@ -2843,16 +2829,6 @@ procfs_files_info (struct target_ops *ignore)
                   target_pid_to_str (inferior_ptid));
 }
 
-/* Stop the child process asynchronously, as when the gdb user types
-   control-c or presses a "stop" button.  Works by sending
-   kill(SIGINT) to the child's process group.  */
-
-static void
-procfs_interrupt (struct target_ops *self, ptid_t ptid)
-{
-  kill (-inferior_process_group (), SIGINT);
-}
-
 /* Make it die.  Wait for it to die.  Clean up after it.  Note: this
    should only be applied to the real process, not to an LWP, because
    of the check for parent-process.  If we need this to work for an
@@ -3445,40 +3421,33 @@ iterate_over_mappings (procinfo *pi, find_memory_region_ftype child_func,
   struct prmap *prmaps;
   struct prmap *prmap;
   int funcstat;
-  int map_fd;
   int nmap;
-  struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
   struct stat sbuf;
 
   /* Get the number of mappings, allocate space,
      and read the mappings into prmaps.  */
   /* Open map fd.  */
   sprintf (pathname, "/proc/%d/map", pi->pid);
-  if ((map_fd = open (pathname, O_RDONLY)) < 0)
-    proc_error (pi, "iterate_over_mappings (open)", __LINE__);
 
-  /* Make sure it gets closed again.  */
-  make_cleanup_close (map_fd);
+  scoped_fd map_fd (open (pathname, O_RDONLY));
+  if (map_fd.get () < 0)
+    proc_error (pi, "iterate_over_mappings (open)", __LINE__);
 
   /* Use stat to determine the file size, and compute
      the number of prmap_t objects it contains.  */
-  if (fstat (map_fd, &sbuf) != 0)
+  if (fstat (map_fd.get (), &sbuf) != 0)
     proc_error (pi, "iterate_over_mappings (fstat)", __LINE__);
 
   nmap = sbuf.st_size / sizeof (prmap_t);
   prmaps = (struct prmap *) alloca ((nmap + 1) * sizeof (*prmaps));
-  if (read (map_fd, (char *) prmaps, nmap * sizeof (*prmaps))
+  if (read (map_fd.get (), (char *) prmaps, nmap * sizeof (*prmaps))
       != (nmap * sizeof (*prmaps)))
     proc_error (pi, "iterate_over_mappings (read)", __LINE__);
 
   for (prmap = prmaps; nmap > 0; prmap++, nmap--)
     if ((funcstat = (*func) (prmap, child_func, data)) != 0)
-      {
-       do_cleanups (cleanups);
-        return funcstat;
-      }
+      return funcstat;
 
-  do_cleanups (cleanups);
   return 0;
 }
 
@@ -3779,7 +3748,7 @@ proc_untrace_sysexit_cmd (const char *args, int from_tty)
 void
 _initialize_procfs (void)
 {
-  observer_attach_inferior_created (procfs_inferior_created);
+  gdb::observers::inferior_created.attach (procfs_inferior_created);
 
   add_com ("proc-trace-entry", no_class, proc_trace_sysentry_cmd,
           _("Give a trace of entries into the syscall."));
This page took 0.051406 seconds and 4 git commands to generate.