Example #1
0
static gdb_byte *
rs6000_ptrace_ldinfo (ptid_t ptid)
{
    const int pid = ptid_get_pid (ptid);
    int ldi_size = 1024;
    gdb_byte *ldi = xmalloc (ldi_size);
    int rc = -1;

    while (1)
    {
        if (ARCH64 ())
            rc = rs6000_ptrace64 (PT_LDINFO, pid, (unsigned long) ldi, ldi_size,
                                  NULL);
        else
            rc = rs6000_ptrace32 (PT_LDINFO, pid, (int *) ldi, ldi_size, NULL);

        if (rc != -1)
            break; /* Success, we got the entire ld_info data.  */

        if (errno != ENOMEM)
            perror_with_name (_("ptrace ldinfo"));

        /* ldi is not big enough.  Double it and try again.  */
        ldi_size *= 2;
        ldi = xrealloc (ldi, ldi_size);
    }

    return ldi;
}
Example #2
0
static gdb::byte_vector
rs6000_ptrace_ldinfo (ptid_t ptid)
{
  const int pid = ptid.pid ();
  gdb::byte_vector ldi (1024);
  int rc = -1;

  while (1)
    {
      if (ARCH64 ())
	rc = rs6000_ptrace64 (PT_LDINFO, pid, (unsigned long) ldi.data (),
			      ldi.size (), NULL);
      else
	rc = rs6000_ptrace32 (PT_LDINFO, pid, (int *) ldi.data (),
			      ldi.size (), NULL);

      if (rc != -1)
	break; /* Success, we got the entire ld_info data.  */

      if (errno != ENOMEM)
	perror_with_name (_("ptrace ldinfo"));

      /* ldi is not big enough.  Double it and try again.  */
      ldi.resize (ldi.size () * 2);
    }

  return ldi;
}
Example #3
0
static void
store_register (struct regcache *regcache, int regno)
{
    struct gdbarch *gdbarch = get_regcache_arch (regcache);
    int addr[MAX_REGISTER_SIZE];
    int nr, isfloat;

    /* Fetch the register's value from the register cache.  */
    regcache_raw_collect (regcache, regno, addr);

    /* -1 can be a successful return value, so infer errors from errno.  */
    errno = 0;

    nr = regmap (gdbarch, regno, &isfloat);

    /* Floating-point registers.  */
    if (isfloat)
        rs6000_ptrace32 (PT_WRITE_FPR, ptid_get_pid (inferior_ptid), addr, nr, 0);

    /* Bogus register number.  */
    else if (nr < 0)
    {
        if (regno >= gdbarch_num_regs (gdbarch))
            fprintf_unfiltered (gdb_stderr,
                                "gdb error: register no %d not implemented.\n",
                                regno);
    }

    /* Fixed-point registers.  */
    else
    {
        /* The PT_WRITE_GPR operation is rather odd.  For 32-bit inferiors,
           the register's value is passed by value, but for 64-bit inferiors,
        the address of a buffer containing the value is passed.  */
        if (!ARCH64 ())
            rs6000_ptrace32 (PT_WRITE_GPR, ptid_get_pid (inferior_ptid),
                             (int *) nr, *addr, 0);
        else
        {
            /* PT_WRITE_GPR requires the buffer parameter to point to an 8-byte
               area, even if the register is really only 32 bits.  */
            long long buf;
            if (register_size (gdbarch, regno) == 8)
                memcpy (&buf, addr, 8);
            else
                buf = *addr;
            rs6000_ptrace64 (PT_WRITE_GPR, ptid_get_pid (inferior_ptid),
                             nr, 0, &buf);
        }
    }

    if (errno)
    {
        perror (_("ptrace write"));
        errno = 0;
    }
}
Example #4
0
static void
fetch_register (struct regcache *regcache, int regno)
{
    struct gdbarch *gdbarch = get_regcache_arch (regcache);
    int addr[MAX_REGISTER_SIZE];
    int nr, isfloat;

    /* Retrieved values may be -1, so infer errors from errno.  */
    errno = 0;

    nr = regmap (gdbarch, regno, &isfloat);

    /* Floating-point registers.  */
    if (isfloat)
        rs6000_ptrace32 (PT_READ_FPR, ptid_get_pid (inferior_ptid), addr, nr, 0);

    /* Bogus register number.  */
    else if (nr < 0)
    {
        if (regno >= gdbarch_num_regs (gdbarch))
            fprintf_unfiltered (gdb_stderr,
                                "gdb error: register no %d not implemented.\n",
                                regno);
        return;
    }

    /* Fixed-point registers.  */
    else
    {
        if (!ARCH64 ())
            *addr = rs6000_ptrace32 (PT_READ_GPR, ptid_get_pid (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;
            rs6000_ptrace64 (PT_READ_GPR, ptid_get_pid (inferior_ptid),
                             nr, 0, &buf);
            if (register_size (gdbarch, regno) == 8)
                memcpy (addr, &buf, 8);
            else
                *addr = buf;
        }
    }

    if (!errno)
        regcache_raw_supply (regcache, regno, (char *) addr);
    else
    {
#if 0
        /* FIXME: this happens 3 times at the start of each 64-bit program.  */
        perror (_("ptrace read"));
#endif
        errno = 0;
    }
}
Example #5
0
void
xcoff_relocate_symtab (unsigned int pid)
{
  int load_segs = 64; /* number of load segments */
  int rc;
  LdInfo *ldi = NULL;
  int arch64 = ARCH64 ();
  int ldisize = arch64 ? sizeof (ldi->l64) : sizeof (ldi->l32);
  int size;

  do
    {
      size = load_segs * ldisize;
      ldi = (void *) xrealloc (ldi, size);

#if 0
      /* According to my humble theory, AIX has some timing problems and
         when the user stack grows, kernel doesn't update stack info in time
         and ptrace calls step on user stack. That is why we sleep here a
         little, and give kernel to update its internals. */
      usleep (36000);
#endif

      if (arch64)
	rc = rs6000_ptrace64 (PT_LDINFO, pid, (unsigned long) ldi, size, NULL);
      else
	rc = rs6000_ptrace32 (PT_LDINFO, pid, (int *) ldi, size, NULL);

      if (rc == -1)
        {
          if (errno == ENOMEM)
            load_segs *= 2;
          else
            perror_with_name ("ptrace ldinfo");
        }
      else
	{
          vmap_ldinfo (ldi);
          vmap_exec (); /* relocate the exec and core sections as well. */
	}
    } while (rc == -1);
  if (ldi)
    xfree (ldi);
}
Example #6
0
static void
exec_one_dummy_insn (struct regcache *regcache)
{
#define	DUMMY_INSN_ADDR	AIX_TEXT_SEGMENT_BASE+0x200

  struct gdbarch *gdbarch = get_regcache_arch (regcache);
  int ret, status, pid;
  CORE_ADDR prev_pc;
  void *bp;

  /* We plant one dummy breakpoint into DUMMY_INSN_ADDR address.  We
     assume that this address will never be executed again by the real
     code.  */

  bp = deprecated_insert_raw_breakpoint (gdbarch, NULL, DUMMY_INSN_ADDR);

  /* You might think this could be done with a single ptrace call, and
     you'd be correct for just about every platform I've ever worked
     on.  However, rs6000-ibm-aix4.1.3 seems to have screwed this up --
     the inferior never hits the breakpoint (it's also worth noting
     powerpc-ibm-aix4.1.3 works correctly).  */
  prev_pc = regcache_read_pc (regcache);
  regcache_write_pc (regcache, DUMMY_INSN_ADDR);
  if (ARCH64 ())
    ret = rs6000_ptrace64 (PT_CONTINUE, ptid_get_pid (inferior_ptid),
			   1, 0, NULL);
  else
    ret = rs6000_ptrace32 (PT_CONTINUE, ptid_get_pid (inferior_ptid),
			   (int *) 1, 0, NULL);

  if (ret != 0)
    perror (_("pt_continue"));

  do
    {
      pid = waitpid (ptid_get_pid (inferior_ptid), &status, 0);
    }
  while (pid != ptid_get_pid (inferior_ptid));

  regcache_write_pc (regcache, prev_pc);
  deprecated_remove_raw_breakpoint (gdbarch, bp);
}
static void
exec_one_dummy_insn (struct gdbarch *gdbarch)
{
#define	DUMMY_INSN_ADDR	gdbarch_tdep (gdbarch)->text_segment_base+0x200

  int ret, status, pid;
  CORE_ADDR prev_pc;
  void *bp;

  /* We plant one dummy breakpoint into DUMMY_INSN_ADDR address. We
     assume that this address will never be executed again by the real
     code. */

  bp = deprecated_insert_raw_breakpoint (DUMMY_INSN_ADDR);

  /* You might think this could be done with a single ptrace call, and
     you'd be correct for just about every platform I've ever worked
     on.  However, rs6000-ibm-aix4.1.3 seems to have screwed this up --
     the inferior never hits the breakpoint (it's also worth noting
     powerpc-ibm-aix4.1.3 works correctly).  */
  prev_pc = read_pc ();
  write_pc (DUMMY_INSN_ADDR);
  if (ARCH64 ())
    ret = rs6000_ptrace64 (PT_CONTINUE, PIDGET (inferior_ptid), 1, 0, NULL);
  else
    ret = rs6000_ptrace32 (PT_CONTINUE, PIDGET (inferior_ptid), (int *)1, 0, NULL);

  if (ret != 0)
    perror ("pt_continue");

  do
    {
      pid = wait (&status);
    }
  while (pid != PIDGET (inferior_ptid));

  write_pc (prev_pc);
  deprecated_remove_raw_breakpoint (bp);
}
Example #8
0
static void
exec_one_dummy_insn (void)
{
#define	DUMMY_INSN_ADDR	(TEXT_SEGMENT_BASE)+0x200

  char shadow_contents[BREAKPOINT_MAX];		/* Stash old bkpt addr contents */
  int ret, status, pid;
  CORE_ADDR prev_pc;

  /* We plant one dummy breakpoint into DUMMY_INSN_ADDR address. We
     assume that this address will never be executed again by the real
     code. */

  target_insert_breakpoint (DUMMY_INSN_ADDR, shadow_contents);

  /* You might think this could be done with a single ptrace call, and
     you'd be correct for just about every platform I've ever worked
     on.  However, rs6000-ibm-aix4.1.3 seems to have screwed this up --
     the inferior never hits the breakpoint (it's also worth noting
     powerpc-ibm-aix4.1.3 works correctly).  */
  prev_pc = read_pc ();
  write_pc (DUMMY_INSN_ADDR);
  if (ARCH64 ())
    ret = rs6000_ptrace64 (PT_CONTINUE, PIDGET (inferior_ptid), 1, 0, NULL);
  else
    ret = rs6000_ptrace32 (PT_CONTINUE, PIDGET (inferior_ptid), (int *)1, 0, NULL);

  if (ret != 0)
    perror ("pt_continue");

  do
    {
      pid = wait (&status);
    }
  while (pid != PIDGET (inferior_ptid));

  write_pc (prev_pc);
  target_remove_breakpoint (DUMMY_INSN_ADDR, shadow_contents);
}
Example #9
0
static enum target_xfer_status
rs6000_xfer_partial (struct target_ops *ops, enum target_object object,
                     const char *annex, gdb_byte *readbuf,
                     const gdb_byte *writebuf,
                     ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
{
    pid_t pid = ptid_get_pid (inferior_ptid);
    int arch64 = ARCH64 ();

    switch (object)
    {
    case TARGET_OBJECT_LIBRARIES_AIX:
        return rs6000_xfer_shared_libraries (ops, object, annex,
        readbuf, writebuf,
        offset, len, xfered_len);
    case TARGET_OBJECT_MEMORY:
    {
        union
        {
            PTRACE_TYPE_RET word;
            gdb_byte byte[sizeof (PTRACE_TYPE_RET)];
        } buffer;
        ULONGEST rounded_offset;
        LONGEST partial_len;

        /* Round the start offset down to the next long word
           boundary.  */
        rounded_offset = offset & -(ULONGEST) sizeof (PTRACE_TYPE_RET);

        /* Since ptrace will transfer a single word starting at that
           rounded_offset the partial_len needs to be adjusted down to
           that (remember this function only does a single transfer).
           Should the required length be even less, adjust it down
           again.  */
        partial_len = (rounded_offset + sizeof (PTRACE_TYPE_RET)) - offset;
        if (partial_len > len)
            partial_len = len;

        if (writebuf)
        {
            /* If OFFSET:PARTIAL_LEN is smaller than
               ROUNDED_OFFSET:WORDSIZE then a read/modify write will
               be needed.  Read in the entire word.  */
            if (rounded_offset < offset
                    || (offset + partial_len
                        < rounded_offset + sizeof (PTRACE_TYPE_RET)))
            {
                /* Need part of initial word -- fetch it.  */
                if (arch64)
                    buffer.word = rs6000_ptrace64 (PT_READ_I, pid,
                                                   rounded_offset, 0, NULL);
                else
                    buffer.word = rs6000_ptrace32 (PT_READ_I, pid,
                                                   (int *) (uintptr_t)
                                                   rounded_offset,
                                                   0, NULL);
            }

            /* Copy data to be written over corresponding part of
               buffer.  */
            memcpy (buffer.byte + (offset - rounded_offset),
                    writebuf, partial_len);

            errno = 0;
            if (arch64)
                rs6000_ptrace64 (PT_WRITE_D, pid,
                                 rounded_offset, buffer.word, NULL);
            else
                rs6000_ptrace32 (PT_WRITE_D, pid,
                                 (int *) (uintptr_t) rounded_offset,
                                 buffer.word, NULL);
            if (errno)
                return TARGET_XFER_EOF;
        }

        if (readbuf)
        {
            errno = 0;
            if (arch64)
                buffer.word = rs6000_ptrace64 (PT_READ_I, pid,
                                               rounded_offset, 0, NULL);
            else
                buffer.word = rs6000_ptrace32 (PT_READ_I, pid,
                                               (int *)(uintptr_t)rounded_offset,
                                               0, NULL);
            if (errno)
                return TARGET_XFER_EOF;

            /* Copy appropriate bytes out of the buffer.  */
            memcpy (readbuf, buffer.byte + (offset - rounded_offset),
                    partial_len);
        }

        *xfered_len = (ULONGEST) partial_len;
        return TARGET_XFER_OK;
    }

    default:
        return TARGET_XFER_E_IO;
    }
}
Example #10
0
static void
vmap_ldinfo (LdInfo *ldi)
{
  struct stat ii, vi;
  struct vmap *vp;
  int got_one, retried;
  int got_exec_file = 0;
  uint next;
  int arch64 = ARCH64 ();

  /* For each *ldi, see if we have a corresponding *vp.
     If so, update the mapping, and symbol table.
     If not, add an entry and symbol table.  */

  do
    {
      char *name = LDI_FILENAME (ldi, arch64);
      char *memb = name + strlen (name) + 1;
      int fd = LDI_FD (ldi, arch64);

      retried = 0;

      if (fstat (fd, &ii) < 0)
	{
	  /* The kernel sets ld_info to -1, if the process is still using the
	     object, and the object is removed. Keep the symbol info for the
	     removed object and issue a warning.  */
	  warning (_("%s (fd=%d) has disappeared, keeping its symbols"),
		   name, fd);
	  continue;
	}
    retry:
      for (got_one = 0, vp = vmap; vp; vp = vp->nxt)
	{
	  struct objfile *objfile;

	  /* First try to find a `vp', which is the same as in ldinfo.
	     If not the same, just continue and grep the next `vp'. If same,
	     relocate its tstart, tend, dstart, dend values. If no such `vp'
	     found, get out of this for loop, add this ldi entry as a new vmap
	     (add_vmap) and come back, find its `vp' and so on... */

	  /* The filenames are not always sufficient to match on. */

	  if ((name[0] == '/' && strcmp (name, vp->name) != 0)
	      || (memb[0] && strcmp (memb, vp->member) != 0))
	    continue;

	  /* See if we are referring to the same file.
	     We have to check objfile->obfd, symfile.c:reread_symbols might
	     have updated the obfd after a change.  */
	  objfile = vp->objfile == NULL ? symfile_objfile : vp->objfile;
	  if (objfile == NULL
	      || objfile->obfd == NULL
	      || bfd_stat (objfile->obfd, &vi) < 0)
	    {
	      warning (_("Unable to stat %s, keeping its symbols"), name);
	      continue;
	    }

	  if (ii.st_dev != vi.st_dev || ii.st_ino != vi.st_ino)
	    continue;

	  if (!retried)
	    close (fd);

	  ++got_one;

	  /* Found a corresponding VMAP.  Remap!  */

	  vmap_secs (vp, ldi, arch64);

	  /* The objfile is only NULL for the exec file.  */
	  if (vp->objfile == NULL)
	    got_exec_file = 1;

	  /* relocate symbol table(s). */
	  vmap_symtab (vp);

	  /* Announce new object files.  Doing this after symbol relocation
	     makes aix-thread.c's job easier.  */
	  if (vp->objfile)
	    observer_notify_new_objfile (vp->objfile);

	  /* There may be more, so we don't break out of the loop.  */
	}

      /* if there was no matching *vp, we must perforce create the sucker(s) */
      if (!got_one && !retried)
	{
	  add_vmap (ldi);
	  ++retried;
	  goto retry;
	}
    }
  while ((next = LDI_NEXT (ldi, arch64))
	 && (ldi = (void *) (next + (char *) ldi)));

  /* If we don't find the symfile_objfile anywhere in the ldinfo, it
     is unlikely that the symbol file is relocated to the proper
     address.  And we might have attached to a process which is
     running a different copy of the same executable.  */
  if (symfile_objfile != NULL && !got_exec_file)
    {
      warning (_("Symbol file %s\nis not mapped; discarding it.\n\
If in fact that file has symbols which the mapped files listed by\n\
\"info files\" lack, you can load symbols with the \"symbol-file\" or\n\
\"add-symbol-file\" commands (note that you must take care of relocating\n\
symbols to the proper address)."),
	       symfile_objfile->name);
      free_objfile (symfile_objfile);
      gdb_assert (symfile_objfile == NULL);
    }
Example #11
0
static void
store_register (struct regcache *regcache, int regno)
{
  struct gdbarch *gdbarch = get_regcache_arch (regcache);
  int addr[MAX_REGISTER_SIZE];
  int nr, isfloat;

  /* Fetch the register's value from the register cache.  */
  regcache_raw_collect (regcache, regno, addr);

  /* -1 can be a successful return value, so infer errors from errno. */
  errno = 0;

  nr = regmap (gdbarch, regno, &isfloat);

  /* Floating-point registers. */
  if (isfloat)
    rs6000_ptrace32 (PT_WRITE_FPR, PIDGET (inferior_ptid), addr, nr, 0);

  /* Bogus register number. */
  else if (nr < 0)
    {
      if (regno >= gdbarch_num_regs (gdbarch))
	fprintf_unfiltered (gdb_stderr,
			    "gdb error: register no %d not implemented.\n",
			    regno);
    }

  /* Fixed-point registers. */
  else
    {
      if (regno == gdbarch_sp_regnum (gdbarch))
	/* Execute one dummy instruction (which is a breakpoint) in inferior
	   process to give kernel a chance to do internal housekeeping.
	   Otherwise the following ptrace(2) calls will mess up user stack
	   since kernel will get confused about the bottom of the stack
	   (%sp). */
	exec_one_dummy_insn (regcache);

      /* The PT_WRITE_GPR operation is rather odd.  For 32-bit inferiors,
         the register's value is passed by value, but for 64-bit inferiors,
	 the address of a buffer containing the value is passed.  */
      if (!ARCH64 ())
	rs6000_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
	     area, even if the register is really only 32 bits. */
	  long long buf;
	  if (register_size (gdbarch, regno) == 8)
	    memcpy (&buf, addr, 8);
	  else
	    buf = *addr;
	  rs6000_ptrace64 (PT_WRITE_GPR, PIDGET (inferior_ptid), nr, 0, &buf);
	}
    }

  if (errno)
    {
      perror ("ptrace write");
      errno = 0;
    }
}
Example #12
0
static LONGEST
rs6000_xfer_shared_libraries
  (struct target_ops *ops, enum target_object object,
   const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf,
   ULONGEST offset, LONGEST len)
{
  const int arch64 = ARCH64 ();
  LdInfo *ldi_data;
  LdInfo *ldi;
  struct obstack obstack;
  const char *buf;
  LONGEST len_avail;

  if (writebuf)
    return -1;

  /* Get the ldinfo raw data: If debugging a live process, we get it
     using ptrace.  Otherwise, the info is stored in the .ldinfo
     section of the core file.  */

  if (target_has_execution)
    ldi_data = rs6000_ptrace_ldinfo (inferior_ptid);
  else
    ldi_data = rs6000_core_ldinfo (core_bfd);

  /* Convert the raw data into an XML representation.  */

  obstack_init (&obstack);
  obstack_grow_str (&obstack, "<library-list version=\"1.0\">\n");

  ldi = ldi_data;
  while (1)
    {
      /* Close the fd.  We cannot use it, because we cannot assume
	 that the user of this descriptor will be in the same
	 process.  */
      close (LDI_FD (ldi, arch64));

      rs6000_xfer_shared_library (ldi, &obstack);

      if (!LDI_NEXT (ldi, arch64))
	break;
      ldi = (LdInfo *) ((char *) ldi + LDI_NEXT (ldi, arch64));
    }

  xfree (ldi_data);

  obstack_grow_str0 (&obstack, "</library-list>\n");

  buf = obstack_finish (&obstack);
  len_avail = strlen (buf);
  if (offset >= len_avail)
    len= 0;
  else
    {
      if (len > len_avail - offset)
        len = len_avail - offset;
      memcpy (readbuf, buf + offset, len);
    }

  obstack_free (&obstack, NULL);
  return len;
}
Example #13
0
static void
rs6000_xfer_shared_library (LdInfo *ldi, struct obstack *obstack)
{
  const int arch64 = ARCH64 ();
  const char *archive_name = LDI_FILENAME (ldi, arch64);
  const char *member_name = archive_name + strlen (archive_name) + 1;
  CORE_ADDR text_addr, data_addr;
  ULONGEST text_size, data_size;
  char *p;

  if (arch64)
    {
      text_addr = ldi->l64.ldinfo_textorg;
      text_size = ldi->l64.ldinfo_textsize;
      data_addr = ldi->l64.ldinfo_dataorg;
      data_size = ldi->l64.ldinfo_datasize;
    }
  else
    {
      /* The text and data addresses are defined as pointers.
	 To avoid sign-extending their value in the assignments
	 below, we cast their value to unsigned long first.  */
      text_addr = (unsigned long) ldi->l32.ldinfo_textorg;
      text_size = ldi->l32.ldinfo_textsize;
      data_addr = (unsigned long) ldi->l32.ldinfo_dataorg;
      data_size = ldi->l32.ldinfo_datasize;
    }

  obstack_grow_str (obstack, "<library name=\"");
  p = xml_escape_text (archive_name);
  obstack_grow_str (obstack, p);
  xfree (p);
  obstack_grow_str (obstack, "\"");

  if (member_name[0] != '\0')
    {
      obstack_grow_str (obstack, " member=\"");
      p = xml_escape_text (member_name);
      obstack_grow_str (obstack, p);
      xfree (p);
      obstack_grow_str (obstack, "\"");
    }

  obstack_grow_str (obstack, " text_addr=\"");
  obstack_grow_str (obstack, core_addr_to_string (text_addr));
  obstack_grow_str (obstack, "\"");

  obstack_grow_str (obstack, " text_size=\"");
  obstack_grow_str (obstack, pulongest (text_size));
  obstack_grow_str (obstack, "\"");

  obstack_grow_str (obstack, " data_addr=\"");
  obstack_grow_str (obstack, core_addr_to_string (data_addr));
  obstack_grow_str (obstack, "\"");

  obstack_grow_str (obstack, " data_size=\"");
  obstack_grow_str (obstack, pulongest (data_size));
  obstack_grow_str (obstack, "\"");

  obstack_grow_str (obstack, "></library>");
}
Example #14
0
static void
fetch_core_registers (char *core_reg_sect, unsigned core_reg_size,
		      int which, CORE_ADDR reg_addr)
{
  CoreRegs *regs;
  int regi;
  struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); 

  if (which != 0)
    {
      fprintf_unfiltered
	(gdb_stderr,
	 "Gdb error: unknown parameter to fetch_core_registers().\n");
      return;
    }

  regs = (CoreRegs *) core_reg_sect;

  /* Put the register values from the core file section in the regcache.  */

  if (ARCH64 ())
    {
      for (regi = 0; regi < ppc_num_gprs; regi++)
        regcache_raw_supply (current_regcache, tdep->ppc_gp0_regnum + regi,
			     (char *) &regs->r64.gpr[regi]);

      if (tdep->ppc_fp0_regnum >= 0)
        for (regi = 0; regi < ppc_num_fprs; regi++)
          regcache_raw_supply (current_regcache, tdep->ppc_fp0_regnum + regi,
			       (char *) &regs->r64.fpr[regi]);

      regcache_raw_supply (current_regcache, PC_REGNUM,
			   (char *) &regs->r64.iar);
      regcache_raw_supply (current_regcache, tdep->ppc_ps_regnum,
			   (char *) &regs->r64.msr);
      regcache_raw_supply (current_regcache, tdep->ppc_cr_regnum,
			   (char *) &regs->r64.cr);
      regcache_raw_supply (current_regcache, tdep->ppc_lr_regnum,
			   (char *) &regs->r64.lr);
      regcache_raw_supply (current_regcache, tdep->ppc_ctr_regnum,
			   (char *) &regs->r64.ctr);
      regcache_raw_supply (current_regcache, tdep->ppc_xer_regnum,
			   (char *) &regs->r64.xer);
      if (tdep->ppc_fpscr_regnum >= 0)
        regcache_raw_supply (current_regcache, tdep->ppc_fpscr_regnum,
			     (char *) &regs->r64.fpscr);
    }
  else
    {
      for (regi = 0; regi < ppc_num_gprs; regi++)
        regcache_raw_supply (current_regcache, tdep->ppc_gp0_regnum + regi,
			     (char *) &regs->r32.gpr[regi]);

      if (tdep->ppc_fp0_regnum >= 0)
        for (regi = 0; regi < ppc_num_fprs; regi++)
          regcache_raw_supply (current_regcache, tdep->ppc_fp0_regnum + regi,
			       (char *) &regs->r32.fpr[regi]);

      regcache_raw_supply (current_regcache, PC_REGNUM,
			   (char *) &regs->r32.iar);
      regcache_raw_supply (current_regcache, tdep->ppc_ps_regnum,
			   (char *) &regs->r32.msr);
      regcache_raw_supply (current_regcache, tdep->ppc_cr_regnum,
			   (char *) &regs->r32.cr);
      regcache_raw_supply (current_regcache, tdep->ppc_lr_regnum,
			   (char *) &regs->r32.lr);
      regcache_raw_supply (current_regcache, tdep->ppc_ctr_regnum,
			   (char *) &regs->r32.ctr);
      regcache_raw_supply (current_regcache, tdep->ppc_xer_regnum,
			   (char *) &regs->r32.xer);
      if (tdep->ppc_fpscr_regnum >= 0)
        regcache_raw_supply (current_regcache, tdep->ppc_fpscr_regnum,
			     (char *) &regs->r32.fpscr);
      if (tdep->ppc_mq_regnum >= 0)
	regcache_raw_supply (current_regcache, tdep->ppc_mq_regnum,
			     (char *) &regs->r32.mq);
    }
}
Example #15
0
int
child_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len,
		   int write, struct mem_attrib *attrib,
		   struct target_ops *target)
{
  /* Round starting address down to 32-bit word boundary. */
  int mask = sizeof (int) - 1;
  CORE_ADDR addr = memaddr & ~(CORE_ADDR)mask;

  /* Round ending address up to 32-bit word boundary. */
  int count = ((memaddr + len - addr + mask) & ~(CORE_ADDR)mask)
    / sizeof (int);

  /* Allocate word transfer buffer. */
  /* FIXME (alloca): This code, cloned from infptrace.c, is unsafe
     because it uses alloca to allocate a buffer of arbitrary size.
     For very large xfers, this could crash GDB's stack.  */
  int *buf = (int *) alloca (count * sizeof (int));

  int arch64 = ARCH64 ();
  int i;

  if (!write)
    {
      /* Retrieve memory a word at a time. */
      for (i = 0; i < count; i++, addr += sizeof (int))
	{
	  if (!read_word (addr, buf + i, arch64))
	    return 0;
	  QUIT;
	}

      /* Copy memory to supplied buffer. */
      addr -= count * sizeof (int);
      memcpy (myaddr, (char *)buf + (memaddr - addr), len);
    }
  else
    {
      /* Fetch leading memory needed for alignment. */
      if (addr < memaddr)
	if (!read_word (addr, buf, arch64))
	  return 0;

      /* Fetch trailing memory needed for alignment. */
      if (addr + count * sizeof (int) > memaddr + len)
	if (!read_word (addr + (count - 1) * sizeof (int),
                        buf + count - 1, arch64))
	  return 0;

      /* Copy supplied data into memory buffer. */
      memcpy ((char *)buf + (memaddr - addr), myaddr, len);

      /* Store memory one word at a time. */
      for (i = 0, errno = 0; i < count; i++, addr += sizeof (int))
	{
	  if (arch64)
	    rs6000_ptrace64 (PT_WRITE_D, PIDGET (inferior_ptid), addr, buf[i], NULL);
	  else
	    rs6000_ptrace32 (PT_WRITE_D, PIDGET (inferior_ptid), (int *)(long) addr,
		      buf[i], NULL);

	  if (errno)
	    return 0;
	  QUIT;
	}
    }

  return len;
}
Example #16
0
void
xcoff_relocate_core (struct target_ops *target)
{
  struct bfd_section *ldinfo_sec;
  int offset = 0;
  LdInfo *ldi;
  struct vmap *vp;
  int arch64 = ARCH64 ();

  /* Size of a struct ld_info except for the variable-length filename. */
  int nonfilesz = (int)LDI_FILENAME ((LdInfo *)0, arch64);

  /* Allocated size of buffer.  */
  int buffer_size = nonfilesz;
  char *buffer = xmalloc (buffer_size);
  struct cleanup *old = make_cleanup (free_current_contents, &buffer);

  ldinfo_sec = bfd_get_section_by_name (core_bfd, ".ldinfo");
  if (ldinfo_sec == NULL)
    {
    bfd_err:
      fprintf_filtered (gdb_stderr, "Couldn't get ldinfo from core file: %s\n",
			bfd_errmsg (bfd_get_error ()));
      do_cleanups (old);
      return;
    }
  do
    {
      int i;
      int names_found = 0;

      /* Read in everything but the name.  */
      if (bfd_get_section_contents (core_bfd, ldinfo_sec, buffer,
				    offset, nonfilesz) == 0)
	goto bfd_err;

      /* Now the name.  */
      i = nonfilesz;
      do
	{
	  if (i == buffer_size)
	    {
	      buffer_size *= 2;
	      buffer = xrealloc (buffer, buffer_size);
	    }
	  if (bfd_get_section_contents (core_bfd, ldinfo_sec, &buffer[i],
					offset + i, 1) == 0)
	    goto bfd_err;
	  if (buffer[i++] == '\0')
	    ++names_found;
	}
      while (names_found < 2);

      ldi = (LdInfo *) buffer;

      /* Can't use a file descriptor from the core file; need to open it.  */
      if (arch64)
	ldi->l64.ldinfo_fd = -1;
      else
	ldi->l32.ldinfo_fd = -1;

      /* The first ldinfo is for the exec file, allocated elsewhere.  */
      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,
         add our sections to the section table for the core target.  */
      if (vp != vmap)
	{
	  struct section_table *stp;

	  target_resize_to_sections (target, 2);
	  stp = target->to_sections_end - 2;

	  stp->bfd = vp->bfd;
	  stp->the_bfd_section = bfd_get_section_by_name (stp->bfd, ".text");
	  stp->addr = vp->tstart;
	  stp->endaddr = vp->tend;
	  stp++;

	  stp->bfd = vp->bfd;
	  stp->the_bfd_section = bfd_get_section_by_name (stp->bfd, ".data");
	  stp->addr = vp->dstart;
	  stp->endaddr = vp->dend;
	}

      vmap_symtab (vp);

      if (deprecated_target_new_objfile_hook && vp != vmap && vp->objfile)
	deprecated_target_new_objfile_hook (vp->objfile);
    }
  while (LDI_NEXT (ldi, arch64) != 0);
  vmap_exec ();
  breakpoint_re_set ();
  do_cleanups (old);
}