1 /* IBM RS/6000 native-dependent code for GDB, the GNU debugger.
3 Copyright (C) 1986-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
26 #include "gdb-stabs.h"
28 #include "arch-utils.h"
29 #include "inf-child.h"
30 #include "inf-ptrace.h"
32 #include "rs6000-aix-tdep.h"
34 #include "observable.h"
35 #include "xcoffread.h"
37 #include <sys/ptrace.h>
43 #include <sys/ioctl.h>
51 #define __LDINFO_PTRACE32__ /* for __ld_info32 */
52 #define __LDINFO_PTRACE64__ /* for __ld_info64 */
54 #include <sys/systemcfg.h>
56 /* Header files for getting ppid in AIX of a child process. */
58 #include <sys/types.h>
60 /* Header files for alti-vec reg. */
61 #include <sys/context.h>
63 /* On AIX4.3+, sys/ldr.h provides different versions of struct ld_info for
64 debugging 32-bit and 64-bit processes. Define a typedef and macros for
65 accessing fields in the appropriate structures. */
67 /* In 32-bit compilation mode (which is the only mode from which ptrace()
68 works on 4.3), __ld_info32 is #defined as equivalent to ld_info. */
70 #if defined (__ld_info32) || defined (__ld_info64)
74 /* Return whether the current architecture is 64-bit. */
79 # define ARCH64() (register_size (current_inferior ()->arch (), 0) == 8)
82 class rs6000_nat_target final
: public inf_ptrace_target
85 void fetch_registers (struct regcache
*, int) override
;
86 void store_registers (struct regcache
*, int) override
;
88 enum target_xfer_status
xfer_partial (enum target_object object
,
91 const gdb_byte
*writebuf
,
92 ULONGEST offset
, ULONGEST len
,
93 ULONGEST
*xfered_len
) override
;
95 void create_inferior (const char *, const std::string
&,
96 char **, int) override
;
98 ptid_t
wait (ptid_t
, struct target_waitstatus
*, target_wait_flags
) override
;
100 /* Fork detection related functions, For adding multi process debugging
102 void follow_fork (inferior
*, ptid_t
, target_waitkind
, bool, bool) override
;
104 const struct target_desc
*read_description () override
;
106 int insert_fork_catchpoint (int) override
;
107 int remove_fork_catchpoint (int) override
;
111 void post_startup_inferior (ptid_t ptid
) override
;
114 enum target_xfer_status
115 xfer_shared_libraries (enum target_object object
,
116 const char *annex
, gdb_byte
*readbuf
,
117 const gdb_byte
*writebuf
,
118 ULONGEST offset
, ULONGEST len
,
119 ULONGEST
*xfered_len
);
122 static rs6000_nat_target the_rs6000_nat_target
;
124 /* The below declaration is to track number of times, parent has
125 reported fork event before its children. */
127 static std::list
<pid_t
> aix_pending_parent
;
129 /* The below declaration is for a child process event that
130 is reported before its corresponding parent process in
131 the event of a fork (). */
133 static std::list
<pid_t
> aix_pending_children
;
136 aix_remember_child (pid_t pid
)
138 aix_pending_children
.push_front (pid
);
142 aix_remember_parent (pid_t pid
)
144 aix_pending_parent
.push_front (pid
);
147 /* This function returns a parent of a child process. */
150 find_my_aix_parent (pid_t child_pid
)
152 struct procsinfo ProcessBuffer1
;
154 if (getprocs (&ProcessBuffer1
, sizeof (ProcessBuffer1
),
155 NULL
, 0, &child_pid
, 1) != 1)
158 return ProcessBuffer1
.pi_ppid
;
161 /* In the below function we check if there was any child
162 process pending. If it exists we return it from the
163 list, otherwise we return a null. */
166 has_my_aix_child_reported (pid_t parent_pid
)
169 auto it
= std::find_if (aix_pending_children
.begin (),
170 aix_pending_children
.end (),
171 [=] (pid_t child_pid
)
173 return find_my_aix_parent (child_pid
) == parent_pid
;
175 if (it
!= aix_pending_children
.end ())
178 aix_pending_children
.erase (it
);
183 /* In the below function we check if there was any parent
184 process pending. If it exists we return it from the
185 list, otherwise we return a null. */
188 has_my_aix_parent_reported (pid_t child_pid
)
190 pid_t my_parent
= find_my_aix_parent (child_pid
);
191 auto it
= std::find (aix_pending_parent
.begin (),
192 aix_pending_parent
.end (),
194 if (it
!= aix_pending_parent
.end ())
196 aix_pending_parent
.erase (it
);
202 /* Given REGNO, a gdb register number, return the corresponding
203 number suitable for use as a ptrace() parameter. Return -1 if
204 there's no suitable mapping. Also, set the int pointed to by
205 ISFLOAT to indicate whether REGNO is a floating point register. */
208 regmap (struct gdbarch
*gdbarch
, int regno
, int *isfloat
)
210 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
213 if (tdep
->ppc_gp0_regnum
<= regno
214 && regno
< tdep
->ppc_gp0_regnum
+ ppc_num_gprs
)
216 else if (tdep
->ppc_fp0_regnum
>= 0
217 && tdep
->ppc_fp0_regnum
<= regno
218 && regno
< tdep
->ppc_fp0_regnum
+ ppc_num_fprs
)
221 return regno
- tdep
->ppc_fp0_regnum
+ FPR0
;
223 else if (regno
== gdbarch_pc_regnum (gdbarch
))
225 else if (regno
== tdep
->ppc_ps_regnum
)
227 else if (regno
== tdep
->ppc_cr_regnum
)
229 else if (regno
== tdep
->ppc_lr_regnum
)
231 else if (regno
== tdep
->ppc_ctr_regnum
)
233 else if (regno
== tdep
->ppc_xer_regnum
)
235 else if (tdep
->ppc_fpscr_regnum
>= 0
236 && regno
== tdep
->ppc_fpscr_regnum
)
238 else if (tdep
->ppc_mq_regnum
>= 0 && regno
== tdep
->ppc_mq_regnum
)
244 /* Call ptrace(REQ, ID, ADDR, DATA, BUF). */
247 rs6000_ptrace32 (int req
, int id
, int *addr
, int data
, int *buf
)
250 int ret
= ptrace64 (req
, id
, (uintptr_t) addr
, data
, buf
);
252 int ret
= ptrace (req
, id
, (int *)addr
, data
, buf
);
255 printf ("rs6000_ptrace32 (%d, %d, 0x%x, %08x, 0x%x) = 0x%x\n",
256 req
, id
, (unsigned int)addr
, data
, (unsigned int)buf
, ret
);
261 /* Call ptracex(REQ, ID, ADDR, DATA, BUF). */
264 rs6000_ptrace64 (int req
, int id
, long long addr
, int data
, void *buf
)
267 # ifdef HAVE_PTRACE64
268 int ret
= ptrace64 (req
, id
, addr
, data
, (PTRACE_TYPE_ARG5
) buf
);
270 int ret
= ptracex (req
, id
, addr
, data
, (PTRACE_TYPE_ARG5
) buf
);
276 printf ("rs6000_ptrace64 (%d, %d, %s, %08x, 0x%x) = 0x%x\n",
277 req
, id
, hex_string (addr
), data
, (unsigned int)buf
, ret
);
282 /* Store the vsx registers. */
285 store_vsx_register_aix (struct regcache
*regcache
, int regno
)
288 struct gdbarch
*gdbarch
= regcache
->arch ();
289 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
290 struct thrdentry64 thrdentry
;
292 pid_t pid
= inferior_ptid
.pid ();
295 if (getthrds64(pid
, &thrdentry
, sizeof(struct thrdentry64
),
297 thrd_i
= thrdentry
.ti_tid
;
299 memset(&vsx
, 0, sizeof(__vsx_context_t
));
300 if (__power_vsx() && thrd_i
> 0)
303 ret
= rs6000_ptrace64 (PTT_READ_VSX
, thrd_i
, (long long) &vsx
, 0, 0);
305 ret
= rs6000_ptrace32 (PTT_READ_VSX
, thrd_i
, (int *)&vsx
, 0, 0);
309 regcache
->raw_collect (regno
, &(vsx
.__vsr_dw1
[0])+
310 regno
- tdep
->ppc_vsr0_upper_regnum
);
313 ret
= rs6000_ptrace64 (PTT_WRITE_VSX
, thrd_i
, (long long) &vsx
, 0, 0);
315 ret
= rs6000_ptrace32 (PTT_WRITE_VSX
, thrd_i
, (int *) &vsx
, 0, 0);
318 perror_with_name (_("Unable to write VSX registers after reading it"));
322 /* Store Altivec registers. */
325 store_altivec_register_aix (struct regcache
*regcache
, int regno
)
328 struct gdbarch
*gdbarch
= regcache
->arch ();
329 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
330 struct thrdentry64 thrdentry
;
332 pid_t pid
= inferior_ptid
.pid ();
335 if (getthrds64(pid
, &thrdentry
, sizeof(struct thrdentry64
),
337 thrd_i
= thrdentry
.ti_tid
;
339 memset(&vmx
, 0, sizeof(__vmx_context_t
));
340 if (__power_vmx() && thrd_i
> 0)
343 ret
= rs6000_ptrace64 (PTT_READ_VEC
, thrd_i
, (long long) &vmx
, 0, 0);
345 ret
= rs6000_ptrace32 (PTT_READ_VEC
, thrd_i
, (int *) &vmx
, 0, 0);
349 regcache
->raw_collect (regno
, &(vmx
.__vr
[0]) + regno
350 - tdep
->ppc_vr0_regnum
);
353 ret
= rs6000_ptrace64 (PTT_WRITE_VEC
, thrd_i
, (long long) &vmx
, 0, 0);
355 ret
= rs6000_ptrace32 (PTT_WRITE_VEC
, thrd_i
, (int *) &vmx
, 0, 0);
357 perror_with_name (_("Unable to store AltiVec register after reading it"));
361 /* Supply altivec registers. */
364 supply_vrregset_aix (struct regcache
*regcache
, __vmx_context_t
*vmx
)
367 struct gdbarch
*gdbarch
= regcache
->arch ();
368 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
369 int num_of_vrregs
= tdep
->ppc_vrsave_regnum
- tdep
->ppc_vr0_regnum
+ 1;
371 for (i
= 0; i
< num_of_vrregs
; i
++)
372 regcache
->raw_supply (tdep
->ppc_vr0_regnum
+ i
,
374 regcache
->raw_supply (tdep
->ppc_vrsave_regnum
, &(vmx
->__vrsave
));
375 regcache
->raw_supply (tdep
->ppc_vrsave_regnum
- 1, &(vmx
->__vscr
));
378 /* Fetch altivec register. */
381 fetch_altivec_registers_aix (struct regcache
*regcache
)
383 struct thrdentry64 thrdentry
;
385 pid_t pid
= current_inferior ()->pid
;
388 if (getthrds64(pid
, &thrdentry
, sizeof(struct thrdentry64
),
390 thrd_i
= thrdentry
.ti_tid
;
392 memset(&vmx
, 0, sizeof(__vmx_context_t
));
393 if (__power_vmx() && thrd_i
> 0)
396 rs6000_ptrace64 (PTT_READ_VEC
, thrd_i
, (long long) &vmx
, 0, 0);
398 rs6000_ptrace32 (PTT_READ_VEC
, thrd_i
, (int *) &vmx
, 0, 0);
399 supply_vrregset_aix (regcache
, &vmx
);
403 /* supply vsx register. */
406 supply_vsxregset_aix (struct regcache
*regcache
, __vsx_context_t
*vsx
)
409 struct gdbarch
*gdbarch
= regcache
->arch ();
410 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
412 for (i
= 0; i
< ppc_num_vshrs
; i
++)
413 regcache
->raw_supply (tdep
->ppc_vsr0_upper_regnum
+ i
,
414 &(vsx
->__vsr_dw1
[i
]));
417 /* Fetch vsx registers. */
419 fetch_vsx_registers_aix (struct regcache
*regcache
)
421 struct thrdentry64 thrdentry
;
423 pid_t pid
= current_inferior ()->pid
;
426 if (getthrds64(pid
, &thrdentry
, sizeof(struct thrdentry64
),
428 thrd_i
= thrdentry
.ti_tid
;
430 memset(&vsx
, 0, sizeof(__vsx_context_t
));
431 if (__power_vsx() && thrd_i
> 0)
434 rs6000_ptrace64 (PTT_READ_VSX
, thrd_i
, (long long) &vsx
, 0, 0);
436 rs6000_ptrace32 (PTT_READ_VSX
, thrd_i
, (int *) &vsx
, 0, 0);
437 supply_vsxregset_aix (regcache
, &vsx
);
441 void rs6000_nat_target::post_startup_inferior (ptid_t ptid
)
444 /* In AIX to turn on multi process debugging in ptrace
445 PT_MULTI is the option to be passed,
446 with the process ID which can fork () and
447 the data parameter [fourth parameter] must be 1. */
450 rs6000_ptrace32 (PT_MULTI
, ptid
.pid(), 0, 1, 0);
452 rs6000_ptrace64 (PT_MULTI
, ptid
.pid(), 0, 1, 0);
456 rs6000_nat_target::follow_fork (inferior
*child_inf
, ptid_t child_ptid
,
457 target_waitkind fork_kind
, bool follow_child
,
461 /* Once the fork event is detected the infrun.c code
462 calls the target_follow_fork to take care of
463 follow child and detach the child activity which is
464 done using the function below. */
466 inf_ptrace_target::follow_fork (child_inf
, child_ptid
, fork_kind
,
467 follow_child
, detach_fork
);
469 /* If we detach fork and follow child we do not want the child
470 process to generate events that ptrace can trace. Hence we
473 if (detach_fork
&& !follow_child
)
476 rs6000_ptrace64 (PT_DETACH
, child_ptid
.pid (), 0, 0, 0);
478 rs6000_ptrace32 (PT_DETACH
, child_ptid
.pid (), 0, 0, 0);
482 /* Functions for catchpoint in AIX. */
484 rs6000_nat_target::insert_fork_catchpoint (int pid
)
490 rs6000_nat_target::remove_fork_catchpoint (int pid
)
495 /* Fetch register REGNO from the inferior. */
498 fetch_register (struct regcache
*regcache
, int regno
)
500 struct gdbarch
*gdbarch
= regcache
->arch ();
501 int addr
[PPC_MAX_REGISTER_SIZE
];
503 pid_t pid
= regcache
->ptid ().pid ();
505 /* Retrieved values may be -1, so infer errors from errno. */
508 /* Alti-vec register. */
509 if (altivec_register_p (gdbarch
, regno
))
511 fetch_altivec_registers_aix (regcache
);
516 if (vsx_register_p (gdbarch
, regno
))
518 fetch_vsx_registers_aix (regcache
);
522 nr
= regmap (gdbarch
, regno
, &isfloat
);
524 /* Floating-point registers. */
526 rs6000_ptrace32 (PT_READ_FPR
, pid
, addr
, nr
, 0);
528 /* Bogus register number. */
531 if (regno
>= gdbarch_num_regs (gdbarch
))
532 gdb_printf (gdb_stderr
,
533 "gdb error: register no %d not implemented.\n",
538 /* Fixed-point registers. */
542 *addr
= rs6000_ptrace32 (PT_READ_GPR
, pid
, (int *) nr
, 0, 0);
545 /* PT_READ_GPR requires the buffer parameter to point to long long,
546 even if the register is really only 32 bits. */
548 rs6000_ptrace64 (PT_READ_GPR
, pid
, nr
, 0, &buf
);
549 if (register_size (gdbarch
, regno
) == 8)
550 memcpy (addr
, &buf
, 8);
557 regcache
->raw_supply (regno
, (char *) addr
);
561 /* FIXME: this happens 3 times at the start of each 64-bit program. */
562 perror (_("ptrace read"));
568 /* Store register REGNO back into the inferior. */
571 store_register (struct regcache
*regcache
, int regno
)
573 struct gdbarch
*gdbarch
= regcache
->arch ();
574 int addr
[PPC_MAX_REGISTER_SIZE
];
576 pid_t pid
= regcache
->ptid ().pid ();
578 /* Fetch the register's value from the register cache. */
579 regcache
->raw_collect (regno
, addr
);
581 /* -1 can be a successful return value, so infer errors from errno. */
584 if (altivec_register_p (gdbarch
, regno
))
586 store_altivec_register_aix (regcache
, regno
);
590 if (vsx_register_p (gdbarch
, regno
))
592 store_vsx_register_aix (regcache
, regno
);
596 nr
= regmap (gdbarch
, regno
, &isfloat
);
598 /* Floating-point registers. */
600 rs6000_ptrace32 (PT_WRITE_FPR
, pid
, addr
, nr
, 0);
602 /* Bogus register number. */
605 if (regno
>= gdbarch_num_regs (gdbarch
))
606 gdb_printf (gdb_stderr
,
607 "gdb error: register no %d not implemented.\n",
611 /* Fixed-point registers. */
614 /* The PT_WRITE_GPR operation is rather odd. For 32-bit inferiors,
615 the register's value is passed by value, but for 64-bit inferiors,
616 the address of a buffer containing the value is passed. */
618 rs6000_ptrace32 (PT_WRITE_GPR
, pid
, (int *) nr
, *addr
, 0);
621 /* PT_WRITE_GPR requires the buffer parameter to point to an 8-byte
622 area, even if the register is really only 32 bits. */
624 if (register_size (gdbarch
, regno
) == 8)
625 memcpy (&buf
, addr
, 8);
628 rs6000_ptrace64 (PT_WRITE_GPR
, pid
, nr
, 0, &buf
);
634 perror (_("ptrace write"));
639 /* Read from the inferior all registers if REGNO == -1 and just register
643 rs6000_nat_target::fetch_registers (struct regcache
*regcache
, int regno
)
645 struct gdbarch
*gdbarch
= regcache
->arch ();
647 fetch_register (regcache
, regno
);
651 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
653 /* Read 32 general purpose registers. */
654 for (regno
= tdep
->ppc_gp0_regnum
;
655 regno
< tdep
->ppc_gp0_regnum
+ ppc_num_gprs
;
658 fetch_register (regcache
, regno
);
661 /* Read general purpose floating point registers. */
662 if (tdep
->ppc_fp0_regnum
>= 0)
663 for (regno
= 0; regno
< ppc_num_fprs
; regno
++)
664 fetch_register (regcache
, tdep
->ppc_fp0_regnum
+ regno
);
666 if (tdep
->ppc_vr0_regnum
!= -1 && tdep
->ppc_vrsave_regnum
!= -1)
667 fetch_altivec_registers_aix (regcache
);
669 if (tdep
->ppc_vsr0_upper_regnum
!= -1)
670 fetch_vsx_registers_aix (regcache
);
672 /* Read special registers. */
673 fetch_register (regcache
, gdbarch_pc_regnum (gdbarch
));
674 fetch_register (regcache
, tdep
->ppc_ps_regnum
);
675 fetch_register (regcache
, tdep
->ppc_cr_regnum
);
676 fetch_register (regcache
, tdep
->ppc_lr_regnum
);
677 fetch_register (regcache
, tdep
->ppc_ctr_regnum
);
678 fetch_register (regcache
, tdep
->ppc_xer_regnum
);
679 if (tdep
->ppc_fpscr_regnum
>= 0)
680 fetch_register (regcache
, tdep
->ppc_fpscr_regnum
);
681 if (tdep
->ppc_mq_regnum
>= 0)
682 fetch_register (regcache
, tdep
->ppc_mq_regnum
);
686 const struct target_desc
*
687 rs6000_nat_target::read_description ()
692 return tdesc_powerpc_vsx64
;
693 else if (__power_vmx ())
694 return tdesc_powerpc_altivec64
;
699 return tdesc_powerpc_vsx32
;
700 else if (__power_vmx ())
701 return tdesc_powerpc_altivec32
;
706 /* Store our register values back into the inferior.
707 If REGNO is -1, do this for all registers.
708 Otherwise, REGNO specifies which register (so we can save time). */
711 rs6000_nat_target::store_registers (struct regcache
*regcache
, int regno
)
713 struct gdbarch
*gdbarch
= regcache
->arch ();
715 store_register (regcache
, regno
);
719 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
721 /* Write general purpose registers first. */
722 for (regno
= tdep
->ppc_gp0_regnum
;
723 regno
< tdep
->ppc_gp0_regnum
+ ppc_num_gprs
;
726 store_register (regcache
, regno
);
729 /* Write floating point registers. */
730 if (tdep
->ppc_fp0_regnum
>= 0)
731 for (regno
= 0; regno
< ppc_num_fprs
; regno
++)
732 store_register (regcache
, tdep
->ppc_fp0_regnum
+ regno
);
734 /* Write special registers. */
735 store_register (regcache
, gdbarch_pc_regnum (gdbarch
));
736 store_register (regcache
, tdep
->ppc_ps_regnum
);
737 store_register (regcache
, tdep
->ppc_cr_regnum
);
738 store_register (regcache
, tdep
->ppc_lr_regnum
);
739 store_register (regcache
, tdep
->ppc_ctr_regnum
);
740 store_register (regcache
, tdep
->ppc_xer_regnum
);
741 if (tdep
->ppc_fpscr_regnum
>= 0)
742 store_register (regcache
, tdep
->ppc_fpscr_regnum
);
743 if (tdep
->ppc_mq_regnum
>= 0)
744 store_register (regcache
, tdep
->ppc_mq_regnum
);
748 /* Implement the to_xfer_partial target_ops method. */
750 enum target_xfer_status
751 rs6000_nat_target::xfer_partial (enum target_object object
,
752 const char *annex
, gdb_byte
*readbuf
,
753 const gdb_byte
*writebuf
,
754 ULONGEST offset
, ULONGEST len
,
755 ULONGEST
*xfered_len
)
757 pid_t pid
= inferior_ptid
.pid ();
758 int arch64
= ARCH64 ();
762 case TARGET_OBJECT_LIBRARIES_AIX
:
763 return xfer_shared_libraries (object
, annex
,
765 offset
, len
, xfered_len
);
766 case TARGET_OBJECT_MEMORY
:
770 PTRACE_TYPE_RET word
;
771 gdb_byte byte
[sizeof (PTRACE_TYPE_RET
)];
773 ULONGEST rounded_offset
;
776 /* Round the start offset down to the next long word
778 rounded_offset
= offset
& -(ULONGEST
) sizeof (PTRACE_TYPE_RET
);
780 /* Since ptrace will transfer a single word starting at that
781 rounded_offset the partial_len needs to be adjusted down to
782 that (remember this function only does a single transfer).
783 Should the required length be even less, adjust it down
785 partial_len
= (rounded_offset
+ sizeof (PTRACE_TYPE_RET
)) - offset
;
786 if (partial_len
> len
)
791 /* If OFFSET:PARTIAL_LEN is smaller than
792 ROUNDED_OFFSET:WORDSIZE then a read/modify write will
793 be needed. Read in the entire word. */
794 if (rounded_offset
< offset
795 || (offset
+ partial_len
796 < rounded_offset
+ sizeof (PTRACE_TYPE_RET
)))
798 /* Need part of initial word -- fetch it. */
800 buffer
.word
= rs6000_ptrace64 (PT_READ_I
, pid
,
801 rounded_offset
, 0, NULL
);
803 buffer
.word
= rs6000_ptrace32 (PT_READ_I
, pid
,
809 /* Copy data to be written over corresponding part of
811 memcpy (buffer
.byte
+ (offset
- rounded_offset
),
812 writebuf
, partial_len
);
816 rs6000_ptrace64 (PT_WRITE_D
, pid
,
817 rounded_offset
, buffer
.word
, NULL
);
819 rs6000_ptrace32 (PT_WRITE_D
, pid
,
820 (int *) (uintptr_t) rounded_offset
,
823 return TARGET_XFER_EOF
;
830 buffer
.word
= rs6000_ptrace64 (PT_READ_I
, pid
,
831 rounded_offset
, 0, NULL
);
833 buffer
.word
= rs6000_ptrace32 (PT_READ_I
, pid
,
834 (int *)(uintptr_t)rounded_offset
,
837 return TARGET_XFER_EOF
;
839 /* Copy appropriate bytes out of the buffer. */
840 memcpy (readbuf
, buffer
.byte
+ (offset
- rounded_offset
),
844 *xfered_len
= (ULONGEST
) partial_len
;
845 return TARGET_XFER_OK
;
849 return TARGET_XFER_E_IO
;
853 /* Wait for the child specified by PTID to do something. Return the
854 process ID of the child, or MINUS_ONE_PTID in case of error; store
855 the status in *OURSTATUS. */
858 rs6000_nat_target::wait (ptid_t ptid
, struct target_waitstatus
*ourstatus
,
859 target_wait_flags options
)
862 int status
, save_errno
;
870 pid
= waitpid (ptid
.pid (), &status
, 0);
873 while (pid
== -1 && errno
== EINTR
);
875 clear_sigint_trap ();
879 gdb_printf (gdb_stderr
,
880 _("Child process unexpectedly missing: %s.\n"),
881 safe_strerror (save_errno
));
883 ourstatus
->set_ignore ();
884 return minus_one_ptid
;
887 /* Ignore terminated detached child processes. */
888 if (!WIFSTOPPED (status
) && find_inferior_pid (this, pid
) == nullptr)
891 /* Check for a fork () event. */
892 if ((status
& 0xff) == W_SFWTED
)
894 /* Checking whether it is a parent or a child event. */
896 /* If the event is a child we check if there was a parent
897 event recorded before. If yes we got the parent child
898 relationship. If not we push this child and wait for
899 the next fork () event. */
900 if (find_inferior_pid (this, pid
) == nullptr)
902 pid_t parent_pid
= has_my_aix_parent_reported (pid
);
905 ourstatus
->set_forked (ptid_t (pid
));
906 return ptid_t (parent_pid
);
908 aix_remember_child (pid
);
911 /* If the event is a parent we check if there was a child
912 event recorded before. If yes we got the parent child
913 relationship. If not we push this parent and wait for
914 the next fork () event. */
917 pid_t child_pid
= has_my_aix_child_reported (pid
);
920 ourstatus
->set_forked (ptid_t (child_pid
));
923 aix_remember_parent (pid
);
931 /* AIX has a couple of strange returns from wait(). */
933 /* stop after load" status. */
935 ourstatus
->set_loaded ();
936 /* 0x7f is signal 0. */
937 else if (status
== 0x7f)
938 ourstatus
->set_spurious ();
939 /* A normal waitstatus. Let the usual macros deal with it. */
941 *ourstatus
= host_status_to_waitstatus (status
);
947 /* Set the current architecture from the host running GDB. Called when
948 starting a child process. */
951 rs6000_nat_target::create_inferior (const char *exec_file
,
952 const std::string
&allargs
,
953 char **env
, int from_tty
)
955 enum bfd_architecture arch
;
959 inf_ptrace_target::create_inferior (exec_file
, allargs
, env
, from_tty
);
963 arch
= bfd_arch_rs6000
;
964 mach
= bfd_mach_rs6k
;
968 arch
= bfd_arch_powerpc
;
972 /* FIXME: schauer/2002-02-25:
973 We don't know if we are executing a 32 or 64 bit executable,
974 and have no way to pass the proper word size to rs6000_gdbarch_init.
975 So we have to avoid switching to a new architecture, if the architecture
977 Blindly calling rs6000_gdbarch_init used to work in older versions of
978 GDB, as rs6000_gdbarch_init incorrectly used the previous tdep to
979 determine the wordsize. */
980 if (current_program_space
->exec_bfd ())
982 const struct bfd_arch_info
*exec_bfd_arch_info
;
985 = bfd_get_arch_info (current_program_space
->exec_bfd ());
986 if (arch
== exec_bfd_arch_info
->arch
)
990 bfd_default_set_arch_mach (&abfd
, arch
, mach
);
993 info
.bfd_arch_info
= bfd_get_arch_info (&abfd
);
994 info
.abfd
= current_program_space
->exec_bfd ();
996 if (!gdbarch_update_p (info
))
997 internal_error (_("rs6000_create_inferior: failed "
998 "to select architecture"));
1002 /* Shared Object support. */
1004 /* Return the LdInfo data for the given process. Raises an error
1005 if the data could not be obtained. */
1007 static gdb::byte_vector
1008 rs6000_ptrace_ldinfo (ptid_t ptid
)
1010 const int pid
= ptid
.pid ();
1011 gdb::byte_vector
ldi (1024);
1017 rc
= rs6000_ptrace64 (PT_LDINFO
, pid
, (unsigned long) ldi
.data (),
1020 rc
= rs6000_ptrace32 (PT_LDINFO
, pid
, (int *) ldi
.data (),
1024 break; /* Success, we got the entire ld_info data. */
1026 if (errno
!= ENOMEM
)
1027 perror_with_name (_("ptrace ldinfo"));
1029 /* ldi is not big enough. Double it and try again. */
1030 ldi
.resize (ldi
.size () * 2);
1036 /* Implement the to_xfer_partial target_ops method for
1037 TARGET_OBJECT_LIBRARIES_AIX objects. */
1039 enum target_xfer_status
1040 rs6000_nat_target::xfer_shared_libraries
1041 (enum target_object object
,
1042 const char *annex
, gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1043 ULONGEST offset
, ULONGEST len
, ULONGEST
*xfered_len
)
1047 /* This function assumes that it is being run with a live process.
1048 Core files are handled via gdbarch. */
1049 gdb_assert (target_has_execution ());
1052 return TARGET_XFER_E_IO
;
1054 gdb::byte_vector ldi_buf
= rs6000_ptrace_ldinfo (inferior_ptid
);
1055 result
= rs6000_aix_ld_info_to_xml (current_inferior ()->arch (),
1057 readbuf
, offset
, len
, 1);
1060 return TARGET_XFER_EOF
;
1063 *xfered_len
= result
;
1064 return TARGET_XFER_OK
;
1068 void _initialize_rs6000_nat ();
1070 _initialize_rs6000_nat ()
1072 add_inf_child_target (&the_rs6000_nat_target
);