gdb/rs6000-nat.c - gdb

Global variables defined

Functions defined

Macros defined

Source code

  1. /* IBM RS/6000 native-dependent code for GDB, the GNU debugger.

  2.    Copyright (C) 1986-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. #include "defs.h"
  15. #include "inferior.h"
  16. #include "target.h"
  17. #include "gdbcore.h"
  18. #include "symfile.h"
  19. #include "objfiles.h"
  20. #include "libbfd.h"                /* For bfd_default_set_arch_mach (FIXME) */
  21. #include "bfd.h"
  22. #include "gdb-stabs.h"
  23. #include "regcache.h"
  24. #include "arch-utils.h"
  25. #include "inf-child.h"
  26. #include "inf-ptrace.h"
  27. #include "ppc-tdep.h"
  28. #include "rs6000-tdep.h"
  29. #include "rs6000-aix-tdep.h"
  30. #include "exec.h"
  31. #include "observer.h"
  32. #include "xcoffread.h"

  33. #include <sys/ptrace.h>
  34. #include <sys/reg.h>

  35. #include <sys/dir.h>
  36. #include <sys/user.h>
  37. #include <signal.h>
  38. #include <sys/ioctl.h>
  39. #include <fcntl.h>

  40. #include <a.out.h>
  41. #include <sys/file.h>
  42. #include <sys/stat.h>
  43. #include "gdb_bfd.h"
  44. #include <sys/core.h>
  45. #define __LDINFO_PTRACE32__        /* for __ld_info32 */
  46. #define __LDINFO_PTRACE64__        /* for __ld_info64 */
  47. #include <sys/ldr.h>
  48. #include <sys/systemcfg.h>

  49. /* On AIX4.3+, sys/ldr.h provides different versions of struct ld_info for
  50.    debugging 32-bit and 64-bit processes.  Define a typedef and macros for
  51.    accessing fields in the appropriate structures.  */

  52. /* In 32-bit compilation mode (which is the only mode from which ptrace()
  53.    works on 4.3), __ld_info32 is #defined as equivalent to ld_info.  */

  54. #if defined (__ld_info32) || defined (__ld_info64)
  55. # define ARCH3264
  56. #endif

  57. /* Return whether the current architecture is 64-bit.  */

  58. #ifndef ARCH3264
  59. # define ARCH64() 0
  60. #else
  61. # define ARCH64() (register_size (target_gdbarch (), 0) == 8)
  62. #endif

  63. static target_xfer_partial_ftype rs6000_xfer_shared_libraries;

  64. /* Given REGNO, a gdb register number, return the corresponding
  65.    number suitable for use as a ptrace() parameter.  Return -1 if
  66.    there's no suitable mapping.  Also, set the int pointed to by
  67.    ISFLOAT to indicate whether REGNO is a floating point register.  */

  68. static int
  69. regmap (struct gdbarch *gdbarch, int regno, int *isfloat)
  70. {
  71.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  72.   *isfloat = 0;
  73.   if (tdep->ppc_gp0_regnum <= regno
  74.       && regno < tdep->ppc_gp0_regnum + ppc_num_gprs)
  75.     return regno;
  76.   else if (tdep->ppc_fp0_regnum >= 0
  77.            && tdep->ppc_fp0_regnum <= regno
  78.            && regno < tdep->ppc_fp0_regnum + ppc_num_fprs)
  79.     {
  80.       *isfloat = 1;
  81.       return regno - tdep->ppc_fp0_regnum + FPR0;
  82.     }
  83.   else if (regno == gdbarch_pc_regnum (gdbarch))
  84.     return IAR;
  85.   else if (regno == tdep->ppc_ps_regnum)
  86.     return MSR;
  87.   else if (regno == tdep->ppc_cr_regnum)
  88.     return CR;
  89.   else if (regno == tdep->ppc_lr_regnum)
  90.     return LR;
  91.   else if (regno == tdep->ppc_ctr_regnum)
  92.     return CTR;
  93.   else if (regno == tdep->ppc_xer_regnum)
  94.     return XER;
  95.   else if (tdep->ppc_fpscr_regnum >= 0
  96.            && regno == tdep->ppc_fpscr_regnum)
  97.     return FPSCR;
  98.   else if (tdep->ppc_mq_regnum >= 0 && regno == tdep->ppc_mq_regnum)
  99.     return MQ;
  100.   else
  101.     return -1;
  102. }

  103. /* Call ptrace(REQ, ID, ADDR, DATA, BUF).  */

  104. static int
  105. rs6000_ptrace32 (int req, int id, int *addr, int data, int *buf)
  106. {
  107. #ifdef HAVE_PTRACE64
  108.   int ret = ptrace64 (req, id, (uintptr_t) addr, data, buf);
  109. #else
  110.   int ret = ptrace (req, id, (int *)addr, data, buf);
  111. #endif
  112. #if 0
  113.   printf ("rs6000_ptrace32 (%d, %d, 0x%x, %08x, 0x%x) = 0x%x\n",
  114.           req, id, (unsigned int)addr, data, (unsigned int)buf, ret);
  115. #endif
  116.   return ret;
  117. }

  118. /* Call ptracex(REQ, ID, ADDR, DATA, BUF).  */

  119. static int
  120. rs6000_ptrace64 (int req, int id, long long addr, int data, void *buf)
  121. {
  122. #ifdef ARCH3264
  123. #  ifdef HAVE_PTRACE64
  124.   int ret = ptrace64 (req, id, addr, data, buf);
  125. #  else
  126.   int ret = ptracex (req, id, addr, data, buf);
  127. #  endif
  128. #else
  129.   int ret = 0;
  130. #endif
  131. #if 0
  132.   printf ("rs6000_ptrace64 (%d, %d, %s, %08x, 0x%x) = 0x%x\n",
  133.           req, id, hex_string (addr), data, (unsigned int)buf, ret);
  134. #endif
  135.   return ret;
  136. }

  137. /* Fetch register REGNO from the inferior.  */

  138. static void
  139. fetch_register (struct regcache *regcache, int regno)
  140. {
  141.   struct gdbarch *gdbarch = get_regcache_arch (regcache);
  142.   int addr[MAX_REGISTER_SIZE];
  143.   int nr, isfloat;

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

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

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

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

  159.   /* Fixed-point registers.  */
  160.   else
  161.     {
  162.       if (!ARCH64 ())
  163.         *addr = rs6000_ptrace32 (PT_READ_GPR, ptid_get_pid (inferior_ptid),
  164.                                  (int *) nr, 0, 0);
  165.       else
  166.         {
  167.           /* PT_READ_GPR requires the buffer parameter to point to long long,
  168.              even if the register is really only 32 bits.  */
  169.           long long buf;
  170.           rs6000_ptrace64 (PT_READ_GPR, ptid_get_pid (inferior_ptid),
  171.                            nr, 0, &buf);
  172.           if (register_size (gdbarch, regno) == 8)
  173.             memcpy (addr, &buf, 8);
  174.           else
  175.             *addr = buf;
  176.         }
  177.     }

  178.   if (!errno)
  179.     regcache_raw_supply (regcache, regno, (char *) addr);
  180.   else
  181.     {
  182. #if 0
  183.       /* FIXME: this happens 3 times at the start of each 64-bit program.  */
  184.       perror (_("ptrace read"));
  185. #endif
  186.       errno = 0;
  187.     }
  188. }

  189. /* Store register REGNO back into the inferior.  */

  190. static void
  191. store_register (struct regcache *regcache, int regno)
  192. {
  193.   struct gdbarch *gdbarch = get_regcache_arch (regcache);
  194.   int addr[MAX_REGISTER_SIZE];
  195.   int nr, isfloat;

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

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

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

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

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

  212.   /* Fixed-point registers.  */
  213.   else
  214.     {
  215.       /* The PT_WRITE_GPR operation is rather odd.  For 32-bit inferiors,
  216.          the register's value is passed by value, but for 64-bit inferiors,
  217.          the address of a buffer containing the value is passed.  */
  218.       if (!ARCH64 ())
  219.         rs6000_ptrace32 (PT_WRITE_GPR, ptid_get_pid (inferior_ptid),
  220.                          (int *) nr, *addr, 0);
  221.       else
  222.         {
  223.           /* PT_WRITE_GPR requires the buffer parameter to point to an 8-byte
  224.              area, even if the register is really only 32 bits.  */
  225.           long long buf;
  226.           if (register_size (gdbarch, regno) == 8)
  227.             memcpy (&buf, addr, 8);
  228.           else
  229.             buf = *addr;
  230.           rs6000_ptrace64 (PT_WRITE_GPR, ptid_get_pid (inferior_ptid),
  231.                            nr, 0, &buf);
  232.         }
  233.     }

  234.   if (errno)
  235.     {
  236.       perror (_("ptrace write"));
  237.       errno = 0;
  238.     }
  239. }

  240. /* Read from the inferior all registers if REGNO == -1 and just register
  241.    REGNO otherwise.  */

  242. static void
  243. rs6000_fetch_inferior_registers (struct target_ops *ops,
  244.                                  struct regcache *regcache, int regno)
  245. {
  246.   struct gdbarch *gdbarch = get_regcache_arch (regcache);
  247.   if (regno != -1)
  248.     fetch_register (regcache, regno);

  249.   else
  250.     {
  251.       struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  252.       /* Read 32 general purpose registers.  */
  253.       for (regno = tdep->ppc_gp0_regnum;
  254.            regno < tdep->ppc_gp0_regnum + ppc_num_gprs;
  255.            regno++)
  256.         {
  257.           fetch_register (regcache, regno);
  258.         }

  259.       /* Read general purpose floating point registers.  */
  260.       if (tdep->ppc_fp0_regnum >= 0)
  261.         for (regno = 0; regno < ppc_num_fprs; regno++)
  262.           fetch_register (regcache, tdep->ppc_fp0_regnum + regno);

  263.       /* Read special registers.  */
  264.       fetch_register (regcache, gdbarch_pc_regnum (gdbarch));
  265.       fetch_register (regcache, tdep->ppc_ps_regnum);
  266.       fetch_register (regcache, tdep->ppc_cr_regnum);
  267.       fetch_register (regcache, tdep->ppc_lr_regnum);
  268.       fetch_register (regcache, tdep->ppc_ctr_regnum);
  269.       fetch_register (regcache, tdep->ppc_xer_regnum);
  270.       if (tdep->ppc_fpscr_regnum >= 0)
  271.         fetch_register (regcache, tdep->ppc_fpscr_regnum);
  272.       if (tdep->ppc_mq_regnum >= 0)
  273.         fetch_register (regcache, tdep->ppc_mq_regnum);
  274.     }
  275. }

  276. /* Store our register values back into the inferior.
  277.    If REGNO is -1, do this for all registers.
  278.    Otherwise, REGNO specifies which register (so we can save time).  */

  279. static void
  280. rs6000_store_inferior_registers (struct target_ops *ops,
  281.                                  struct regcache *regcache, int regno)
  282. {
  283.   struct gdbarch *gdbarch = get_regcache_arch (regcache);
  284.   if (regno != -1)
  285.     store_register (regcache, regno);

  286.   else
  287.     {
  288.       struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  289.       /* Write general purpose registers first.  */
  290.       for (regno = tdep->ppc_gp0_regnum;
  291.            regno < tdep->ppc_gp0_regnum + ppc_num_gprs;
  292.            regno++)
  293.         {
  294.           store_register (regcache, regno);
  295.         }

  296.       /* Write floating point registers.  */
  297.       if (tdep->ppc_fp0_regnum >= 0)
  298.         for (regno = 0; regno < ppc_num_fprs; regno++)
  299.           store_register (regcache, tdep->ppc_fp0_regnum + regno);

  300.       /* Write special registers.  */
  301.       store_register (regcache, gdbarch_pc_regnum (gdbarch));
  302.       store_register (regcache, tdep->ppc_ps_regnum);
  303.       store_register (regcache, tdep->ppc_cr_regnum);
  304.       store_register (regcache, tdep->ppc_lr_regnum);
  305.       store_register (regcache, tdep->ppc_ctr_regnum);
  306.       store_register (regcache, tdep->ppc_xer_regnum);
  307.       if (tdep->ppc_fpscr_regnum >= 0)
  308.         store_register (regcache, tdep->ppc_fpscr_regnum);
  309.       if (tdep->ppc_mq_regnum >= 0)
  310.         store_register (regcache, tdep->ppc_mq_regnum);
  311.     }
  312. }

  313. /* Implement the to_xfer_partial target_ops method.  */

  314. static enum target_xfer_status
  315. rs6000_xfer_partial (struct target_ops *ops, enum target_object object,
  316.                      const char *annex, gdb_byte *readbuf,
  317.                      const gdb_byte *writebuf,
  318.                      ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
  319. {
  320.   pid_t pid = ptid_get_pid (inferior_ptid);
  321.   int arch64 = ARCH64 ();

  322.   switch (object)
  323.     {
  324.     case TARGET_OBJECT_LIBRARIES_AIX:
  325.       return rs6000_xfer_shared_libraries (ops, object, annex,
  326.                                            readbuf, writebuf,
  327.                                            offset, len, xfered_len);
  328.     case TARGET_OBJECT_MEMORY:
  329.       {
  330.         union
  331.         {
  332.           PTRACE_TYPE_RET word;
  333.           gdb_byte byte[sizeof (PTRACE_TYPE_RET)];
  334.         } buffer;
  335.         ULONGEST rounded_offset;
  336.         LONGEST partial_len;

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

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

  348.         if (writebuf)
  349.           {
  350.             /* If OFFSET:PARTIAL_LEN is smaller than
  351.                ROUNDED_OFFSET:WORDSIZE then a read/modify write will
  352.                be needed.  Read in the entire word.  */
  353.             if (rounded_offset < offset
  354.                 || (offset + partial_len
  355.                     < rounded_offset + sizeof (PTRACE_TYPE_RET)))
  356.               {
  357.                 /* Need part of initial word -- fetch it.  */
  358.                 if (arch64)
  359.                   buffer.word = rs6000_ptrace64 (PT_READ_I, pid,
  360.                                                  rounded_offset, 0, NULL);
  361.                 else
  362.                   buffer.word = rs6000_ptrace32 (PT_READ_I, pid,
  363.                                                  (int *) (uintptr_t)
  364.                                                  rounded_offset,
  365.                                                  0, NULL);
  366.               }

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

  371.             errno = 0;
  372.             if (arch64)
  373.               rs6000_ptrace64 (PT_WRITE_D, pid,
  374.                                rounded_offset, buffer.word, NULL);
  375.             else
  376.               rs6000_ptrace32 (PT_WRITE_D, pid,
  377.                                (int *) (uintptr_t) rounded_offset,
  378.                                buffer.word, NULL);
  379.             if (errno)
  380.               return TARGET_XFER_EOF;
  381.           }

  382.         if (readbuf)
  383.           {
  384.             errno = 0;
  385.             if (arch64)
  386.               buffer.word = rs6000_ptrace64 (PT_READ_I, pid,
  387.                                              rounded_offset, 0, NULL);
  388.             else
  389.               buffer.word = rs6000_ptrace32 (PT_READ_I, pid,
  390.                                              (int *)(uintptr_t)rounded_offset,
  391.                                              0, NULL);
  392.             if (errno)
  393.               return TARGET_XFER_EOF;

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

  398.         *xfered_len = (ULONGEST) partial_len;
  399.         return TARGET_XFER_OK;
  400.       }

  401.     default:
  402.       return TARGET_XFER_E_IO;
  403.     }
  404. }

  405. /* Wait for the child specified by PTID to do something.  Return the
  406.    process ID of the child, or MINUS_ONE_PTID in case of error; store
  407.    the status in *OURSTATUS.  */

  408. static ptid_t
  409. rs6000_wait (struct target_ops *ops,
  410.              ptid_t ptid, struct target_waitstatus *ourstatus, int options)
  411. {
  412.   pid_t pid;
  413.   int status, save_errno;

  414.   do
  415.     {
  416.       set_sigint_trap ();

  417.       do
  418.         {
  419.           pid = waitpid (ptid_get_pid (ptid), &status, 0);
  420.           save_errno = errno;
  421.         }
  422.       while (pid == -1 && errno == EINTR);

  423.       clear_sigint_trap ();

  424.       if (pid == -1)
  425.         {
  426.           fprintf_unfiltered (gdb_stderr,
  427.                               _("Child process unexpectedly missing: %s.\n"),
  428.                               safe_strerror (save_errno));

  429.           /* Claim it exited with unknown signal.  */
  430.           ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
  431.           ourstatus->value.sig = GDB_SIGNAL_UNKNOWN;
  432.           return inferior_ptid;
  433.         }

  434.       /* Ignore terminated detached child processes.  */
  435.       if (!WIFSTOPPED (status) && pid != ptid_get_pid (inferior_ptid))
  436.         pid = -1;
  437.     }
  438.   while (pid == -1);

  439.   /* AIX has a couple of strange returns from wait().  */

  440.   /* stop after load" status.  */
  441.   if (status == 0x57c)
  442.     ourstatus->kind = TARGET_WAITKIND_LOADED;
  443.   /* signal 0.  I have no idea why wait(2) returns with this status word.  */
  444.   else if (status == 0x7f)
  445.     ourstatus->kind = TARGET_WAITKIND_SPURIOUS;
  446.   /* A normal waitstatus.  Let the usual macros deal with it.  */
  447.   else
  448.     store_waitstatus (ourstatus, status);

  449.   return pid_to_ptid (pid);
  450. }


  451. /* Set the current architecture from the host running GDB.  Called when
  452.    starting a child process.  */

  453. static void (*super_create_inferior) (struct target_ops *,char *exec_file,
  454.                                       char *allargs, char **env, int from_tty);
  455. static void
  456. rs6000_create_inferior (struct target_ops * ops, char *exec_file,
  457.                         char *allargs, char **env, int from_tty)
  458. {
  459.   enum bfd_architecture arch;
  460.   unsigned long mach;
  461.   bfd abfd;
  462.   struct gdbarch_info info;

  463.   super_create_inferior (ops, exec_file, allargs, env, from_tty);

  464.   if (__power_rs ())
  465.     {
  466.       arch = bfd_arch_rs6000;
  467.       mach = bfd_mach_rs6k;
  468.     }
  469.   else
  470.     {
  471.       arch = bfd_arch_powerpc;
  472.       mach = bfd_mach_ppc;
  473.     }

  474.   /* FIXME: schauer/2002-02-25:
  475.      We don't know if we are executing a 32 or 64 bit executable,
  476.      and have no way to pass the proper word size to rs6000_gdbarch_init.
  477.      So we have to avoid switching to a new architecture, if the architecture
  478.      matches already.
  479.      Blindly calling rs6000_gdbarch_init used to work in older versions of
  480.      GDB, as rs6000_gdbarch_init incorrectly used the previous tdep to
  481.      determine the wordsize.  */
  482.   if (exec_bfd)
  483.     {
  484.       const struct bfd_arch_info *exec_bfd_arch_info;

  485.       exec_bfd_arch_info = bfd_get_arch_info (exec_bfd);
  486.       if (arch == exec_bfd_arch_info->arch)
  487.         return;
  488.     }

  489.   bfd_default_set_arch_mach (&abfd, arch, mach);

  490.   gdbarch_info_init (&info);
  491.   info.bfd_arch_info = bfd_get_arch_info (&abfd);
  492.   info.abfd = exec_bfd;

  493.   if (!gdbarch_update_p (info))
  494.     internal_error (__FILE__, __LINE__,
  495.                     _("rs6000_create_inferior: failed "
  496.                       "to select architecture"));
  497. }


  498. /* Shared Object support.  */

  499. /* Return the LdInfo data for the given process.  Raises an error
  500.    if the data could not be obtained.

  501.    The returned value must be deallocated after use.  */

  502. static gdb_byte *
  503. rs6000_ptrace_ldinfo (ptid_t ptid)
  504. {
  505.   const int pid = ptid_get_pid (ptid);
  506.   int ldi_size = 1024;
  507.   gdb_byte *ldi = xmalloc (ldi_size);
  508.   int rc = -1;

  509.   while (1)
  510.     {
  511.       if (ARCH64 ())
  512.         rc = rs6000_ptrace64 (PT_LDINFO, pid, (unsigned long) ldi, ldi_size,
  513.                               NULL);
  514.       else
  515.         rc = rs6000_ptrace32 (PT_LDINFO, pid, (int *) ldi, ldi_size, NULL);

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

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

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

  524.   return ldi;
  525. }

  526. /* Implement the to_xfer_partial target_ops method for
  527.    TARGET_OBJECT_LIBRARIES_AIX objects.  */

  528. static enum target_xfer_status
  529. rs6000_xfer_shared_libraries
  530.   (struct target_ops *ops, enum target_object object,
  531.    const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf,
  532.    ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
  533. {
  534.   gdb_byte *ldi_buf;
  535.   ULONGEST result;
  536.   struct cleanup *cleanup;

  537.   /* This function assumes that it is being run with a live process.
  538.      Core files are handled via gdbarch.  */
  539.   gdb_assert (target_has_execution);

  540.   if (writebuf)
  541.     return TARGET_XFER_E_IO;

  542.   ldi_buf = rs6000_ptrace_ldinfo (inferior_ptid);
  543.   gdb_assert (ldi_buf != NULL);
  544.   cleanup = make_cleanup (xfree, ldi_buf);
  545.   result = rs6000_aix_ld_info_to_xml (target_gdbarch (), ldi_buf,
  546.                                       readbuf, offset, len, 1);
  547.   xfree (ldi_buf);

  548.   do_cleanups (cleanup);

  549.   if (result == 0)
  550.     return TARGET_XFER_EOF;
  551.   else
  552.     {
  553.       *xfered_len = result;
  554.       return TARGET_XFER_OK;
  555.     }
  556. }

  557. void _initialize_rs6000_nat (void);

  558. void
  559. _initialize_rs6000_nat (void)
  560. {
  561.   struct target_ops *t;

  562.   t = inf_ptrace_target ();
  563.   t->to_fetch_registers = rs6000_fetch_inferior_registers;
  564.   t->to_store_registers = rs6000_store_inferior_registers;
  565.   t->to_xfer_partial = rs6000_xfer_partial;

  566.   super_create_inferior = t->to_create_inferior;
  567.   t->to_create_inferior = rs6000_create_inferior;

  568.   t->to_wait = rs6000_wait;

  569.   add_target (t);
  570. }