Update Copyright year range in all files maintained by GDB.
[external/binutils.git] / gdb / rs6000-nat.c
1 /* IBM RS/6000 native-dependent code for GDB, the GNU debugger.
2
3    Copyright (C) 1986-2014 Free Software Foundation, Inc.
4
5    This file is part of GDB.
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19
20 #include "defs.h"
21 #include "inferior.h"
22 #include "target.h"
23 #include "gdbcore.h"
24 #include "symfile.h"
25 #include "objfiles.h"
26 #include "libbfd.h"             /* For bfd_default_set_arch_mach (FIXME) */
27 #include "bfd.h"
28 #include "exceptions.h"
29 #include "gdb-stabs.h"
30 #include "regcache.h"
31 #include "arch-utils.h"
32 #include "inf-child.h"
33 #include "inf-ptrace.h"
34 #include "ppc-tdep.h"
35 #include "rs6000-tdep.h"
36 #include "rs6000-aix-tdep.h"
37 #include "exec.h"
38 #include "observer.h"
39 #include "xcoffread.h"
40
41 #include <sys/ptrace.h>
42 #include <sys/reg.h>
43
44 #include <sys/dir.h>
45 #include <sys/user.h>
46 #include <signal.h>
47 #include <sys/ioctl.h>
48 #include <fcntl.h>
49 #include <errno.h>
50
51 #include <a.out.h>
52 #include <sys/file.h>
53 #include <sys/stat.h>
54 #include "gdb_bfd.h"
55 #include <sys/core.h>
56 #define __LDINFO_PTRACE32__     /* for __ld_info32 */
57 #define __LDINFO_PTRACE64__     /* for __ld_info64 */
58 #include <sys/ldr.h>
59 #include <sys/systemcfg.h>
60
61 /* On AIX4.3+, sys/ldr.h provides different versions of struct ld_info for
62    debugging 32-bit and 64-bit processes.  Define a typedef and macros for
63    accessing fields in the appropriate structures.  */
64
65 /* In 32-bit compilation mode (which is the only mode from which ptrace()
66    works on 4.3), __ld_info32 is #defined as equivalent to ld_info.  */
67
68 #if defined (__ld_info32) || defined (__ld_info64)
69 # define ARCH3264
70 #endif
71
72 /* Return whether the current architecture is 64-bit.  */
73
74 #ifndef ARCH3264
75 # define ARCH64() 0
76 #else
77 # define ARCH64() (register_size (target_gdbarch (), 0) == 8)
78 #endif
79
80 static void exec_one_dummy_insn (struct regcache *);
81
82 static LONGEST rs6000_xfer_shared_libraries
83   (struct target_ops *ops, enum target_object object,
84    const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf,
85    ULONGEST offset, LONGEST len);
86
87 /* Given REGNO, a gdb register number, return the corresponding
88    number suitable for use as a ptrace() parameter.  Return -1 if
89    there's no suitable mapping.  Also, set the int pointed to by
90    ISFLOAT to indicate whether REGNO is a floating point register.  */
91
92 static int
93 regmap (struct gdbarch *gdbarch, int regno, int *isfloat)
94 {
95   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
96
97   *isfloat = 0;
98   if (tdep->ppc_gp0_regnum <= regno
99       && regno < tdep->ppc_gp0_regnum + ppc_num_gprs)
100     return regno;
101   else if (tdep->ppc_fp0_regnum >= 0
102            && tdep->ppc_fp0_regnum <= regno
103            && regno < tdep->ppc_fp0_regnum + ppc_num_fprs)
104     {
105       *isfloat = 1;
106       return regno - tdep->ppc_fp0_regnum + FPR0;
107     }
108   else if (regno == gdbarch_pc_regnum (gdbarch))
109     return IAR;
110   else if (regno == tdep->ppc_ps_regnum)
111     return MSR;
112   else if (regno == tdep->ppc_cr_regnum)
113     return CR;
114   else if (regno == tdep->ppc_lr_regnum)
115     return LR;
116   else if (regno == tdep->ppc_ctr_regnum)
117     return CTR;
118   else if (regno == tdep->ppc_xer_regnum)
119     return XER;
120   else if (tdep->ppc_fpscr_regnum >= 0
121            && regno == tdep->ppc_fpscr_regnum)
122     return FPSCR;
123   else if (tdep->ppc_mq_regnum >= 0 && regno == tdep->ppc_mq_regnum)
124     return MQ;
125   else
126     return -1;
127 }
128
129 /* Call ptrace(REQ, ID, ADDR, DATA, BUF).  */
130
131 static int
132 rs6000_ptrace32 (int req, int id, int *addr, int data, int *buf)
133 {
134 #ifdef HAVE_PTRACE64
135   int ret = ptrace64 (req, id, (uintptr_t) addr, data, buf);
136 #else
137   int ret = ptrace (req, id, (int *)addr, data, buf);
138 #endif
139 #if 0
140   printf ("rs6000_ptrace32 (%d, %d, 0x%x, %08x, 0x%x) = 0x%x\n",
141           req, id, (unsigned int)addr, data, (unsigned int)buf, ret);
142 #endif
143   return ret;
144 }
145
146 /* Call ptracex(REQ, ID, ADDR, DATA, BUF).  */
147
148 static int
149 rs6000_ptrace64 (int req, int id, long long addr, int data, void *buf)
150 {
151 #ifdef ARCH3264
152 #  ifdef HAVE_PTRACE64
153   int ret = ptrace64 (req, id, addr, data, buf);
154 #  else
155   int ret = ptracex (req, id, addr, data, buf);
156 #  endif
157 #else
158   int ret = 0;
159 #endif
160 #if 0
161   printf ("rs6000_ptrace64 (%d, %d, %s, %08x, 0x%x) = 0x%x\n",
162           req, id, hex_string (addr), data, (unsigned int)buf, ret);
163 #endif
164   return ret;
165 }
166
167 /* Fetch register REGNO from the inferior.  */
168
169 static void
170 fetch_register (struct regcache *regcache, int regno)
171 {
172   struct gdbarch *gdbarch = get_regcache_arch (regcache);
173   int addr[MAX_REGISTER_SIZE];
174   int nr, isfloat;
175
176   /* Retrieved values may be -1, so infer errors from errno.  */
177   errno = 0;
178
179   nr = regmap (gdbarch, regno, &isfloat);
180
181   /* Floating-point registers.  */
182   if (isfloat)
183     rs6000_ptrace32 (PT_READ_FPR, ptid_get_pid (inferior_ptid), addr, nr, 0);
184
185   /* Bogus register number.  */
186   else if (nr < 0)
187     {
188       if (regno >= gdbarch_num_regs (gdbarch))
189         fprintf_unfiltered (gdb_stderr,
190                             "gdb error: register no %d not implemented.\n",
191                             regno);
192       return;
193     }
194
195   /* Fixed-point registers.  */
196   else
197     {
198       if (!ARCH64 ())
199         *addr = rs6000_ptrace32 (PT_READ_GPR, ptid_get_pid (inferior_ptid),
200                                  (int *) nr, 0, 0);
201       else
202         {
203           /* PT_READ_GPR requires the buffer parameter to point to long long,
204              even if the register is really only 32 bits.  */
205           long long buf;
206           rs6000_ptrace64 (PT_READ_GPR, ptid_get_pid (inferior_ptid),
207                            nr, 0, &buf);
208           if (register_size (gdbarch, regno) == 8)
209             memcpy (addr, &buf, 8);
210           else
211             *addr = buf;
212         }
213     }
214
215   if (!errno)
216     regcache_raw_supply (regcache, regno, (char *) addr);
217   else
218     {
219 #if 0
220       /* FIXME: this happens 3 times at the start of each 64-bit program.  */
221       perror (_("ptrace read"));
222 #endif
223       errno = 0;
224     }
225 }
226
227 /* Store register REGNO back into the inferior.  */
228
229 static void
230 store_register (struct regcache *regcache, int regno)
231 {
232   struct gdbarch *gdbarch = get_regcache_arch (regcache);
233   int addr[MAX_REGISTER_SIZE];
234   int nr, isfloat;
235
236   /* Fetch the register's value from the register cache.  */
237   regcache_raw_collect (regcache, regno, addr);
238
239   /* -1 can be a successful return value, so infer errors from errno.  */
240   errno = 0;
241
242   nr = regmap (gdbarch, regno, &isfloat);
243
244   /* Floating-point registers.  */
245   if (isfloat)
246     rs6000_ptrace32 (PT_WRITE_FPR, ptid_get_pid (inferior_ptid), addr, nr, 0);
247
248   /* Bogus register number.  */
249   else if (nr < 0)
250     {
251       if (regno >= gdbarch_num_regs (gdbarch))
252         fprintf_unfiltered (gdb_stderr,
253                             "gdb error: register no %d not implemented.\n",
254                             regno);
255     }
256
257   /* Fixed-point registers.  */
258   else
259     {
260       if (regno == gdbarch_sp_regnum (gdbarch))
261         /* Execute one dummy instruction (which is a breakpoint) in inferior
262            process to give kernel a chance to do internal housekeeping.
263            Otherwise the following ptrace(2) calls will mess up user stack
264            since kernel will get confused about the bottom of the stack
265            (%sp).  */
266         exec_one_dummy_insn (regcache);
267
268       /* The PT_WRITE_GPR operation is rather odd.  For 32-bit inferiors,
269          the register's value is passed by value, but for 64-bit inferiors,
270          the address of a buffer containing the value is passed.  */
271       if (!ARCH64 ())
272         rs6000_ptrace32 (PT_WRITE_GPR, ptid_get_pid (inferior_ptid),
273                          (int *) nr, *addr, 0);
274       else
275         {
276           /* PT_WRITE_GPR requires the buffer parameter to point to an 8-byte
277              area, even if the register is really only 32 bits.  */
278           long long buf;
279           if (register_size (gdbarch, regno) == 8)
280             memcpy (&buf, addr, 8);
281           else
282             buf = *addr;
283           rs6000_ptrace64 (PT_WRITE_GPR, ptid_get_pid (inferior_ptid),
284                            nr, 0, &buf);
285         }
286     }
287
288   if (errno)
289     {
290       perror (_("ptrace write"));
291       errno = 0;
292     }
293 }
294
295 /* Read from the inferior all registers if REGNO == -1 and just register
296    REGNO otherwise.  */
297
298 static void
299 rs6000_fetch_inferior_registers (struct target_ops *ops,
300                                  struct regcache *regcache, int regno)
301 {
302   struct gdbarch *gdbarch = get_regcache_arch (regcache);
303   if (regno != -1)
304     fetch_register (regcache, regno);
305
306   else
307     {
308       struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
309
310       /* Read 32 general purpose registers.  */
311       for (regno = tdep->ppc_gp0_regnum;
312            regno < tdep->ppc_gp0_regnum + ppc_num_gprs;
313            regno++)
314         {
315           fetch_register (regcache, regno);
316         }
317
318       /* Read general purpose floating point registers.  */
319       if (tdep->ppc_fp0_regnum >= 0)
320         for (regno = 0; regno < ppc_num_fprs; regno++)
321           fetch_register (regcache, tdep->ppc_fp0_regnum + regno);
322
323       /* Read special registers.  */
324       fetch_register (regcache, gdbarch_pc_regnum (gdbarch));
325       fetch_register (regcache, tdep->ppc_ps_regnum);
326       fetch_register (regcache, tdep->ppc_cr_regnum);
327       fetch_register (regcache, tdep->ppc_lr_regnum);
328       fetch_register (regcache, tdep->ppc_ctr_regnum);
329       fetch_register (regcache, tdep->ppc_xer_regnum);
330       if (tdep->ppc_fpscr_regnum >= 0)
331         fetch_register (regcache, tdep->ppc_fpscr_regnum);
332       if (tdep->ppc_mq_regnum >= 0)
333         fetch_register (regcache, tdep->ppc_mq_regnum);
334     }
335 }
336
337 /* Store our register values back into the inferior.
338    If REGNO is -1, do this for all registers.
339    Otherwise, REGNO specifies which register (so we can save time).  */
340
341 static void
342 rs6000_store_inferior_registers (struct target_ops *ops,
343                                  struct regcache *regcache, int regno)
344 {
345   struct gdbarch *gdbarch = get_regcache_arch (regcache);
346   if (regno != -1)
347     store_register (regcache, regno);
348
349   else
350     {
351       struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
352
353       /* Write general purpose registers first.  */
354       for (regno = tdep->ppc_gp0_regnum;
355            regno < tdep->ppc_gp0_regnum + ppc_num_gprs;
356            regno++)
357         {
358           store_register (regcache, regno);
359         }
360
361       /* Write floating point registers.  */
362       if (tdep->ppc_fp0_regnum >= 0)
363         for (regno = 0; regno < ppc_num_fprs; regno++)
364           store_register (regcache, tdep->ppc_fp0_regnum + regno);
365
366       /* Write special registers.  */
367       store_register (regcache, gdbarch_pc_regnum (gdbarch));
368       store_register (regcache, tdep->ppc_ps_regnum);
369       store_register (regcache, tdep->ppc_cr_regnum);
370       store_register (regcache, tdep->ppc_lr_regnum);
371       store_register (regcache, tdep->ppc_ctr_regnum);
372       store_register (regcache, tdep->ppc_xer_regnum);
373       if (tdep->ppc_fpscr_regnum >= 0)
374         store_register (regcache, tdep->ppc_fpscr_regnum);
375       if (tdep->ppc_mq_regnum >= 0)
376         store_register (regcache, tdep->ppc_mq_regnum);
377     }
378 }
379
380
381 /* Attempt a transfer all LEN bytes starting at OFFSET between the
382    inferior's OBJECT:ANNEX space and GDB's READBUF/WRITEBUF buffer.
383    Return the number of bytes actually transferred.  */
384
385 static LONGEST
386 rs6000_xfer_partial (struct target_ops *ops, enum target_object object,
387                      const char *annex, gdb_byte *readbuf,
388                      const gdb_byte *writebuf,
389                      ULONGEST offset, LONGEST len)
390 {
391   pid_t pid = ptid_get_pid (inferior_ptid);
392   int arch64 = ARCH64 ();
393
394   switch (object)
395     {
396     case TARGET_OBJECT_LIBRARIES_AIX:
397       return rs6000_xfer_shared_libraries (ops, object, annex,
398                                            readbuf, writebuf,
399                                            offset, len);
400     case TARGET_OBJECT_MEMORY:
401       {
402         union
403         {
404           PTRACE_TYPE_RET word;
405           gdb_byte byte[sizeof (PTRACE_TYPE_RET)];
406         } buffer;
407         ULONGEST rounded_offset;
408         LONGEST partial_len;
409
410         /* Round the start offset down to the next long word
411            boundary.  */
412         rounded_offset = offset & -(ULONGEST) sizeof (PTRACE_TYPE_RET);
413
414         /* Since ptrace will transfer a single word starting at that
415            rounded_offset the partial_len needs to be adjusted down to
416            that (remember this function only does a single transfer).
417            Should the required length be even less, adjust it down
418            again.  */
419         partial_len = (rounded_offset + sizeof (PTRACE_TYPE_RET)) - offset;
420         if (partial_len > len)
421           partial_len = len;
422
423         if (writebuf)
424           {
425             /* If OFFSET:PARTIAL_LEN is smaller than
426                ROUNDED_OFFSET:WORDSIZE then a read/modify write will
427                be needed.  Read in the entire word.  */
428             if (rounded_offset < offset
429                 || (offset + partial_len
430                     < rounded_offset + sizeof (PTRACE_TYPE_RET)))
431               {
432                 /* Need part of initial word -- fetch it.  */
433                 if (arch64)
434                   buffer.word = rs6000_ptrace64 (PT_READ_I, pid,
435                                                  rounded_offset, 0, NULL);
436                 else
437                   buffer.word = rs6000_ptrace32 (PT_READ_I, pid,
438                                                  (int *) (uintptr_t)
439                                                  rounded_offset,
440                                                  0, NULL);
441               }
442
443             /* Copy data to be written over corresponding part of
444                buffer.  */
445             memcpy (buffer.byte + (offset - rounded_offset),
446                     writebuf, partial_len);
447
448             errno = 0;
449             if (arch64)
450               rs6000_ptrace64 (PT_WRITE_D, pid,
451                                rounded_offset, buffer.word, NULL);
452             else
453               rs6000_ptrace32 (PT_WRITE_D, pid,
454                                (int *) (uintptr_t) rounded_offset,
455                                buffer.word, NULL);
456             if (errno)
457               return 0;
458           }
459
460         if (readbuf)
461           {
462             errno = 0;
463             if (arch64)
464               buffer.word = rs6000_ptrace64 (PT_READ_I, pid,
465                                              rounded_offset, 0, NULL);
466             else
467               buffer.word = rs6000_ptrace32 (PT_READ_I, pid,
468                                              (int *)(uintptr_t)rounded_offset,
469                                              0, NULL);
470             if (errno)
471               return 0;
472
473             /* Copy appropriate bytes out of the buffer.  */
474             memcpy (readbuf, buffer.byte + (offset - rounded_offset),
475                     partial_len);
476           }
477
478         return partial_len;
479       }
480
481     default:
482       return -1;
483     }
484 }
485
486 /* Wait for the child specified by PTID to do something.  Return the
487    process ID of the child, or MINUS_ONE_PTID in case of error; store
488    the status in *OURSTATUS.  */
489
490 static ptid_t
491 rs6000_wait (struct target_ops *ops,
492              ptid_t ptid, struct target_waitstatus *ourstatus, int options)
493 {
494   pid_t pid;
495   int status, save_errno;
496
497   do
498     {
499       set_sigint_trap ();
500
501       do
502         {
503           pid = waitpid (ptid_get_pid (ptid), &status, 0);
504           save_errno = errno;
505         }
506       while (pid == -1 && errno == EINTR);
507
508       clear_sigint_trap ();
509
510       if (pid == -1)
511         {
512           fprintf_unfiltered (gdb_stderr,
513                               _("Child process unexpectedly missing: %s.\n"),
514                               safe_strerror (save_errno));
515
516           /* Claim it exited with unknown signal.  */
517           ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
518           ourstatus->value.sig = GDB_SIGNAL_UNKNOWN;
519           return inferior_ptid;
520         }
521
522       /* Ignore terminated detached child processes.  */
523       if (!WIFSTOPPED (status) && pid != ptid_get_pid (inferior_ptid))
524         pid = -1;
525     }
526   while (pid == -1);
527
528   /* AIX has a couple of strange returns from wait().  */
529
530   /* stop after load" status.  */
531   if (status == 0x57c)
532     ourstatus->kind = TARGET_WAITKIND_LOADED;
533   /* signal 0.  I have no idea why wait(2) returns with this status word.  */
534   else if (status == 0x7f)
535     ourstatus->kind = TARGET_WAITKIND_SPURIOUS;
536   /* A normal waitstatus.  Let the usual macros deal with it.  */
537   else
538     store_waitstatus (ourstatus, status);
539
540   return pid_to_ptid (pid);
541 }
542
543 /* Execute one dummy breakpoint instruction.  This way we give the kernel
544    a chance to do some housekeeping and update inferior's internal data,
545    including u_area.  */
546
547 static void
548 exec_one_dummy_insn (struct regcache *regcache)
549 {
550 #define DUMMY_INSN_ADDR AIX_TEXT_SEGMENT_BASE+0x200
551
552   struct gdbarch *gdbarch = get_regcache_arch (regcache);
553   int ret, status, pid;
554   CORE_ADDR prev_pc;
555   void *bp;
556
557   /* We plant one dummy breakpoint into DUMMY_INSN_ADDR address.  We
558      assume that this address will never be executed again by the real
559      code.  */
560
561   bp = deprecated_insert_raw_breakpoint (gdbarch, NULL, DUMMY_INSN_ADDR);
562
563   /* You might think this could be done with a single ptrace call, and
564      you'd be correct for just about every platform I've ever worked
565      on.  However, rs6000-ibm-aix4.1.3 seems to have screwed this up --
566      the inferior never hits the breakpoint (it's also worth noting
567      powerpc-ibm-aix4.1.3 works correctly).  */
568   prev_pc = regcache_read_pc (regcache);
569   regcache_write_pc (regcache, DUMMY_INSN_ADDR);
570   if (ARCH64 ())
571     ret = rs6000_ptrace64 (PT_CONTINUE, ptid_get_pid (inferior_ptid),
572                            1, 0, NULL);
573   else
574     ret = rs6000_ptrace32 (PT_CONTINUE, ptid_get_pid (inferior_ptid),
575                            (int *) 1, 0, NULL);
576
577   if (ret != 0)
578     perror (_("pt_continue"));
579
580   do
581     {
582       pid = waitpid (ptid_get_pid (inferior_ptid), &status, 0);
583     }
584   while (pid != ptid_get_pid (inferior_ptid));
585
586   regcache_write_pc (regcache, prev_pc);
587   deprecated_remove_raw_breakpoint (gdbarch, bp);
588 }
589 \f
590
591 /* Set the current architecture from the host running GDB.  Called when
592    starting a child process.  */
593
594 static void (*super_create_inferior) (struct target_ops *,char *exec_file, 
595                                       char *allargs, char **env, int from_tty);
596 static void
597 rs6000_create_inferior (struct target_ops * ops, char *exec_file,
598                         char *allargs, char **env, int from_tty)
599 {
600   enum bfd_architecture arch;
601   unsigned long mach;
602   bfd abfd;
603   struct gdbarch_info info;
604
605   super_create_inferior (ops, exec_file, allargs, env, from_tty);
606
607   if (__power_rs ())
608     {
609       arch = bfd_arch_rs6000;
610       mach = bfd_mach_rs6k;
611     }
612   else
613     {
614       arch = bfd_arch_powerpc;
615       mach = bfd_mach_ppc;
616     }
617
618   /* FIXME: schauer/2002-02-25:
619      We don't know if we are executing a 32 or 64 bit executable,
620      and have no way to pass the proper word size to rs6000_gdbarch_init.
621      So we have to avoid switching to a new architecture, if the architecture
622      matches already.
623      Blindly calling rs6000_gdbarch_init used to work in older versions of
624      GDB, as rs6000_gdbarch_init incorrectly used the previous tdep to
625      determine the wordsize.  */
626   if (exec_bfd)
627     {
628       const struct bfd_arch_info *exec_bfd_arch_info;
629
630       exec_bfd_arch_info = bfd_get_arch_info (exec_bfd);
631       if (arch == exec_bfd_arch_info->arch)
632         return;
633     }
634
635   bfd_default_set_arch_mach (&abfd, arch, mach);
636
637   gdbarch_info_init (&info);
638   info.bfd_arch_info = bfd_get_arch_info (&abfd);
639   info.abfd = exec_bfd;
640
641   if (!gdbarch_update_p (info))
642     internal_error (__FILE__, __LINE__,
643                     _("rs6000_create_inferior: failed "
644                       "to select architecture"));
645 }
646 \f
647
648 /* Shared Object support.  */
649
650 /* Return the LdInfo data for the given process.  Raises an error
651    if the data could not be obtained.
652
653    The returned value must be deallocated after use.  */
654
655 static gdb_byte *
656 rs6000_ptrace_ldinfo (ptid_t ptid)
657 {
658   const int pid = ptid_get_pid (ptid);
659   int ldi_size = 1024;
660   gdb_byte *ldi = xmalloc (ldi_size);
661   int rc = -1;
662
663   while (1)
664     {
665       if (ARCH64 ())
666         rc = rs6000_ptrace64 (PT_LDINFO, pid, (unsigned long) ldi, ldi_size,
667                               NULL);
668       else
669         rc = rs6000_ptrace32 (PT_LDINFO, pid, (int *) ldi, ldi_size, NULL);
670
671       if (rc != -1)
672         break; /* Success, we got the entire ld_info data.  */
673
674       if (errno != ENOMEM)
675         perror_with_name (_("ptrace ldinfo"));
676
677       /* ldi is not big enough.  Double it and try again.  */
678       ldi_size *= 2;
679       ldi = xrealloc (ldi, ldi_size);
680     }
681
682   return ldi;
683 }
684
685 /* Implement the to_xfer_partial target_ops method for
686    TARGET_OBJECT_LIBRARIES_AIX objects.  */
687
688 static LONGEST
689 rs6000_xfer_shared_libraries
690   (struct target_ops *ops, enum target_object object,
691    const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf,
692    ULONGEST offset, LONGEST len)
693 {
694   gdb_byte *ldi_buf;
695   ULONGEST result;
696   struct cleanup *cleanup;
697
698   /* This function assumes that it is being run with a live process.
699      Core files are handled via gdbarch.  */
700   gdb_assert (target_has_execution);
701
702   if (writebuf)
703     return -1;
704
705   ldi_buf = rs6000_ptrace_ldinfo (inferior_ptid);
706   gdb_assert (ldi_buf != NULL);
707   cleanup = make_cleanup (xfree, ldi_buf);
708   result = rs6000_aix_ld_info_to_xml (target_gdbarch (), ldi_buf,
709                                       readbuf, offset, len, 1);
710   xfree (ldi_buf);
711
712   do_cleanups (cleanup);
713   return result;
714 }
715
716 void _initialize_rs6000_nat (void);
717
718 void
719 _initialize_rs6000_nat (void)
720 {
721   struct target_ops *t;
722
723   t = inf_ptrace_target ();
724   t->to_fetch_registers = rs6000_fetch_inferior_registers;
725   t->to_store_registers = rs6000_store_inferior_registers;
726   t->to_xfer_partial = rs6000_xfer_partial;
727
728   super_create_inferior = t->to_create_inferior;
729   t->to_create_inferior = rs6000_create_inferior;
730
731   t->to_wait = rs6000_wait;
732
733   add_target (t);
734 }