1 /* Native support code for PPC AIX, for GDB the GNU debugger.
3 Copyright (C) 2006-2019 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"
41 #include "trad-frame.h"
42 #include "frame-unwind.h"
44 /* If the kernel has to deliver a signal, it pushes a sigcontext
45 structure on the stack and then calls the signal handler, passing
46 the address of the sigcontext in an argument register. Usually
47 the signal handler doesn't save this register, so we have to
48 access the sigcontext structure via an offset from the signal handler
50 The following constants were determined by experimentation on AIX 3.2.
52 sigcontext structure have the mstsave saved under the
53 sc_jmpbuf.jmp_context. STKMIN(minimum stack size) is 56 for 32-bit
54 processes, and iar offset under sc_jmpbuf.jmp_context is 40.
55 ie offsetof(struct sigcontext, sc_jmpbuf.jmp_context.iar).
56 so PC offset in this case is STKMIN+iar offset, which is 96. */
58 #define SIG_FRAME_PC_OFFSET 96
59 #define SIG_FRAME_LR_OFFSET 108
60 /* STKMIN+grp1 offset, which is 56+228=284 */
61 #define SIG_FRAME_FP_OFFSET 284
64 STKMIN64 is 112 and iar offset is 312. So 112+312=424 */
65 #define SIG_FRAME_LR_OFFSET64 424
66 /* STKMIN64+grp1 offset. 112+56=168 */
67 #define SIG_FRAME_FP_OFFSET64 168
69 static struct trad_frame_cache *
70 aix_sighandle_frame_cache (struct frame_info *this_frame,
74 CORE_ADDR base, base_orig, func;
75 struct gdbarch *gdbarch = get_frame_arch (this_frame);
76 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
77 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
78 struct trad_frame_cache *this_trad_cache;
80 if ((*this_cache) != NULL)
81 return (struct trad_frame_cache *) (*this_cache);
83 this_trad_cache = trad_frame_cache_zalloc (this_frame);
84 (*this_cache) = this_trad_cache;
86 base = get_frame_register_unsigned (this_frame,
87 gdbarch_sp_regnum (gdbarch));
90 if (tdep->wordsize == 4)
92 func = read_memory_unsigned_integer (base_orig +
93 SIG_FRAME_PC_OFFSET + 8,
94 tdep->wordsize, byte_order);
95 safe_read_memory_integer (base_orig + SIG_FRAME_FP_OFFSET + 8,
96 tdep->wordsize, byte_order, &backchain);
97 base = (CORE_ADDR)backchain;
101 func = read_memory_unsigned_integer (base_orig +
102 SIG_FRAME_LR_OFFSET64,
103 tdep->wordsize, byte_order);
104 safe_read_memory_integer (base_orig + SIG_FRAME_FP_OFFSET64,
105 tdep->wordsize, byte_order, &backchain);
106 base = (CORE_ADDR)backchain;
109 trad_frame_set_reg_value (this_trad_cache, gdbarch_pc_regnum (gdbarch), func);
110 trad_frame_set_reg_value (this_trad_cache, gdbarch_sp_regnum (gdbarch), base);
112 if (tdep->wordsize == 4)
113 trad_frame_set_reg_addr (this_trad_cache, tdep->ppc_lr_regnum,
114 base_orig + 0x38 + 52 + 8);
116 trad_frame_set_reg_addr (this_trad_cache, tdep->ppc_lr_regnum,
117 base_orig + 0x70 + 320);
119 trad_frame_set_id (this_trad_cache, frame_id_build (base, func));
120 trad_frame_set_this_base (this_trad_cache, base);
122 return this_trad_cache;
126 aix_sighandle_frame_this_id (struct frame_info *this_frame,
127 void **this_prologue_cache,
128 struct frame_id *this_id)
130 struct trad_frame_cache *this_trad_cache
131 = aix_sighandle_frame_cache (this_frame, this_prologue_cache);
132 trad_frame_get_id (this_trad_cache, this_id);
135 static struct value *
136 aix_sighandle_frame_prev_register (struct frame_info *this_frame,
137 void **this_prologue_cache, int regnum)
139 struct trad_frame_cache *this_trad_cache
140 = aix_sighandle_frame_cache (this_frame, this_prologue_cache);
141 return trad_frame_get_register (this_trad_cache, this_frame, regnum);
145 aix_sighandle_frame_sniffer (const struct frame_unwind *self,
146 struct frame_info *this_frame,
147 void **this_prologue_cache)
149 CORE_ADDR pc = get_frame_pc (this_frame);
150 if (pc && pc < AIX_TEXT_SEGMENT_BASE)
156 /* AIX signal handler frame unwinder */
158 static const struct frame_unwind aix_sighandle_frame_unwind = {
160 default_frame_unwind_stop_reason,
161 aix_sighandle_frame_this_id,
162 aix_sighandle_frame_prev_register,
164 aix_sighandle_frame_sniffer
167 /* Core file support. */
169 static struct ppc_reg_offsets rs6000_aix32_reg_offsets =
171 /* General-purpose registers. */
183 /* Floating-point registers. */
185 56, /* fpscr_offset */
189 static struct ppc_reg_offsets rs6000_aix64_reg_offsets =
191 /* General-purpose registers. */
199 280, /* ctr_offset */
200 292, /* xer_offset */
203 /* Floating-point registers. */
205 296, /* fpscr_offset */
210 /* Supply register REGNUM in the general-purpose register set REGSET
211 from the buffer specified by GREGS and LEN to register cache
212 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
215 rs6000_aix_supply_regset (const struct regset *regset,
216 struct regcache *regcache, int regnum,
217 const void *gregs, size_t len)
219 ppc_supply_gregset (regset, regcache, regnum, gregs, len);
220 ppc_supply_fpregset (regset, regcache, regnum, gregs, len);
223 /* Collect register REGNUM in the general-purpose register set
224 REGSET, from register cache REGCACHE into the buffer specified by
225 GREGS and LEN. If REGNUM is -1, do this for all registers in
229 rs6000_aix_collect_regset (const struct regset *regset,
230 const struct regcache *regcache, int regnum,
231 void *gregs, size_t len)
233 ppc_collect_gregset (regset, regcache, regnum, gregs, len);
234 ppc_collect_fpregset (regset, regcache, regnum, gregs, len);
237 /* AIX register set. */
239 static const struct regset rs6000_aix32_regset =
241 &rs6000_aix32_reg_offsets,
242 rs6000_aix_supply_regset,
243 rs6000_aix_collect_regset,
246 static const struct regset rs6000_aix64_regset =
248 &rs6000_aix64_reg_offsets,
249 rs6000_aix_supply_regset,
250 rs6000_aix_collect_regset,
253 /* Iterate over core file register note sections. */
256 rs6000_aix_iterate_over_regset_sections (struct gdbarch *gdbarch,
257 iterate_over_regset_sections_cb *cb,
259 const struct regcache *regcache)
261 if (gdbarch_tdep (gdbarch)->wordsize == 4)
262 cb (".reg", 592, 592, &rs6000_aix32_regset, NULL, cb_data);
264 cb (".reg", 576, 576, &rs6000_aix64_regset, NULL, cb_data);
268 /* Pass the arguments in either registers, or in the stack. In RS/6000,
269 the first eight words of the argument list (that might be less than
270 eight parameters if some parameters occupy more than one word) are
271 passed in r3..r10 registers. Float and double parameters are
272 passed in fpr's, in addition to that. Rest of the parameters if any
273 are passed in user stack. There might be cases in which half of the
274 parameter is copied into registers, the other half is pushed into
277 Stack must be aligned on 64-bit boundaries when synthesizing
280 If the function is returning a structure, then the return address is passed
281 in r3, then the first 7 words of the parameters can be passed in registers,
285 rs6000_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
286 struct regcache *regcache, CORE_ADDR bp_addr,
287 int nargs, struct value **args, CORE_ADDR sp,
288 function_call_return_method return_method,
289 CORE_ADDR struct_addr)
291 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
292 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
295 int argno; /* current argument number */
296 int argbytes; /* current argument byte */
297 gdb_byte tmp_buffer[50];
298 int f_argno = 0; /* current floating point argno */
299 int wordsize = gdbarch_tdep (gdbarch)->wordsize;
300 CORE_ADDR func_addr = find_function_addr (function, NULL);
302 struct value *arg = 0;
307 /* The calling convention this function implements assumes the
308 processor has floating-point registers. We shouldn't be using it
309 on PPC variants that lack them. */
310 gdb_assert (ppc_floating_point_unit_p (gdbarch));
312 /* The first eight words of ther arguments are passed in registers.
313 Copy them appropriately. */
316 /* If the function is returning a `struct', then the first word
317 (which will be passed in r3) is used for struct return address.
318 In that case we should advance one word and start from r4
319 register to copy parameters. */
320 if (return_method == return_method_struct)
322 regcache_raw_write_unsigned (regcache, tdep->ppc_gp0_regnum + 3,
327 /* effectively indirect call... gcc does...
329 return_val example( float, int);
332 float in fp0, int in r3
333 offset of stack on overflow 8/16
334 for varargs, must go by type.
336 float in r3&r4, int in r5
337 offset of stack on overflow different
339 return in r3 or f0. If no float, must study how gcc emulates floats;
340 pay attention to arg promotion.
341 User may have to cast\args to handle promotion correctly
342 since gdb won't know if prototype supplied or not. */
344 for (argno = 0, argbytes = 0; argno < nargs && ii < 8; ++ii)
346 int reg_size = register_size (gdbarch, ii + 3);
349 type = check_typedef (value_type (arg));
350 len = TYPE_LENGTH (type);
352 if (TYPE_CODE (type) == TYPE_CODE_FLT)
354 /* Floating point arguments are passed in fpr's, as well as gpr's.
355 There are 13 fpr's reserved for passing parameters. At this point
356 there is no way we would run out of them.
358 Always store the floating point value using the register's
359 floating-point format. */
360 const int fp_regnum = tdep->ppc_fp0_regnum + 1 + f_argno;
361 gdb_byte reg_val[PPC_MAX_REGISTER_SIZE];
362 struct type *reg_type = register_type (gdbarch, fp_regnum);
364 gdb_assert (len <= 8);
366 target_float_convert (value_contents (arg), type, reg_val, reg_type);
367 regcache->cooked_write (fp_regnum, reg_val);
374 /* Argument takes more than one register. */
375 while (argbytes < len)
377 gdb_byte word[PPC_MAX_REGISTER_SIZE];
378 memset (word, 0, reg_size);
380 ((char *) value_contents (arg)) + argbytes,
381 (len - argbytes) > reg_size
382 ? reg_size : len - argbytes);
383 regcache->cooked_write (tdep->ppc_gp0_regnum + 3 + ii, word);
384 ++ii, argbytes += reg_size;
387 goto ran_out_of_registers_for_arguments;
394 /* Argument can fit in one register. No problem. */
395 gdb_byte word[PPC_MAX_REGISTER_SIZE];
397 memset (word, 0, reg_size);
398 memcpy (word, value_contents (arg), len);
399 regcache->cooked_write (tdep->ppc_gp0_regnum + 3 +ii, word);
404 ran_out_of_registers_for_arguments:
406 regcache_cooked_read_unsigned (regcache,
407 gdbarch_sp_regnum (gdbarch),
410 /* Location for 8 parameters are always reserved. */
413 /* Another six words for back chain, TOC register, link register, etc. */
416 /* Stack pointer must be quadword aligned. */
419 /* If there are more arguments, allocate space for them in
420 the stack, then push them starting from the ninth one. */
422 if ((argno < nargs) || argbytes)
428 space += ((len - argbytes + 3) & -4);
434 for (; jj < nargs; ++jj)
436 struct value *val = args[jj];
437 space += ((TYPE_LENGTH (value_type (val))) + 3) & -4;
440 /* Add location required for the rest of the parameters. */
441 space = (space + 15) & -16;
444 /* This is another instance we need to be concerned about
445 securing our stack space. If we write anything underneath %sp
446 (r1), we might conflict with the kernel who thinks he is free
447 to use this area. So, update %sp first before doing anything
450 regcache_raw_write_signed (regcache,
451 gdbarch_sp_regnum (gdbarch), sp);
453 /* If the last argument copied into the registers didn't fit there
454 completely, push the rest of it into stack. */
458 write_memory (sp + 24 + (ii * 4),
459 value_contents (arg) + argbytes,
462 ii += ((len - argbytes + 3) & -4) / 4;
465 /* Push the rest of the arguments into stack. */
466 for (; argno < nargs; ++argno)
470 type = check_typedef (value_type (arg));
471 len = TYPE_LENGTH (type);
474 /* Float types should be passed in fpr's, as well as in the
476 if (TYPE_CODE (type) == TYPE_CODE_FLT && f_argno < 13)
479 gdb_assert (len <= 8);
481 regcache->cooked_write (tdep->ppc_fp0_regnum + 1 + f_argno,
482 value_contents (arg));
486 write_memory (sp + 24 + (ii * 4), value_contents (arg), len);
487 ii += ((len + 3) & -4) / 4;
491 /* Set the stack pointer. According to the ABI, the SP is meant to
492 be set _before_ the corresponding stack space is used. On AIX,
493 this even applies when the target has been completely stopped!
494 Not doing this can lead to conflicts with the kernel which thinks
495 that it still has control over this not-yet-allocated stack
497 regcache_raw_write_signed (regcache, gdbarch_sp_regnum (gdbarch), sp);
499 /* Set back chain properly. */
500 store_unsigned_integer (tmp_buffer, wordsize, byte_order, saved_sp);
501 write_memory (sp, tmp_buffer, wordsize);
503 /* Point the inferior function call's return address at the dummy's
505 regcache_raw_write_signed (regcache, tdep->ppc_lr_regnum, bp_addr);
507 /* Set the TOC register value. */
508 regcache_raw_write_signed (regcache, tdep->ppc_toc_regnum,
509 solib_aix_get_toc_value (func_addr));
511 target_store_registers (regcache, -1);
515 static enum return_value_convention
516 rs6000_return_value (struct gdbarch *gdbarch, struct value *function,
517 struct type *valtype, struct regcache *regcache,
518 gdb_byte *readbuf, const gdb_byte *writebuf)
520 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
521 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
523 /* The calling convention this function implements assumes the
524 processor has floating-point registers. We shouldn't be using it
525 on PowerPC variants that lack them. */
526 gdb_assert (ppc_floating_point_unit_p (gdbarch));
528 /* AltiVec extension: Functions that declare a vector data type as a
529 return value place that return value in VR2. */
530 if (TYPE_CODE (valtype) == TYPE_CODE_ARRAY && TYPE_VECTOR (valtype)
531 && TYPE_LENGTH (valtype) == 16)
534 regcache->cooked_read (tdep->ppc_vr0_regnum + 2, readbuf);
536 regcache->cooked_write (tdep->ppc_vr0_regnum + 2, writebuf);
538 return RETURN_VALUE_REGISTER_CONVENTION;
541 /* If the called subprogram returns an aggregate, there exists an
542 implicit first argument, whose value is the address of a caller-
543 allocated buffer into which the callee is assumed to store its
544 return value. All explicit parameters are appropriately
546 if (TYPE_CODE (valtype) == TYPE_CODE_STRUCT
547 || TYPE_CODE (valtype) == TYPE_CODE_UNION
548 || TYPE_CODE (valtype) == TYPE_CODE_ARRAY)
549 return RETURN_VALUE_STRUCT_CONVENTION;
551 /* Scalar floating-point values are returned in FPR1 for float or
552 double, and in FPR1:FPR2 for quadword precision. Fortran
553 complex*8 and complex*16 are returned in FPR1:FPR2, and
554 complex*32 is returned in FPR1:FPR4. */
555 if (TYPE_CODE (valtype) == TYPE_CODE_FLT
556 && (TYPE_LENGTH (valtype) == 4 || TYPE_LENGTH (valtype) == 8))
558 struct type *regtype = register_type (gdbarch, tdep->ppc_fp0_regnum);
561 /* FIXME: kettenis/2007-01-01: Add support for quadword
562 precision and complex. */
566 regcache->cooked_read (tdep->ppc_fp0_regnum + 1, regval);
567 target_float_convert (regval, regtype, readbuf, valtype);
571 target_float_convert (writebuf, valtype, regval, regtype);
572 regcache->cooked_write (tdep->ppc_fp0_regnum + 1, regval);
575 return RETURN_VALUE_REGISTER_CONVENTION;
578 /* Values of the types int, long, short, pointer, and char (length
579 is less than or equal to four bytes), as well as bit values of
580 lengths less than or equal to 32 bits, must be returned right
581 justified in GPR3 with signed values sign extended and unsigned
582 values zero extended, as necessary. */
583 if (TYPE_LENGTH (valtype) <= tdep->wordsize)
589 /* For reading we don't have to worry about sign extension. */
590 regcache_cooked_read_unsigned (regcache, tdep->ppc_gp0_regnum + 3,
592 store_unsigned_integer (readbuf, TYPE_LENGTH (valtype), byte_order,
597 /* For writing, use unpack_long since that should handle any
598 required sign extension. */
599 regcache_cooked_write_unsigned (regcache, tdep->ppc_gp0_regnum + 3,
600 unpack_long (valtype, writebuf));
603 return RETURN_VALUE_REGISTER_CONVENTION;
606 /* Eight-byte non-floating-point scalar values must be returned in
609 if (TYPE_LENGTH (valtype) == 8)
611 gdb_assert (TYPE_CODE (valtype) != TYPE_CODE_FLT);
612 gdb_assert (tdep->wordsize == 4);
618 regcache->cooked_read (tdep->ppc_gp0_regnum + 3, regval);
619 regcache->cooked_read (tdep->ppc_gp0_regnum + 4, regval + 4);
620 memcpy (readbuf, regval, 8);
624 regcache->cooked_write (tdep->ppc_gp0_regnum + 3, writebuf);
625 regcache->cooked_write (tdep->ppc_gp0_regnum + 4, writebuf + 4);
628 return RETURN_VALUE_REGISTER_CONVENTION;
631 return RETURN_VALUE_STRUCT_CONVENTION;
634 /* Support for CONVERT_FROM_FUNC_PTR_ADDR (ARCH, ADDR, TARG).
636 Usually a function pointer's representation is simply the address
637 of the function. On the RS/6000 however, a function pointer is
638 represented by a pointer to an OPD entry. This OPD entry contains
639 three words, the first word is the address of the function, the
640 second word is the TOC pointer (r2), and the third word is the
641 static chain value. Throughout GDB it is currently assumed that a
642 function pointer contains the address of the function, which is not
643 easy to fix. In addition, the conversion of a function address to
644 a function pointer would require allocation of an OPD entry in the
645 inferior's memory space, with all its drawbacks. To be able to
646 call C++ virtual methods in the inferior (which are called via
647 function pointers), find_function_addr uses this function to get the
648 function address from a function pointer. */
650 /* Return real function address if ADDR (a function pointer) is in the data
651 space and is therefore a special function pointer. */
654 rs6000_convert_from_func_ptr_addr (struct gdbarch *gdbarch,
656 struct target_ops *targ)
658 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
659 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
660 struct obj_section *s;
662 s = find_pc_section (addr);
664 /* Normally, functions live inside a section that is executable.
665 So, if ADDR points to a non-executable section, then treat it
666 as a function descriptor and return the target address iff
667 the target address itself points to a section that is executable. */
668 if (s && (s->the_bfd_section->flags & SEC_CODE) == 0)
671 struct obj_section *pc_section;
675 pc = read_memory_unsigned_integer (addr, tdep->wordsize, byte_order);
677 CATCH (e, RETURN_MASK_ERROR)
679 /* An error occured during reading. Probably a memory error
680 due to the section not being loaded yet. This address
681 cannot be a function descriptor. */
686 pc_section = find_pc_section (pc);
688 if (pc_section && (pc_section->the_bfd_section->flags & SEC_CODE))
696 /* Calculate the destination of a branch/jump. Return -1 if not a branch. */
699 branch_dest (struct regcache *regcache, int opcode, int instr,
700 CORE_ADDR pc, CORE_ADDR safety)
702 struct gdbarch *gdbarch = regcache->arch ();
703 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
704 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
710 absolute = (int) ((instr >> 1) & 1);
715 immediate = ((instr & ~3) << 6) >> 6; /* br unconditional */
719 dest = pc + immediate;
723 immediate = ((instr & ~3) << 16) >> 16; /* br conditional */
727 dest = pc + immediate;
731 ext_op = (instr >> 1) & 0x3ff;
733 if (ext_op == 16) /* br conditional register */
735 dest = regcache_raw_get_unsigned (regcache, tdep->ppc_lr_regnum) & ~3;
737 /* If we are about to return from a signal handler, dest is
738 something like 0x3c90. The current frame is a signal handler
739 caller frame, upon completion of the sigreturn system call
740 execution will return to the saved PC in the frame. */
741 if (dest < AIX_TEXT_SEGMENT_BASE)
743 struct frame_info *frame = get_current_frame ();
745 dest = read_memory_unsigned_integer
746 (get_frame_base (frame) + SIG_FRAME_PC_OFFSET,
747 tdep->wordsize, byte_order);
751 else if (ext_op == 528) /* br cond to count reg */
753 dest = regcache_raw_get_unsigned (regcache,
754 tdep->ppc_ctr_regnum) & ~3;
756 /* If we are about to execute a system call, dest is something
757 like 0x22fc or 0x3b00. Upon completion the system call
758 will return to the address in the link register. */
759 if (dest < AIX_TEXT_SEGMENT_BASE)
760 dest = regcache_raw_get_unsigned (regcache,
761 tdep->ppc_lr_regnum) & ~3;
770 return (dest < AIX_TEXT_SEGMENT_BASE) ? safety : dest;
773 /* AIX does not support PT_STEP. Simulate it. */
775 static std::vector<CORE_ADDR>
776 rs6000_software_single_step (struct regcache *regcache)
778 struct gdbarch *gdbarch = regcache->arch ();
779 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
785 loc = regcache_read_pc (regcache);
787 insn = read_memory_integer (loc, 4, byte_order);
789 std::vector<CORE_ADDR> next_pcs = ppc_deal_with_atomic_sequence (regcache);
790 if (!next_pcs.empty ())
793 breaks[0] = loc + PPC_INSN_SIZE;
795 breaks[1] = branch_dest (regcache, opcode, insn, loc, breaks[0]);
797 /* Don't put two breakpoints on the same address. */
798 if (breaks[1] == breaks[0])
801 for (ii = 0; ii < 2; ++ii)
803 /* ignore invalid breakpoint. */
804 if (breaks[ii] == -1)
807 next_pcs.push_back (breaks[ii]);
810 errno = 0; /* FIXME, don't ignore errors! */
811 /* What errors? {read,write}_memory call error(). */
815 /* Implement the "auto_wide_charset" gdbarch method for this platform. */
818 rs6000_aix_auto_wide_charset (void)
823 /* Implement an osabi sniffer for RS6000/AIX.
825 This function assumes that ABFD's flavour is XCOFF. In other words,
826 it should be registered as a sniffer for bfd_target_xcoff_flavour
827 objfiles only. A failed assertion will be raised if this condition
830 static enum gdb_osabi
831 rs6000_aix_osabi_sniffer (bfd *abfd)
833 gdb_assert (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
835 /* The only noticeable difference between Lynx178 XCOFF files and
836 AIX XCOFF files comes from the fact that there are no shared
837 libraries on Lynx178. On AIX, we are betting that an executable
838 linked with no shared library will never exist. */
839 if (xcoff_get_n_import_files (abfd) <= 0)
840 return GDB_OSABI_UNKNOWN;
842 return GDB_OSABI_AIX;
845 /* A structure encoding the offset and size of a field within
854 /* A structure describing the layout of all the fields of interest
855 in AIX's struct ld_info. Each field in this struct corresponds
856 to the field of the same name in struct ld_info. */
860 struct field_info ldinfo_next;
861 struct field_info ldinfo_fd;
862 struct field_info ldinfo_textorg;
863 struct field_info ldinfo_textsize;
864 struct field_info ldinfo_dataorg;
865 struct field_info ldinfo_datasize;
866 struct field_info ldinfo_filename;
869 /* The following data has been generated by compiling and running
870 the following program on AIX 5.3. */
875 #define __LDINFO_PTRACE32__
876 #define __LDINFO_PTRACE64__
879 #define pinfo(type,member) \
881 struct type ldi = {0}; \
883 printf (" {%d, %d},\t/* %s */\n", \
884 offsetof (struct type, member), \
885 sizeof (ldi.member), \
893 printf ("static const struct ld_info_desc ld_info32_desc =\n{\n");
894 pinfo (__ld_info32, ldinfo_next);
895 pinfo (__ld_info32, ldinfo_fd);
896 pinfo (__ld_info32, ldinfo_textorg);
897 pinfo (__ld_info32, ldinfo_textsize);
898 pinfo (__ld_info32, ldinfo_dataorg);
899 pinfo (__ld_info32, ldinfo_datasize);
900 pinfo (__ld_info32, ldinfo_filename);
905 printf ("static const struct ld_info_desc ld_info64_desc =\n{\n");
906 pinfo (__ld_info64, ldinfo_next);
907 pinfo (__ld_info64, ldinfo_fd);
908 pinfo (__ld_info64, ldinfo_textorg);
909 pinfo (__ld_info64, ldinfo_textsize);
910 pinfo (__ld_info64, ldinfo_dataorg);
911 pinfo (__ld_info64, ldinfo_datasize);
912 pinfo (__ld_info64, ldinfo_filename);
919 /* Layout of the 32bit version of struct ld_info. */
921 static const struct ld_info_desc ld_info32_desc =
923 {0, 4}, /* ldinfo_next */
924 {4, 4}, /* ldinfo_fd */
925 {8, 4}, /* ldinfo_textorg */
926 {12, 4}, /* ldinfo_textsize */
927 {16, 4}, /* ldinfo_dataorg */
928 {20, 4}, /* ldinfo_datasize */
929 {24, 2}, /* ldinfo_filename */
932 /* Layout of the 64bit version of struct ld_info. */
934 static const struct ld_info_desc ld_info64_desc =
936 {0, 4}, /* ldinfo_next */
937 {8, 4}, /* ldinfo_fd */
938 {16, 8}, /* ldinfo_textorg */
939 {24, 8}, /* ldinfo_textsize */
940 {32, 8}, /* ldinfo_dataorg */
941 {40, 8}, /* ldinfo_datasize */
942 {48, 2}, /* ldinfo_filename */
945 /* A structured representation of one entry read from the ld_info
946 binary data provided by the AIX loader. */
960 /* Return a struct ld_info object corresponding to the entry at
963 Note that the filename and member_name strings still point
964 to the data in LDI_BUF. So LDI_BUF must not be deallocated
965 while the struct ld_info object returned is in use. */
967 static struct ld_info
968 rs6000_aix_extract_ld_info (struct gdbarch *gdbarch,
969 const gdb_byte *ldi_buf)
971 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
972 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
973 struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
974 const struct ld_info_desc desc
975 = tdep->wordsize == 8 ? ld_info64_desc : ld_info32_desc;
978 info.next = extract_unsigned_integer (ldi_buf + desc.ldinfo_next.offset,
979 desc.ldinfo_next.size,
981 info.fd = extract_signed_integer (ldi_buf + desc.ldinfo_fd.offset,
984 info.textorg = extract_typed_address (ldi_buf + desc.ldinfo_textorg.offset,
987 = extract_unsigned_integer (ldi_buf + desc.ldinfo_textsize.offset,
988 desc.ldinfo_textsize.size,
990 info.dataorg = extract_typed_address (ldi_buf + desc.ldinfo_dataorg.offset,
993 = extract_unsigned_integer (ldi_buf + desc.ldinfo_datasize.offset,
994 desc.ldinfo_datasize.size,
996 info.filename = (char *) ldi_buf + desc.ldinfo_filename.offset;
997 info.member_name = info.filename + strlen (info.filename) + 1;
1002 /* Append to OBJSTACK an XML string description of the shared library
1003 corresponding to LDI, following the TARGET_OBJECT_LIBRARIES_AIX
1007 rs6000_aix_shared_library_to_xml (struct ld_info *ldi,
1008 struct obstack *obstack)
1010 obstack_grow_str (obstack, "<library name=\"");
1011 std::string p = xml_escape_text (ldi->filename);
1012 obstack_grow_str (obstack, p.c_str ());
1013 obstack_grow_str (obstack, "\"");
1015 if (ldi->member_name[0] != '\0')
1017 obstack_grow_str (obstack, " member=\"");
1018 p = xml_escape_text (ldi->member_name);
1019 obstack_grow_str (obstack, p.c_str ());
1020 obstack_grow_str (obstack, "\"");
1023 obstack_grow_str (obstack, " text_addr=\"");
1024 obstack_grow_str (obstack, core_addr_to_string (ldi->textorg));
1025 obstack_grow_str (obstack, "\"");
1027 obstack_grow_str (obstack, " text_size=\"");
1028 obstack_grow_str (obstack, pulongest (ldi->textsize));
1029 obstack_grow_str (obstack, "\"");
1031 obstack_grow_str (obstack, " data_addr=\"");
1032 obstack_grow_str (obstack, core_addr_to_string (ldi->dataorg));
1033 obstack_grow_str (obstack, "\"");
1035 obstack_grow_str (obstack, " data_size=\"");
1036 obstack_grow_str (obstack, pulongest (ldi->datasize));
1037 obstack_grow_str (obstack, "\"");
1039 obstack_grow_str (obstack, "></library>");
1042 /* Convert the ld_info binary data provided by the AIX loader into
1043 an XML representation following the TARGET_OBJECT_LIBRARIES_AIX
1046 LDI_BUF is a buffer containing the ld_info data.
1047 READBUF, OFFSET and LEN follow the same semantics as target_ops'
1048 to_xfer_partial target_ops method.
1050 If CLOSE_LDINFO_FD is nonzero, then this routine also closes
1051 the ldinfo_fd file descriptor. This is useful when the ldinfo
1052 data is obtained via ptrace, as ptrace opens a file descriptor
1053 for each and every entry; but we cannot use this descriptor
1054 as the consumer of the XML library list might live in a different
1058 rs6000_aix_ld_info_to_xml (struct gdbarch *gdbarch, const gdb_byte *ldi_buf,
1059 gdb_byte *readbuf, ULONGEST offset, ULONGEST len,
1060 int close_ldinfo_fd)
1062 struct obstack obstack;
1066 obstack_init (&obstack);
1067 obstack_grow_str (&obstack, "<library-list-aix version=\"1.0\">\n");
1071 struct ld_info ldi = rs6000_aix_extract_ld_info (gdbarch, ldi_buf);
1073 rs6000_aix_shared_library_to_xml (&ldi, &obstack);
1074 if (close_ldinfo_fd)
1079 ldi_buf = ldi_buf + ldi.next;
1082 obstack_grow_str0 (&obstack, "</library-list-aix>\n");
1084 buf = (const char *) obstack_finish (&obstack);
1085 len_avail = strlen (buf);
1086 if (offset >= len_avail)
1090 if (len > len_avail - offset)
1091 len = len_avail - offset;
1092 memcpy (readbuf, buf + offset, len);
1095 obstack_free (&obstack, NULL);
1099 /* Implement the core_xfer_shared_libraries_aix gdbarch method. */
1102 rs6000_aix_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch,
1107 struct bfd_section *ldinfo_sec;
1110 ldinfo_sec = bfd_get_section_by_name (core_bfd, ".ldinfo");
1111 if (ldinfo_sec == NULL)
1112 error (_("cannot find .ldinfo section from core file: %s"),
1113 bfd_errmsg (bfd_get_error ()));
1114 ldinfo_size = bfd_get_section_size (ldinfo_sec);
1116 gdb::byte_vector ldinfo_buf (ldinfo_size);
1118 if (! bfd_get_section_contents (core_bfd, ldinfo_sec,
1119 ldinfo_buf.data (), 0, ldinfo_size))
1120 error (_("unable to read .ldinfo section from core file: %s"),
1121 bfd_errmsg (bfd_get_error ()));
1123 return rs6000_aix_ld_info_to_xml (gdbarch, ldinfo_buf.data (), readbuf,
1128 rs6000_aix_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch)
1130 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1132 /* RS6000/AIX does not support PT_STEP. Has to be simulated. */
1133 set_gdbarch_software_single_step (gdbarch, rs6000_software_single_step);
1135 /* Displaced stepping is currently not supported in combination with
1136 software single-stepping. */
1137 set_gdbarch_displaced_step_copy_insn (gdbarch, NULL);
1138 set_gdbarch_displaced_step_fixup (gdbarch, NULL);
1139 set_gdbarch_displaced_step_location (gdbarch, NULL);
1141 set_gdbarch_push_dummy_call (gdbarch, rs6000_push_dummy_call);
1142 set_gdbarch_return_value (gdbarch, rs6000_return_value);
1143 set_gdbarch_long_double_bit (gdbarch, 8 * TARGET_CHAR_BIT);
1145 /* Handle RS/6000 function pointers (which are really function
1147 set_gdbarch_convert_from_func_ptr_addr
1148 (gdbarch, rs6000_convert_from_func_ptr_addr);
1150 /* Core file support. */
1151 set_gdbarch_iterate_over_regset_sections
1152 (gdbarch, rs6000_aix_iterate_over_regset_sections);
1153 set_gdbarch_core_xfer_shared_libraries_aix
1154 (gdbarch, rs6000_aix_core_xfer_shared_libraries_aix);
1156 if (tdep->wordsize == 8)
1157 tdep->lr_frame_offset = 16;
1159 tdep->lr_frame_offset = 8;
1161 if (tdep->wordsize == 4)
1162 /* PowerOpen / AIX 32 bit. The saved area or red zone consists of
1163 19 4 byte GPRS + 18 8 byte FPRs giving a total of 220 bytes.
1164 Problem is, 220 isn't frame (16 byte) aligned. Round it up to
1166 set_gdbarch_frame_red_zone_size (gdbarch, 224);
1168 set_gdbarch_frame_red_zone_size (gdbarch, 0);
1170 if (tdep->wordsize == 8)
1171 set_gdbarch_wchar_bit (gdbarch, 32);
1173 set_gdbarch_wchar_bit (gdbarch, 16);
1174 set_gdbarch_wchar_signed (gdbarch, 0);
1175 set_gdbarch_auto_wide_charset (gdbarch, rs6000_aix_auto_wide_charset);
1177 set_solib_ops (gdbarch, &solib_aix_so_ops);
1178 frame_unwind_append_unwinder (gdbarch, &aix_sighandle_frame_unwind);
1182 _initialize_rs6000_aix_tdep (void)
1184 gdbarch_register_osabi_sniffer (bfd_arch_rs6000,
1185 bfd_target_xcoff_flavour,
1186 rs6000_aix_osabi_sniffer);
1187 gdbarch_register_osabi_sniffer (bfd_arch_powerpc,
1188 bfd_target_xcoff_flavour,
1189 rs6000_aix_osabi_sniffer);
1191 gdbarch_register_osabi (bfd_arch_rs6000, 0, GDB_OSABI_AIX,
1192 rs6000_aix_init_osabi);
1193 gdbarch_register_osabi (bfd_arch_powerpc, 0, GDB_OSABI_AIX,
1194 rs6000_aix_init_osabi);