Fix warnings resulting from fact that GET_LWP() now returns a long rather
[deliverable/binutils-gdb.git] / gdb / rs6000-nat.c
index 6fa4560703ffeab678076603c358be620ec245db..e6693cc31a07f1d967dc36e51c62af226a951e08 100644 (file)
@@ -1,5 +1,6 @@
 /* IBM RS/6000 native-dependent code for GDB, the GNU debugger.
-   Copyright 1986, 1987, 1989, 1991, 1992, 1994, 1995, 1996, 1997, 1998
+   Copyright 1986, 1987, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
+   1998, 1999, 2000, 2001
    Free Software Foundation, Inc.
 
    This file is part of GDB.
@@ -29,6 +30,7 @@
 #include "libbfd.h"            /* For bfd_cache_lookup (FIXME) */
 #include "bfd.h"
 #include "gdb-stabs.h"
+#include "regcache.h"
 
 #include <sys/ptrace.h>
 #include <sys/reg.h>
@@ -199,7 +201,7 @@ fetch_register (int regno)
   if (regno >= FP0_REGNUM && regno <= FPLAST_REGNUM)
     {
       nr = regno - FP0_REGNUM + FPR0;
-      ptrace32 (PT_READ_FPR, inferior_pid, addr, nr, 0);
+      ptrace32 (PT_READ_FPR, PIDGET (inferior_ptid), addr, nr, 0);
     }
 
   /* Bogus register number. */
@@ -217,13 +219,13 @@ fetch_register (int regno)
        nr = regno;
 
       if (!ARCH64 ())
-       *addr = ptrace32 (PT_READ_GPR, inferior_pid, (int *)nr, 0, 0);
+       *addr = ptrace32 (PT_READ_GPR, PIDGET (inferior_ptid), (int *)nr, 0, 0);
       else
        {
          /* PT_READ_GPR requires the buffer parameter to point to long long,
             even if the register is really only 32 bits. */
          long long buf;
-         ptrace64 (PT_READ_GPR, inferior_pid, nr, 0, (int *)&buf);
+         ptrace64 (PT_READ_GPR, PIDGET (inferior_ptid), nr, 0, (int *)&buf);
          if (REGISTER_RAW_SIZE (regno) == 8)
            memcpy (addr, &buf, 8);
          else
@@ -258,7 +260,7 @@ store_register (int regno)
   if (regno >= FP0_REGNUM && regno <= FPLAST_REGNUM)
     {
       nr = regno - FP0_REGNUM + FPR0;
-      ptrace32 (PT_WRITE_FPR, inferior_pid, addr, nr, 0);
+      ptrace32 (PT_WRITE_FPR, PIDGET (inferior_ptid), addr, nr, 0);
     }
 
   /* Bogus register number. */
@@ -287,7 +289,7 @@ store_register (int regno)
        nr = regno;
 
       if (!ARCH64 ())
-       ptrace32 (PT_WRITE_GPR, inferior_pid, (int *)nr, *addr, 0);
+       ptrace32 (PT_WRITE_GPR, PIDGET (inferior_ptid), (int *)nr, *addr, 0);
       else
        {
          /* PT_WRITE_GPR requires the buffer parameter to point to an 8-byte
@@ -297,7 +299,7 @@ store_register (int regno)
            memcpy (&buf, addr, 8);
          else
            buf = *addr;
-         ptrace64 (PT_WRITE_GPR, inferior_pid, nr, 0, (int *)&buf);
+         ptrace64 (PT_WRITE_GPR, PIDGET (inferior_ptid), nr, 0, (int *)&buf);
        }
     }
 
@@ -371,9 +373,10 @@ read_word (CORE_ADDR from, int *to, int arch64)
   errno = 0;
 
   if (arch64)
-    *to = ptrace64 (PT_READ_I, inferior_pid, from, 0, NULL);
+    *to = ptrace64 (PT_READ_I, PIDGET (inferior_ptid), from, 0, NULL);
   else
-    *to = ptrace32 (PT_READ_I, inferior_pid, (int *)(long) from, 0, NULL);
+    *to = ptrace32 (PT_READ_I, PIDGET (inferior_ptid), (int *)(long) from,
+                    0, NULL);
 
   return !errno;
 }
@@ -389,7 +392,8 @@ read_word (CORE_ADDR from, int *to, int arch64)
 
 int
 child_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len,
-                  int write, struct target_ops *target)
+                  int write, struct mem_attrib *attrib,
+                  struct target_ops *target)
 {
   /* Round starting address down to 32-bit word boundary. */
   int mask = sizeof (int) - 1;
@@ -438,9 +442,9 @@ child_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len,
       for (i = 0, errno = 0; i < count; i++, addr += sizeof (int))
        {
          if (arch64)
-           ptrace64 (PT_WRITE_D, inferior_pid, addr, buf[i], NULL);
+           ptrace64 (PT_WRITE_D, PIDGET (inferior_ptid), addr, buf[i], NULL);
          else
-           ptrace32 (PT_WRITE_D, inferior_pid, (int *)(long) addr,
+           ptrace32 (PT_WRITE_D, PIDGET (inferior_ptid), (int *)(long) addr,
                      buf[i], NULL);
 
          if (errno)
@@ -479,9 +483,9 @@ exec_one_dummy_insn (void)
   prev_pc = read_pc ();
   write_pc (DUMMY_INSN_ADDR);
   if (ARCH64 ())
-    ret = ptrace64 (PT_CONTINUE, inferior_pid, 1, 0, NULL);
+    ret = ptrace64 (PT_CONTINUE, PIDGET (inferior_ptid), 1, 0, NULL);
   else
-    ret = ptrace32 (PT_CONTINUE, inferior_pid, (int *)1, 0, NULL);
+    ret = ptrace32 (PT_CONTINUE, PIDGET (inferior_ptid), (int *)1, 0, NULL);
 
   if (ret != 0)
     perror ("pt_continue");
@@ -490,7 +494,7 @@ exec_one_dummy_insn (void)
     {
       pid = wait (&status);
     }
-  while (pid != inferior_pid);
+  while (pid != PIDGET (inferior_ptid));
 
   write_pc (prev_pc);
   target_remove_breakpoint (DUMMY_INSN_ADDR, shadow_contents);
@@ -605,6 +609,9 @@ vmap_symtab (struct vmap *vp)
        return;
       objfile = symfile_objfile;
     }
+  else if (!vp->loaded)
+    /* If symbols are not yet loaded, offsets are not yet valid. */
+    return;
 
   new_offsets = (struct section_offsets *) alloca (SIZEOF_SECTION_OFFSETS);
 
@@ -632,6 +639,23 @@ objfile_symbol_add (void *arg)
   return 1;
 }
 
+/* Add symbols for a vmap. Return zero upon error.  */
+
+int
+vmap_add_symbols (struct vmap *vp)
+{
+  if (catch_errors (objfile_symbol_add, vp->objfile,
+                   "Error while reading shared library symbols:\n",
+                   RETURN_MASK_ALL))
+    {
+      /* Note this is only done if symbol reading was successful.  */
+      vp->loaded = 1;
+      vmap_symtab (vp);
+      return 1;
+    }
+  return 0;
+}
+
 /* Add a new vmap entry based on ldinfo() information.
 
    If ldi->ldinfo_fd is not valid (e.g. this struct ld_info is from a
@@ -666,8 +690,11 @@ add_vmap (LdInfo *ldi)
   else
     abfd = bfd_fdopenr (objname, gnutarget, fd);
   if (!abfd)
-    error ("Could not open `%s' as an executable file: %s",
-          objname, bfd_errmsg (bfd_get_error ()));
+    {
+      warning ("Could not open `%s' as an executable file: %s",
+              objname, bfd_errmsg (bfd_get_error ()));
+      return NULL;
+    }
 
   /* make sure we have an object file */
 
@@ -684,41 +711,35 @@ add_vmap (LdInfo *ldi)
 
       if (!last)
        {
+         warning ("\"%s\": member \"%s\" missing.", objname, mem);
          bfd_close (abfd);
-         /* FIXME -- should be error */
-         warning ("\"%s\": member \"%s\" missing.", abfd->filename, mem);
-         return 0;
+         return NULL;
        }
 
       if (!bfd_check_format (last, bfd_object))
        {
-         bfd_close (last);     /* XXX???       */
-         goto obj_err;
+         warning ("\"%s\": member \"%s\" not in executable format: %s.",
+                  objname, mem, bfd_errmsg (bfd_get_error ()));
+         bfd_close (last);
+         bfd_close (abfd);
+         return NULL;
        }
 
       vp = map_vmap (last, abfd);
     }
   else
     {
-    obj_err:
+      warning ("\"%s\": not in executable format: %s.",
+              objname, bfd_errmsg (bfd_get_error ()));
       bfd_close (abfd);
-      error ("\"%s\": not in executable format: %s.",
-            objname, bfd_errmsg (bfd_get_error ()));
-      /*NOTREACHED */
+      return NULL;
     }
   obj = allocate_objfile (vp->bfd, 0);
   vp->objfile = obj;
 
-#ifndef SOLIB_SYMBOLS_MANUAL
-  if (catch_errors (objfile_symbol_add, obj,
-                   "Error while reading shared library symbols:\n",
-                   RETURN_MASK_ALL))
-    {
-      /* Note this is only done if symbol reading was successful.  */
-      vmap_symtab (vp);
-      vp->loaded = 1;
-    }
-#endif
+  /* Always add symbols for the main objfile.  */
+  if (vp == vmap || auto_solib_add)
+    vmap_add_symbols (vp);
   return vp;
 }
 \f
@@ -910,7 +931,8 @@ set_host_arch (int pid)
 
   if (!gdbarch_update_p (info))
     {
-      internal_error ("set_host_arch: failed to select architecture");
+      internal_error (__FILE__, __LINE__,
+                     "set_host_arch: failed to select architecture");
     }
 }
 
@@ -960,7 +982,7 @@ xcoff_relocate_symtab (unsigned int pid)
        }
     } while (rc == -1);
   if (ldi)
-    free (ldi);
+    xfree (ldi);
 }
 \f
 /* Core file stuff.  */
@@ -985,12 +1007,6 @@ xcoff_relocate_core (struct target_ops *target)
   char *buffer = xmalloc (buffer_size);
   struct cleanup *old = make_cleanup (free_current_contents, &buffer);
 
-  /* FIXME, this restriction should not exist.  For now, though I'll
-     avoid coredumps with error() pending a real fix.  */
-  if (vmap == NULL)
-    error
-      ("Can't debug a core file without an executable file (on the RS/6000)");
-
   ldinfo_sec = bfd_get_section_by_name (core_bfd, ".ldinfo");
   if (ldinfo_sec == NULL)
     {
@@ -1036,12 +1052,16 @@ xcoff_relocate_core (struct target_ops *target)
        ldi->l32.ldinfo_fd = -1;
 
       /* The first ldinfo is for the exec file, allocated elsewhere.  */
-      if (offset == 0)
+      if (offset == 0 && vmap != NULL)
        vp = vmap;
       else
        vp = add_vmap (ldi);
 
+      /* Process next shared library upon error. */
       offset += LDI_NEXT (ldi, arch64);
+      if (vp == NULL)
+       continue;
+
       vmap_secs (vp, ldi, arch64);
 
       /* Unless this is the exec file,
@@ -1125,9 +1145,5 @@ _initialize_core_rs6000 (void)
      starting a child process. */
   rs6000_set_host_arch_hook = set_host_arch;
 
-  /* For native configurations, where this module is included, inform
-     the xcoffsolib module where it can find the function for symbol table
-     relocation at runtime. */
-  xcoff_relocate_symtab_hook = xcoff_relocate_symtab;
   add_core_fns (&rs6000_core_fns);
 }
This page took 0.027284 seconds and 4 git commands to generate.