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>
45 #include "gdbsupport/eintr.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
;
107 int insert_fork_catchpoint (int) override
;
108 int remove_fork_catchpoint (int) override
;
112 void post_startup_inferior (ptid_t ptid
) override
;
115 enum target_xfer_status
116 xfer_shared_libraries (enum target_object object
,
117 const char *annex
, gdb_byte
*readbuf
,
118 const gdb_byte
*writebuf
,
119 ULONGEST offset
, ULONGEST len
,
120 ULONGEST
*xfered_len
);
123 static rs6000_nat_target the_rs6000_nat_target
;
125 /* The below declaration is to track number of times, parent has
126 reported fork event before its children. */
128 static std::list
<pid_t
> aix_pending_parent
;
130 /* The below declaration is for a child process event that
131 is reported before its corresponding parent process in
132 the event of a fork (). */
134 static std::list
<pid_t
> aix_pending_children
;
137 aix_remember_child (pid_t pid
)
139 aix_pending_children
.push_front (pid
);
143 aix_remember_parent (pid_t pid
)
145 aix_pending_parent
.push_front (pid
);
148 /* This function returns a parent of a child process. */
151 find_my_aix_parent (pid_t child_pid
)
153 struct procsinfo ProcessBuffer1
;
155 if (getprocs (&ProcessBuffer1
, sizeof (ProcessBuffer1
),
156 NULL
, 0, &child_pid
, 1) != 1)
159 return ProcessBuffer1
.pi_ppid
;
162 /* In the below function we check if there was any child
163 process pending. If it exists we return it from the
164 list, otherwise we return a null. */
167 has_my_aix_child_reported (pid_t parent_pid
)
170 auto it
= std::find_if (aix_pending_children
.begin (),
171 aix_pending_children
.end (),
172 [=] (pid_t child_pid
)
174 return find_my_aix_parent (child_pid
) == parent_pid
;
176 if (it
!= aix_pending_children
.end ())
179 aix_pending_children
.erase (it
);
184 /* In the below function we check if there was any parent
185 process pending. If it exists we return it from the
186 list, otherwise we return a null. */
189 has_my_aix_parent_reported (pid_t child_pid
)
191 pid_t my_parent
= find_my_aix_parent (child_pid
);
192 auto it
= std::find (aix_pending_parent
.begin (),
193 aix_pending_parent
.end (),
195 if (it
!= aix_pending_parent
.end ())
197 aix_pending_parent
.erase (it
);
203 /* Given REGNO, a gdb register number, return the corresponding
204 number suitable for use as a ptrace() parameter. Return -1 if
205 there's no suitable mapping. Also, set the int pointed to by
206 ISFLOAT to indicate whether REGNO is a floating point register. */
209 regmap (struct gdbarch
*gdbarch
, int regno
, int *isfloat
)
211 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
214 if (tdep
->ppc_gp0_regnum
<= regno
215 && regno
< tdep
->ppc_gp0_regnum
+ ppc_num_gprs
)
217 else if (tdep
->ppc_fp0_regnum
>= 0
218 && tdep
->ppc_fp0_regnum
<= regno
219 && regno
< tdep
->ppc_fp0_regnum
+ ppc_num_fprs
)
222 return regno
- tdep
->ppc_fp0_regnum
+ FPR0
;
224 else if (regno
== gdbarch_pc_regnum (gdbarch
))
226 else if (regno
== tdep
->ppc_ps_regnum
)
228 else if (regno
== tdep
->ppc_cr_regnum
)
230 else if (regno
== tdep
->ppc_lr_regnum
)
232 else if (regno
== tdep
->ppc_ctr_regnum
)
234 else if (regno
== tdep
->ppc_xer_regnum
)
236 else if (tdep
->ppc_fpscr_regnum
>= 0
237 && regno
== tdep
->ppc_fpscr_regnum
)
239 else if (tdep
->ppc_mq_regnum
>= 0 && regno
== tdep
->ppc_mq_regnum
)
245 /* Call ptrace(REQ, ID, ADDR, DATA, BUF). */
248 rs6000_ptrace32 (int req
, int id
, int *addr
, int data
, int *buf
)
251 int ret
= ptrace64 (req
, id
, (uintptr_t) addr
, data
, buf
);
253 int ret
= ptrace (req
, id
, (int *)addr
, data
, buf
);
256 printf ("rs6000_ptrace32 (%d, %d, 0x%x, %08x, 0x%x) = 0x%x\n",
257 req
, id
, (unsigned int)addr
, data
, (unsigned int)buf
, ret
);
262 /* Call ptracex(REQ, ID, ADDR, DATA, BUF). */
265 rs6000_ptrace64 (int req
, int id
, long long addr
, int data
, void *buf
)
268 # ifdef HAVE_PTRACE64
269 int ret
= ptrace64 (req
, id
, addr
, data
, (PTRACE_TYPE_ARG5
) buf
);
271 int ret
= ptracex (req
, id
, addr
, data
, (PTRACE_TYPE_ARG5
) buf
);
277 printf ("rs6000_ptrace64 (%d, %d, %s, %08x, 0x%x) = 0x%x\n",
278 req
, id
, hex_string (addr
), data
, (unsigned int)buf
, ret
);
283 /* Store the vsx registers. */
286 store_vsx_register_aix (struct regcache
*regcache
, int regno
)
289 struct gdbarch
*gdbarch
= regcache
->arch ();
290 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
291 struct thrdentry64 thrdentry
;
293 pid_t pid
= inferior_ptid
.pid ();
296 if (getthrds64(pid
, &thrdentry
, sizeof(struct thrdentry64
),
298 thrd_i
= thrdentry
.ti_tid
;
300 memset(&vsx
, 0, sizeof(__vsx_context_t
));
301 if (__power_vsx() && thrd_i
> 0)
304 ret
= rs6000_ptrace64 (PTT_READ_VSX
, thrd_i
, (long long) &vsx
, 0, 0);
306 ret
= rs6000_ptrace32 (PTT_READ_VSX
, thrd_i
, (int *)&vsx
, 0, 0);
310 regcache
->raw_collect (regno
, &(vsx
.__vsr_dw1
[0])+
311 regno
- tdep
->ppc_vsr0_upper_regnum
);
314 ret
= rs6000_ptrace64 (PTT_WRITE_VSX
, thrd_i
, (long long) &vsx
, 0, 0);
316 ret
= rs6000_ptrace32 (PTT_WRITE_VSX
, thrd_i
, (int *) &vsx
, 0, 0);
319 perror_with_name (_("Unable to write VSX registers after reading it"));
323 /* Store Altivec registers. */
326 store_altivec_register_aix (struct regcache
*regcache
, int regno
)
329 struct gdbarch
*gdbarch
= regcache
->arch ();
330 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
331 struct thrdentry64 thrdentry
;
333 pid_t pid
= inferior_ptid
.pid ();
336 if (getthrds64(pid
, &thrdentry
, sizeof(struct thrdentry64
),
338 thrd_i
= thrdentry
.ti_tid
;
340 memset(&vmx
, 0, sizeof(__vmx_context_t
));
341 if (__power_vmx() && thrd_i
> 0)
344 ret
= rs6000_ptrace64 (PTT_READ_VEC
, thrd_i
, (long long) &vmx
, 0, 0);
346 ret
= rs6000_ptrace32 (PTT_READ_VEC
, thrd_i
, (int *) &vmx
, 0, 0);
350 regcache
->raw_collect (regno
, &(vmx
.__vr
[0]) + regno
351 - tdep
->ppc_vr0_regnum
);
354 ret
= rs6000_ptrace64 (PTT_WRITE_VEC
, thrd_i
, (long long) &vmx
, 0, 0);
356 ret
= rs6000_ptrace32 (PTT_WRITE_VEC
, thrd_i
, (int *) &vmx
, 0, 0);
358 perror_with_name (_("Unable to store AltiVec register after reading it"));
362 /* Supply altivec registers. */
365 supply_vrregset_aix (struct regcache
*regcache
, __vmx_context_t
*vmx
)
368 struct gdbarch
*gdbarch
= regcache
->arch ();
369 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
370 int num_of_vrregs
= tdep
->ppc_vrsave_regnum
- tdep
->ppc_vr0_regnum
+ 1;
372 for (i
= 0; i
< num_of_vrregs
; i
++)
373 regcache
->raw_supply (tdep
->ppc_vr0_regnum
+ i
,
375 regcache
->raw_supply (tdep
->ppc_vrsave_regnum
, &(vmx
->__vrsave
));
376 regcache
->raw_supply (tdep
->ppc_vrsave_regnum
- 1, &(vmx
->__vscr
));
379 /* Fetch altivec register. */
382 fetch_altivec_registers_aix (struct regcache
*regcache
)
384 struct thrdentry64 thrdentry
;
386 pid_t pid
= current_inferior ()->pid
;
389 if (getthrds64(pid
, &thrdentry
, sizeof(struct thrdentry64
),
391 thrd_i
= thrdentry
.ti_tid
;
393 memset(&vmx
, 0, sizeof(__vmx_context_t
));
394 if (__power_vmx() && thrd_i
> 0)
397 rs6000_ptrace64 (PTT_READ_VEC
, thrd_i
, (long long) &vmx
, 0, 0);
399 rs6000_ptrace32 (PTT_READ_VEC
, thrd_i
, (int *) &vmx
, 0, 0);
400 supply_vrregset_aix (regcache
, &vmx
);
404 /* supply vsx register. */
407 supply_vsxregset_aix (struct regcache
*regcache
, __vsx_context_t
*vsx
)
410 struct gdbarch
*gdbarch
= regcache
->arch ();
411 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
413 for (i
= 0; i
< ppc_num_vshrs
; i
++)
414 regcache
->raw_supply (tdep
->ppc_vsr0_upper_regnum
+ i
,
415 &(vsx
->__vsr_dw1
[i
]));
418 /* Fetch vsx registers. */
420 fetch_vsx_registers_aix (struct regcache
*regcache
)
422 struct thrdentry64 thrdentry
;
424 pid_t pid
= current_inferior ()->pid
;
427 if (getthrds64(pid
, &thrdentry
, sizeof(struct thrdentry64
),
429 thrd_i
= thrdentry
.ti_tid
;
431 memset(&vsx
, 0, sizeof(__vsx_context_t
));
432 if (__power_vsx() && thrd_i
> 0)
435 rs6000_ptrace64 (PTT_READ_VSX
, thrd_i
, (long long) &vsx
, 0, 0);
437 rs6000_ptrace32 (PTT_READ_VSX
, thrd_i
, (int *) &vsx
, 0, 0);
438 supply_vsxregset_aix (regcache
, &vsx
);
442 void rs6000_nat_target::post_startup_inferior (ptid_t ptid
)
445 /* In AIX to turn on multi process debugging in ptrace
446 PT_MULTI is the option to be passed,
447 with the process ID which can fork () and
448 the data parameter [fourth parameter] must be 1. */
451 rs6000_ptrace32 (PT_MULTI
, ptid
.pid(), 0, 1, 0);
453 rs6000_ptrace64 (PT_MULTI
, ptid
.pid(), 0, 1, 0);
457 rs6000_nat_target::follow_fork (inferior
*child_inf
, ptid_t child_ptid
,
458 target_waitkind fork_kind
, bool follow_child
,
462 /* Once the fork event is detected the infrun.c code
463 calls the target_follow_fork to take care of
464 follow child and detach the child activity which is
465 done using the function below. */
467 inf_ptrace_target::follow_fork (child_inf
, child_ptid
, fork_kind
,
468 follow_child
, detach_fork
);
470 /* If we detach fork and follow child we do not want the child
471 process to generate events that ptrace can trace. Hence we
474 if (detach_fork
&& !follow_child
)
477 rs6000_ptrace64 (PT_DETACH
, child_ptid
.pid (), 0, 0, 0);
479 rs6000_ptrace32 (PT_DETACH
, child_ptid
.pid (), 0, 0, 0);
483 /* Functions for catchpoint in AIX. */
485 rs6000_nat_target::insert_fork_catchpoint (int pid
)
491 rs6000_nat_target::remove_fork_catchpoint (int pid
)
496 /* Fetch register REGNO from the inferior. */
499 fetch_register (struct regcache
*regcache
, int regno
)
501 struct gdbarch
*gdbarch
= regcache
->arch ();
502 int addr
[PPC_MAX_REGISTER_SIZE
];
504 pid_t pid
= regcache
->ptid ().pid ();
506 /* Retrieved values may be -1, so infer errors from errno. */
509 /* Alti-vec register. */
510 if (altivec_register_p (gdbarch
, regno
))
512 fetch_altivec_registers_aix (regcache
);
517 if (vsx_register_p (gdbarch
, regno
))
519 fetch_vsx_registers_aix (regcache
);
523 nr
= regmap (gdbarch
, regno
, &isfloat
);
525 /* Floating-point registers. */
527 rs6000_ptrace32 (PT_READ_FPR
, pid
, addr
, nr
, 0);
529 /* Bogus register number. */
532 if (regno
>= gdbarch_num_regs (gdbarch
))
533 gdb_printf (gdb_stderr
,
534 "gdb error: register no %d not implemented.\n",
539 /* Fixed-point registers. */
543 *addr
= rs6000_ptrace32 (PT_READ_GPR
, pid
, (int *) nr
, 0, 0);
546 /* PT_READ_GPR requires the buffer parameter to point to long long,
547 even if the register is really only 32 bits. */
549 rs6000_ptrace64 (PT_READ_GPR
, pid
, nr
, 0, &buf
);
550 if (register_size (gdbarch
, regno
) == 8)
551 memcpy (addr
, &buf
, 8);
558 regcache
->raw_supply (regno
, (char *) addr
);
562 /* FIXME: this happens 3 times at the start of each 64-bit program. */
563 perror (_("ptrace read"));
569 /* Store register REGNO back into the inferior. */
572 store_register (struct regcache
*regcache
, int regno
)
574 struct gdbarch
*gdbarch
= regcache
->arch ();
575 int addr
[PPC_MAX_REGISTER_SIZE
];
577 pid_t pid
= regcache
->ptid ().pid ();
579 /* Fetch the register's value from the register cache. */
580 regcache
->raw_collect (regno
, addr
);
582 /* -1 can be a successful return value, so infer errors from errno. */
585 if (altivec_register_p (gdbarch
, regno
))
587 store_altivec_register_aix (regcache
, regno
);
591 if (vsx_register_p (gdbarch
, regno
))
593 store_vsx_register_aix (regcache
, regno
);
597 nr
= regmap (gdbarch
, regno
, &isfloat
);
599 /* Floating-point registers. */
601 rs6000_ptrace32 (PT_WRITE_FPR
, pid
, addr
, nr
, 0);
603 /* Bogus register number. */
606 if (regno
>= gdbarch_num_regs (gdbarch
))
607 gdb_printf (gdb_stderr
,
608 "gdb error: register no %d not implemented.\n",
612 /* Fixed-point registers. */
615 /* The PT_WRITE_GPR operation is rather odd. For 32-bit inferiors,
616 the register's value is passed by value, but for 64-bit inferiors,
617 the address of a buffer containing the value is passed. */
619 rs6000_ptrace32 (PT_WRITE_GPR
, pid
, (int *) nr
, *addr
, 0);
622 /* PT_WRITE_GPR requires the buffer parameter to point to an 8-byte
623 area, even if the register is really only 32 bits. */
625 if (register_size (gdbarch
, regno
) == 8)
626 memcpy (&buf
, addr
, 8);
629 rs6000_ptrace64 (PT_WRITE_GPR
, pid
, nr
, 0, &buf
);
635 perror (_("ptrace write"));
640 /* Read from the inferior all registers if REGNO == -1 and just register
644 rs6000_nat_target::fetch_registers (struct regcache
*regcache
, int regno
)
646 struct gdbarch
*gdbarch
= regcache
->arch ();
648 fetch_register (regcache
, regno
);
652 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
654 /* Read 32 general purpose registers. */
655 for (regno
= tdep
->ppc_gp0_regnum
;
656 regno
< tdep
->ppc_gp0_regnum
+ ppc_num_gprs
;
659 fetch_register (regcache
, regno
);
662 /* Read general purpose floating point registers. */
663 if (tdep
->ppc_fp0_regnum
>= 0)
664 for (regno
= 0; regno
< ppc_num_fprs
; regno
++)
665 fetch_register (regcache
, tdep
->ppc_fp0_regnum
+ regno
);
667 if (tdep
->ppc_vr0_regnum
!= -1 && tdep
->ppc_vrsave_regnum
!= -1)
668 fetch_altivec_registers_aix (regcache
);
670 if (tdep
->ppc_vsr0_upper_regnum
!= -1)
671 fetch_vsx_registers_aix (regcache
);
673 /* Read special registers. */
674 fetch_register (regcache
, gdbarch_pc_regnum (gdbarch
));
675 fetch_register (regcache
, tdep
->ppc_ps_regnum
);
676 fetch_register (regcache
, tdep
->ppc_cr_regnum
);
677 fetch_register (regcache
, tdep
->ppc_lr_regnum
);
678 fetch_register (regcache
, tdep
->ppc_ctr_regnum
);
679 fetch_register (regcache
, tdep
->ppc_xer_regnum
);
680 if (tdep
->ppc_fpscr_regnum
>= 0)
681 fetch_register (regcache
, tdep
->ppc_fpscr_regnum
);
682 if (tdep
->ppc_mq_regnum
>= 0)
683 fetch_register (regcache
, tdep
->ppc_mq_regnum
);
687 const struct target_desc
*
688 rs6000_nat_target::read_description ()
693 return tdesc_powerpc_vsx64
;
694 else if (__power_vmx ())
695 return tdesc_powerpc_altivec64
;
700 return tdesc_powerpc_vsx32
;
701 else if (__power_vmx ())
702 return tdesc_powerpc_altivec32
;
707 /* Store our register values back into the inferior.
708 If REGNO is -1, do this for all registers.
709 Otherwise, REGNO specifies which register (so we can save time). */
712 rs6000_nat_target::store_registers (struct regcache
*regcache
, int regno
)
714 struct gdbarch
*gdbarch
= regcache
->arch ();
716 store_register (regcache
, regno
);
720 ppc_gdbarch_tdep
*tdep
= gdbarch_tdep
<ppc_gdbarch_tdep
> (gdbarch
);
722 /* Write general purpose registers first. */
723 for (regno
= tdep
->ppc_gp0_regnum
;
724 regno
< tdep
->ppc_gp0_regnum
+ ppc_num_gprs
;
727 store_register (regcache
, regno
);
730 /* Write floating point registers. */
731 if (tdep
->ppc_fp0_regnum
>= 0)
732 for (regno
= 0; regno
< ppc_num_fprs
; regno
++)
733 store_register (regcache
, tdep
->ppc_fp0_regnum
+ regno
);
735 /* Write special registers. */
736 store_register (regcache
, gdbarch_pc_regnum (gdbarch
));
737 store_register (regcache
, tdep
->ppc_ps_regnum
);
738 store_register (regcache
, tdep
->ppc_cr_regnum
);
739 store_register (regcache
, tdep
->ppc_lr_regnum
);
740 store_register (regcache
, tdep
->ppc_ctr_regnum
);
741 store_register (regcache
, tdep
->ppc_xer_regnum
);
742 if (tdep
->ppc_fpscr_regnum
>= 0)
743 store_register (regcache
, tdep
->ppc_fpscr_regnum
);
744 if (tdep
->ppc_mq_regnum
>= 0)
745 store_register (regcache
, tdep
->ppc_mq_regnum
);
749 /* Implement the to_xfer_partial target_ops method. */
751 enum target_xfer_status
752 rs6000_nat_target::xfer_partial (enum target_object object
,
753 const char *annex
, gdb_byte
*readbuf
,
754 const gdb_byte
*writebuf
,
755 ULONGEST offset
, ULONGEST len
,
756 ULONGEST
*xfered_len
)
758 pid_t pid
= inferior_ptid
.pid ();
759 int arch64
= ARCH64 ();
763 case TARGET_OBJECT_LIBRARIES_AIX
:
764 return xfer_shared_libraries (object
, annex
,
766 offset
, len
, xfered_len
);
767 case TARGET_OBJECT_MEMORY
:
771 PTRACE_TYPE_RET word
;
772 gdb_byte byte
[sizeof (PTRACE_TYPE_RET
)];
774 ULONGEST rounded_offset
;
777 /* Round the start offset down to the next long word
779 rounded_offset
= offset
& -(ULONGEST
) sizeof (PTRACE_TYPE_RET
);
781 /* Since ptrace will transfer a single word starting at that
782 rounded_offset the partial_len needs to be adjusted down to
783 that (remember this function only does a single transfer).
784 Should the required length be even less, adjust it down
786 partial_len
= (rounded_offset
+ sizeof (PTRACE_TYPE_RET
)) - offset
;
787 if (partial_len
> len
)
792 /* If OFFSET:PARTIAL_LEN is smaller than
793 ROUNDED_OFFSET:WORDSIZE then a read/modify write will
794 be needed. Read in the entire word. */
795 if (rounded_offset
< offset
796 || (offset
+ partial_len
797 < rounded_offset
+ sizeof (PTRACE_TYPE_RET
)))
799 /* Need part of initial word -- fetch it. */
801 buffer
.word
= rs6000_ptrace64 (PT_READ_I
, pid
,
802 rounded_offset
, 0, NULL
);
804 buffer
.word
= rs6000_ptrace32 (PT_READ_I
, pid
,
810 /* Copy data to be written over corresponding part of
812 memcpy (buffer
.byte
+ (offset
- rounded_offset
),
813 writebuf
, partial_len
);
817 rs6000_ptrace64 (PT_WRITE_D
, pid
,
818 rounded_offset
, buffer
.word
, NULL
);
820 rs6000_ptrace32 (PT_WRITE_D
, pid
,
821 (int *) (uintptr_t) rounded_offset
,
824 return TARGET_XFER_EOF
;
831 buffer
.word
= rs6000_ptrace64 (PT_READ_I
, pid
,
832 rounded_offset
, 0, NULL
);
834 buffer
.word
= rs6000_ptrace32 (PT_READ_I
, pid
,
835 (int *)(uintptr_t)rounded_offset
,
838 return TARGET_XFER_EOF
;
840 /* Copy appropriate bytes out of the buffer. */
841 memcpy (readbuf
, buffer
.byte
+ (offset
- rounded_offset
),
845 *xfered_len
= (ULONGEST
) partial_len
;
846 return TARGET_XFER_OK
;
850 return TARGET_XFER_E_IO
;
854 /* Wait for the child specified by PTID to do something. Return the
855 process ID of the child, or MINUS_ONE_PTID in case of error; store
856 the status in *OURSTATUS. */
859 rs6000_nat_target::wait (ptid_t ptid
, struct target_waitstatus
*ourstatus
,
860 target_wait_flags options
)
863 int status
, save_errno
;
869 pid
= gdb::waitpid (ptid
.pid (), &status
, 0);
872 clear_sigint_trap ();
876 gdb_printf (gdb_stderr
,
877 _("Child process unexpectedly missing: %s.\n"),
878 safe_strerror (save_errno
));
880 ourstatus
->set_ignore ();
881 return minus_one_ptid
;
884 /* Ignore terminated detached child processes. */
885 if (!WIFSTOPPED (status
) && find_inferior_pid (this, pid
) == nullptr)
888 /* Check for a fork () event. */
889 if ((status
& 0xff) == W_SFWTED
)
891 /* Checking whether it is a parent or a child event. */
893 /* If the event is a child we check if there was a parent
894 event recorded before. If yes we got the parent child
895 relationship. If not we push this child and wait for
896 the next fork () event. */
897 if (find_inferior_pid (this, pid
) == nullptr)
899 pid_t parent_pid
= has_my_aix_parent_reported (pid
);
902 ourstatus
->set_forked (ptid_t (pid
));
903 return ptid_t (parent_pid
);
905 aix_remember_child (pid
);
908 /* If the event is a parent we check if there was a child
909 event recorded before. If yes we got the parent child
910 relationship. If not we push this parent and wait for
911 the next fork () event. */
914 pid_t child_pid
= has_my_aix_child_reported (pid
);
917 ourstatus
->set_forked (ptid_t (child_pid
));
920 aix_remember_parent (pid
);
928 /* AIX has a couple of strange returns from wait(). */
930 /* stop after load" status. */
932 ourstatus
->set_loaded ();
933 /* 0x7f is signal 0. */
934 else if (status
== 0x7f)
935 ourstatus
->set_spurious ();
936 /* A normal waitstatus. Let the usual macros deal with it. */
938 *ourstatus
= host_status_to_waitstatus (status
);
944 /* Set the current architecture from the host running GDB. Called when
945 starting a child process. */
948 rs6000_nat_target::create_inferior (const char *exec_file
,
949 const std::string
&allargs
,
950 char **env
, int from_tty
)
952 enum bfd_architecture arch
;
956 inf_ptrace_target::create_inferior (exec_file
, allargs
, env
, from_tty
);
960 arch
= bfd_arch_rs6000
;
961 mach
= bfd_mach_rs6k
;
965 arch
= bfd_arch_powerpc
;
969 /* FIXME: schauer/2002-02-25:
970 We don't know if we are executing a 32 or 64 bit executable,
971 and have no way to pass the proper word size to rs6000_gdbarch_init.
972 So we have to avoid switching to a new architecture, if the architecture
974 Blindly calling rs6000_gdbarch_init used to work in older versions of
975 GDB, as rs6000_gdbarch_init incorrectly used the previous tdep to
976 determine the wordsize. */
977 if (current_program_space
->exec_bfd ())
979 const struct bfd_arch_info
*exec_bfd_arch_info
;
982 = bfd_get_arch_info (current_program_space
->exec_bfd ());
983 if (arch
== exec_bfd_arch_info
->arch
)
987 bfd_default_set_arch_mach (&abfd
, arch
, mach
);
990 info
.bfd_arch_info
= bfd_get_arch_info (&abfd
);
991 info
.abfd
= current_program_space
->exec_bfd ();
993 if (!gdbarch_update_p (current_inferior (), info
))
994 internal_error (_("rs6000_create_inferior: failed "
995 "to select architecture"));
999 /* Shared Object support. */
1001 /* Return the LdInfo data for the given process. Raises an error
1002 if the data could not be obtained. */
1004 static gdb::byte_vector
1005 rs6000_ptrace_ldinfo (ptid_t ptid
)
1007 const int pid
= ptid
.pid ();
1008 gdb::byte_vector
ldi (1024);
1014 rc
= rs6000_ptrace64 (PT_LDINFO
, pid
, (unsigned long) ldi
.data (),
1017 rc
= rs6000_ptrace32 (PT_LDINFO
, pid
, (int *) ldi
.data (),
1021 break; /* Success, we got the entire ld_info data. */
1023 if (errno
!= ENOMEM
)
1024 perror_with_name (_("ptrace ldinfo"));
1026 /* ldi is not big enough. Double it and try again. */
1027 ldi
.resize (ldi
.size () * 2);
1033 /* Implement the to_xfer_partial target_ops method for
1034 TARGET_OBJECT_LIBRARIES_AIX objects. */
1036 enum target_xfer_status
1037 rs6000_nat_target::xfer_shared_libraries
1038 (enum target_object object
,
1039 const char *annex
, gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
1040 ULONGEST offset
, ULONGEST len
, ULONGEST
*xfered_len
)
1044 /* This function assumes that it is being run with a live process.
1045 Core files are handled via gdbarch. */
1046 gdb_assert (target_has_execution ());
1049 return TARGET_XFER_E_IO
;
1051 gdb::byte_vector ldi_buf
= rs6000_ptrace_ldinfo (inferior_ptid
);
1052 result
= rs6000_aix_ld_info_to_xml (current_inferior ()->arch (),
1054 readbuf
, offset
, len
, 1);
1057 return TARGET_XFER_EOF
;
1060 *xfered_len
= result
;
1061 return TARGET_XFER_OK
;
1065 void _initialize_rs6000_nat ();
1067 _initialize_rs6000_nat ()
1069 add_inf_child_target (&the_rs6000_nat_target
);