1 /* Native support code for PPC AIX, for GDB the GNU debugger.
3 Copyright (C) 2006-2018 Free Software Foundation, Inc.
5 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
32 #include "breakpoint.h"
33 #include "rs6000-tdep.h"
35 #include "rs6000-aix-tdep.h"
36 #include "xcoffread.h"
38 #include "solib-aix.h"
39 #include "target-float.h"
40 #include "xml-utils.h"
42 /* If the kernel has to deliver a signal, it pushes a sigcontext
43 structure on the stack and then calls the signal handler, passing
44 the address of the sigcontext in an argument register. Usually
45 the signal handler doesn't save this register, so we have to
46 access the sigcontext structure via an offset from the signal handler
48 The following constants were determined by experimentation on AIX 3.2. */
49 #define SIG_FRAME_PC_OFFSET 96
50 #define SIG_FRAME_LR_OFFSET 108
51 #define SIG_FRAME_FP_OFFSET 284
54 /* Core file support. */
56 static struct ppc_reg_offsets rs6000_aix32_reg_offsets
=
58 /* General-purpose registers. */
70 /* Floating-point registers. */
72 56, /* fpscr_offset */
76 static struct ppc_reg_offsets rs6000_aix64_reg_offsets
=
78 /* General-purpose registers. */
90 /* Floating-point registers. */
92 296, /* fpscr_offset */
97 /* Supply register REGNUM in the general-purpose register set REGSET
98 from the buffer specified by GREGS and LEN to register cache
99 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
102 rs6000_aix_supply_regset (const struct regset
*regset
,
103 struct regcache
*regcache
, int regnum
,
104 const void *gregs
, size_t len
)
106 ppc_supply_gregset (regset
, regcache
, regnum
, gregs
, len
);
107 ppc_supply_fpregset (regset
, regcache
, regnum
, gregs
, len
);
110 /* Collect register REGNUM in the general-purpose register set
111 REGSET, from register cache REGCACHE into the buffer specified by
112 GREGS and LEN. If REGNUM is -1, do this for all registers in
116 rs6000_aix_collect_regset (const struct regset
*regset
,
117 const struct regcache
*regcache
, int regnum
,
118 void *gregs
, size_t len
)
120 ppc_collect_gregset (regset
, regcache
, regnum
, gregs
, len
);
121 ppc_collect_fpregset (regset
, regcache
, regnum
, gregs
, len
);
124 /* AIX register set. */
126 static const struct regset rs6000_aix32_regset
=
128 &rs6000_aix32_reg_offsets
,
129 rs6000_aix_supply_regset
,
130 rs6000_aix_collect_regset
,
133 static const struct regset rs6000_aix64_regset
=
135 &rs6000_aix64_reg_offsets
,
136 rs6000_aix_supply_regset
,
137 rs6000_aix_collect_regset
,
140 /* Iterate over core file register note sections. */
143 rs6000_aix_iterate_over_regset_sections (struct gdbarch
*gdbarch
,
144 iterate_over_regset_sections_cb
*cb
,
146 const struct regcache
*regcache
)
148 if (gdbarch_tdep (gdbarch
)->wordsize
== 4)
149 cb (".reg", 592, &rs6000_aix32_regset
, NULL
, cb_data
);
151 cb (".reg", 576, &rs6000_aix64_regset
, NULL
, cb_data
);
155 /* Pass the arguments in either registers, or in the stack. In RS/6000,
156 the first eight words of the argument list (that might be less than
157 eight parameters if some parameters occupy more than one word) are
158 passed in r3..r10 registers. Float and double parameters are
159 passed in fpr's, in addition to that. Rest of the parameters if any
160 are passed in user stack. There might be cases in which half of the
161 parameter is copied into registers, the other half is pushed into
164 Stack must be aligned on 64-bit boundaries when synthesizing
167 If the function is returning a structure, then the return address is passed
168 in r3, then the first 7 words of the parameters can be passed in registers,
172 rs6000_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
173 struct regcache
*regcache
, CORE_ADDR bp_addr
,
174 int nargs
, struct value
**args
, CORE_ADDR sp
,
175 int struct_return
, CORE_ADDR struct_addr
)
177 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
178 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
181 int argno
; /* current argument number */
182 int argbytes
; /* current argument byte */
183 gdb_byte tmp_buffer
[50];
184 int f_argno
= 0; /* current floating point argno */
185 int wordsize
= gdbarch_tdep (gdbarch
)->wordsize
;
186 CORE_ADDR func_addr
= find_function_addr (function
, NULL
);
188 struct value
*arg
= 0;
193 /* The calling convention this function implements assumes the
194 processor has floating-point registers. We shouldn't be using it
195 on PPC variants that lack them. */
196 gdb_assert (ppc_floating_point_unit_p (gdbarch
));
198 /* The first eight words of ther arguments are passed in registers.
199 Copy them appropriately. */
202 /* If the function is returning a `struct', then the first word
203 (which will be passed in r3) is used for struct return address.
204 In that case we should advance one word and start from r4
205 register to copy parameters. */
208 regcache_raw_write_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
213 /* effectively indirect call... gcc does...
215 return_val example( float, int);
218 float in fp0, int in r3
219 offset of stack on overflow 8/16
220 for varargs, must go by type.
222 float in r3&r4, int in r5
223 offset of stack on overflow different
225 return in r3 or f0. If no float, must study how gcc emulates floats;
226 pay attention to arg promotion.
227 User may have to cast\args to handle promotion correctly
228 since gdb won't know if prototype supplied or not. */
230 for (argno
= 0, argbytes
= 0; argno
< nargs
&& ii
< 8; ++ii
)
232 int reg_size
= register_size (gdbarch
, ii
+ 3);
235 type
= check_typedef (value_type (arg
));
236 len
= TYPE_LENGTH (type
);
238 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
240 /* Floating point arguments are passed in fpr's, as well as gpr's.
241 There are 13 fpr's reserved for passing parameters. At this point
242 there is no way we would run out of them.
244 Always store the floating point value using the register's
245 floating-point format. */
246 const int fp_regnum
= tdep
->ppc_fp0_regnum
+ 1 + f_argno
;
247 gdb_byte reg_val
[PPC_MAX_REGISTER_SIZE
];
248 struct type
*reg_type
= register_type (gdbarch
, fp_regnum
);
250 gdb_assert (len
<= 8);
252 target_float_convert (value_contents (arg
), type
, reg_val
, reg_type
);
253 regcache_cooked_write (regcache
, fp_regnum
, reg_val
);
260 /* Argument takes more than one register. */
261 while (argbytes
< len
)
263 gdb_byte word
[PPC_MAX_REGISTER_SIZE
];
264 memset (word
, 0, reg_size
);
266 ((char *) value_contents (arg
)) + argbytes
,
267 (len
- argbytes
) > reg_size
268 ? reg_size
: len
- argbytes
);
269 regcache_cooked_write (regcache
,
270 tdep
->ppc_gp0_regnum
+ 3 + ii
,
272 ++ii
, argbytes
+= reg_size
;
275 goto ran_out_of_registers_for_arguments
;
282 /* Argument can fit in one register. No problem. */
283 gdb_byte word
[PPC_MAX_REGISTER_SIZE
];
285 memset (word
, 0, reg_size
);
286 memcpy (word
, value_contents (arg
), len
);
287 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 3 +ii
, word
);
292 ran_out_of_registers_for_arguments
:
294 regcache_cooked_read_unsigned (regcache
,
295 gdbarch_sp_regnum (gdbarch
),
298 /* Location for 8 parameters are always reserved. */
301 /* Another six words for back chain, TOC register, link register, etc. */
304 /* Stack pointer must be quadword aligned. */
307 /* If there are more arguments, allocate space for them in
308 the stack, then push them starting from the ninth one. */
310 if ((argno
< nargs
) || argbytes
)
316 space
+= ((len
- argbytes
+ 3) & -4);
322 for (; jj
< nargs
; ++jj
)
324 struct value
*val
= args
[jj
];
325 space
+= ((TYPE_LENGTH (value_type (val
))) + 3) & -4;
328 /* Add location required for the rest of the parameters. */
329 space
= (space
+ 15) & -16;
332 /* This is another instance we need to be concerned about
333 securing our stack space. If we write anything underneath %sp
334 (r1), we might conflict with the kernel who thinks he is free
335 to use this area. So, update %sp first before doing anything
338 regcache_raw_write_signed (regcache
,
339 gdbarch_sp_regnum (gdbarch
), sp
);
341 /* If the last argument copied into the registers didn't fit there
342 completely, push the rest of it into stack. */
346 write_memory (sp
+ 24 + (ii
* 4),
347 value_contents (arg
) + argbytes
,
350 ii
+= ((len
- argbytes
+ 3) & -4) / 4;
353 /* Push the rest of the arguments into stack. */
354 for (; argno
< nargs
; ++argno
)
358 type
= check_typedef (value_type (arg
));
359 len
= TYPE_LENGTH (type
);
362 /* Float types should be passed in fpr's, as well as in the
364 if (TYPE_CODE (type
) == TYPE_CODE_FLT
&& f_argno
< 13)
367 gdb_assert (len
<= 8);
369 regcache_cooked_write (regcache
,
370 tdep
->ppc_fp0_regnum
+ 1 + f_argno
,
371 value_contents (arg
));
375 write_memory (sp
+ 24 + (ii
* 4), value_contents (arg
), len
);
376 ii
+= ((len
+ 3) & -4) / 4;
380 /* Set the stack pointer. According to the ABI, the SP is meant to
381 be set _before_ the corresponding stack space is used. On AIX,
382 this even applies when the target has been completely stopped!
383 Not doing this can lead to conflicts with the kernel which thinks
384 that it still has control over this not-yet-allocated stack
386 regcache_raw_write_signed (regcache
, gdbarch_sp_regnum (gdbarch
), sp
);
388 /* Set back chain properly. */
389 store_unsigned_integer (tmp_buffer
, wordsize
, byte_order
, saved_sp
);
390 write_memory (sp
, tmp_buffer
, wordsize
);
392 /* Point the inferior function call's return address at the dummy's
394 regcache_raw_write_signed (regcache
, tdep
->ppc_lr_regnum
, bp_addr
);
396 /* Set the TOC register value. */
397 regcache_raw_write_signed (regcache
, tdep
->ppc_toc_regnum
,
398 solib_aix_get_toc_value (func_addr
));
400 target_store_registers (regcache
, -1);
404 static enum return_value_convention
405 rs6000_return_value (struct gdbarch
*gdbarch
, struct value
*function
,
406 struct type
*valtype
, struct regcache
*regcache
,
407 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
409 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
410 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
412 /* The calling convention this function implements assumes the
413 processor has floating-point registers. We shouldn't be using it
414 on PowerPC variants that lack them. */
415 gdb_assert (ppc_floating_point_unit_p (gdbarch
));
417 /* AltiVec extension: Functions that declare a vector data type as a
418 return value place that return value in VR2. */
419 if (TYPE_CODE (valtype
) == TYPE_CODE_ARRAY
&& TYPE_VECTOR (valtype
)
420 && TYPE_LENGTH (valtype
) == 16)
423 regcache_cooked_read (regcache
, tdep
->ppc_vr0_regnum
+ 2, readbuf
);
425 regcache_cooked_write (regcache
, tdep
->ppc_vr0_regnum
+ 2, writebuf
);
427 return RETURN_VALUE_REGISTER_CONVENTION
;
430 /* If the called subprogram returns an aggregate, there exists an
431 implicit first argument, whose value is the address of a caller-
432 allocated buffer into which the callee is assumed to store its
433 return value. All explicit parameters are appropriately
435 if (TYPE_CODE (valtype
) == TYPE_CODE_STRUCT
436 || TYPE_CODE (valtype
) == TYPE_CODE_UNION
437 || TYPE_CODE (valtype
) == TYPE_CODE_ARRAY
)
438 return RETURN_VALUE_STRUCT_CONVENTION
;
440 /* Scalar floating-point values are returned in FPR1 for float or
441 double, and in FPR1:FPR2 for quadword precision. Fortran
442 complex*8 and complex*16 are returned in FPR1:FPR2, and
443 complex*32 is returned in FPR1:FPR4. */
444 if (TYPE_CODE (valtype
) == TYPE_CODE_FLT
445 && (TYPE_LENGTH (valtype
) == 4 || TYPE_LENGTH (valtype
) == 8))
447 struct type
*regtype
= register_type (gdbarch
, tdep
->ppc_fp0_regnum
);
450 /* FIXME: kettenis/2007-01-01: Add support for quadword
451 precision and complex. */
455 regcache_cooked_read (regcache
, tdep
->ppc_fp0_regnum
+ 1, regval
);
456 target_float_convert (regval
, regtype
, readbuf
, valtype
);
460 target_float_convert (writebuf
, valtype
, regval
, regtype
);
461 regcache_cooked_write (regcache
, tdep
->ppc_fp0_regnum
+ 1, regval
);
464 return RETURN_VALUE_REGISTER_CONVENTION
;
467 /* Values of the types int, long, short, pointer, and char (length
468 is less than or equal to four bytes), as well as bit values of
469 lengths less than or equal to 32 bits, must be returned right
470 justified in GPR3 with signed values sign extended and unsigned
471 values zero extended, as necessary. */
472 if (TYPE_LENGTH (valtype
) <= tdep
->wordsize
)
478 /* For reading we don't have to worry about sign extension. */
479 regcache_cooked_read_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
481 store_unsigned_integer (readbuf
, TYPE_LENGTH (valtype
), byte_order
,
486 /* For writing, use unpack_long since that should handle any
487 required sign extension. */
488 regcache_cooked_write_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
489 unpack_long (valtype
, writebuf
));
492 return RETURN_VALUE_REGISTER_CONVENTION
;
495 /* Eight-byte non-floating-point scalar values must be returned in
498 if (TYPE_LENGTH (valtype
) == 8)
500 gdb_assert (TYPE_CODE (valtype
) != TYPE_CODE_FLT
);
501 gdb_assert (tdep
->wordsize
== 4);
507 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 3, regval
);
508 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 4,
510 memcpy (readbuf
, regval
, 8);
514 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 3, writebuf
);
515 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 4,
519 return RETURN_VALUE_REGISTER_CONVENTION
;
522 return RETURN_VALUE_STRUCT_CONVENTION
;
525 /* Support for CONVERT_FROM_FUNC_PTR_ADDR (ARCH, ADDR, TARG).
527 Usually a function pointer's representation is simply the address
528 of the function. On the RS/6000 however, a function pointer is
529 represented by a pointer to an OPD entry. This OPD entry contains
530 three words, the first word is the address of the function, the
531 second word is the TOC pointer (r2), and the third word is the
532 static chain value. Throughout GDB it is currently assumed that a
533 function pointer contains the address of the function, which is not
534 easy to fix. In addition, the conversion of a function address to
535 a function pointer would require allocation of an OPD entry in the
536 inferior's memory space, with all its drawbacks. To be able to
537 call C++ virtual methods in the inferior (which are called via
538 function pointers), find_function_addr uses this function to get the
539 function address from a function pointer. */
541 /* Return real function address if ADDR (a function pointer) is in the data
542 space and is therefore a special function pointer. */
545 rs6000_convert_from_func_ptr_addr (struct gdbarch
*gdbarch
,
547 struct target_ops
*targ
)
549 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
550 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
551 struct obj_section
*s
;
553 s
= find_pc_section (addr
);
555 /* Normally, functions live inside a section that is executable.
556 So, if ADDR points to a non-executable section, then treat it
557 as a function descriptor and return the target address iff
558 the target address itself points to a section that is executable. */
559 if (s
&& (s
->the_bfd_section
->flags
& SEC_CODE
) == 0)
562 struct obj_section
*pc_section
;
566 pc
= read_memory_unsigned_integer (addr
, tdep
->wordsize
, byte_order
);
568 CATCH (e
, RETURN_MASK_ERROR
)
570 /* An error occured during reading. Probably a memory error
571 due to the section not being loaded yet. This address
572 cannot be a function descriptor. */
577 pc_section
= find_pc_section (pc
);
579 if (pc_section
&& (pc_section
->the_bfd_section
->flags
& SEC_CODE
))
587 /* Calculate the destination of a branch/jump. Return -1 if not a branch. */
590 branch_dest (struct regcache
*regcache
, int opcode
, int instr
,
591 CORE_ADDR pc
, CORE_ADDR safety
)
593 struct gdbarch
*gdbarch
= regcache
->arch ();
594 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
595 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
601 absolute
= (int) ((instr
>> 1) & 1);
606 immediate
= ((instr
& ~3) << 6) >> 6; /* br unconditional */
610 dest
= pc
+ immediate
;
614 immediate
= ((instr
& ~3) << 16) >> 16; /* br conditional */
618 dest
= pc
+ immediate
;
622 ext_op
= (instr
>> 1) & 0x3ff;
624 if (ext_op
== 16) /* br conditional register */
626 dest
= regcache_raw_get_unsigned (regcache
, tdep
->ppc_lr_regnum
) & ~3;
628 /* If we are about to return from a signal handler, dest is
629 something like 0x3c90. The current frame is a signal handler
630 caller frame, upon completion of the sigreturn system call
631 execution will return to the saved PC in the frame. */
632 if (dest
< AIX_TEXT_SEGMENT_BASE
)
634 struct frame_info
*frame
= get_current_frame ();
636 dest
= read_memory_unsigned_integer
637 (get_frame_base (frame
) + SIG_FRAME_PC_OFFSET
,
638 tdep
->wordsize
, byte_order
);
642 else if (ext_op
== 528) /* br cond to count reg */
644 dest
= regcache_raw_get_unsigned (regcache
,
645 tdep
->ppc_ctr_regnum
) & ~3;
647 /* If we are about to execute a system call, dest is something
648 like 0x22fc or 0x3b00. Upon completion the system call
649 will return to the address in the link register. */
650 if (dest
< AIX_TEXT_SEGMENT_BASE
)
651 dest
= regcache_raw_get_unsigned (regcache
,
652 tdep
->ppc_lr_regnum
) & ~3;
661 return (dest
< AIX_TEXT_SEGMENT_BASE
) ? safety
: dest
;
664 /* AIX does not support PT_STEP. Simulate it. */
666 static std::vector
<CORE_ADDR
>
667 rs6000_software_single_step (struct regcache
*regcache
)
669 struct gdbarch
*gdbarch
= regcache
->arch ();
670 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
676 loc
= regcache_read_pc (regcache
);
678 insn
= read_memory_integer (loc
, 4, byte_order
);
680 std::vector
<CORE_ADDR
> next_pcs
= ppc_deal_with_atomic_sequence (regcache
);
681 if (!next_pcs
.empty ())
684 breaks
[0] = loc
+ PPC_INSN_SIZE
;
686 breaks
[1] = branch_dest (regcache
, opcode
, insn
, loc
, breaks
[0]);
688 /* Don't put two breakpoints on the same address. */
689 if (breaks
[1] == breaks
[0])
692 for (ii
= 0; ii
< 2; ++ii
)
694 /* ignore invalid breakpoint. */
695 if (breaks
[ii
] == -1)
698 next_pcs
.push_back (breaks
[ii
]);
701 errno
= 0; /* FIXME, don't ignore errors! */
702 /* What errors? {read,write}_memory call error(). */
706 /* Implement the "auto_wide_charset" gdbarch method for this platform. */
709 rs6000_aix_auto_wide_charset (void)
714 /* Implement an osabi sniffer for RS6000/AIX.
716 This function assumes that ABFD's flavour is XCOFF. In other words,
717 it should be registered as a sniffer for bfd_target_xcoff_flavour
718 objfiles only. A failed assertion will be raised if this condition
721 static enum gdb_osabi
722 rs6000_aix_osabi_sniffer (bfd
*abfd
)
724 gdb_assert (bfd_get_flavour (abfd
) == bfd_target_xcoff_flavour
);
726 /* The only noticeable difference between Lynx178 XCOFF files and
727 AIX XCOFF files comes from the fact that there are no shared
728 libraries on Lynx178. On AIX, we are betting that an executable
729 linked with no shared library will never exist. */
730 if (xcoff_get_n_import_files (abfd
) <= 0)
731 return GDB_OSABI_UNKNOWN
;
733 return GDB_OSABI_AIX
;
736 /* A structure encoding the offset and size of a field within
745 /* A structure describing the layout of all the fields of interest
746 in AIX's struct ld_info. Each field in this struct corresponds
747 to the field of the same name in struct ld_info. */
751 struct field_info ldinfo_next
;
752 struct field_info ldinfo_fd
;
753 struct field_info ldinfo_textorg
;
754 struct field_info ldinfo_textsize
;
755 struct field_info ldinfo_dataorg
;
756 struct field_info ldinfo_datasize
;
757 struct field_info ldinfo_filename
;
760 /* The following data has been generated by compiling and running
761 the following program on AIX 5.3. */
766 #define __LDINFO_PTRACE32__
767 #define __LDINFO_PTRACE64__
770 #define pinfo(type,member) \
772 struct type ldi = {0}; \
774 printf (" {%d, %d},\t/* %s */\n", \
775 offsetof (struct type, member), \
776 sizeof (ldi.member), \
784 printf ("static const struct ld_info_desc ld_info32_desc =\n{\n");
785 pinfo (__ld_info32
, ldinfo_next
);
786 pinfo (__ld_info32
, ldinfo_fd
);
787 pinfo (__ld_info32
, ldinfo_textorg
);
788 pinfo (__ld_info32
, ldinfo_textsize
);
789 pinfo (__ld_info32
, ldinfo_dataorg
);
790 pinfo (__ld_info32
, ldinfo_datasize
);
791 pinfo (__ld_info32
, ldinfo_filename
);
796 printf ("static const struct ld_info_desc ld_info64_desc =\n{\n");
797 pinfo (__ld_info64
, ldinfo_next
);
798 pinfo (__ld_info64
, ldinfo_fd
);
799 pinfo (__ld_info64
, ldinfo_textorg
);
800 pinfo (__ld_info64
, ldinfo_textsize
);
801 pinfo (__ld_info64
, ldinfo_dataorg
);
802 pinfo (__ld_info64
, ldinfo_datasize
);
803 pinfo (__ld_info64
, ldinfo_filename
);
810 /* Layout of the 32bit version of struct ld_info. */
812 static const struct ld_info_desc ld_info32_desc
=
814 {0, 4}, /* ldinfo_next */
815 {4, 4}, /* ldinfo_fd */
816 {8, 4}, /* ldinfo_textorg */
817 {12, 4}, /* ldinfo_textsize */
818 {16, 4}, /* ldinfo_dataorg */
819 {20, 4}, /* ldinfo_datasize */
820 {24, 2}, /* ldinfo_filename */
823 /* Layout of the 64bit version of struct ld_info. */
825 static const struct ld_info_desc ld_info64_desc
=
827 {0, 4}, /* ldinfo_next */
828 {8, 4}, /* ldinfo_fd */
829 {16, 8}, /* ldinfo_textorg */
830 {24, 8}, /* ldinfo_textsize */
831 {32, 8}, /* ldinfo_dataorg */
832 {40, 8}, /* ldinfo_datasize */
833 {48, 2}, /* ldinfo_filename */
836 /* A structured representation of one entry read from the ld_info
837 binary data provided by the AIX loader. */
851 /* Return a struct ld_info object corresponding to the entry at
854 Note that the filename and member_name strings still point
855 to the data in LDI_BUF. So LDI_BUF must not be deallocated
856 while the struct ld_info object returned is in use. */
858 static struct ld_info
859 rs6000_aix_extract_ld_info (struct gdbarch
*gdbarch
,
860 const gdb_byte
*ldi_buf
)
862 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
863 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
864 struct type
*ptr_type
= builtin_type (gdbarch
)->builtin_data_ptr
;
865 const struct ld_info_desc desc
866 = tdep
->wordsize
== 8 ? ld_info64_desc
: ld_info32_desc
;
869 info
.next
= extract_unsigned_integer (ldi_buf
+ desc
.ldinfo_next
.offset
,
870 desc
.ldinfo_next
.size
,
872 info
.fd
= extract_signed_integer (ldi_buf
+ desc
.ldinfo_fd
.offset
,
875 info
.textorg
= extract_typed_address (ldi_buf
+ desc
.ldinfo_textorg
.offset
,
878 = extract_unsigned_integer (ldi_buf
+ desc
.ldinfo_textsize
.offset
,
879 desc
.ldinfo_textsize
.size
,
881 info
.dataorg
= extract_typed_address (ldi_buf
+ desc
.ldinfo_dataorg
.offset
,
884 = extract_unsigned_integer (ldi_buf
+ desc
.ldinfo_datasize
.offset
,
885 desc
.ldinfo_datasize
.size
,
887 info
.filename
= (char *) ldi_buf
+ desc
.ldinfo_filename
.offset
;
888 info
.member_name
= info
.filename
+ strlen (info
.filename
) + 1;
893 /* Append to OBJSTACK an XML string description of the shared library
894 corresponding to LDI, following the TARGET_OBJECT_LIBRARIES_AIX
898 rs6000_aix_shared_library_to_xml (struct ld_info
*ldi
,
899 struct obstack
*obstack
)
901 obstack_grow_str (obstack
, "<library name=\"");
902 std::string p
= xml_escape_text (ldi
->filename
);
903 obstack_grow_str (obstack
, p
.c_str ());
904 obstack_grow_str (obstack
, "\"");
906 if (ldi
->member_name
[0] != '\0')
908 obstack_grow_str (obstack
, " member=\"");
909 p
= xml_escape_text (ldi
->member_name
);
910 obstack_grow_str (obstack
, p
.c_str ());
911 obstack_grow_str (obstack
, "\"");
914 obstack_grow_str (obstack
, " text_addr=\"");
915 obstack_grow_str (obstack
, core_addr_to_string (ldi
->textorg
));
916 obstack_grow_str (obstack
, "\"");
918 obstack_grow_str (obstack
, " text_size=\"");
919 obstack_grow_str (obstack
, pulongest (ldi
->textsize
));
920 obstack_grow_str (obstack
, "\"");
922 obstack_grow_str (obstack
, " data_addr=\"");
923 obstack_grow_str (obstack
, core_addr_to_string (ldi
->dataorg
));
924 obstack_grow_str (obstack
, "\"");
926 obstack_grow_str (obstack
, " data_size=\"");
927 obstack_grow_str (obstack
, pulongest (ldi
->datasize
));
928 obstack_grow_str (obstack
, "\"");
930 obstack_grow_str (obstack
, "></library>");
933 /* Convert the ld_info binary data provided by the AIX loader into
934 an XML representation following the TARGET_OBJECT_LIBRARIES_AIX
937 LDI_BUF is a buffer containing the ld_info data.
938 READBUF, OFFSET and LEN follow the same semantics as target_ops'
939 to_xfer_partial target_ops method.
941 If CLOSE_LDINFO_FD is nonzero, then this routine also closes
942 the ldinfo_fd file descriptor. This is useful when the ldinfo
943 data is obtained via ptrace, as ptrace opens a file descriptor
944 for each and every entry; but we cannot use this descriptor
945 as the consumer of the XML library list might live in a different
949 rs6000_aix_ld_info_to_xml (struct gdbarch
*gdbarch
, const gdb_byte
*ldi_buf
,
950 gdb_byte
*readbuf
, ULONGEST offset
, ULONGEST len
,
953 struct obstack obstack
;
957 obstack_init (&obstack
);
958 obstack_grow_str (&obstack
, "<library-list-aix version=\"1.0\">\n");
962 struct ld_info ldi
= rs6000_aix_extract_ld_info (gdbarch
, ldi_buf
);
964 rs6000_aix_shared_library_to_xml (&ldi
, &obstack
);
970 ldi_buf
= ldi_buf
+ ldi
.next
;
973 obstack_grow_str0 (&obstack
, "</library-list-aix>\n");
975 buf
= (const char *) obstack_finish (&obstack
);
976 len_avail
= strlen (buf
);
977 if (offset
>= len_avail
)
981 if (len
> len_avail
- offset
)
982 len
= len_avail
- offset
;
983 memcpy (readbuf
, buf
+ offset
, len
);
986 obstack_free (&obstack
, NULL
);
990 /* Implement the core_xfer_shared_libraries_aix gdbarch method. */
993 rs6000_aix_core_xfer_shared_libraries_aix (struct gdbarch
*gdbarch
,
998 struct bfd_section
*ldinfo_sec
;
1001 ldinfo_sec
= bfd_get_section_by_name (core_bfd
, ".ldinfo");
1002 if (ldinfo_sec
== NULL
)
1003 error (_("cannot find .ldinfo section from core file: %s"),
1004 bfd_errmsg (bfd_get_error ()));
1005 ldinfo_size
= bfd_get_section_size (ldinfo_sec
);
1007 gdb::byte_vector
ldinfo_buf (ldinfo_size
);
1009 if (! bfd_get_section_contents (core_bfd
, ldinfo_sec
,
1010 ldinfo_buf
.data (), 0, ldinfo_size
))
1011 error (_("unable to read .ldinfo section from core file: %s"),
1012 bfd_errmsg (bfd_get_error ()));
1014 return rs6000_aix_ld_info_to_xml (gdbarch
, ldinfo_buf
.data (), readbuf
,
1019 rs6000_aix_init_osabi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
1021 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1023 /* RS6000/AIX does not support PT_STEP. Has to be simulated. */
1024 set_gdbarch_software_single_step (gdbarch
, rs6000_software_single_step
);
1026 /* Displaced stepping is currently not supported in combination with
1027 software single-stepping. */
1028 set_gdbarch_displaced_step_copy_insn (gdbarch
, NULL
);
1029 set_gdbarch_displaced_step_fixup (gdbarch
, NULL
);
1030 set_gdbarch_displaced_step_location (gdbarch
, NULL
);
1032 set_gdbarch_push_dummy_call (gdbarch
, rs6000_push_dummy_call
);
1033 set_gdbarch_return_value (gdbarch
, rs6000_return_value
);
1034 set_gdbarch_long_double_bit (gdbarch
, 8 * TARGET_CHAR_BIT
);
1036 /* Handle RS/6000 function pointers (which are really function
1038 set_gdbarch_convert_from_func_ptr_addr
1039 (gdbarch
, rs6000_convert_from_func_ptr_addr
);
1041 /* Core file support. */
1042 set_gdbarch_iterate_over_regset_sections
1043 (gdbarch
, rs6000_aix_iterate_over_regset_sections
);
1044 set_gdbarch_core_xfer_shared_libraries_aix
1045 (gdbarch
, rs6000_aix_core_xfer_shared_libraries_aix
);
1047 if (tdep
->wordsize
== 8)
1048 tdep
->lr_frame_offset
= 16;
1050 tdep
->lr_frame_offset
= 8;
1052 if (tdep
->wordsize
== 4)
1053 /* PowerOpen / AIX 32 bit. The saved area or red zone consists of
1054 19 4 byte GPRS + 18 8 byte FPRs giving a total of 220 bytes.
1055 Problem is, 220 isn't frame (16 byte) aligned. Round it up to
1057 set_gdbarch_frame_red_zone_size (gdbarch
, 224);
1059 set_gdbarch_frame_red_zone_size (gdbarch
, 0);
1061 if (tdep
->wordsize
== 8)
1062 set_gdbarch_wchar_bit (gdbarch
, 32);
1064 set_gdbarch_wchar_bit (gdbarch
, 16);
1065 set_gdbarch_wchar_signed (gdbarch
, 0);
1066 set_gdbarch_auto_wide_charset (gdbarch
, rs6000_aix_auto_wide_charset
);
1068 set_solib_ops (gdbarch
, &solib_aix_so_ops
);
1072 _initialize_rs6000_aix_tdep (void)
1074 gdbarch_register_osabi_sniffer (bfd_arch_rs6000
,
1075 bfd_target_xcoff_flavour
,
1076 rs6000_aix_osabi_sniffer
);
1077 gdbarch_register_osabi_sniffer (bfd_arch_powerpc
,
1078 bfd_target_xcoff_flavour
,
1079 rs6000_aix_osabi_sniffer
);
1081 gdbarch_register_osabi (bfd_arch_rs6000
, 0, GDB_OSABI_AIX
,
1082 rs6000_aix_init_osabi
);
1083 gdbarch_register_osabi (bfd_arch_powerpc
, 0, GDB_OSABI_AIX
,
1084 rs6000_aix_init_osabi
);