* config/pa/linux.mh (XDEPFILES): Remove.
[binutils-gdb.git] / gdb / procfs.c
index 703415c98f7cab9a26c850d91d5e3cf1d659277b..ea8648e61a798d53e415a1bbe06ff9d1c70043fd 100644 (file)
@@ -1,6 +1,6 @@
 /* Machine independent support for SVR4 /proc (process file system) for GDB.
 
-   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2006, 2007, 2008
+   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2006, 2007, 2008, 2009
    Free Software Foundation, Inc.
 
    Written by Michael Snyder at Cygnus Solutions.
  */
 
 static void procfs_open (char *, int);
-static void procfs_attach (char *, int);
-static void procfs_detach (char *, int);
+static void procfs_attach (struct target_ops *, char *, int);
+static void procfs_detach (struct target_ops *, char *, int);
 static void procfs_resume (ptid_t, int, enum target_signal);
 static int procfs_can_run (void);
 static void procfs_stop (ptid_t);
@@ -123,16 +123,17 @@ static void procfs_store_registers (struct regcache *, int);
 static void procfs_notice_signals (ptid_t);
 static void procfs_prepare_to_store (struct regcache *);
 static void procfs_kill_inferior (void);
-static void procfs_mourn_inferior (void);
-static void procfs_create_inferior (char *, char *, char **, int);
+static void procfs_mourn_inferior (struct target_ops *ops);
+static void procfs_create_inferior (struct target_ops *, char *, 
+                                   char *, char **, int);
 static ptid_t procfs_wait (ptid_t, struct target_waitstatus *);
-static int procfs_xfer_memory (CORE_ADDR, char *, int, int,
+static int procfs_xfer_memory (CORE_ADDR, gdb_byte *, int, int,
                               struct mem_attrib *attrib,
                               struct target_ops *);
 static LONGEST procfs_xfer_partial (struct target_ops *ops,
                                    enum target_object object,
                                    const char *annex,
-                                   void *readbuf, const void *writebuf,
+                                   gdb_byte *readbuf, const gdb_byte *writebuf,
                                    ULONGEST offset, LONGEST len);
 
 static int procfs_thread_alive (ptid_t);
@@ -715,7 +716,7 @@ open_procinfo_files (procinfo *pi, int which)
 static procinfo *
 create_procinfo (int pid, int tid)
 {
-  procinfo *pi, *parent;
+  procinfo *pi, *parent = NULL;
 
   if ((pi = find_procinfo (pid, tid)))
     return pi;                 /* Already exists, nothing to do. */
@@ -866,7 +867,7 @@ dead_procinfo (procinfo *pi, char *msg, int kill_p)
     kill (pi->pid, SIGKILL);
 
   destroy_procinfo (pi);
-  error ((msg));
+  error ("%s", msg);
 }
 
 /*
@@ -2902,7 +2903,8 @@ procfs_address_to_host_pointer (CORE_ADDR addr)
   void *ptr;
 
   gdb_assert (sizeof (ptr) == TYPE_LENGTH (ptr_type));
-  gdbarch_address_to_pointer (target_gdbarch, ptr_type, &ptr, addr);
+  gdbarch_address_to_pointer (target_gdbarch, ptr_type,
+                             (gdb_byte *) &ptr, addr);
   return ptr;
 }
 
@@ -3064,14 +3066,14 @@ procfs_find_LDT_entry (ptid_t ptid)
   /* Find procinfo for the lwp. */
   if ((pi = find_procinfo (PIDGET (ptid), TIDGET (ptid))) == NULL)
     {
-      warning (_("procfs_find_LDT_entry: could not find procinfo for %d:%d."),
+      warning (_("procfs_find_LDT_entry: could not find procinfo for %d:%ld."),
               PIDGET (ptid), TIDGET (ptid));
       return NULL;
     }
   /* get its general registers. */
   if ((gregs = proc_get_gregs (pi)) == NULL)
     {
-      warning (_("procfs_find_LDT_entry: could not read gregs for %d:%d."),
+      warning (_("procfs_find_LDT_entry: could not read gregs for %d:%ld."),
               PIDGET (ptid), TIDGET (ptid));
       return NULL;
     }
@@ -3601,7 +3603,7 @@ procfs_debug_inferior (procinfo *pi)
 }
 
 static void
-procfs_attach (char *args, int from_tty)
+procfs_attach (struct target_ops *ops, char *args, int from_tty)
 {
   char *exec_file;
   int   pid;
@@ -3631,16 +3633,16 @@ procfs_attach (char *args, int from_tty)
 }
 
 static void
-procfs_detach (char *args, int from_tty)
+procfs_detach (struct target_ops *ops, char *args, int from_tty)
 {
   int sig = 0;
+  int pid = PIDGET (inferior_ptid);
 
   if (args)
     sig = atoi (args);
 
   if (from_tty)
     {
-      int pid = PIDGET (inferior_ptid);
       char *exec_file;
 
       exec_file = get_exec_file (0);
@@ -3655,6 +3657,7 @@ procfs_detach (char *args, int from_tty)
   do_detach (sig);
 
   inferior_ptid = null_ptid;
+  detach_inferior (pid);
   unpush_target (&procfs_ops);
 }
 
@@ -3662,6 +3665,7 @@ static ptid_t
 do_attach (ptid_t ptid)
 {
   procinfo *pi;
+  struct inferior *inf;
   int fail;
   int lwpid;
 
@@ -3711,8 +3715,9 @@ do_attach (ptid_t ptid)
   if ((fail = procfs_debug_inferior (pi)) != 0)
     dead_procinfo (pi, "do_attach: failed in procfs_debug_inferior", NOKILL);
 
+  inf = add_inferior (pi->pid);
   /* Let GDB know that the inferior was attached.  */
-  attach_flag = 1;
+  inf->attach_flag = 1;
 
   /* Create a procinfo for the current lwp.  */
   lwpid = proc_get_current_thread (pi);
@@ -3766,7 +3771,6 @@ do_detach (int signo)
          proc_warn (pi, "do_detach, set_rlc", __LINE__);
       }
 
-  attach_flag = 0;
   destroy_procinfo (pi);
 }
 
@@ -4072,6 +4076,8 @@ wait_again:
                  }
                else if (syscall_is_exit (pi, what))
                  {
+                   struct inferior *inf;
+
                    /* Handle SYS_exit call only */
                    /* Stopped at entry to SYS_exit.
                       Make it runnable, resume it, then use
@@ -4085,7 +4091,9 @@ wait_again:
                       TARGET_WAITKIND_SPURIOUS.  */
                    if (!proc_run_process (pi, 0, 0))
                      proc_error (pi, "target_wait, run_process", __LINE__);
-                   if (attach_flag)
+
+                   inf = find_inferior_pid (pi->pid);
+                   if (inf->attach_flag)
                      {
                        /* Don't call wait: simulate waiting for exit,
                           return a "success" exit code.  Bogus: what if
@@ -4369,18 +4377,18 @@ wait_again:
 
 static LONGEST
 procfs_xfer_partial (struct target_ops *ops, enum target_object object,
-                    const char *annex, void *readbuf,
-                    const void *writebuf, ULONGEST offset, LONGEST len)
+                    const char *annex, gdb_byte *readbuf,
+                    const gdb_byte *writebuf, ULONGEST offset, LONGEST len)
 {
   switch (object)
     {
     case TARGET_OBJECT_MEMORY:
       if (readbuf)
-       return (*ops->deprecated_xfer_memory) (offset, readbuf, len,
-                                              0/*read*/, NULL, ops);
+       return (*ops->deprecated_xfer_memory) (offset, readbuf,
+                                              len, 0/*read*/, NULL, ops);
       if (writebuf)
-       return (*ops->deprecated_xfer_memory) (offset, writebuf, len,
-                                              1/*write*/, NULL, ops);
+       return (*ops->deprecated_xfer_memory) (offset, (gdb_byte *) writebuf,
+                                              len, 1/*write*/, NULL, ops);
       return -1;
 
 #ifdef NEW_PROC_API
@@ -4409,7 +4417,7 @@ procfs_xfer_partial (struct target_ops *ops, enum target_object object,
    negative values, but this capability isn't implemented here.) */
 
 static int
-procfs_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int dowrite,
+procfs_xfer_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len, int dowrite,
                    struct mem_attrib *attrib, struct target_ops *target)
 {
   procinfo *pi;
@@ -4684,8 +4692,9 @@ procfs_notice_signals (ptid_t ptid)
 static void
 procfs_files_info (struct target_ops *ignore)
 {
+  struct inferior *inf = current_inferior ();
   printf_filtered (_("\tUsing the running image of %s %s via /proc.\n"),
-                  attach_flag? "attached": "child",
+                  inf->attach_flag? "attached": "child",
                   target_pid_to_str (inferior_ptid));
 }
 
@@ -4834,7 +4843,7 @@ procfs_kill_inferior (void)
  */
 
 static void
-procfs_mourn_inferior (void)
+procfs_mourn_inferior (struct target_ops *ops)
 {
   procinfo *pi;
 
@@ -5103,8 +5112,8 @@ procfs_set_exec_trap (void)
  */
 
 static void
-procfs_create_inferior (char *exec_file, char *allargs, char **env,
-                       int from_tty)
+procfs_create_inferior (struct target_ops *ops, char *exec_file,
+                       char *allargs, char **env, int from_tty)
 {
   char *shell_file = getenv ("SHELL");
   char *tryname;
@@ -5773,23 +5782,28 @@ mappingflags (long flags)
 static int
 info_mappings_callback (struct prmap *map, int (*ignore) (), void *unused)
 {
-  char *data_fmt_string;
-
-  if (gdbarch_addr_bit (current_gdbarch) == 32)
-    data_fmt_string   = "\t%#10lx %#10lx %#10x %#10x %7s\n";
-  else
-    data_fmt_string   = "  %#18lx %#18lx %#10x %#10x %7s\n";
+  unsigned int pr_off;
 
-  printf_filtered (data_fmt_string,
-                  (unsigned long) map->pr_vaddr,
-                  (unsigned long) map->pr_vaddr + map->pr_size - 1,
-                  map->pr_size,
 #ifdef PCAGENT /* Horrible hack: only defined on Solaris 2.6+ */
-                  (unsigned int) map->pr_offset,
+  pr_off = (unsigned int) map->pr_offset;
 #else
-                  map->pr_off,
+  pr_off = map->pr_off;
 #endif
-                  mappingflags (map->pr_mflags));
+
+  if (gdbarch_addr_bit (current_gdbarch) == 32)
+    printf_filtered ("\t%#10lx %#10lx %#10x %#10x %7s\n",
+                    (unsigned long) map->pr_vaddr,
+                    (unsigned long) map->pr_vaddr + map->pr_size - 1,
+                    map->pr_size,
+                    pr_off,
+                    mappingflags (map->pr_mflags));
+  else
+    printf_filtered ("  %#18lx %#18lx %#10x %#10x %7s\n",
+                    (unsigned long) map->pr_vaddr,
+                    (unsigned long) map->pr_vaddr + map->pr_size - 1,
+                    map->pr_size,
+                    pr_off,
+                    mappingflags (map->pr_mflags));
 
   return 0;
 }
@@ -5803,23 +5817,24 @@ info_mappings_callback (struct prmap *map, int (*ignore) (), void *unused)
 static void
 info_proc_mappings (procinfo *pi, int summary)
 {
-  char *header_fmt_string;
-
-  if (gdbarch_ptr_bit (current_gdbarch) == 32)
-    header_fmt_string = "\t%10s %10s %10s %10s %7s\n";
-  else
-    header_fmt_string = "  %18s %18s %10s %10s %7s\n";
-
   if (summary)
     return;    /* No output for summary mode. */
 
   printf_filtered (_("Mapped address spaces:\n\n"));
-  printf_filtered (header_fmt_string,
-                  "Start Addr",
-                  "  End Addr",
-                  "      Size",
-                  "    Offset",
-                  "Flags");
+  if (gdbarch_ptr_bit (current_gdbarch) == 32)
+    printf_filtered ("\t%10s %10s %10s %10s %7s\n",
+                    "Start Addr",
+                    "  End Addr",
+                    "      Size",
+                    "    Offset",
+                    "Flags");
+  else
+    printf_filtered ("  %18s %18s %10s %10s %7s\n",
+                    "Start Addr",
+                    "  End Addr",
+                    "      Size",
+                    "    Offset",
+                    "Flags");
 
   iterate_over_mappings (pi, NULL, NULL, info_mappings_callback);
   printf_filtered ("\n");
@@ -5846,10 +5861,8 @@ info_proc_cmd (char *args, int from_tty)
   old_chain = make_cleanup (null_cleanup, 0);
   if (args)
     {
-      if ((argv = buildargv (args)) == NULL)
-       nomem (0);
-      else
-       make_cleanup_freeargv (argv);
+      argv = gdb_buildargv (args);
+      make_cleanup_freeargv (argv);
     }
   while (argv != NULL && *argv != NULL)
     {
@@ -6145,7 +6158,7 @@ procfs_make_note_section (bfd *obfd, int *note_size)
   char *note_data = NULL;
   char *inf_args;
   struct procfs_corefile_thread_data thread_args;
-  char *auxv;
+  gdb_byte *auxv;
   int auxv_len;
 
   if (get_exec_file (0))