1 /* Native support code for PPC AIX, for GDB the GNU debugger.
3 Copyright (C) 2006-2017 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 */
75 /* AltiVec registers. */
78 -1 /* vrsave_offset */
81 static struct ppc_reg_offsets rs6000_aix64_reg_offsets
=
83 /* General-purpose registers. */
95 /* Floating-point registers. */
97 296, /* fpscr_offset */
100 /* AltiVec registers. */
102 -1, /* vscr_offset */
103 -1 /* vrsave_offset */
107 /* Supply register REGNUM in the general-purpose register set REGSET
108 from the buffer specified by GREGS and LEN to register cache
109 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
112 rs6000_aix_supply_regset (const struct regset
*regset
,
113 struct regcache
*regcache
, int regnum
,
114 const void *gregs
, size_t len
)
116 ppc_supply_gregset (regset
, regcache
, regnum
, gregs
, len
);
117 ppc_supply_fpregset (regset
, regcache
, regnum
, gregs
, len
);
120 /* Collect register REGNUM in the general-purpose register set
121 REGSET, from register cache REGCACHE into the buffer specified by
122 GREGS and LEN. If REGNUM is -1, do this for all registers in
126 rs6000_aix_collect_regset (const struct regset
*regset
,
127 const struct regcache
*regcache
, int regnum
,
128 void *gregs
, size_t len
)
130 ppc_collect_gregset (regset
, regcache
, regnum
, gregs
, len
);
131 ppc_collect_fpregset (regset
, regcache
, regnum
, gregs
, len
);
134 /* AIX register set. */
136 static const struct regset rs6000_aix32_regset
=
138 &rs6000_aix32_reg_offsets
,
139 rs6000_aix_supply_regset
,
140 rs6000_aix_collect_regset
,
143 static const struct regset rs6000_aix64_regset
=
145 &rs6000_aix64_reg_offsets
,
146 rs6000_aix_supply_regset
,
147 rs6000_aix_collect_regset
,
150 /* Iterate over core file register note sections. */
153 rs6000_aix_iterate_over_regset_sections (struct gdbarch
*gdbarch
,
154 iterate_over_regset_sections_cb
*cb
,
156 const struct regcache
*regcache
)
158 if (gdbarch_tdep (gdbarch
)->wordsize
== 4)
159 cb (".reg", 592, &rs6000_aix32_regset
, NULL
, cb_data
);
161 cb (".reg", 576, &rs6000_aix64_regset
, NULL
, cb_data
);
165 /* Pass the arguments in either registers, or in the stack. In RS/6000,
166 the first eight words of the argument list (that might be less than
167 eight parameters if some parameters occupy more than one word) are
168 passed in r3..r10 registers. Float and double parameters are
169 passed in fpr's, in addition to that. Rest of the parameters if any
170 are passed in user stack. There might be cases in which half of the
171 parameter is copied into registers, the other half is pushed into
174 Stack must be aligned on 64-bit boundaries when synthesizing
177 If the function is returning a structure, then the return address is passed
178 in r3, then the first 7 words of the parameters can be passed in registers,
182 rs6000_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
183 struct regcache
*regcache
, CORE_ADDR bp_addr
,
184 int nargs
, struct value
**args
, CORE_ADDR sp
,
185 int struct_return
, CORE_ADDR struct_addr
)
187 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
188 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
191 int argno
; /* current argument number */
192 int argbytes
; /* current argument byte */
193 gdb_byte tmp_buffer
[50];
194 int f_argno
= 0; /* current floating point argno */
195 int wordsize
= gdbarch_tdep (gdbarch
)->wordsize
;
196 CORE_ADDR func_addr
= find_function_addr (function
, NULL
);
198 struct value
*arg
= 0;
203 /* The calling convention this function implements assumes the
204 processor has floating-point registers. We shouldn't be using it
205 on PPC variants that lack them. */
206 gdb_assert (ppc_floating_point_unit_p (gdbarch
));
208 /* The first eight words of ther arguments are passed in registers.
209 Copy them appropriately. */
212 /* If the function is returning a `struct', then the first word
213 (which will be passed in r3) is used for struct return address.
214 In that case we should advance one word and start from r4
215 register to copy parameters. */
218 regcache_raw_write_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
223 /* effectively indirect call... gcc does...
225 return_val example( float, int);
228 float in fp0, int in r3
229 offset of stack on overflow 8/16
230 for varargs, must go by type.
232 float in r3&r4, int in r5
233 offset of stack on overflow different
235 return in r3 or f0. If no float, must study how gcc emulates floats;
236 pay attention to arg promotion.
237 User may have to cast\args to handle promotion correctly
238 since gdb won't know if prototype supplied or not. */
240 for (argno
= 0, argbytes
= 0; argno
< nargs
&& ii
< 8; ++ii
)
242 int reg_size
= register_size (gdbarch
, ii
+ 3);
245 type
= check_typedef (value_type (arg
));
246 len
= TYPE_LENGTH (type
);
248 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
250 /* Floating point arguments are passed in fpr's, as well as gpr's.
251 There are 13 fpr's reserved for passing parameters. At this point
252 there is no way we would run out of them.
254 Always store the floating point value using the register's
255 floating-point format. */
256 const int fp_regnum
= tdep
->ppc_fp0_regnum
+ 1 + f_argno
;
257 gdb_byte reg_val
[PPC_MAX_REGISTER_SIZE
];
258 struct type
*reg_type
= register_type (gdbarch
, fp_regnum
);
260 gdb_assert (len
<= 8);
262 target_float_convert (value_contents (arg
), type
, reg_val
, reg_type
);
263 regcache_cooked_write (regcache
, fp_regnum
, reg_val
);
270 /* Argument takes more than one register. */
271 while (argbytes
< len
)
273 gdb_byte word
[PPC_MAX_REGISTER_SIZE
];
274 memset (word
, 0, reg_size
);
276 ((char *) value_contents (arg
)) + argbytes
,
277 (len
- argbytes
) > reg_size
278 ? reg_size
: len
- argbytes
);
279 regcache_cooked_write (regcache
,
280 tdep
->ppc_gp0_regnum
+ 3 + ii
,
282 ++ii
, argbytes
+= reg_size
;
285 goto ran_out_of_registers_for_arguments
;
292 /* Argument can fit in one register. No problem. */
293 gdb_byte word
[PPC_MAX_REGISTER_SIZE
];
295 memset (word
, 0, reg_size
);
296 memcpy (word
, value_contents (arg
), len
);
297 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 3 +ii
, word
);
302 ran_out_of_registers_for_arguments
:
304 regcache_cooked_read_unsigned (regcache
,
305 gdbarch_sp_regnum (gdbarch
),
308 /* Location for 8 parameters are always reserved. */
311 /* Another six words for back chain, TOC register, link register, etc. */
314 /* Stack pointer must be quadword aligned. */
317 /* If there are more arguments, allocate space for them in
318 the stack, then push them starting from the ninth one. */
320 if ((argno
< nargs
) || argbytes
)
326 space
+= ((len
- argbytes
+ 3) & -4);
332 for (; jj
< nargs
; ++jj
)
334 struct value
*val
= args
[jj
];
335 space
+= ((TYPE_LENGTH (value_type (val
))) + 3) & -4;
338 /* Add location required for the rest of the parameters. */
339 space
= (space
+ 15) & -16;
342 /* This is another instance we need to be concerned about
343 securing our stack space. If we write anything underneath %sp
344 (r1), we might conflict with the kernel who thinks he is free
345 to use this area. So, update %sp first before doing anything
348 regcache_raw_write_signed (regcache
,
349 gdbarch_sp_regnum (gdbarch
), sp
);
351 /* If the last argument copied into the registers didn't fit there
352 completely, push the rest of it into stack. */
356 write_memory (sp
+ 24 + (ii
* 4),
357 value_contents (arg
) + argbytes
,
360 ii
+= ((len
- argbytes
+ 3) & -4) / 4;
363 /* Push the rest of the arguments into stack. */
364 for (; argno
< nargs
; ++argno
)
368 type
= check_typedef (value_type (arg
));
369 len
= TYPE_LENGTH (type
);
372 /* Float types should be passed in fpr's, as well as in the
374 if (TYPE_CODE (type
) == TYPE_CODE_FLT
&& f_argno
< 13)
377 gdb_assert (len
<= 8);
379 regcache_cooked_write (regcache
,
380 tdep
->ppc_fp0_regnum
+ 1 + f_argno
,
381 value_contents (arg
));
385 write_memory (sp
+ 24 + (ii
* 4), value_contents (arg
), len
);
386 ii
+= ((len
+ 3) & -4) / 4;
390 /* Set the stack pointer. According to the ABI, the SP is meant to
391 be set _before_ the corresponding stack space is used. On AIX,
392 this even applies when the target has been completely stopped!
393 Not doing this can lead to conflicts with the kernel which thinks
394 that it still has control over this not-yet-allocated stack
396 regcache_raw_write_signed (regcache
, gdbarch_sp_regnum (gdbarch
), sp
);
398 /* Set back chain properly. */
399 store_unsigned_integer (tmp_buffer
, wordsize
, byte_order
, saved_sp
);
400 write_memory (sp
, tmp_buffer
, wordsize
);
402 /* Point the inferior function call's return address at the dummy's
404 regcache_raw_write_signed (regcache
, tdep
->ppc_lr_regnum
, bp_addr
);
406 /* Set the TOC register value. */
407 regcache_raw_write_signed (regcache
, tdep
->ppc_toc_regnum
,
408 solib_aix_get_toc_value (func_addr
));
410 target_store_registers (regcache
, -1);
414 static enum return_value_convention
415 rs6000_return_value (struct gdbarch
*gdbarch
, struct value
*function
,
416 struct type
*valtype
, struct regcache
*regcache
,
417 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
419 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
420 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
422 /* The calling convention this function implements assumes the
423 processor has floating-point registers. We shouldn't be using it
424 on PowerPC variants that lack them. */
425 gdb_assert (ppc_floating_point_unit_p (gdbarch
));
427 /* AltiVec extension: Functions that declare a vector data type as a
428 return value place that return value in VR2. */
429 if (TYPE_CODE (valtype
) == TYPE_CODE_ARRAY
&& TYPE_VECTOR (valtype
)
430 && TYPE_LENGTH (valtype
) == 16)
433 regcache_cooked_read (regcache
, tdep
->ppc_vr0_regnum
+ 2, readbuf
);
435 regcache_cooked_write (regcache
, tdep
->ppc_vr0_regnum
+ 2, writebuf
);
437 return RETURN_VALUE_REGISTER_CONVENTION
;
440 /* If the called subprogram returns an aggregate, there exists an
441 implicit first argument, whose value is the address of a caller-
442 allocated buffer into which the callee is assumed to store its
443 return value. All explicit parameters are appropriately
445 if (TYPE_CODE (valtype
) == TYPE_CODE_STRUCT
446 || TYPE_CODE (valtype
) == TYPE_CODE_UNION
447 || TYPE_CODE (valtype
) == TYPE_CODE_ARRAY
)
448 return RETURN_VALUE_STRUCT_CONVENTION
;
450 /* Scalar floating-point values are returned in FPR1 for float or
451 double, and in FPR1:FPR2 for quadword precision. Fortran
452 complex*8 and complex*16 are returned in FPR1:FPR2, and
453 complex*32 is returned in FPR1:FPR4. */
454 if (TYPE_CODE (valtype
) == TYPE_CODE_FLT
455 && (TYPE_LENGTH (valtype
) == 4 || TYPE_LENGTH (valtype
) == 8))
457 struct type
*regtype
= register_type (gdbarch
, tdep
->ppc_fp0_regnum
);
460 /* FIXME: kettenis/2007-01-01: Add support for quadword
461 precision and complex. */
465 regcache_cooked_read (regcache
, tdep
->ppc_fp0_regnum
+ 1, regval
);
466 target_float_convert (regval
, regtype
, readbuf
, valtype
);
470 target_float_convert (writebuf
, valtype
, regval
, regtype
);
471 regcache_cooked_write (regcache
, tdep
->ppc_fp0_regnum
+ 1, regval
);
474 return RETURN_VALUE_REGISTER_CONVENTION
;
477 /* Values of the types int, long, short, pointer, and char (length
478 is less than or equal to four bytes), as well as bit values of
479 lengths less than or equal to 32 bits, must be returned right
480 justified in GPR3 with signed values sign extended and unsigned
481 values zero extended, as necessary. */
482 if (TYPE_LENGTH (valtype
) <= tdep
->wordsize
)
488 /* For reading we don't have to worry about sign extension. */
489 regcache_cooked_read_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
491 store_unsigned_integer (readbuf
, TYPE_LENGTH (valtype
), byte_order
,
496 /* For writing, use unpack_long since that should handle any
497 required sign extension. */
498 regcache_cooked_write_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
499 unpack_long (valtype
, writebuf
));
502 return RETURN_VALUE_REGISTER_CONVENTION
;
505 /* Eight-byte non-floating-point scalar values must be returned in
508 if (TYPE_LENGTH (valtype
) == 8)
510 gdb_assert (TYPE_CODE (valtype
) != TYPE_CODE_FLT
);
511 gdb_assert (tdep
->wordsize
== 4);
517 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 3, regval
);
518 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 4,
520 memcpy (readbuf
, regval
, 8);
524 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 3, writebuf
);
525 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 4,
529 return RETURN_VALUE_REGISTER_CONVENTION
;
532 return RETURN_VALUE_STRUCT_CONVENTION
;
535 /* Support for CONVERT_FROM_FUNC_PTR_ADDR (ARCH, ADDR, TARG).
537 Usually a function pointer's representation is simply the address
538 of the function. On the RS/6000 however, a function pointer is
539 represented by a pointer to an OPD entry. This OPD entry contains
540 three words, the first word is the address of the function, the
541 second word is the TOC pointer (r2), and the third word is the
542 static chain value. Throughout GDB it is currently assumed that a
543 function pointer contains the address of the function, which is not
544 easy to fix. In addition, the conversion of a function address to
545 a function pointer would require allocation of an OPD entry in the
546 inferior's memory space, with all its drawbacks. To be able to
547 call C++ virtual methods in the inferior (which are called via
548 function pointers), find_function_addr uses this function to get the
549 function address from a function pointer. */
551 /* Return real function address if ADDR (a function pointer) is in the data
552 space and is therefore a special function pointer. */
555 rs6000_convert_from_func_ptr_addr (struct gdbarch
*gdbarch
,
557 struct target_ops
*targ
)
559 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
560 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
561 struct obj_section
*s
;
563 s
= find_pc_section (addr
);
565 /* Normally, functions live inside a section that is executable.
566 So, if ADDR points to a non-executable section, then treat it
567 as a function descriptor and return the target address iff
568 the target address itself points to a section that is executable. */
569 if (s
&& (s
->the_bfd_section
->flags
& SEC_CODE
) == 0)
572 struct obj_section
*pc_section
;
576 pc
= read_memory_unsigned_integer (addr
, tdep
->wordsize
, byte_order
);
578 CATCH (e
, RETURN_MASK_ERROR
)
580 /* An error occured during reading. Probably a memory error
581 due to the section not being loaded yet. This address
582 cannot be a function descriptor. */
587 pc_section
= find_pc_section (pc
);
589 if (pc_section
&& (pc_section
->the_bfd_section
->flags
& SEC_CODE
))
597 /* Calculate the destination of a branch/jump. Return -1 if not a branch. */
600 branch_dest (struct regcache
*regcache
, int opcode
, int instr
,
601 CORE_ADDR pc
, CORE_ADDR safety
)
603 struct gdbarch
*gdbarch
= regcache
->arch ();
604 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
605 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
611 absolute
= (int) ((instr
>> 1) & 1);
616 immediate
= ((instr
& ~3) << 6) >> 6; /* br unconditional */
620 dest
= pc
+ immediate
;
624 immediate
= ((instr
& ~3) << 16) >> 16; /* br conditional */
628 dest
= pc
+ immediate
;
632 ext_op
= (instr
>> 1) & 0x3ff;
634 if (ext_op
== 16) /* br conditional register */
636 dest
= regcache_raw_get_unsigned (regcache
, tdep
->ppc_lr_regnum
) & ~3;
638 /* If we are about to return from a signal handler, dest is
639 something like 0x3c90. The current frame is a signal handler
640 caller frame, upon completion of the sigreturn system call
641 execution will return to the saved PC in the frame. */
642 if (dest
< AIX_TEXT_SEGMENT_BASE
)
644 struct frame_info
*frame
= get_current_frame ();
646 dest
= read_memory_unsigned_integer
647 (get_frame_base (frame
) + SIG_FRAME_PC_OFFSET
,
648 tdep
->wordsize
, byte_order
);
652 else if (ext_op
== 528) /* br cond to count reg */
654 dest
= regcache_raw_get_unsigned (regcache
,
655 tdep
->ppc_ctr_regnum
) & ~3;
657 /* If we are about to execute a system call, dest is something
658 like 0x22fc or 0x3b00. Upon completion the system call
659 will return to the address in the link register. */
660 if (dest
< AIX_TEXT_SEGMENT_BASE
)
661 dest
= regcache_raw_get_unsigned (regcache
,
662 tdep
->ppc_lr_regnum
) & ~3;
671 return (dest
< AIX_TEXT_SEGMENT_BASE
) ? safety
: dest
;
674 /* AIX does not support PT_STEP. Simulate it. */
676 static std::vector
<CORE_ADDR
>
677 rs6000_software_single_step (struct regcache
*regcache
)
679 struct gdbarch
*gdbarch
= regcache
->arch ();
680 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
686 loc
= regcache_read_pc (regcache
);
688 insn
= read_memory_integer (loc
, 4, byte_order
);
690 std::vector
<CORE_ADDR
> next_pcs
= ppc_deal_with_atomic_sequence (regcache
);
691 if (!next_pcs
.empty ())
694 breaks
[0] = loc
+ PPC_INSN_SIZE
;
696 breaks
[1] = branch_dest (regcache
, opcode
, insn
, loc
, breaks
[0]);
698 /* Don't put two breakpoints on the same address. */
699 if (breaks
[1] == breaks
[0])
702 for (ii
= 0; ii
< 2; ++ii
)
704 /* ignore invalid breakpoint. */
705 if (breaks
[ii
] == -1)
708 next_pcs
.push_back (breaks
[ii
]);
711 errno
= 0; /* FIXME, don't ignore errors! */
712 /* What errors? {read,write}_memory call error(). */
716 /* Implement the "auto_wide_charset" gdbarch method for this platform. */
719 rs6000_aix_auto_wide_charset (void)
724 /* Implement an osabi sniffer for RS6000/AIX.
726 This function assumes that ABFD's flavour is XCOFF. In other words,
727 it should be registered as a sniffer for bfd_target_xcoff_flavour
728 objfiles only. A failed assertion will be raised if this condition
731 static enum gdb_osabi
732 rs6000_aix_osabi_sniffer (bfd
*abfd
)
734 gdb_assert (bfd_get_flavour (abfd
) == bfd_target_xcoff_flavour
);
736 /* The only noticeable difference between Lynx178 XCOFF files and
737 AIX XCOFF files comes from the fact that there are no shared
738 libraries on Lynx178. On AIX, we are betting that an executable
739 linked with no shared library will never exist. */
740 if (xcoff_get_n_import_files (abfd
) <= 0)
741 return GDB_OSABI_UNKNOWN
;
743 return GDB_OSABI_AIX
;
746 /* A structure encoding the offset and size of a field within
755 /* A structure describing the layout of all the fields of interest
756 in AIX's struct ld_info. Each field in this struct corresponds
757 to the field of the same name in struct ld_info. */
761 struct field_info ldinfo_next
;
762 struct field_info ldinfo_fd
;
763 struct field_info ldinfo_textorg
;
764 struct field_info ldinfo_textsize
;
765 struct field_info ldinfo_dataorg
;
766 struct field_info ldinfo_datasize
;
767 struct field_info ldinfo_filename
;
770 /* The following data has been generated by compiling and running
771 the following program on AIX 5.3. */
776 #define __LDINFO_PTRACE32__
777 #define __LDINFO_PTRACE64__
780 #define pinfo(type,member) \
782 struct type ldi = {0}; \
784 printf (" {%d, %d},\t/* %s */\n", \
785 offsetof (struct type, member), \
786 sizeof (ldi.member), \
794 printf ("static const struct ld_info_desc ld_info32_desc =\n{\n");
795 pinfo (__ld_info32
, ldinfo_next
);
796 pinfo (__ld_info32
, ldinfo_fd
);
797 pinfo (__ld_info32
, ldinfo_textorg
);
798 pinfo (__ld_info32
, ldinfo_textsize
);
799 pinfo (__ld_info32
, ldinfo_dataorg
);
800 pinfo (__ld_info32
, ldinfo_datasize
);
801 pinfo (__ld_info32
, ldinfo_filename
);
806 printf ("static const struct ld_info_desc ld_info64_desc =\n{\n");
807 pinfo (__ld_info64
, ldinfo_next
);
808 pinfo (__ld_info64
, ldinfo_fd
);
809 pinfo (__ld_info64
, ldinfo_textorg
);
810 pinfo (__ld_info64
, ldinfo_textsize
);
811 pinfo (__ld_info64
, ldinfo_dataorg
);
812 pinfo (__ld_info64
, ldinfo_datasize
);
813 pinfo (__ld_info64
, ldinfo_filename
);
820 /* Layout of the 32bit version of struct ld_info. */
822 static const struct ld_info_desc ld_info32_desc
=
824 {0, 4}, /* ldinfo_next */
825 {4, 4}, /* ldinfo_fd */
826 {8, 4}, /* ldinfo_textorg */
827 {12, 4}, /* ldinfo_textsize */
828 {16, 4}, /* ldinfo_dataorg */
829 {20, 4}, /* ldinfo_datasize */
830 {24, 2}, /* ldinfo_filename */
833 /* Layout of the 64bit version of struct ld_info. */
835 static const struct ld_info_desc ld_info64_desc
=
837 {0, 4}, /* ldinfo_next */
838 {8, 4}, /* ldinfo_fd */
839 {16, 8}, /* ldinfo_textorg */
840 {24, 8}, /* ldinfo_textsize */
841 {32, 8}, /* ldinfo_dataorg */
842 {40, 8}, /* ldinfo_datasize */
843 {48, 2}, /* ldinfo_filename */
846 /* A structured representation of one entry read from the ld_info
847 binary data provided by the AIX loader. */
861 /* Return a struct ld_info object corresponding to the entry at
864 Note that the filename and member_name strings still point
865 to the data in LDI_BUF. So LDI_BUF must not be deallocated
866 while the struct ld_info object returned is in use. */
868 static struct ld_info
869 rs6000_aix_extract_ld_info (struct gdbarch
*gdbarch
,
870 const gdb_byte
*ldi_buf
)
872 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
873 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
874 struct type
*ptr_type
= builtin_type (gdbarch
)->builtin_data_ptr
;
875 const struct ld_info_desc desc
876 = tdep
->wordsize
== 8 ? ld_info64_desc
: ld_info32_desc
;
879 info
.next
= extract_unsigned_integer (ldi_buf
+ desc
.ldinfo_next
.offset
,
880 desc
.ldinfo_next
.size
,
882 info
.fd
= extract_signed_integer (ldi_buf
+ desc
.ldinfo_fd
.offset
,
885 info
.textorg
= extract_typed_address (ldi_buf
+ desc
.ldinfo_textorg
.offset
,
888 = extract_unsigned_integer (ldi_buf
+ desc
.ldinfo_textsize
.offset
,
889 desc
.ldinfo_textsize
.size
,
891 info
.dataorg
= extract_typed_address (ldi_buf
+ desc
.ldinfo_dataorg
.offset
,
894 = extract_unsigned_integer (ldi_buf
+ desc
.ldinfo_datasize
.offset
,
895 desc
.ldinfo_datasize
.size
,
897 info
.filename
= (char *) ldi_buf
+ desc
.ldinfo_filename
.offset
;
898 info
.member_name
= info
.filename
+ strlen (info
.filename
) + 1;
903 /* Append to OBJSTACK an XML string description of the shared library
904 corresponding to LDI, following the TARGET_OBJECT_LIBRARIES_AIX
908 rs6000_aix_shared_library_to_xml (struct ld_info
*ldi
,
909 struct obstack
*obstack
)
911 obstack_grow_str (obstack
, "<library name=\"");
912 std::string p
= xml_escape_text (ldi
->filename
);
913 obstack_grow_str (obstack
, p
.c_str ());
914 obstack_grow_str (obstack
, "\"");
916 if (ldi
->member_name
[0] != '\0')
918 obstack_grow_str (obstack
, " member=\"");
919 p
= xml_escape_text (ldi
->member_name
);
920 obstack_grow_str (obstack
, p
.c_str ());
921 obstack_grow_str (obstack
, "\"");
924 obstack_grow_str (obstack
, " text_addr=\"");
925 obstack_grow_str (obstack
, core_addr_to_string (ldi
->textorg
));
926 obstack_grow_str (obstack
, "\"");
928 obstack_grow_str (obstack
, " text_size=\"");
929 obstack_grow_str (obstack
, pulongest (ldi
->textsize
));
930 obstack_grow_str (obstack
, "\"");
932 obstack_grow_str (obstack
, " data_addr=\"");
933 obstack_grow_str (obstack
, core_addr_to_string (ldi
->dataorg
));
934 obstack_grow_str (obstack
, "\"");
936 obstack_grow_str (obstack
, " data_size=\"");
937 obstack_grow_str (obstack
, pulongest (ldi
->datasize
));
938 obstack_grow_str (obstack
, "\"");
940 obstack_grow_str (obstack
, "></library>");
943 /* Convert the ld_info binary data provided by the AIX loader into
944 an XML representation following the TARGET_OBJECT_LIBRARIES_AIX
947 LDI_BUF is a buffer containing the ld_info data.
948 READBUF, OFFSET and LEN follow the same semantics as target_ops'
949 to_xfer_partial target_ops method.
951 If CLOSE_LDINFO_FD is nonzero, then this routine also closes
952 the ldinfo_fd file descriptor. This is useful when the ldinfo
953 data is obtained via ptrace, as ptrace opens a file descriptor
954 for each and every entry; but we cannot use this descriptor
955 as the consumer of the XML library list might live in a different
959 rs6000_aix_ld_info_to_xml (struct gdbarch
*gdbarch
, const gdb_byte
*ldi_buf
,
960 gdb_byte
*readbuf
, ULONGEST offset
, ULONGEST len
,
963 struct obstack obstack
;
967 obstack_init (&obstack
);
968 obstack_grow_str (&obstack
, "<library-list-aix version=\"1.0\">\n");
972 struct ld_info ldi
= rs6000_aix_extract_ld_info (gdbarch
, ldi_buf
);
974 rs6000_aix_shared_library_to_xml (&ldi
, &obstack
);
980 ldi_buf
= ldi_buf
+ ldi
.next
;
983 obstack_grow_str0 (&obstack
, "</library-list-aix>\n");
985 buf
= (const char *) obstack_finish (&obstack
);
986 len_avail
= strlen (buf
);
987 if (offset
>= len_avail
)
991 if (len
> len_avail
- offset
)
992 len
= len_avail
- offset
;
993 memcpy (readbuf
, buf
+ offset
, len
);
996 obstack_free (&obstack
, NULL
);
1000 /* Implement the core_xfer_shared_libraries_aix gdbarch method. */
1003 rs6000_aix_core_xfer_shared_libraries_aix (struct gdbarch
*gdbarch
,
1008 struct bfd_section
*ldinfo_sec
;
1010 gdb_byte
*ldinfo_buf
;
1011 struct cleanup
*cleanup
;
1014 ldinfo_sec
= bfd_get_section_by_name (core_bfd
, ".ldinfo");
1015 if (ldinfo_sec
== NULL
)
1016 error (_("cannot find .ldinfo section from core file: %s"),
1017 bfd_errmsg (bfd_get_error ()));
1018 ldinfo_size
= bfd_get_section_size (ldinfo_sec
);
1020 ldinfo_buf
= (gdb_byte
*) xmalloc (ldinfo_size
);
1021 cleanup
= make_cleanup (xfree
, ldinfo_buf
);
1023 if (! bfd_get_section_contents (core_bfd
, ldinfo_sec
,
1024 ldinfo_buf
, 0, ldinfo_size
))
1025 error (_("unable to read .ldinfo section from core file: %s"),
1026 bfd_errmsg (bfd_get_error ()));
1028 result
= rs6000_aix_ld_info_to_xml (gdbarch
, ldinfo_buf
, readbuf
,
1031 do_cleanups (cleanup
);
1036 rs6000_aix_init_osabi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
1038 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1040 /* RS6000/AIX does not support PT_STEP. Has to be simulated. */
1041 set_gdbarch_software_single_step (gdbarch
, rs6000_software_single_step
);
1043 /* Displaced stepping is currently not supported in combination with
1044 software single-stepping. */
1045 set_gdbarch_displaced_step_copy_insn (gdbarch
, NULL
);
1046 set_gdbarch_displaced_step_fixup (gdbarch
, NULL
);
1047 set_gdbarch_displaced_step_location (gdbarch
, NULL
);
1049 set_gdbarch_push_dummy_call (gdbarch
, rs6000_push_dummy_call
);
1050 set_gdbarch_return_value (gdbarch
, rs6000_return_value
);
1051 set_gdbarch_long_double_bit (gdbarch
, 8 * TARGET_CHAR_BIT
);
1053 /* Handle RS/6000 function pointers (which are really function
1055 set_gdbarch_convert_from_func_ptr_addr
1056 (gdbarch
, rs6000_convert_from_func_ptr_addr
);
1058 /* Core file support. */
1059 set_gdbarch_iterate_over_regset_sections
1060 (gdbarch
, rs6000_aix_iterate_over_regset_sections
);
1061 set_gdbarch_core_xfer_shared_libraries_aix
1062 (gdbarch
, rs6000_aix_core_xfer_shared_libraries_aix
);
1064 if (tdep
->wordsize
== 8)
1065 tdep
->lr_frame_offset
= 16;
1067 tdep
->lr_frame_offset
= 8;
1069 if (tdep
->wordsize
== 4)
1070 /* PowerOpen / AIX 32 bit. The saved area or red zone consists of
1071 19 4 byte GPRS + 18 8 byte FPRs giving a total of 220 bytes.
1072 Problem is, 220 isn't frame (16 byte) aligned. Round it up to
1074 set_gdbarch_frame_red_zone_size (gdbarch
, 224);
1076 set_gdbarch_frame_red_zone_size (gdbarch
, 0);
1078 if (tdep
->wordsize
== 8)
1079 set_gdbarch_wchar_bit (gdbarch
, 32);
1081 set_gdbarch_wchar_bit (gdbarch
, 16);
1082 set_gdbarch_wchar_signed (gdbarch
, 0);
1083 set_gdbarch_auto_wide_charset (gdbarch
, rs6000_aix_auto_wide_charset
);
1085 set_solib_ops (gdbarch
, &solib_aix_so_ops
);
1089 _initialize_rs6000_aix_tdep (void)
1091 gdbarch_register_osabi_sniffer (bfd_arch_rs6000
,
1092 bfd_target_xcoff_flavour
,
1093 rs6000_aix_osabi_sniffer
);
1094 gdbarch_register_osabi_sniffer (bfd_arch_powerpc
,
1095 bfd_target_xcoff_flavour
,
1096 rs6000_aix_osabi_sniffer
);
1098 gdbarch_register_osabi (bfd_arch_rs6000
, 0, GDB_OSABI_AIX
,
1099 rs6000_aix_init_osabi
);
1100 gdbarch_register_osabi (bfd_arch_powerpc
, 0, GDB_OSABI_AIX
,
1101 rs6000_aix_init_osabi
);