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