1 /* Native support code for PPC AIX, for GDB the GNU debugger.
3 Copyright (C) 2006-2014 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/>. */
33 #include "breakpoint.h"
34 #include "rs6000-tdep.h"
36 #include "rs6000-aix-tdep.h"
37 #include "exceptions.h"
38 #include "xcoffread.h"
40 #include "solib-aix.h"
41 #include "xml-utils.h"
43 /* If the kernel has to deliver a signal, it pushes a sigcontext
44 structure on the stack and then calls the signal handler, passing
45 the address of the sigcontext in an argument register. Usually
46 the signal handler doesn't save this register, so we have to
47 access the sigcontext structure via an offset from the signal handler
49 The following constants were determined by experimentation on AIX 3.2. */
50 #define SIG_FRAME_PC_OFFSET 96
51 #define SIG_FRAME_LR_OFFSET 108
52 #define SIG_FRAME_FP_OFFSET 284
55 /* Core file support. */
57 static struct ppc_reg_offsets rs6000_aix32_reg_offsets
=
59 /* General-purpose registers. */
71 /* Floating-point registers. */
73 56, /* fpscr_offset */
76 /* AltiVec registers. */
79 -1 /* vrsave_offset */
82 static struct ppc_reg_offsets rs6000_aix64_reg_offsets
=
84 /* General-purpose registers. */
96 /* Floating-point registers. */
98 296, /* fpscr_offset */
101 /* AltiVec registers. */
103 -1, /* vscr_offset */
104 -1 /* vrsave_offset */
108 /* Supply register REGNUM in the general-purpose register set REGSET
109 from the buffer specified by GREGS and LEN to register cache
110 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
113 rs6000_aix_supply_regset (const struct regset
*regset
,
114 struct regcache
*regcache
, int regnum
,
115 const void *gregs
, size_t len
)
117 ppc_supply_gregset (regset
, regcache
, regnum
, gregs
, len
);
118 ppc_supply_fpregset (regset
, regcache
, regnum
, gregs
, len
);
121 /* Collect register REGNUM in the general-purpose register set
122 REGSET, from register cache REGCACHE into the buffer specified by
123 GREGS and LEN. If REGNUM is -1, do this for all registers in
127 rs6000_aix_collect_regset (const struct regset
*regset
,
128 const struct regcache
*regcache
, int regnum
,
129 void *gregs
, size_t len
)
131 ppc_collect_gregset (regset
, regcache
, regnum
, gregs
, len
);
132 ppc_collect_fpregset (regset
, regcache
, regnum
, gregs
, len
);
135 /* AIX register set. */
137 static const struct regset rs6000_aix32_regset
=
139 &rs6000_aix32_reg_offsets
,
140 rs6000_aix_supply_regset
,
141 rs6000_aix_collect_regset
,
144 static const struct regset rs6000_aix64_regset
=
146 &rs6000_aix64_reg_offsets
,
147 rs6000_aix_supply_regset
,
148 rs6000_aix_collect_regset
,
151 /* Return the appropriate register set for the core section identified
152 by SECT_NAME and SECT_SIZE. */
154 static const struct regset
*
155 rs6000_aix_regset_from_core_section (struct gdbarch
*gdbarch
,
156 const char *sect_name
, size_t sect_size
)
158 if (gdbarch_tdep (gdbarch
)->wordsize
== 4)
160 if (strcmp (sect_name
, ".reg") == 0 && sect_size
>= 592)
161 return &rs6000_aix32_regset
;
165 if (strcmp (sect_name
, ".reg") == 0 && sect_size
>= 576)
166 return &rs6000_aix64_regset
;
173 /* Pass the arguments in either registers, or in the stack. In RS/6000,
174 the first eight words of the argument list (that might be less than
175 eight parameters if some parameters occupy more than one word) are
176 passed in r3..r10 registers. Float and double parameters are
177 passed in fpr's, in addition to that. Rest of the parameters if any
178 are passed in user stack. There might be cases in which half of the
179 parameter is copied into registers, the other half is pushed into
182 Stack must be aligned on 64-bit boundaries when synthesizing
185 If the function is returning a structure, then the return address is passed
186 in r3, then the first 7 words of the parameters can be passed in registers,
190 rs6000_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
191 struct regcache
*regcache
, CORE_ADDR bp_addr
,
192 int nargs
, struct value
**args
, CORE_ADDR sp
,
193 int struct_return
, CORE_ADDR struct_addr
)
195 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
196 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
199 int argno
; /* current argument number */
200 int argbytes
; /* current argument byte */
201 gdb_byte tmp_buffer
[50];
202 int f_argno
= 0; /* current floating point argno */
203 int wordsize
= gdbarch_tdep (gdbarch
)->wordsize
;
204 CORE_ADDR func_addr
= find_function_addr (function
, NULL
);
206 struct value
*arg
= 0;
211 /* The calling convention this function implements assumes the
212 processor has floating-point registers. We shouldn't be using it
213 on PPC variants that lack them. */
214 gdb_assert (ppc_floating_point_unit_p (gdbarch
));
216 /* The first eight words of ther arguments are passed in registers.
217 Copy them appropriately. */
220 /* If the function is returning a `struct', then the first word
221 (which will be passed in r3) is used for struct return address.
222 In that case we should advance one word and start from r4
223 register to copy parameters. */
226 regcache_raw_write_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
231 /* effectively indirect call... gcc does...
233 return_val example( float, int);
236 float in fp0, int in r3
237 offset of stack on overflow 8/16
238 for varargs, must go by type.
240 float in r3&r4, int in r5
241 offset of stack on overflow different
243 return in r3 or f0. If no float, must study how gcc emulates floats;
244 pay attention to arg promotion.
245 User may have to cast\args to handle promotion correctly
246 since gdb won't know if prototype supplied or not. */
248 for (argno
= 0, argbytes
= 0; argno
< nargs
&& ii
< 8; ++ii
)
250 int reg_size
= register_size (gdbarch
, ii
+ 3);
253 type
= check_typedef (value_type (arg
));
254 len
= TYPE_LENGTH (type
);
256 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
258 /* Floating point arguments are passed in fpr's, as well as gpr's.
259 There are 13 fpr's reserved for passing parameters. At this point
260 there is no way we would run out of them.
262 Always store the floating point value using the register's
263 floating-point format. */
264 const int fp_regnum
= tdep
->ppc_fp0_regnum
+ 1 + f_argno
;
265 gdb_byte reg_val
[MAX_REGISTER_SIZE
];
266 struct type
*reg_type
= register_type (gdbarch
, fp_regnum
);
268 gdb_assert (len
<= 8);
270 convert_typed_floating (value_contents (arg
), type
,
272 regcache_cooked_write (regcache
, fp_regnum
, reg_val
);
279 /* Argument takes more than one register. */
280 while (argbytes
< len
)
282 gdb_byte word
[MAX_REGISTER_SIZE
];
283 memset (word
, 0, reg_size
);
285 ((char *) value_contents (arg
)) + argbytes
,
286 (len
- argbytes
) > reg_size
287 ? reg_size
: len
- argbytes
);
288 regcache_cooked_write (regcache
,
289 tdep
->ppc_gp0_regnum
+ 3 + ii
,
291 ++ii
, argbytes
+= reg_size
;
294 goto ran_out_of_registers_for_arguments
;
301 /* Argument can fit in one register. No problem. */
302 int adj
= gdbarch_byte_order (gdbarch
)
303 == BFD_ENDIAN_BIG
? reg_size
- len
: 0;
304 gdb_byte word
[MAX_REGISTER_SIZE
];
306 memset (word
, 0, reg_size
);
307 memcpy (word
, value_contents (arg
), len
);
308 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 3 +ii
, word
);
313 ran_out_of_registers_for_arguments
:
315 regcache_cooked_read_unsigned (regcache
,
316 gdbarch_sp_regnum (gdbarch
),
319 /* Location for 8 parameters are always reserved. */
322 /* Another six words for back chain, TOC register, link register, etc. */
325 /* Stack pointer must be quadword aligned. */
328 /* If there are more arguments, allocate space for them in
329 the stack, then push them starting from the ninth one. */
331 if ((argno
< nargs
) || argbytes
)
337 space
+= ((len
- argbytes
+ 3) & -4);
343 for (; jj
< nargs
; ++jj
)
345 struct value
*val
= args
[jj
];
346 space
+= ((TYPE_LENGTH (value_type (val
))) + 3) & -4;
349 /* Add location required for the rest of the parameters. */
350 space
= (space
+ 15) & -16;
353 /* This is another instance we need to be concerned about
354 securing our stack space. If we write anything underneath %sp
355 (r1), we might conflict with the kernel who thinks he is free
356 to use this area. So, update %sp first before doing anything
359 regcache_raw_write_signed (regcache
,
360 gdbarch_sp_regnum (gdbarch
), sp
);
362 /* If the last argument copied into the registers didn't fit there
363 completely, push the rest of it into stack. */
367 write_memory (sp
+ 24 + (ii
* 4),
368 value_contents (arg
) + argbytes
,
371 ii
+= ((len
- argbytes
+ 3) & -4) / 4;
374 /* Push the rest of the arguments into stack. */
375 for (; argno
< nargs
; ++argno
)
379 type
= check_typedef (value_type (arg
));
380 len
= TYPE_LENGTH (type
);
383 /* Float types should be passed in fpr's, as well as in the
385 if (TYPE_CODE (type
) == TYPE_CODE_FLT
&& f_argno
< 13)
388 gdb_assert (len
<= 8);
390 regcache_cooked_write (regcache
,
391 tdep
->ppc_fp0_regnum
+ 1 + f_argno
,
392 value_contents (arg
));
396 write_memory (sp
+ 24 + (ii
* 4), value_contents (arg
), len
);
397 ii
+= ((len
+ 3) & -4) / 4;
401 /* Set the stack pointer. According to the ABI, the SP is meant to
402 be set _before_ the corresponding stack space is used. On AIX,
403 this even applies when the target has been completely stopped!
404 Not doing this can lead to conflicts with the kernel which thinks
405 that it still has control over this not-yet-allocated stack
407 regcache_raw_write_signed (regcache
, gdbarch_sp_regnum (gdbarch
), sp
);
409 /* Set back chain properly. */
410 store_unsigned_integer (tmp_buffer
, wordsize
, byte_order
, saved_sp
);
411 write_memory (sp
, tmp_buffer
, wordsize
);
413 /* Point the inferior function call's return address at the dummy's
415 regcache_raw_write_signed (regcache
, tdep
->ppc_lr_regnum
, bp_addr
);
417 /* Set the TOC register value. */
418 regcache_raw_write_signed (regcache
, tdep
->ppc_toc_regnum
,
419 solib_aix_get_toc_value (func_addr
));
421 target_store_registers (regcache
, -1);
425 static enum return_value_convention
426 rs6000_return_value (struct gdbarch
*gdbarch
, struct value
*function
,
427 struct type
*valtype
, struct regcache
*regcache
,
428 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
430 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
431 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
433 /* The calling convention this function implements assumes the
434 processor has floating-point registers. We shouldn't be using it
435 on PowerPC variants that lack them. */
436 gdb_assert (ppc_floating_point_unit_p (gdbarch
));
438 /* AltiVec extension: Functions that declare a vector data type as a
439 return value place that return value in VR2. */
440 if (TYPE_CODE (valtype
) == TYPE_CODE_ARRAY
&& TYPE_VECTOR (valtype
)
441 && TYPE_LENGTH (valtype
) == 16)
444 regcache_cooked_read (regcache
, tdep
->ppc_vr0_regnum
+ 2, readbuf
);
446 regcache_cooked_write (regcache
, tdep
->ppc_vr0_regnum
+ 2, writebuf
);
448 return RETURN_VALUE_REGISTER_CONVENTION
;
451 /* If the called subprogram returns an aggregate, there exists an
452 implicit first argument, whose value is the address of a caller-
453 allocated buffer into which the callee is assumed to store its
454 return value. All explicit parameters are appropriately
456 if (TYPE_CODE (valtype
) == TYPE_CODE_STRUCT
457 || TYPE_CODE (valtype
) == TYPE_CODE_UNION
458 || TYPE_CODE (valtype
) == TYPE_CODE_ARRAY
)
459 return RETURN_VALUE_STRUCT_CONVENTION
;
461 /* Scalar floating-point values are returned in FPR1 for float or
462 double, and in FPR1:FPR2 for quadword precision. Fortran
463 complex*8 and complex*16 are returned in FPR1:FPR2, and
464 complex*32 is returned in FPR1:FPR4. */
465 if (TYPE_CODE (valtype
) == TYPE_CODE_FLT
466 && (TYPE_LENGTH (valtype
) == 4 || TYPE_LENGTH (valtype
) == 8))
468 struct type
*regtype
= register_type (gdbarch
, tdep
->ppc_fp0_regnum
);
471 /* FIXME: kettenis/2007-01-01: Add support for quadword
472 precision and complex. */
476 regcache_cooked_read (regcache
, tdep
->ppc_fp0_regnum
+ 1, regval
);
477 convert_typed_floating (regval
, regtype
, readbuf
, valtype
);
481 convert_typed_floating (writebuf
, valtype
, regval
, regtype
);
482 regcache_cooked_write (regcache
, tdep
->ppc_fp0_regnum
+ 1, regval
);
485 return RETURN_VALUE_REGISTER_CONVENTION
;
488 /* Values of the types int, long, short, pointer, and char (length
489 is less than or equal to four bytes), as well as bit values of
490 lengths less than or equal to 32 bits, must be returned right
491 justified in GPR3 with signed values sign extended and unsigned
492 values zero extended, as necessary. */
493 if (TYPE_LENGTH (valtype
) <= tdep
->wordsize
)
499 /* For reading we don't have to worry about sign extension. */
500 regcache_cooked_read_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
502 store_unsigned_integer (readbuf
, TYPE_LENGTH (valtype
), byte_order
,
507 /* For writing, use unpack_long since that should handle any
508 required sign extension. */
509 regcache_cooked_write_unsigned (regcache
, tdep
->ppc_gp0_regnum
+ 3,
510 unpack_long (valtype
, writebuf
));
513 return RETURN_VALUE_REGISTER_CONVENTION
;
516 /* Eight-byte non-floating-point scalar values must be returned in
519 if (TYPE_LENGTH (valtype
) == 8)
521 gdb_assert (TYPE_CODE (valtype
) != TYPE_CODE_FLT
);
522 gdb_assert (tdep
->wordsize
== 4);
528 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 3, regval
);
529 regcache_cooked_read (regcache
, tdep
->ppc_gp0_regnum
+ 4,
531 memcpy (readbuf
, regval
, 8);
535 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 3, writebuf
);
536 regcache_cooked_write (regcache
, tdep
->ppc_gp0_regnum
+ 4,
540 return RETURN_VALUE_REGISTER_CONVENTION
;
543 return RETURN_VALUE_STRUCT_CONVENTION
;
546 /* Support for CONVERT_FROM_FUNC_PTR_ADDR (ARCH, ADDR, TARG).
548 Usually a function pointer's representation is simply the address
549 of the function. On the RS/6000 however, a function pointer is
550 represented by a pointer to an OPD entry. This OPD entry contains
551 three words, the first word is the address of the function, the
552 second word is the TOC pointer (r2), and the third word is the
553 static chain value. Throughout GDB it is currently assumed that a
554 function pointer contains the address of the function, which is not
555 easy to fix. In addition, the conversion of a function address to
556 a function pointer would require allocation of an OPD entry in the
557 inferior's memory space, with all its drawbacks. To be able to
558 call C++ virtual methods in the inferior (which are called via
559 function pointers), find_function_addr uses this function to get the
560 function address from a function pointer. */
562 /* Return real function address if ADDR (a function pointer) is in the data
563 space and is therefore a special function pointer. */
566 rs6000_convert_from_func_ptr_addr (struct gdbarch
*gdbarch
,
568 struct target_ops
*targ
)
570 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
571 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
572 struct obj_section
*s
;
574 s
= find_pc_section (addr
);
576 /* Normally, functions live inside a section that is executable.
577 So, if ADDR points to a non-executable section, then treat it
578 as a function descriptor and return the target address iff
579 the target address itself points to a section that is executable. */
580 if (s
&& (s
->the_bfd_section
->flags
& SEC_CODE
) == 0)
583 struct obj_section
*pc_section
;
584 volatile struct gdb_exception e
;
586 TRY_CATCH (e
, RETURN_MASK_ERROR
)
588 pc
= read_memory_unsigned_integer (addr
, tdep
->wordsize
, byte_order
);
592 /* An error occured during reading. Probably a memory error
593 due to the section not being loaded yet. This address
594 cannot be a function descriptor. */
597 pc_section
= find_pc_section (pc
);
599 if (pc_section
&& (pc_section
->the_bfd_section
->flags
& SEC_CODE
))
607 /* Calculate the destination of a branch/jump. Return -1 if not a branch. */
610 branch_dest (struct frame_info
*frame
, int opcode
, int instr
,
611 CORE_ADDR pc
, CORE_ADDR safety
)
613 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
614 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
615 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
621 absolute
= (int) ((instr
>> 1) & 1);
626 immediate
= ((instr
& ~3) << 6) >> 6; /* br unconditional */
630 dest
= pc
+ immediate
;
634 immediate
= ((instr
& ~3) << 16) >> 16; /* br conditional */
638 dest
= pc
+ immediate
;
642 ext_op
= (instr
>> 1) & 0x3ff;
644 if (ext_op
== 16) /* br conditional register */
646 dest
= get_frame_register_unsigned (frame
, tdep
->ppc_lr_regnum
) & ~3;
648 /* If we are about to return from a signal handler, dest is
649 something like 0x3c90. The current frame is a signal handler
650 caller frame, upon completion of the sigreturn system call
651 execution will return to the saved PC in the frame. */
652 if (dest
< AIX_TEXT_SEGMENT_BASE
)
653 dest
= read_memory_unsigned_integer
654 (get_frame_base (frame
) + SIG_FRAME_PC_OFFSET
,
655 tdep
->wordsize
, byte_order
);
658 else if (ext_op
== 528) /* br cond to count reg */
660 dest
= get_frame_register_unsigned (frame
,
661 tdep
->ppc_ctr_regnum
) & ~3;
663 /* If we are about to execute a system call, dest is something
664 like 0x22fc or 0x3b00. Upon completion the system call
665 will return to the address in the link register. */
666 if (dest
< AIX_TEXT_SEGMENT_BASE
)
667 dest
= get_frame_register_unsigned (frame
,
668 tdep
->ppc_lr_regnum
) & ~3;
677 return (dest
< AIX_TEXT_SEGMENT_BASE
) ? safety
: dest
;
680 /* AIX does not support PT_STEP. Simulate it. */
683 rs6000_software_single_step (struct frame_info
*frame
)
685 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
686 struct address_space
*aspace
= get_frame_address_space (frame
);
687 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
693 loc
= get_frame_pc (frame
);
695 insn
= read_memory_integer (loc
, 4, byte_order
);
697 if (ppc_deal_with_atomic_sequence (frame
))
700 breaks
[0] = loc
+ PPC_INSN_SIZE
;
702 breaks
[1] = branch_dest (frame
, opcode
, insn
, loc
, breaks
[0]);
704 /* Don't put two breakpoints on the same address. */
705 if (breaks
[1] == breaks
[0])
708 for (ii
= 0; ii
< 2; ++ii
)
710 /* ignore invalid breakpoint. */
711 if (breaks
[ii
] == -1)
713 insert_single_step_breakpoint (gdbarch
, aspace
, breaks
[ii
]);
716 errno
= 0; /* FIXME, don't ignore errors! */
717 /* What errors? {read,write}_memory call error(). */
721 /* Implement the "auto_wide_charset" gdbarch method for this platform. */
724 rs6000_aix_auto_wide_charset (void)
729 /* Implement an osabi sniffer for RS6000/AIX.
731 This function assumes that ABFD's flavour is XCOFF. In other words,
732 it should be registered as a sniffer for bfd_target_xcoff_flavour
733 objfiles only. A failed assertion will be raised if this condition
736 static enum gdb_osabi
737 rs6000_aix_osabi_sniffer (bfd
*abfd
)
739 gdb_assert (bfd_get_flavour (abfd
) == bfd_target_xcoff_flavour
);
741 /* The only noticeable difference between Lynx178 XCOFF files and
742 AIX XCOFF files comes from the fact that there are no shared
743 libraries on Lynx178. On AIX, we are betting that an executable
744 linked with no shared library will never exist. */
745 if (xcoff_get_n_import_files (abfd
) <= 0)
746 return GDB_OSABI_UNKNOWN
;
748 return GDB_OSABI_AIX
;
751 /* A structure encoding the offset and size of a field within
760 /* A structure describing the layout of all the fields of interest
761 in AIX's struct ld_info. Each field in this struct corresponds
762 to the field of the same name in struct ld_info. */
766 struct field_info ldinfo_next
;
767 struct field_info ldinfo_fd
;
768 struct field_info ldinfo_textorg
;
769 struct field_info ldinfo_textsize
;
770 struct field_info ldinfo_dataorg
;
771 struct field_info ldinfo_datasize
;
772 struct field_info ldinfo_filename
;
775 /* The following data has been generated by compiling and running
776 the following program on AIX 5.3. */
781 #define __LDINFO_PTRACE32__
782 #define __LDINFO_PTRACE64__
785 #define pinfo(type,member) \
787 struct type ldi = {0}; \
789 printf (" {%d, %d},\t/* %s */\n", \
790 offsetof (struct type, member), \
791 sizeof (ldi.member), \
799 printf ("static const struct ld_info_desc ld_info32_desc =\n{\n");
800 pinfo (__ld_info32
, ldinfo_next
);
801 pinfo (__ld_info32
, ldinfo_fd
);
802 pinfo (__ld_info32
, ldinfo_textorg
);
803 pinfo (__ld_info32
, ldinfo_textsize
);
804 pinfo (__ld_info32
, ldinfo_dataorg
);
805 pinfo (__ld_info32
, ldinfo_datasize
);
806 pinfo (__ld_info32
, ldinfo_filename
);
811 printf ("static const struct ld_info_desc ld_info64_desc =\n{\n");
812 pinfo (__ld_info64
, ldinfo_next
);
813 pinfo (__ld_info64
, ldinfo_fd
);
814 pinfo (__ld_info64
, ldinfo_textorg
);
815 pinfo (__ld_info64
, ldinfo_textsize
);
816 pinfo (__ld_info64
, ldinfo_dataorg
);
817 pinfo (__ld_info64
, ldinfo_datasize
);
818 pinfo (__ld_info64
, ldinfo_filename
);
825 /* Layout of the 32bit version of struct ld_info. */
827 static const struct ld_info_desc ld_info32_desc
=
829 {0, 4}, /* ldinfo_next */
830 {4, 4}, /* ldinfo_fd */
831 {8, 4}, /* ldinfo_textorg */
832 {12, 4}, /* ldinfo_textsize */
833 {16, 4}, /* ldinfo_dataorg */
834 {20, 4}, /* ldinfo_datasize */
835 {24, 2}, /* ldinfo_filename */
838 /* Layout of the 64bit version of struct ld_info. */
840 static const struct ld_info_desc ld_info64_desc
=
842 {0, 4}, /* ldinfo_next */
843 {8, 4}, /* ldinfo_fd */
844 {16, 8}, /* ldinfo_textorg */
845 {24, 8}, /* ldinfo_textsize */
846 {32, 8}, /* ldinfo_dataorg */
847 {40, 8}, /* ldinfo_datasize */
848 {48, 2}, /* ldinfo_filename */
851 /* A structured representation of one entry read from the ld_info
852 binary data provided by the AIX loader. */
866 /* Return a struct ld_info object corresponding to the entry at
869 Note that the filename and member_name strings still point
870 to the data in LDI_BUF. So LDI_BUF must not be deallocated
871 while the struct ld_info object returned is in use. */
873 static struct ld_info
874 rs6000_aix_extract_ld_info (struct gdbarch
*gdbarch
,
875 const gdb_byte
*ldi_buf
)
877 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
878 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
879 struct type
*ptr_type
= builtin_type (gdbarch
)->builtin_data_ptr
;
880 const struct ld_info_desc desc
881 = tdep
->wordsize
== 8 ? ld_info64_desc
: ld_info32_desc
;
884 info
.next
= extract_unsigned_integer (ldi_buf
+ desc
.ldinfo_next
.offset
,
885 desc
.ldinfo_next
.size
,
887 info
.fd
= extract_signed_integer (ldi_buf
+ desc
.ldinfo_fd
.offset
,
890 info
.textorg
= extract_typed_address (ldi_buf
+ desc
.ldinfo_textorg
.offset
,
893 = extract_unsigned_integer (ldi_buf
+ desc
.ldinfo_textsize
.offset
,
894 desc
.ldinfo_textsize
.size
,
896 info
.dataorg
= extract_typed_address (ldi_buf
+ desc
.ldinfo_dataorg
.offset
,
899 = extract_unsigned_integer (ldi_buf
+ desc
.ldinfo_datasize
.offset
,
900 desc
.ldinfo_datasize
.size
,
902 info
.filename
= (char *) ldi_buf
+ desc
.ldinfo_filename
.offset
;
903 info
.member_name
= info
.filename
+ strlen (info
.filename
) + 1;
908 /* Append to OBJSTACK an XML string description of the shared library
909 corresponding to LDI, following the TARGET_OBJECT_LIBRARIES_AIX
913 rs6000_aix_shared_library_to_xml (struct ld_info
*ldi
,
914 struct obstack
*obstack
)
918 obstack_grow_str (obstack
, "<library name=\"");
919 p
= xml_escape_text (ldi
->filename
);
920 obstack_grow_str (obstack
, p
);
922 obstack_grow_str (obstack
, "\"");
924 if (ldi
->member_name
[0] != '\0')
926 obstack_grow_str (obstack
, " member=\"");
927 p
= xml_escape_text (ldi
->member_name
);
928 obstack_grow_str (obstack
, p
);
930 obstack_grow_str (obstack
, "\"");
933 obstack_grow_str (obstack
, " text_addr=\"");
934 obstack_grow_str (obstack
, core_addr_to_string (ldi
->textorg
));
935 obstack_grow_str (obstack
, "\"");
937 obstack_grow_str (obstack
, " text_size=\"");
938 obstack_grow_str (obstack
, pulongest (ldi
->textsize
));
939 obstack_grow_str (obstack
, "\"");
941 obstack_grow_str (obstack
, " data_addr=\"");
942 obstack_grow_str (obstack
, core_addr_to_string (ldi
->dataorg
));
943 obstack_grow_str (obstack
, "\"");
945 obstack_grow_str (obstack
, " data_size=\"");
946 obstack_grow_str (obstack
, pulongest (ldi
->datasize
));
947 obstack_grow_str (obstack
, "\"");
949 obstack_grow_str (obstack
, "></library>");
952 /* Convert the ld_info binary data provided by the AIX loader into
953 an XML representation following the TARGET_OBJECT_LIBRARIES_AIX
956 LDI_BUF is a buffer containing the ld_info data.
957 READBUF, OFFSET and LEN follow the same semantics as target_ops'
958 to_xfer_partial target_ops method.
960 If CLOSE_LDINFO_FD is nonzero, then this routine also closes
961 the ldinfo_fd file descriptor. This is useful when the ldinfo
962 data is obtained via ptrace, as ptrace opens a file descriptor
963 for each and every entry; but we cannot use this descriptor
964 as the consumer of the XML library list might live in a different
968 rs6000_aix_ld_info_to_xml (struct gdbarch
*gdbarch
, const gdb_byte
*ldi_buf
,
969 gdb_byte
*readbuf
, ULONGEST offset
, ULONGEST len
,
972 struct obstack obstack
;
976 obstack_init (&obstack
);
977 obstack_grow_str (&obstack
, "<library-list-aix version=\"1.0\">\n");
981 struct ld_info ldi
= rs6000_aix_extract_ld_info (gdbarch
, ldi_buf
);
983 rs6000_aix_shared_library_to_xml (&ldi
, &obstack
);
989 ldi_buf
= ldi_buf
+ ldi
.next
;
992 obstack_grow_str0 (&obstack
, "</library-list-aix>\n");
994 buf
= obstack_finish (&obstack
);
995 len_avail
= strlen (buf
);
996 if (offset
>= len_avail
)
1000 if (len
> len_avail
- offset
)
1001 len
= len_avail
- offset
;
1002 memcpy (readbuf
, buf
+ offset
, len
);
1005 obstack_free (&obstack
, NULL
);
1009 /* Implement the core_xfer_shared_libraries_aix gdbarch method. */
1012 rs6000_aix_core_xfer_shared_libraries_aix (struct gdbarch
*gdbarch
,
1017 struct bfd_section
*ldinfo_sec
;
1019 gdb_byte
*ldinfo_buf
;
1020 struct cleanup
*cleanup
;
1023 ldinfo_sec
= bfd_get_section_by_name (core_bfd
, ".ldinfo");
1024 if (ldinfo_sec
== NULL
)
1025 error (_("cannot find .ldinfo section from core file: %s"),
1026 bfd_errmsg (bfd_get_error ()));
1027 ldinfo_size
= bfd_get_section_size (ldinfo_sec
);
1029 ldinfo_buf
= xmalloc (ldinfo_size
);
1030 cleanup
= make_cleanup (xfree
, ldinfo_buf
);
1032 if (! bfd_get_section_contents (core_bfd
, ldinfo_sec
,
1033 ldinfo_buf
, 0, ldinfo_size
))
1034 error (_("unable to read .ldinfo section from core file: %s"),
1035 bfd_errmsg (bfd_get_error ()));
1037 result
= rs6000_aix_ld_info_to_xml (gdbarch
, ldinfo_buf
, readbuf
,
1040 do_cleanups (cleanup
);
1045 rs6000_aix_init_osabi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
1047 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1049 /* RS6000/AIX does not support PT_STEP. Has to be simulated. */
1050 set_gdbarch_software_single_step (gdbarch
, rs6000_software_single_step
);
1052 /* Displaced stepping is currently not supported in combination with
1053 software single-stepping. */
1054 set_gdbarch_displaced_step_copy_insn (gdbarch
, NULL
);
1055 set_gdbarch_displaced_step_fixup (gdbarch
, NULL
);
1056 set_gdbarch_displaced_step_free_closure (gdbarch
, NULL
);
1057 set_gdbarch_displaced_step_location (gdbarch
, NULL
);
1059 set_gdbarch_push_dummy_call (gdbarch
, rs6000_push_dummy_call
);
1060 set_gdbarch_return_value (gdbarch
, rs6000_return_value
);
1061 set_gdbarch_long_double_bit (gdbarch
, 8 * TARGET_CHAR_BIT
);
1063 /* Handle RS/6000 function pointers (which are really function
1065 set_gdbarch_convert_from_func_ptr_addr
1066 (gdbarch
, rs6000_convert_from_func_ptr_addr
);
1068 /* Core file support. */
1069 set_gdbarch_regset_from_core_section
1070 (gdbarch
, rs6000_aix_regset_from_core_section
);
1071 set_gdbarch_core_xfer_shared_libraries_aix
1072 (gdbarch
, rs6000_aix_core_xfer_shared_libraries_aix
);
1074 if (tdep
->wordsize
== 8)
1075 tdep
->lr_frame_offset
= 16;
1077 tdep
->lr_frame_offset
= 8;
1079 if (tdep
->wordsize
== 4)
1080 /* PowerOpen / AIX 32 bit. The saved area or red zone consists of
1081 19 4 byte GPRS + 18 8 byte FPRs giving a total of 220 bytes.
1082 Problem is, 220 isn't frame (16 byte) aligned. Round it up to
1084 set_gdbarch_frame_red_zone_size (gdbarch
, 224);
1086 set_gdbarch_frame_red_zone_size (gdbarch
, 0);
1088 set_gdbarch_auto_wide_charset (gdbarch
, rs6000_aix_auto_wide_charset
);
1090 set_solib_ops (gdbarch
, &solib_aix_so_ops
);
1093 /* Provide a prototype to silence -Wmissing-prototypes. */
1094 extern initialize_file_ftype _initialize_rs6000_aix_tdep
;
1097 _initialize_rs6000_aix_tdep (void)
1099 gdbarch_register_osabi_sniffer (bfd_arch_rs6000
,
1100 bfd_target_xcoff_flavour
,
1101 rs6000_aix_osabi_sniffer
);
1102 gdbarch_register_osabi_sniffer (bfd_arch_powerpc
,
1103 bfd_target_xcoff_flavour
,
1104 rs6000_aix_osabi_sniffer
);
1106 gdbarch_register_osabi (bfd_arch_rs6000
, 0, GDB_OSABI_AIX
,
1107 rs6000_aix_init_osabi
);
1108 gdbarch_register_osabi (bfd_arch_powerpc
, 0, GDB_OSABI_AIX
,
1109 rs6000_aix_init_osabi
);