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