* windows-tdep.c (windows_get_tlb_type): Remember last GDBARCH
[deliverable/binutils-gdb.git] / gdb / procfs.c
index b2868bcc3413d6e21c1c4a90fcd56e83ee3086fb..faf840948e83989d41bce798d7f4aa75aee51fbd 100644 (file)
@@ -1,6 +1,6 @@
 /* Machine independent support for SVR4 /proc (process file system) for GDB.
 
 /* Machine independent support for SVR4 /proc (process file system) for GDB.
 
-   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2006, 2007, 2008, 2009
+   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2006, 2007, 2008, 2009, 2010
    Free Software Foundation, Inc.
 
    Written by Michael Snyder at Cygnus Solutions.
    Free Software Foundation, Inc.
 
    Written by Michael Snyder at Cygnus Solutions.
@@ -51,6 +51,7 @@
 #include "inflow.h"
 #include "auxv.h"
 #include "procfs.h"
 #include "inflow.h"
 #include "auxv.h"
 #include "procfs.h"
+#include "observer.h"
 
 /*
  * PROCFS.C
 
 /*
  * PROCFS.C
@@ -270,6 +271,15 @@ typedef pr_siginfo64_t gdb_siginfo_t;
 typedef struct siginfo gdb_siginfo_t;
 #endif
 
 typedef struct siginfo gdb_siginfo_t;
 #endif
 
+/* On mips-irix, praddset and prdelset are defined in such a way that
+   they return a value, which causes GCC to emit a -Wunused error
+   because the returned value is not used.  Prevent this warning
+   by casting the return value to void.  On sparc-solaris, this issue
+   does not exist because the definition of these macros already include
+   that cast to void.  */
+#define gdb_praddset(sp, flag) ((void) praddset (sp, flag))
+#define gdb_prdelset(sp, flag) ((void) prdelset (sp, flag))
+
 /* gdb_premptysysset */
 #ifdef premptysysset
 #define gdb_premptysysset premptysysset
 /* gdb_premptysysset */
 #ifdef premptysysset
 #define gdb_premptysysset premptysysset
@@ -281,14 +291,14 @@ typedef struct siginfo gdb_siginfo_t;
 #ifdef praddsysset
 #define gdb_praddsysset praddsysset
 #else
 #ifdef praddsysset
 #define gdb_praddsysset praddsysset
 #else
-#define gdb_praddsysset praddset
+#define gdb_praddsysset gdb_praddset
 #endif
 
 /* prdelsysset */
 #ifdef prdelsysset
 #define gdb_prdelsysset prdelsysset
 #else
 #endif
 
 /* prdelsysset */
 #ifdef prdelsysset
 #define gdb_prdelsysset prdelsysset
 #else
-#define gdb_prdelsysset prdelset
+#define gdb_prdelsysset gdb_prdelset
 #endif
 
 /* prissyssetmember */
 #endif
 
 /* prissyssetmember */
@@ -435,6 +445,19 @@ static void free_syscalls (procinfo *pi);
 static int find_syscall (procinfo *pi, char *name);
 #endif /* DYNAMIC_SYSCALLS */
 
 static int find_syscall (procinfo *pi, char *name);
 #endif /* DYNAMIC_SYSCALLS */
 
+/* A function type used as a callback back iterate_over_mappings.  */
+typedef int (iterate_over_mappings_cb_ftype)
+  (CORE_ADDR vaddr, unsigned long size, int read, int write, int execute,
+   void *data);
+
+static int iterate_over_mappings
+  (procinfo *pi,
+   iterate_over_mappings_cb_ftype *child_func,
+   void *data,
+   int (*func) (struct prmap *map,
+                iterate_over_mappings_cb_ftype *child_func,
+                void *data));
+
 /* The head of the procinfo list: */
 static procinfo * procinfo_list;
 
 /* The head of the procinfo list: */
 static procinfo * procinfo_list;
 
@@ -2219,7 +2242,7 @@ proc_trace_signal (procinfo *pi, int signo)
     {
       if (proc_get_traced_signals (pi, &temp))
        {
     {
       if (proc_get_traced_signals (pi, &temp))
        {
-         praddset (&temp, signo);
+         gdb_praddset (&temp, signo);
          return proc_set_traced_signals (pi, &temp);
        }
     }
          return proc_set_traced_signals (pi, &temp);
        }
     }
@@ -2253,7 +2276,7 @@ proc_ignore_signal (procinfo *pi, int signo)
     {
       if (proc_get_traced_signals (pi, &temp))
        {
     {
       if (proc_get_traced_signals (pi, &temp))
        {
-         prdelset (&temp, signo);
+         gdb_prdelset (&temp, signo);
          return proc_set_traced_signals (pi, &temp);
        }
     }
          return proc_set_traced_signals (pi, &temp);
        }
     }
@@ -2879,10 +2902,11 @@ proc_parent_pid (procinfo *pi)
   return pi->prstatus.pr_ppid;
 }
 
   return pi->prstatus.pr_ppid;
 }
 
-
 /* Convert a target address (a.k.a. CORE_ADDR) into a host address
    (a.k.a void pointer)!  */
 
 /* Convert a target address (a.k.a. CORE_ADDR) into a host address
    (a.k.a void pointer)!  */
 
+#if (defined (PCWATCH) || defined (PIOCSWATCH)) \
+    && !(defined (PIOCOPENLWP) || defined (UNIXWARE))
 static void *
 procfs_address_to_host_pointer (CORE_ADDR addr)
 {
 static void *
 procfs_address_to_host_pointer (CORE_ADDR addr)
 {
@@ -2894,6 +2918,7 @@ procfs_address_to_host_pointer (CORE_ADDR addr)
                              (gdb_byte *) &ptr, addr);
   return ptr;
 }
                              (gdb_byte *) &ptr, addr);
   return ptr;
 }
+#endif
 
 /*
  * Function: proc_set_watchpoint
 
 /*
  * Function: proc_set_watchpoint
@@ -3453,8 +3478,6 @@ static void do_detach (int signo);
 static int register_gdb_signals (procinfo *, gdb_sigset_t *);
 static void proc_trace_syscalls_1 (procinfo *pi, int syscallnum,
                                    int entry_or_exit, int mode, int from_tty);
 static int register_gdb_signals (procinfo *, gdb_sigset_t *);
 static void proc_trace_syscalls_1 (procinfo *pi, int syscallnum,
                                    int entry_or_exit, int mode, int from_tty);
-static int insert_dbx_link_breakpoint (procinfo *pi);
-static void remove_dbx_link_breakpoint (void);
 
 /* On mips-irix, we need to insert a breakpoint at __dbx_link during
    the startup phase.  The following two variables are used to record
 
 /* On mips-irix, we need to insert a breakpoint at __dbx_link during
    the startup phase.  The following two variables are used to record
@@ -3491,7 +3514,7 @@ procfs_debug_inferior (procinfo *pi)
 #else
   /* Register to trace hardware faults in the child. */
   prfillset (&traced_faults);          /* trace all faults... */
 #else
   /* Register to trace hardware faults in the child. */
   prfillset (&traced_faults);          /* trace all faults... */
-  prdelset  (&traced_faults, FLTPAGE); /* except page fault.  */
+  gdb_prdelset  (&traced_faults, FLTPAGE);     /* except page fault.  */
 #endif
   if (!proc_set_traced_faults  (pi, &traced_faults))
     return __LINE__;
 #endif
   if (!proc_set_traced_faults  (pi, &traced_faults))
     return __LINE__;
@@ -3598,10 +3621,8 @@ procfs_attach (struct target_ops *ops, char *args, int from_tty)
   char *exec_file;
   int   pid;
 
   char *exec_file;
   int   pid;
 
-  if (!args)
-    error_no_arg (_("process-id to attach"));
+  pid = parse_pid_to_attach (args);
 
 
-  pid = atoi (args);
   if (pid == getpid ())
     error (_("Attaching GDB to itself is not a good idea..."));
 
   if (pid == getpid ())
     error (_("Attaching GDB to itself is not a good idea..."));
 
@@ -3705,7 +3726,8 @@ do_attach (ptid_t ptid)
   if ((fail = procfs_debug_inferior (pi)) != 0)
     dead_procinfo (pi, "do_attach: failed in procfs_debug_inferior", NOKILL);
 
   if ((fail = procfs_debug_inferior (pi)) != 0)
     dead_procinfo (pi, "do_attach: failed in procfs_debug_inferior", NOKILL);
 
-  inf = add_inferior (pi->pid);
+  inf = current_inferior ();
+  inferior_appeared (inf, pi->pid);
   /* Let GDB know that the inferior was attached.  */
   inf->attach_flag = 1;
 
   /* Let GDB know that the inferior was attached.  */
   inf->attach_flag = 1;
 
@@ -3937,6 +3959,182 @@ syscall_is_lwp_create (procinfo *pi, int scall)
   return 0;
 }
 
   return 0;
 }
 
+/* Remove the breakpoint that we inserted in __dbx_link().
+   Does nothing if the breakpoint hasn't been inserted or has already
+   been removed.  */
+
+static void
+remove_dbx_link_breakpoint (void)
+{
+  if (dbx_link_bpt_addr == 0)
+    return;
+
+  if (deprecated_remove_raw_breakpoint (target_gdbarch, dbx_link_bpt) != 0)
+    warning (_("Unable to remove __dbx_link breakpoint."));
+
+  dbx_link_bpt_addr = 0;
+  dbx_link_bpt = NULL;
+}
+
+#ifdef SYS_syssgi
+/* Return the address of the __dbx_link() function in the file
+   refernced by ABFD by scanning its symbol table.  Return 0 if
+   the symbol was not found.  */
+
+static CORE_ADDR
+dbx_link_addr (bfd *abfd)
+{
+  long storage_needed;
+  asymbol **symbol_table;
+  long number_of_symbols;
+  long i;
+
+  storage_needed = bfd_get_symtab_upper_bound (abfd);
+  if (storage_needed <= 0)
+    return 0;
+
+  symbol_table = (asymbol **) xmalloc (storage_needed);
+  make_cleanup (xfree, symbol_table);
+
+  number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table);
+
+  for (i = 0; i < number_of_symbols; i++)
+    {
+      asymbol *sym = symbol_table[i];
+
+      if ((sym->flags & BSF_GLOBAL)
+          && sym->name != NULL && strcmp (sym->name, "__dbx_link") == 0)
+        return (sym->value + sym->section->vma);
+    }
+
+  /* Symbol not found, return NULL.  */
+  return 0;
+}
+
+/* Search the symbol table of the file referenced by FD for a symbol
+   named __dbx_link(). If found, then insert a breakpoint at this location,
+   and return nonzero.  Return zero otherwise.  */
+
+static int
+insert_dbx_link_bpt_in_file (int fd, CORE_ADDR ignored)
+{
+  bfd *abfd;
+  long storage_needed;
+  CORE_ADDR sym_addr;
+
+  abfd = bfd_fdopenr ("unamed", 0, fd);
+  if (abfd == NULL)
+    {
+      warning (_("Failed to create a bfd: %s."), bfd_errmsg (bfd_get_error ()));
+      return 0;
+    }
+
+  if (!bfd_check_format (abfd, bfd_object))
+    {
+      /* Not the correct format, so we can not possibly find the dbx_link
+         symbol in it.  */
+      bfd_close (abfd);
+      return 0;
+    }
+
+  sym_addr = dbx_link_addr (abfd);
+  if (sym_addr != 0)
+    {
+      /* Insert the breakpoint.  */
+      dbx_link_bpt_addr = sym_addr;
+      dbx_link_bpt = deprecated_insert_raw_breakpoint (target_gdbarch, NULL,
+                                                      sym_addr);
+      if (dbx_link_bpt == NULL)
+        {
+          warning (_("Failed to insert dbx_link breakpoint."));
+          bfd_close (abfd);
+          return 0;
+        }
+      bfd_close (abfd);
+      return 1;
+    }
+
+  bfd_close (abfd);
+  return 0;
+}
+
+/* Calls the supplied callback function once for each mapped address
+   space in the process.  The callback function  receives an open
+   file descriptor for the file corresponding to that mapped
+   address space (if there is one), and the base address of the
+   mapped space.  Quit when the callback function returns a
+   nonzero value, or at teh end of the mappings.
+
+   Returns: the first non-zero return value of the callback function,
+   or zero.  */
+
+static int
+solib_mappings_callback (struct prmap *map, int (*func) (int, CORE_ADDR),
+                        void *data)
+{
+  procinfo *pi = data;
+  int fd;
+
+#ifdef NEW_PROC_API
+  char name[MAX_PROC_NAME_SIZE + sizeof (map->pr_mapname)];
+
+  if (map->pr_vaddr == 0 && map->pr_size == 0)
+    return -1;         /* sanity */
+
+  if (map->pr_mapname[0] == 0)
+    {
+      fd = -1; /* no map file */
+    }
+  else
+    {
+      sprintf (name, "/proc/%d/object/%s", pi->pid, map->pr_mapname);
+      /* Note: caller's responsibility to close this fd!  */
+      fd = open_with_retry (name, O_RDONLY);
+      /* Note: we don't test the above call for failure;
+        we just pass the FD on as given.  Sometimes there is
+        no file, so the open may return failure, but that's
+        not a problem.  */
+    }
+#else
+  fd = ioctl (pi->ctl_fd, PIOCOPENM, &map->pr_vaddr);
+  /* Note: we don't test the above call for failure;
+     we just pass the FD on as given.  Sometimes there is
+     no file, so the ioctl may return failure, but that's
+     not a problem.  */
+#endif
+  return (*func) (fd, (CORE_ADDR) map->pr_vaddr);
+}
+
+/* If the given memory region MAP contains a symbol named __dbx_link,
+   insert a breakpoint at this location and return nonzero.  Return
+   zero otherwise.  */
+
+static int
+insert_dbx_link_bpt_in_region (struct prmap *map,
+                               iterate_over_mappings_cb_ftype *child_func,
+                               void *data)
+{
+  procinfo *pi = (procinfo *) data;
+
+  /* We know the symbol we're looking for is in a text region, so
+     only look for it if the region is a text one.  */
+  if (map->pr_mflags & MA_EXEC)
+    return solib_mappings_callback (map, insert_dbx_link_bpt_in_file, pi);
+
+  return 0;
+}
+
+/* Search all memory regions for a symbol named __dbx_link.  If found,
+   insert a breakpoint at its location, and return nonzero.  Return zero
+   otherwise.  */
+
+static int
+insert_dbx_link_breakpoint (procinfo *pi)
+{
+  return iterate_over_mappings (pi, NULL, pi, insert_dbx_link_bpt_in_region);
+}
+#endif
+
 /*
  * Function: target_wait
  *
 /*
  * Function: target_wait
  *
@@ -4376,7 +4574,7 @@ procfs_xfer_partial (struct target_ops *ops, enum target_object object,
 
 #ifdef NEW_PROC_API
     case TARGET_OBJECT_AUXV:
 
 #ifdef NEW_PROC_API
     case TARGET_OBJECT_AUXV:
-      return procfs_xfer_auxv (ops, object, annex, readbuf, writebuf,
+      return memory_xfer_auxv (ops, object, annex, readbuf, writebuf,
                               offset, len);
 #endif
 
                               offset, len);
 #endif
 
@@ -4641,9 +4839,9 @@ register_gdb_signals (procinfo *pi, gdb_sigset_t *signals)
     if (signal_stop_state  (target_signal_from_host (signo)) == 0 &&
        signal_print_state (target_signal_from_host (signo)) == 0 &&
        signal_pass_state  (target_signal_from_host (signo)) == 1)
     if (signal_stop_state  (target_signal_from_host (signo)) == 0 &&
        signal_print_state (target_signal_from_host (signo)) == 0 &&
        signal_pass_state  (target_signal_from_host (signo)) == 1)
-      prdelset (signals, signo);
+      gdb_prdelset (signals, signo);
     else
     else
-      praddset (signals, signo);
+      gdb_praddset (signals, signo);
 
   return proc_set_traced_signals (pi, signals);
 }
 
   return proc_set_traced_signals (pi, signals);
 }
@@ -5136,13 +5334,27 @@ procfs_create_inferior (struct target_ops *ops, char *exec_file,
                       NULL, NULL, shell_file);
 
   procfs_init_inferior (ops, pid);
                       NULL, NULL, shell_file);
 
   procfs_init_inferior (ops, pid);
+}
+
+/* An observer for the "inferior_created" event.  */
 
 
+static void
+procfs_inferior_created (struct target_ops *ops, int from_tty)
+{
 #ifdef SYS_syssgi
   /* Make sure to cancel the syssgi() syscall-exit notifications.  
      They should normally have been removed by now, but they may still
      be activated if the inferior doesn't use shared libraries, or if
      we didn't locate __dbx_link, or if we never stopped in __dbx_link.
 #ifdef SYS_syssgi
   /* Make sure to cancel the syssgi() syscall-exit notifications.  
      They should normally have been removed by now, but they may still
      be activated if the inferior doesn't use shared libraries, or if
      we didn't locate __dbx_link, or if we never stopped in __dbx_link.
-     See procfs_init_inferior() for more details.  */
+     See procfs_init_inferior() for more details.
+
+     Since these notifications are only ever enabled when we spawned
+     the inferior ourselves, there is nothing to do when the inferior
+     was created by attaching to an already running process, or when
+     debugging a core file.  */
+  if (current_inferior ()->attach_flag || !target_can_run (&current_target))
+    return;
+
   proc_trace_syscalls_1 (find_procinfo_or_die (PIDGET (inferior_ptid), 0),
                          SYS_syssgi, PR_SYSEXIT, FLAG_RESET, 0);
 #endif
   proc_trace_syscalls_1 (find_procinfo_or_die (PIDGET (inferior_ptid), 0),
                          SYS_syssgi, PR_SYSEXIT, FLAG_RESET, 0);
 #endif
@@ -5420,9 +5632,11 @@ procfs_use_watchpoints (struct target_ops *t)
  */
 
 static int
  */
 
 static int
-iterate_over_mappings (procinfo *pi, int (*child_func) (), void *data,
+iterate_over_mappings (procinfo *pi,
+                      iterate_over_mappings_cb_ftype *child_func,
+                      void *data,
                       int (*func) (struct prmap *map,
                       int (*func) (struct prmap *map,
-                                   int (*child_func) (),
+                                   iterate_over_mappings_cb_ftype *child_func,
                                    void *data))
 {
   char pathname[MAX_PROC_NAME_SIZE];
                                    void *data))
 {
   char pathname[MAX_PROC_NAME_SIZE];
@@ -5473,57 +5687,6 @@ iterate_over_mappings (procinfo *pi, int (*child_func) (), void *data,
   return 0;
 }
 
   return 0;
 }
 
-/*
- * Function: solib_mappings_callback
- *
- * Calls the supplied callback function once for each mapped address
- * space in the process.  The callback function  receives an open
- * file descriptor for the file corresponding to that mapped
- * address space (if there is one), and the base address of the
- * mapped space.  Quit when the callback function returns a
- * nonzero value, or at teh end of the mappings.
- *
- * Returns: the first non-zero return value of the callback function,
- * or zero.
- */
-
-int solib_mappings_callback (struct prmap *map,
-                            int (*func) (int, CORE_ADDR),
-                            void *data)
-{
-  procinfo *pi = data;
-  int fd;
-
-#ifdef NEW_PROC_API
-  char name[MAX_PROC_NAME_SIZE + sizeof (map->pr_mapname)];
-
-  if (map->pr_vaddr == 0 && map->pr_size == 0)
-    return -1;         /* sanity */
-
-  if (map->pr_mapname[0] == 0)
-    {
-      fd = -1; /* no map file */
-    }
-  else
-    {
-      sprintf (name, "/proc/%d/object/%s", pi->pid, map->pr_mapname);
-      /* Note: caller's responsibility to close this fd!  */
-      fd = open_with_retry (name, O_RDONLY);
-      /* Note: we don't test the above call for failure;
-        we just pass the FD on as given.  Sometimes there is
-        no file, so the open may return failure, but that's
-        not a problem.  */
-    }
-#else
-  fd = ioctl (pi->ctl_fd, PIOCOPENM, &map->pr_vaddr);
-  /* Note: we don't test the above call for failure;
-     we just pass the FD on as given.  Sometimes there is
-     no file, so the ioctl may return failure, but that's
-     not a problem.  */
-#endif
-  return (*func) (fd, (CORE_ADDR) map->pr_vaddr);
-}
-
 /*
  * Function: find_memory_regions_callback
  *
 /*
  * Function: find_memory_regions_callback
  *
@@ -5583,133 +5746,6 @@ proc_find_memory_regions (int (*func) (CORE_ADDR,
                                find_memory_regions_callback);
 }
 
                                find_memory_regions_callback);
 }
 
-/* Remove the breakpoint that we inserted in __dbx_link().
-   Does nothing if the breakpoint hasn't been inserted or has already
-   been removed.  */
-
-static void
-remove_dbx_link_breakpoint (void)
-{
-  if (dbx_link_bpt_addr == 0)
-    return;
-
-  if (deprecated_remove_raw_breakpoint (target_gdbarch, dbx_link_bpt) != 0)
-    warning (_("Unable to remove __dbx_link breakpoint."));
-
-  dbx_link_bpt_addr = 0;
-  dbx_link_bpt = NULL;
-}
-
-/* Return the address of the __dbx_link() function in the file
-   refernced by ABFD by scanning its symbol table.  Return 0 if
-   the symbol was not found.  */
-
-static CORE_ADDR
-dbx_link_addr (bfd *abfd)
-{
-  long storage_needed;
-  asymbol **symbol_table;
-  long number_of_symbols;
-  long i;
-
-  storage_needed = bfd_get_symtab_upper_bound (abfd);
-  if (storage_needed <= 0)
-    return 0;
-
-  symbol_table = (asymbol **) xmalloc (storage_needed);
-  make_cleanup (xfree, symbol_table);
-
-  number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table);
-
-  for (i = 0; i < number_of_symbols; i++)
-    {
-      asymbol *sym = symbol_table[i];
-
-      if ((sym->flags & BSF_GLOBAL)
-          && sym->name != NULL && strcmp (sym->name, "__dbx_link") == 0)
-        return (sym->value + sym->section->vma);
-    }
-
-  /* Symbol not found, return NULL.  */
-  return 0;
-}
-
-/* Search the symbol table of the file referenced by FD for a symbol
-   named __dbx_link(). If found, then insert a breakpoint at this location,
-   and return nonzero.  Return zero otherwise.  */
-
-static int
-insert_dbx_link_bpt_in_file (int fd, CORE_ADDR ignored)
-{
-  bfd *abfd;
-  long storage_needed;
-  CORE_ADDR sym_addr;
-
-  abfd = bfd_fdopenr ("unamed", 0, fd);
-  if (abfd == NULL)
-    {
-      warning (_("Failed to create a bfd: %s."), bfd_errmsg (bfd_get_error ()));
-      return 0;
-    }
-
-  if (!bfd_check_format (abfd, bfd_object))
-    {
-      /* Not the correct format, so we can not possibly find the dbx_link
-         symbol in it.  */
-      bfd_close (abfd);
-      return 0;
-    }
-
-  sym_addr = dbx_link_addr (abfd);
-  if (sym_addr != 0)
-    {
-      /* Insert the breakpoint.  */
-      dbx_link_bpt_addr = sym_addr;
-      dbx_link_bpt = deprecated_insert_raw_breakpoint (target_gdbarch,
-                                                      sym_addr);
-      if (dbx_link_bpt == NULL)
-        {
-          warning (_("Failed to insert dbx_link breakpoint."));
-          bfd_close (abfd);
-          return 0;
-        }
-      bfd_close (abfd);
-      return 1;
-    }
-
-  bfd_close (abfd);
-  return 0;
-} 
-
-/* If the given memory region MAP contains a symbol named __dbx_link,
-   insert a breakpoint at this location and return nonzero.  Return
-   zero otherwise.  */
-
-static int
-insert_dbx_link_bpt_in_region (struct prmap *map,
-                               int (*child_func) (),
-                               void *data)
-{     
-  procinfo *pi = (procinfo *) data;
-        
-  /* We know the symbol we're looking for is in a text region, so
-     only look for it if the region is a text one.  */
-  if (map->pr_mflags & MA_EXEC)
-    return solib_mappings_callback (map, insert_dbx_link_bpt_in_file, pi);
-  return 0;
-}           
-
-/* Search all memory regions for a symbol named __dbx_link.  If found,
-   insert a breakpoint at its location, and return nonzero.  Return zero
-   otherwise.  */
-
-static int
-insert_dbx_link_breakpoint (procinfo *pi)
-{
-  return iterate_over_mappings (pi, NULL, pi, insert_dbx_link_bpt_in_region);
-}
-
 /*
  * Function: mappingflags
  *
 /*
  * Function: mappingflags
  *
@@ -5748,7 +5784,9 @@ mappingflags (long flags)
  */
 
 static int
  */
 
 static int
-info_mappings_callback (struct prmap *map, int (*ignore) (), void *unused)
+info_mappings_callback (struct prmap *map,
+                       iterate_over_mappings_cb_ftype *ignore,
+                       void *unused)
 {
   unsigned int pr_off;
 
 {
   unsigned int pr_off;
 
@@ -5990,6 +6028,8 @@ proc_untrace_sysexit_cmd (char *args, int from_tty)
 void
 _initialize_procfs (void)
 {
 void
 _initialize_procfs (void)
 {
+  observer_attach_inferior_created (procfs_inferior_created);
+
   add_info ("proc", info_proc_cmd, _("\
 Show /proc process information about any running process.\n\
 Specify process id, or use the program being debugged by default.\n\
   add_info ("proc", info_proc_cmd, _("\
 Show /proc process information about any running process.\n\
 Specify process id, or use the program being debugged by default.\n\
@@ -6024,28 +6064,6 @@ procfs_first_available (void)
   return pid_to_ptid (procinfo_list ? procinfo_list->pid : -1);
 }
 
   return pid_to_ptid (procinfo_list ? procinfo_list->pid : -1);
 }
 
-static int
-find_signalled_thread (struct thread_info *info, void *data)
-{
-  if (info->stop_signal != TARGET_SIGNAL_0
-      && ptid_get_pid (info->ptid) == ptid_get_pid (inferior_ptid))
-    return 1;
-
-  return 0;
-}
-
-static enum target_signal
-find_stop_signal (void)
-{
-  struct thread_info *info =
-    iterate_over_threads (find_signalled_thread, NULL);
-
-  if (info)
-    return info->stop_signal;
-  else
-    return TARGET_SIGNAL_0;
-}
-
 /* ===================  GCORE .NOTE "MODULE" =================== */
 #if defined (UNIXWARE) || defined (PIOCOPENLWP) || defined (PCAGENT)
 /* gcore only implemented on solaris and unixware (so far) */
 /* ===================  GCORE .NOTE "MODULE" =================== */
 #if defined (UNIXWARE) || defined (PIOCOPENLWP) || defined (PCAGENT)
 /* gcore only implemented on solaris and unixware (so far) */
@@ -6059,11 +6077,21 @@ procfs_do_thread_registers (bfd *obfd, ptid_t ptid,
   gdb_gregset_t gregs;
   gdb_fpregset_t fpregs;
   unsigned long merged_pid;
   gdb_gregset_t gregs;
   gdb_fpregset_t fpregs;
   unsigned long merged_pid;
+  struct cleanup *old_chain;
 
   merged_pid = TIDGET (ptid) << 16 | PIDGET (ptid);
 
 
   merged_pid = TIDGET (ptid) << 16 | PIDGET (ptid);
 
+  /* This part is the old method for fetching registers.
+     It should be replaced by the newer one using regsets
+     once it is implemented in this platform:
+     gdbarch_regset_from_core_section() and regset->collect_regset(). */
+
+  old_chain = save_inferior_ptid ();
+  inferior_ptid = ptid;
+  target_fetch_registers (regcache, -1);
+
   fill_gregset (regcache, &gregs, -1);
   fill_gregset (regcache, &gregs, -1);
-#if defined (UNIXWARE)
+#if defined (NEW_PROC_API)
   note_data = (char *) elfcore_write_lwpstatus (obfd,
                                                note_data,
                                                note_size,
   note_data = (char *) elfcore_write_lwpstatus (obfd,
                                                note_data,
                                                note_size,
@@ -6084,6 +6112,9 @@ procfs_do_thread_registers (bfd *obfd, ptid_t ptid,
                                              note_size,
                                              &fpregs,
                                              sizeof (fpregs));
                                              note_size,
                                              &fpregs,
                                              sizeof (fpregs));
+
+  do_cleanups (old_chain);
+
   return note_data;
 }
 
   return note_data;
 }
 
@@ -6101,17 +6132,37 @@ procfs_corefile_thread_callback (procinfo *pi, procinfo *thread, void *data)
 
   if (pi != NULL)
     {
 
   if (pi != NULL)
     {
-      ptid_t saved_ptid = inferior_ptid;
-      inferior_ptid = MERGEPID (pi->pid, thread->tid);
-      args->note_data = procfs_do_thread_registers (args->obfd, inferior_ptid,
+      ptid_t ptid = MERGEPID (pi->pid, thread->tid);
+      args->note_data = procfs_do_thread_registers (args->obfd, ptid,
                                                    args->note_data,
                                                    args->note_size,
                                                    args->stop_signal);
                                                    args->note_data,
                                                    args->note_size,
                                                    args->stop_signal);
-      inferior_ptid = saved_ptid;
     }
   return 0;
 }
 
     }
   return 0;
 }
 
+static int
+find_signalled_thread (struct thread_info *info, void *data)
+{
+  if (info->stop_signal != TARGET_SIGNAL_0
+      && ptid_get_pid (info->ptid) == ptid_get_pid (inferior_ptid))
+    return 1;
+
+  return 0;
+}
+
+static enum target_signal
+find_stop_signal (void)
+{
+  struct thread_info *info =
+    iterate_over_threads (find_signalled_thread, NULL);
+
+  if (info)
+    return info->stop_signal;
+  else
+    return TARGET_SIGNAL_0;
+}
+
 static char *
 procfs_make_note_section (bfd *obfd, int *note_size)
 {
 static char *
 procfs_make_note_section (bfd *obfd, int *note_size)
 {
@@ -6153,7 +6204,7 @@ procfs_make_note_section (bfd *obfd, int *note_size)
 
   stop_signal = find_stop_signal ();
 
 
   stop_signal = find_stop_signal ();
 
-#ifdef NEW_PROC_API
+#ifdef UNIXWARE
   fill_gregset (get_current_regcache (), &gregs, -1);
   note_data = elfcore_write_pstatus (obfd, note_data, note_size,
                                     PIDGET (inferior_ptid),
   fill_gregset (get_current_regcache (), &gregs, -1);
   note_data = elfcore_write_pstatus (obfd, note_data, note_size,
                                     PIDGET (inferior_ptid),
This page took 0.03222 seconds and 4 git commands to generate.