1 /* IBM RS/6000 native-dependent code for GDB, the GNU debugger.
3 Copyright (C) 1986-2023 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/>. */
27 #include "gdb-stabs.h"
29 #include "arch-utils.h"
30 #include "inf-child.h"
31 #include "inf-ptrace.h"
33 #include "rs6000-aix-tdep.h"
35 #include "observable.h"
36 #include "xcoffread.h"
38 #include <sys/ptrace.h>
44 #include <sys/ioctl.h>
52 #define __LDINFO_PTRACE32__ /* for __ld_info32 */
53 #define __LDINFO_PTRACE64__ /* for __ld_info64 */
55 #include <sys/systemcfg.h>
57 /* Header files for getting ppid in AIX of a child process. */
59 #include <sys/types.h>
61 /* Header files for alti-vec reg. */
62 #include <sys/context.h>
64 /* On AIX4.3+, sys/ldr.h provides different versions of struct ld_info for
65 debugging 32-bit and 64-bit processes. Define a typedef and macros for
66 accessing fields in the appropriate structures. */
68 /* In 32-bit compilation mode (which is the only mode from which ptrace()
69 works on 4.3), __ld_info32 is #defined as equivalent to ld_info. */
71 #if defined (__ld_info32) || defined (__ld_info64)
75 /* Return whether the current architecture is 64-bit. */
80 # define ARCH64() (register_size (current_inferior ()->arch (), 0) == 8)
83 class rs6000_nat_target final
: public inf_ptrace_target
86 void fetch_registers (struct regcache
*, int) override
;
87 void store_registers (struct regcache
*, int) override
;
89 enum target_xfer_status
xfer_partial (enum target_object object
,
92 const gdb_byte
*writebuf
,
93 ULONGEST offset
, ULONGEST len
,
94 ULONGEST
*xfered_len
) override
;
96 void create_inferior (const char *, const std::string
&,
97 char **, int) override
;
99 ptid_t
wait (ptid_t
, struct target_waitstatus
*, target_wait_flags
) override
;
101 /* Fork detection related functions, For adding multi process debugging
103 void follow_fork (inferior
*, ptid_t
, target_waitkind
, bool, bool) override
;
105 const struct target_desc
*read_description () override
;
109 void post_startup_inferior (ptid_t ptid
) override
;
112 enum target_xfer_status
113 xfer_shared_libraries (enum target_object object
,
114 const char *annex
, gdb_byte
*readbuf
,
115 const gdb_byte
*writebuf
,
116 ULONGEST offset
, ULONGEST len
,
117 ULONGEST
*xfered_len
);
120 static rs6000_nat_target the_rs6000_nat_target
;
122 /* The below declaration is to track number of times, parent has
123 reported fork event before its children. */
125 static std::list
<pid_t
> aix_pending_parent
;
127 /* The below declaration is for a child process event that
128 is reported before its corresponding parent process in
129 the event of a fork (). */
131 static std::list
<pid_t
> aix_pending_children
;
134 aix_remember_child (pid_t pid
)
136 aix_pending_children
.push_front (pid
);
140 aix_remember_parent (pid_t pid
)
142 aix_pending_parent
.push_front (pid
);
145 /* This function returns a parent of a child process. */
148 find_my_aix_parent (pid_t child_pid
)
150 struct procsinfo ProcessBuffer1
;
152 if (getprocs (&ProcessBuffer1
, sizeof (ProcessBuffer1
),
153 NULL
, 0, &child_pid
, 1) != 1)
156 return ProcessBuffer1
.pi_ppid
;
159 /* In the below function we check if there was any child
160 process pending. If it exists we return it from the
161 list, otherwise we return a null. */
164 has_my_aix_child_reported (pid_t parent_pid
)
167 auto it
= std::find_if (aix_pending_children
.begin (),
168 aix_pending_children
.end (),
169 [=] (pid_t child_pid
)
171 return find_my_aix_parent (child_pid
) == parent_pid
;
173 if (it
!= aix_pending_children
.end ())
176 aix_pending_children
.erase (it
);
181 /* In the below function we check if there was any parent
182 process pending. If it exists we return it from the
183 list, otherwise we return a null. */
186 has_my_aix_parent_reported (pid_t child_pid
)
188 pid_t my_parent
= find_my_aix_parent (child_pid
);
189 auto it
= std::find (aix_pending_parent
.begin (),
190 aix_pending_parent
.end (),
192 if (it
!= aix_pending_parent
.end ())
194 aix_pending_parent
.erase (it
);
200 /* Given REGNO, a gdb register number, return the corresponding
201 number suitable for use as a ptrace() parameter. Return -1 if
202 there's no suitable mapping. Also, set the int pointed to by
203 ISFLOAT to indicate whether REGNO is a floating point register. */
206 regmap (struct gdbarch
*gdbarch
, int regno
, int *isfloat
)
208 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
211 if (tdep
->ppc_gp0_regnum
<= regno
212 && regno
< tdep
->ppc_gp0_regnum
+ ppc_num_gprs
)
214 else if (tdep
->ppc_fp0_regnum
>= 0
215 && tdep
->ppc_fp0_regnum
<= regno
216 && regno
< tdep
->ppc_fp0_regnum
+ ppc_num_fprs
)
219 return regno
- tdep
->ppc_fp0_regnum
+ FPR0
;
221 else if (regno
== gdbarch_pc_regnum (gdbarch
))
223 else if (regno
== tdep
->ppc_ps_regnum
)
225 else if (regno
== tdep
->ppc_cr_regnum
)
227 else if (regno
== tdep
->ppc_lr_regnum
)
229 else if (regno
== tdep
->ppc_ctr_regnum
)
231 else if (regno
== tdep
->ppc_xer_regnum
)
233 else if (tdep
->ppc_fpscr_regnum
>= 0
234 && regno
== tdep
->ppc_fpscr_regnum
)
236 else if (tdep
->ppc_mq_regnum
>= 0 && regno
== tdep
->ppc_mq_regnum
)
242 /* Call ptrace(REQ, ID, ADDR, DATA, BUF). */
245 rs6000_ptrace32 (int req
, int id
, int *addr
, int data
, int *buf
)
248 int ret
= ptrace64 (req
, id
, (uintptr_t) addr
, data
, buf
);
250 int ret
= ptrace (req
, id
, (int *)addr
, data
, buf
);
253 printf ("rs6000_ptrace32 (%d, %d, 0x%x, %08x, 0x%x) = 0x%x\n",
254 req
, id
, (unsigned int)addr
, data
, (unsigned int)buf
, ret
);
259 /* Call ptracex(REQ, ID, ADDR, DATA, BUF). */
262 rs6000_ptrace64 (int req
, int id
, long long addr
, int data
, void *buf
)
265 # ifdef HAVE_PTRACE64
266 int ret
= ptrace64 (req
, id
, addr
, data
, (PTRACE_TYPE_ARG5
) buf
);
268 int ret
= ptracex (req
, id
, addr
, data
, (PTRACE_TYPE_ARG5
) buf
);
274 printf ("rs6000_ptrace64 (%d, %d, %s, %08x, 0x%x) = 0x%x\n",
275 req
, id
, hex_string (addr
), data
, (unsigned int)buf
, ret
);
280 /* Store the vsx registers. */
283 store_vsx_register_aix (struct regcache
*regcache
, int regno
)
286 struct gdbarch
*gdbarch
= regcache
->arch ();
287 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
288 struct thrdentry64 thrdentry
;
290 pid_t pid
= inferior_ptid
.pid ();
293 if (getthrds64(pid
, &thrdentry
, sizeof(struct thrdentry64
),
295 thrd_i
= thrdentry
.ti_tid
;
297 memset(&vsx
, 0, sizeof(__vsx_context_t
));
298 if (__power_vsx() && thrd_i
> 0)
301 ret
= rs6000_ptrace64 (PTT_READ_VSX
, thrd_i
, (long long) &vsx
, 0, 0);
303 ret
= rs6000_ptrace32 (PTT_READ_VSX
, thrd_i
, (int *)&vsx
, 0, 0);
307 regcache
->raw_collect (regno
, &(vsx
.__vsr_dw1
[0])+
308 regno
- tdep
->ppc_vsr0_upper_regnum
);
311 ret
= rs6000_ptrace64 (PTT_WRITE_VSX
, thrd_i
, (long long) &vsx
, 0, 0);
313 ret
= rs6000_ptrace32 (PTT_WRITE_VSX
, thrd_i
, (int *) &vsx
, 0, 0);
316 perror_with_name (_("Unable to write VSX registers after reading it"));
320 /* Store Altivec registers. */
323 store_altivec_register_aix (struct regcache
*regcache
, int regno
)
326 struct gdbarch
*gdbarch
= regcache
->arch ();
327 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
328 struct thrdentry64 thrdentry
;
330 pid_t pid
= inferior_ptid
.pid ();
333 if (getthrds64(pid
, &thrdentry
, sizeof(struct thrdentry64
),
335 thrd_i
= thrdentry
.ti_tid
;
337 memset(&vmx
, 0, sizeof(__vmx_context_t
));
338 if (__power_vmx() && thrd_i
> 0)
341 ret
= rs6000_ptrace64 (PTT_READ_VEC
, thrd_i
, (long long) &vmx
, 0, 0);
343 ret
= rs6000_ptrace32 (PTT_READ_VEC
, thrd_i
, (int *) &vmx
, 0, 0);
347 regcache
->raw_collect (regno
, &(vmx
.__vr
[0]) + regno
348 - tdep
->ppc_vr0_regnum
);
351 ret
= rs6000_ptrace64 (PTT_WRITE_VEC
, thrd_i
, (long long) &vmx
, 0, 0);
353 ret
= rs6000_ptrace32 (PTT_WRITE_VEC
, thrd_i
, (int *) &vmx
, 0, 0);
355 perror_with_name (_("Unable to store AltiVec register after reading it"));
359 /* Supply altivec registers. */
362 supply_vrregset_aix (struct regcache
*regcache
, __vmx_context_t
*vmx
)
365 struct gdbarch
*gdbarch
= regcache
->arch ();
366 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
367 int num_of_vrregs
= tdep
->ppc_vrsave_regnum
- tdep
->ppc_vr0_regnum
+ 1;
369 for (i
= 0; i
< num_of_vrregs
; i
++)
370 regcache
->raw_supply (tdep
->ppc_vr0_regnum
+ i
,
372 regcache
->raw_supply (tdep
->ppc_vrsave_regnum
, &(vmx
->__vrsave
));
373 regcache
->raw_supply (tdep
->ppc_vrsave_regnum
- 1, &(vmx
->__vscr
));
376 /* Fetch altivec register. */
379 fetch_altivec_registers_aix (struct regcache
*regcache
)
381 struct thrdentry64 thrdentry
;
383 pid_t pid
= current_inferior ()->pid
;
386 if (getthrds64(pid
, &thrdentry
, sizeof(struct thrdentry64
),
388 thrd_i
= thrdentry
.ti_tid
;
390 memset(&vmx
, 0, sizeof(__vmx_context_t
));
391 if (__power_vmx() && thrd_i
> 0)
394 rs6000_ptrace64 (PTT_READ_VEC
, thrd_i
, (long long) &vmx
, 0, 0);
396 rs6000_ptrace32 (PTT_READ_VEC
, thrd_i
, (int *) &vmx
, 0, 0);
397 supply_vrregset_aix (regcache
, &vmx
);
401 /* supply vsx register. */
404 supply_vsxregset_aix (struct regcache
*regcache
, __vsx_context_t
*vsx
)
407 struct gdbarch
*gdbarch
= regcache
->arch ();
408 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
410 for (i
= 0; i
< ppc_num_vshrs
; i
++)
411 regcache
->raw_supply (tdep
->ppc_vsr0_upper_regnum
+ i
,
412 &(vsx
->__vsr_dw1
[i
]));
415 /* Fetch vsx registers. */
417 fetch_vsx_registers_aix (struct regcache
*regcache
)
419 struct thrdentry64 thrdentry
;
421 pid_t pid
= current_inferior ()->pid
;
424 if (getthrds64(pid
, &thrdentry
, sizeof(struct thrdentry64
),
426 thrd_i
= thrdentry
.ti_tid
;
428 memset(&vsx
, 0, sizeof(__vsx_context_t
));
429 if (__power_vsx() && thrd_i
> 0)
432 rs6000_ptrace64 (PTT_READ_VSX
, thrd_i
, (long long) &vsx
, 0, 0);
434 rs6000_ptrace32 (PTT_READ_VSX
, thrd_i
, (int *) &vsx
, 0, 0);
435 supply_vsxregset_aix (regcache
, &vsx
);
439 void rs6000_nat_target::post_startup_inferior (ptid_t ptid
)
442 /* In AIX to turn on multi process debugging in ptrace
443 PT_MULTI is the option to be passed,
444 with the process ID which can fork () and
445 the data parameter [fourth parameter] must be 1. */
448 rs6000_ptrace32 (PT_MULTI
, ptid
.pid(), 0, 1, 0);
450 rs6000_ptrace64 (PT_MULTI
, ptid
.pid(), 0, 1, 0);
454 rs6000_nat_target::follow_fork (inferior
*child_inf
, ptid_t child_ptid
,
455 target_waitkind fork_kind
, bool follow_child
,
459 /* Once the fork event is detected the infrun.c code
460 calls the target_follow_fork to take care of
461 follow child and detach the child activity which is
462 done using the function below. */
464 inf_ptrace_target::follow_fork (child_inf
, child_ptid
, fork_kind
,
465 follow_child
, detach_fork
);
467 /* If we detach fork and follow child we do not want the child
468 process to generate events that ptrace can trace. Hence we
471 if (detach_fork
&& !follow_child
)
474 rs6000_ptrace64 (PT_DETACH
, child_ptid
.pid (), 0, 0, 0);
476 rs6000_ptrace32 (PT_DETACH
, child_ptid
.pid (), 0, 0, 0);
480 /* Fetch register REGNO from the inferior. */
483 fetch_register (struct regcache
*regcache
, int regno
)
485 struct gdbarch
*gdbarch
= regcache
->arch ();
486 int addr
[PPC_MAX_REGISTER_SIZE
];
488 pid_t pid
= regcache
->ptid ().pid ();
490 /* Retrieved values may be -1, so infer errors from errno. */
493 /* Alti-vec register. */
494 if (altivec_register_p (gdbarch
, regno
))
496 fetch_altivec_registers_aix (regcache
);
501 if (vsx_register_p (gdbarch
, regno
))
503 fetch_vsx_registers_aix (regcache
);
507 nr
= regmap (gdbarch
, regno
, &isfloat
);
509 /* Floating-point registers. */
511 rs6000_ptrace32 (PT_READ_FPR
, pid
, addr
, nr
, 0);
513 /* Bogus register number. */
516 if (regno
>= gdbarch_num_regs (gdbarch
))
517 gdb_printf (gdb_stderr
,
518 "gdb error: register no %d not implemented.\n",
523 /* Fixed-point registers. */
527 *addr
= rs6000_ptrace32 (PT_READ_GPR
, pid
, (int *) nr
, 0, 0);
530 /* PT_READ_GPR requires the buffer parameter to point to long long,
531 even if the register is really only 32 bits. */
533 rs6000_ptrace64 (PT_READ_GPR
, pid
, nr
, 0, &buf
);
534 if (register_size (gdbarch
, regno
) == 8)
535 memcpy (addr
, &buf
, 8);
542 regcache
->raw_supply (regno
, (char *) addr
);
546 /* FIXME: this happens 3 times at the start of each 64-bit program. */
547 perror (_("ptrace read"));
553 /* Store register REGNO back into the inferior. */
556 store_register (struct regcache
*regcache
, int regno
)
558 struct gdbarch
*gdbarch
= regcache
->arch ();
559 int addr
[PPC_MAX_REGISTER_SIZE
];
561 pid_t pid
= regcache
->ptid ().pid ();
563 /* Fetch the register's value from the register cache. */
564 regcache
->raw_collect (regno
, addr
);
566 /* -1 can be a successful return value, so infer errors from errno. */
569 if (altivec_register_p (gdbarch
, regno
))
571 store_altivec_register_aix (regcache
, regno
);
575 if (vsx_register_p (gdbarch
, regno
))
577 store_vsx_register_aix (regcache
, regno
);
581 nr
= regmap (gdbarch
, regno
, &isfloat
);
583 /* Floating-point registers. */
585 rs6000_ptrace32 (PT_WRITE_FPR
, pid
, addr
, nr
, 0);
587 /* Bogus register number. */
590 if (regno
>= gdbarch_num_regs (gdbarch
))
591 gdb_printf (gdb_stderr
,
592 "gdb error: register no %d not implemented.\n",
596 /* Fixed-point registers. */
599 /* The PT_WRITE_GPR operation is rather odd. For 32-bit inferiors,
600 the register's value is passed by value, but for 64-bit inferiors,
601 the address of a buffer containing the value is passed. */
603 rs6000_ptrace32 (PT_WRITE_GPR
, pid
, (int *) nr
, *addr
, 0);
606 /* PT_WRITE_GPR requires the buffer parameter to point to an 8-byte
607 area, even if the register is really only 32 bits. */
609 if (register_size (gdbarch
, regno
) == 8)
610 memcpy (&buf
, addr
, 8);
613 rs6000_ptrace64 (PT_WRITE_GPR
, pid
, nr
, 0, &buf
);
619 perror (_("ptrace write"));
624 /* Read from the inferior all registers if REGNO == -1 and just register
628 rs6000_nat_target::fetch_registers (struct regcache
*regcache
, int regno
)
630 struct gdbarch
*gdbarch
= regcache
->arch ();
632 fetch_register (regcache
, regno
);
636 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
638 /* Read 32 general purpose registers. */
639 for (regno
= tdep
->ppc_gp0_regnum
;
640 regno
< tdep
->ppc_gp0_regnum
+ ppc_num_gprs
;
643 fetch_register (regcache
, regno
);
646 /* Read general purpose floating point registers. */
647 if (tdep
->ppc_fp0_regnum
>= 0)
648 for (regno
= 0; regno
< ppc_num_fprs
; regno
++)
649 fetch_register (regcache
, tdep
->ppc_fp0_regnum
+ regno
);
651 if (tdep
->ppc_vr0_regnum
!= -1 && tdep
->ppc_vrsave_regnum
!= -1)
652 fetch_altivec_registers_aix (regcache
);
654 if (tdep
->ppc_vsr0_upper_regnum
!= -1)
655 fetch_vsx_registers_aix (regcache
);
657 /* Read special registers. */
658 fetch_register (regcache
, gdbarch_pc_regnum (gdbarch
));
659 fetch_register (regcache
, tdep
->ppc_ps_regnum
);
660 fetch_register (regcache
, tdep
->ppc_cr_regnum
);
661 fetch_register (regcache
, tdep
->ppc_lr_regnum
);
662 fetch_register (regcache
, tdep
->ppc_ctr_regnum
);
663 fetch_register (regcache
, tdep
->ppc_xer_regnum
);
664 if (tdep
->ppc_fpscr_regnum
>= 0)
665 fetch_register (regcache
, tdep
->ppc_fpscr_regnum
);
666 if (tdep
->ppc_mq_regnum
>= 0)
667 fetch_register (regcache
, tdep
->ppc_mq_regnum
);
671 const struct target_desc
*
672 rs6000_nat_target::read_description ()
677 return tdesc_powerpc_vsx64
;
678 else if (__power_vmx ())
679 return tdesc_powerpc_altivec64
;
684 return tdesc_powerpc_vsx32
;
685 else if (__power_vmx ())
686 return tdesc_powerpc_altivec32
;
691 /* Store our register values back into the inferior.
692 If REGNO is -1, do this for all registers.
693 Otherwise, REGNO specifies which register (so we can save time). */
696 rs6000_nat_target::store_registers (struct regcache
*regcache
, int regno
)
698 struct gdbarch
*gdbarch
= regcache
->arch ();
700 store_register (regcache
, regno
);
704 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
706 /* Write general purpose registers first. */
707 for (regno
= tdep
->ppc_gp0_regnum
;
708 regno
< tdep
->ppc_gp0_regnum
+ ppc_num_gprs
;
711 store_register (regcache
, regno
);
714 /* Write floating point registers. */
715 if (tdep
->ppc_fp0_regnum
>= 0)
716 for (regno
= 0; regno
< ppc_num_fprs
; regno
++)
717 store_register (regcache
, tdep
->ppc_fp0_regnum
+ regno
);
719 /* Write special registers. */
720 store_register (regcache
, gdbarch_pc_regnum (gdbarch
));
721 store_register (regcache
, tdep
->ppc_ps_regnum
);
722 store_register (regcache
, tdep
->ppc_cr_regnum
);
723 store_register (regcache
, tdep
->ppc_lr_regnum
);
724 store_register (regcache
, tdep
->ppc_ctr_regnum
);
725 store_register (regcache
, tdep
->ppc_xer_regnum
);
726 if (tdep
->ppc_fpscr_regnum
>= 0)
727 store_register (regcache
, tdep
->ppc_fpscr_regnum
);
728 if (tdep
->ppc_mq_regnum
>= 0)
729 store_register (regcache
, tdep
->ppc_mq_regnum
);
733 /* Implement the to_xfer_partial target_ops method. */
735 enum target_xfer_status
736 rs6000_nat_target::xfer_partial (enum target_object object
,
737 const char *annex
, gdb_byte
*readbuf
,
738 const gdb_byte
*writebuf
,
739 ULONGEST offset
, ULONGEST len
,
740 ULONGEST
*xfered_len
)
742 pid_t pid
= inferior_ptid
.pid ();
743 int arch64
= ARCH64 ();
747 case TARGET_OBJECT_LIBRARIES_AIX
:
748 return xfer_shared_libraries (object
, annex
,
750 offset
, len
, xfered_len
);
751 case TARGET_OBJECT_MEMORY
:
755 PTRACE_TYPE_RET word
;
756 gdb_byte byte
[sizeof (PTRACE_TYPE_RET
)];
758 ULONGEST rounded_offset
;
761 /* Round the start offset down to the next long word
763 rounded_offset
= offset
& -(ULONGEST
) sizeof (PTRACE_TYPE_RET
);
765 /* Since ptrace will transfer a single word starting at that
766 rounded_offset the partial_len needs to be adjusted down to
767 that (remember this function only does a single transfer).
768 Should the required length be even less, adjust it down
770 partial_len
= (rounded_offset
+ sizeof (PTRACE_TYPE_RET
)) - offset
;
771 if (partial_len
> len
)
776 /* If OFFSET:PARTIAL_LEN is smaller than
777 ROUNDED_OFFSET:WORDSIZE then a read/modify write will
778 be needed. Read in the entire word. */
779 if (rounded_offset
< offset
780 || (offset
+ partial_len
781 < rounded_offset
+ sizeof (PTRACE_TYPE_RET
)))
783 /* Need part of initial word -- fetch it. */
785 buffer
.word
= rs6000_ptrace64 (PT_READ_I
, pid
,
786 rounded_offset
, 0, NULL
);
788 buffer
.word
= rs6000_ptrace32 (PT_READ_I
, pid
,
794 /* Copy data to be written over corresponding part of
796 memcpy (buffer
.byte
+ (offset
- rounded_offset
),
797 writebuf
, partial_len
);
801 rs6000_ptrace64 (PT_WRITE_D
, pid
,
802 rounded_offset
, buffer
.word
, NULL
);
804 rs6000_ptrace32 (PT_WRITE_D
, pid
,
805 (int *) (uintptr_t) rounded_offset
,
808 return TARGET_XFER_EOF
;
815 buffer
.word
= rs6000_ptrace64 (PT_READ_I
, pid
,
816 rounded_offset
, 0, NULL
);
818 buffer
.word
= rs6000_ptrace32 (PT_READ_I
, pid
,
819 (int *)(uintptr_t)rounded_offset
,
822 return TARGET_XFER_EOF
;
824 /* Copy appropriate bytes out of the buffer. */
825 memcpy (readbuf
, buffer
.byte
+ (offset
- rounded_offset
),
829 *xfered_len
= (ULONGEST
) partial_len
;
830 return TARGET_XFER_OK
;
834 return TARGET_XFER_E_IO
;
838 /* Wait for the child specified by PTID to do something. Return the
839 process ID of the child, or MINUS_ONE_PTID in case of error; store
840 the status in *OURSTATUS. */
843 rs6000_nat_target::wait (ptid_t ptid
, struct target_waitstatus
*ourstatus
,
844 target_wait_flags options
)
847 int status
, save_errno
;
855 pid
= waitpid (ptid
.pid (), &status
, 0);
858 while (pid
== -1 && errno
== EINTR
);
860 clear_sigint_trap ();
864 gdb_printf (gdb_stderr
,
865 _("Child process unexpectedly missing: %s.\n"),
866 safe_strerror (save_errno
));
868 ourstatus
->set_ignore ();
869 return minus_one_ptid
;
872 /* Ignore terminated detached child processes. */
873 if (!WIFSTOPPED (status
) && find_inferior_pid (this, pid
) == nullptr)
876 /* Check for a fork () event. */
877 if ((status
& 0xff) == W_SFWTED
)
879 /* Checking whether it is a parent or a child event. */
881 /* If the event is a child we check if there was a parent
882 event recorded before. If yes we got the parent child
883 relationship. If not we push this child and wait for
884 the next fork () event. */
885 if (find_inferior_pid (this, pid
) == nullptr)
887 pid_t parent_pid
= has_my_aix_parent_reported (pid
);
890 ourstatus
->set_forked (ptid_t (pid
));
891 return ptid_t (parent_pid
);
893 aix_remember_child (pid
);
896 /* If the event is a parent we check if there was a child
897 event recorded before. If yes we got the parent child
898 relationship. If not we push this parent and wait for
899 the next fork () event. */
902 pid_t child_pid
= has_my_aix_child_reported (pid
);
905 ourstatus
->set_forked (ptid_t (child_pid
));
908 aix_remember_parent (pid
);
916 /* AIX has a couple of strange returns from wait(). */
918 /* stop after load" status. */
920 ourstatus
->set_loaded ();
921 /* 0x7f is signal 0. 0x17f and 0x137f are status returned
922 if we follow parent, a switch is made to a child post parent
923 execution and child continues its execution [user switches
924 to child and presses continue]. */
925 else if (status
== 0x7f || status
== 0x17f || status
== 0x137f)
926 ourstatus
->set_spurious ();
927 /* A normal waitstatus. Let the usual macros deal with it. */
929 *ourstatus
= host_status_to_waitstatus (status
);
935 /* Set the current architecture from the host running GDB. Called when
936 starting a child process. */
939 rs6000_nat_target::create_inferior (const char *exec_file
,
940 const std::string
&allargs
,
941 char **env
, int from_tty
)
943 enum bfd_architecture arch
;
947 inf_ptrace_target::create_inferior (exec_file
, allargs
, env
, from_tty
);
951 arch
= bfd_arch_rs6000
;
952 mach
= bfd_mach_rs6k
;
956 arch
= bfd_arch_powerpc
;
960 /* FIXME: schauer/2002-02-25:
961 We don't know if we are executing a 32 or 64 bit executable,
962 and have no way to pass the proper word size to rs6000_gdbarch_init.
963 So we have to avoid switching to a new architecture, if the architecture
965 Blindly calling rs6000_gdbarch_init used to work in older versions of
966 GDB, as rs6000_gdbarch_init incorrectly used the previous tdep to
967 determine the wordsize. */
968 if (current_program_space
->exec_bfd ())
970 const struct bfd_arch_info
*exec_bfd_arch_info
;
973 = bfd_get_arch_info (current_program_space
->exec_bfd ());
974 if (arch
== exec_bfd_arch_info
->arch
)
978 bfd_default_set_arch_mach (&abfd
, arch
, mach
);
981 info
.bfd_arch_info
= bfd_get_arch_info (&abfd
);
982 info
.abfd
= current_program_space
->exec_bfd ();
984 if (!gdbarch_update_p (info
))
985 internal_error (_("rs6000_create_inferior: failed "
986 "to select architecture"));
990 /* Shared Object support. */
992 /* Return the LdInfo data for the given process. Raises an error
993 if the data could not be obtained. */
995 static gdb::byte_vector
996 rs6000_ptrace_ldinfo (ptid_t ptid
)
998 const int pid
= ptid
.pid ();
999 gdb::byte_vector
ldi (1024);
1005 rc
= rs6000_ptrace64 (PT_LDINFO
, pid
, (unsigned long) ldi
.data (),
1008 rc
= rs6000_ptrace32 (PT_LDINFO
, pid
, (int *) ldi
.data (),
1012 break; /* Success, we got the entire ld_info data. */
1014 if (errno
!= ENOMEM
)
1015 perror_with_name (_("ptrace ldinfo"));
1017 /* ldi is not big enough. Double it and try again. */
1018 ldi
.resize (ldi
.size () * 2);
1024 /* Implement the to_xfer_partial target_ops method for
1025 TARGET_OBJECT_LIBRARIES_AIX objects. */
1027 enum target_xfer_status
1028 rs6000_nat_target::xfer_shared_libraries
1029 (enum target_object object
,
1030 const char *annex
, gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1031 ULONGEST offset
, ULONGEST len
, ULONGEST
*xfered_len
)
1035 /* This function assumes that it is being run with a live process.
1036 Core files are handled via gdbarch. */
1037 gdb_assert (target_has_execution ());
1040 return TARGET_XFER_E_IO
;
1042 gdb::byte_vector ldi_buf
= rs6000_ptrace_ldinfo (inferior_ptid
);
1043 result
= rs6000_aix_ld_info_to_xml (current_inferior ()->arch (),
1045 readbuf
, offset
, len
, 1);
1048 return TARGET_XFER_EOF
;
1051 *xfered_len
= result
;
1052 return TARGET_XFER_OK
;
1056 void _initialize_rs6000_nat ();
1058 _initialize_rs6000_nat ()
1060 add_inf_child_target (&the_rs6000_nat_target
);