1 /* Target-dependent code for HP-UX on PA-RISC.
3 Copyright (C) 2002-2014 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "arch-utils.h"
25 #include "frame-unwind.h"
26 #include "trad-frame.h"
32 #include "hppa-tdep.h"
33 #include "solib-som.h"
34 #include "solib-pa64.h"
37 #include "exceptions.h"
39 #define IS_32BIT_TARGET(_gdbarch) \
40 ((gdbarch_tdep (_gdbarch))->bytes_per_address == 4)
42 /* Bit in the `ss_flag' member of `struct save_state' that indicates
43 that the 64-bit register values are live. From
44 <machine/save_state.h>. */
45 #define HPPA_HPUX_SS_WIDEREGS 0x40
47 /* Offsets of various parts of `struct save_state'. From
48 <machine/save_state.h>. */
49 #define HPPA_HPUX_SS_FLAGS_OFFSET 0
50 #define HPPA_HPUX_SS_NARROW_OFFSET 4
51 #define HPPA_HPUX_SS_FPBLOCK_OFFSET 256
52 #define HPPA_HPUX_SS_WIDE_OFFSET 640
54 /* The size of `struct save_state. */
55 #define HPPA_HPUX_SAVE_STATE_SIZE 1152
57 /* The size of `struct pa89_save_state', which corresponds to PA-RISC
58 1.1, the lowest common denominator that we support. */
59 #define HPPA_HPUX_PA89_SAVE_STATE_SIZE 512
62 /* Forward declarations. */
63 extern void _initialize_hppa_hpux_tdep (void);
64 extern initialize_file_ftype _initialize_hppa_hpux_tdep
;
66 /* Return one if PC is in the call path of a trampoline, else return zero.
68 Note we return one for *any* call trampoline (long-call, arg-reloc), not
69 just shared library trampolines (import, export). */
72 hppa32_hpux_in_solib_call_trampoline (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
74 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
75 struct bound_minimal_symbol minsym
;
76 struct unwind_table_entry
*u
;
78 /* First see if PC is in one of the two C-library trampolines. */
79 if (pc
== hppa_symbol_address("$$dyncall")
80 || pc
== hppa_symbol_address("_sr4export"))
83 minsym
= lookup_minimal_symbol_by_pc (pc
);
85 && strcmp (MSYMBOL_LINKAGE_NAME (minsym
.minsym
), ".stub") == 0)
88 /* Get the unwind descriptor corresponding to PC, return zero
89 if no unwind was found. */
90 u
= find_unwind_entry (pc
);
94 /* If this isn't a linker stub, then return now. */
95 if (u
->stub_unwind
.stub_type
== 0)
98 /* By definition a long-branch stub is a call stub. */
99 if (u
->stub_unwind
.stub_type
== LONG_BRANCH
)
102 /* The call and return path execute the same instructions within
103 an IMPORT stub! So an IMPORT stub is both a call and return
105 if (u
->stub_unwind
.stub_type
== IMPORT
)
108 /* Parameter relocation stubs always have a call path and may have a
110 if (u
->stub_unwind
.stub_type
== PARAMETER_RELOCATION
111 || u
->stub_unwind
.stub_type
== EXPORT
)
115 /* Search forward from the current PC until we hit a branch
116 or the end of the stub. */
117 for (addr
= pc
; addr
<= u
->region_end
; addr
+= 4)
121 insn
= read_memory_integer (addr
, 4, byte_order
);
123 /* Does it look like a bl? If so then it's the call path, if
124 we find a bv or be first, then we're on the return path. */
125 if ((insn
& 0xfc00e000) == 0xe8000000)
127 else if ((insn
& 0xfc00e001) == 0xe800c000
128 || (insn
& 0xfc000000) == 0xe0000000)
132 /* Should never happen. */
133 warning (_("Unable to find branch in parameter relocation stub."));
137 /* Unknown stub type. For now, just return zero. */
142 hppa64_hpux_in_solib_call_trampoline (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
144 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
146 /* PA64 has a completely different stub/trampoline scheme. Is it
147 better? Maybe. It's certainly harder to determine with any
148 certainty that we are in a stub because we can not refer to the
151 The heuristic is simple. Try to lookup the current PC value in th
152 minimal symbol table. If that fails, then assume we are not in a
155 Then see if the PC value falls within the section bounds for the
156 section containing the minimal symbol we found in the first
157 step. If it does, then assume we are not in a stub and return.
159 Finally peek at the instructions to see if they look like a stub. */
160 struct bound_minimal_symbol minsym
;
165 minsym
= lookup_minimal_symbol_by_pc (pc
);
169 sec
= MSYMBOL_OBJ_SECTION (minsym
.objfile
, minsym
.minsym
)->the_bfd_section
;
171 if (bfd_get_section_vma (sec
->owner
, sec
) <= pc
172 && pc
< (bfd_get_section_vma (sec
->owner
, sec
)
173 + bfd_section_size (sec
->owner
, sec
)))
176 /* We might be in a stub. Peek at the instructions. Stubs are 3
177 instructions long. */
178 insn
= read_memory_integer (pc
, 4, byte_order
);
180 /* Find out where we think we are within the stub. */
181 if ((insn
& 0xffffc00e) == 0x53610000)
183 else if ((insn
& 0xffffffff) == 0xe820d000)
185 else if ((insn
& 0xffffc00e) == 0x537b0000)
190 /* Now verify each insn in the range looks like a stub instruction. */
191 insn
= read_memory_integer (addr
, 4, byte_order
);
192 if ((insn
& 0xffffc00e) != 0x53610000)
195 /* Now verify each insn in the range looks like a stub instruction. */
196 insn
= read_memory_integer (addr
+ 4, 4, byte_order
);
197 if ((insn
& 0xffffffff) != 0xe820d000)
200 /* Now verify each insn in the range looks like a stub instruction. */
201 insn
= read_memory_integer (addr
+ 8, 4, byte_order
);
202 if ((insn
& 0xffffc00e) != 0x537b0000)
205 /* Looks like a stub. */
209 /* Return one if PC is in the return path of a trampoline, else return zero.
211 Note we return one for *any* call trampoline (long-call, arg-reloc), not
212 just shared library trampolines (import, export). */
215 hppa_hpux_in_solib_return_trampoline (struct gdbarch
*gdbarch
,
216 CORE_ADDR pc
, const char *name
)
218 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
219 struct unwind_table_entry
*u
;
221 /* Get the unwind descriptor corresponding to PC, return zero
222 if no unwind was found. */
223 u
= find_unwind_entry (pc
);
227 /* If this isn't a linker stub or it's just a long branch stub, then
229 if (u
->stub_unwind
.stub_type
== 0 || u
->stub_unwind
.stub_type
== LONG_BRANCH
)
232 /* The call and return path execute the same instructions within
233 an IMPORT stub! So an IMPORT stub is both a call and return
235 if (u
->stub_unwind
.stub_type
== IMPORT
)
238 /* Parameter relocation stubs always have a call path and may have a
240 if (u
->stub_unwind
.stub_type
== PARAMETER_RELOCATION
241 || u
->stub_unwind
.stub_type
== EXPORT
)
245 /* Search forward from the current PC until we hit a branch
246 or the end of the stub. */
247 for (addr
= pc
; addr
<= u
->region_end
; addr
+= 4)
251 insn
= read_memory_integer (addr
, 4, byte_order
);
253 /* Does it look like a bl? If so then it's the call path, if
254 we find a bv or be first, then we're on the return path. */
255 if ((insn
& 0xfc00e000) == 0xe8000000)
257 else if ((insn
& 0xfc00e001) == 0xe800c000
258 || (insn
& 0xfc000000) == 0xe0000000)
262 /* Should never happen. */
263 warning (_("Unable to find branch in parameter relocation stub."));
267 /* Unknown stub type. For now, just return zero. */
272 /* Figure out if PC is in a trampoline, and if so find out where
273 the trampoline will jump to. If not in a trampoline, return zero.
275 Simple code examination probably is not a good idea since the code
276 sequences in trampolines can also appear in user code.
278 We use unwinds and information from the minimal symbol table to
279 determine when we're in a trampoline. This won't work for ELF
280 (yet) since it doesn't create stub unwind entries. Whether or
281 not ELF will create stub unwinds or normal unwinds for linker
282 stubs is still being debated.
284 This should handle simple calls through dyncall or sr4export,
285 long calls, argument relocation stubs, and dyncall/sr4export
286 calling an argument relocation stub. It even handles some stubs
287 used in dynamic executables. */
290 hppa_hpux_skip_trampoline_code (struct frame_info
*frame
, CORE_ADDR pc
)
292 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
293 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
294 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
296 long prev_inst
, curr_inst
, loc
;
297 struct bound_minimal_symbol msym
;
298 struct unwind_table_entry
*u
;
300 /* Addresses passed to dyncall may *NOT* be the actual address
301 of the function. So we may have to do something special. */
302 if (pc
== hppa_symbol_address("$$dyncall"))
304 pc
= (CORE_ADDR
) get_frame_register_unsigned (frame
, 22);
306 /* If bit 30 (counting from the left) is on, then pc is the address of
307 the PLT entry for this function, not the address of the function
308 itself. Bit 31 has meaning too, but only for MPE. */
310 pc
= (CORE_ADDR
) read_memory_integer (pc
& ~0x3, word_size
,
313 if (pc
== hppa_symbol_address("$$dyncall_external"))
315 pc
= (CORE_ADDR
) get_frame_register_unsigned (frame
, 22);
316 pc
= (CORE_ADDR
) read_memory_integer (pc
& ~0x3, word_size
, byte_order
);
318 else if (pc
== hppa_symbol_address("_sr4export"))
319 pc
= (CORE_ADDR
) get_frame_register_unsigned (frame
, 22);
321 /* Get the unwind descriptor corresponding to PC, return zero
322 if no unwind was found. */
323 u
= find_unwind_entry (pc
);
327 /* If this isn't a linker stub, then return now. */
328 /* elz: attention here! (FIXME) because of a compiler/linker
329 error, some stubs which should have a non zero stub_unwind.stub_type
330 have unfortunately a value of zero. So this function would return here
331 as if we were not in a trampoline. To fix this, we go look at the partial
332 symbol information, which reports this guy as a stub.
333 (FIXME): Unfortunately, we are not that lucky: it turns out that the
334 partial symbol information is also wrong sometimes. This is because
335 when it is entered (somread.c::som_symtab_read()) it can happen that
336 if the type of the symbol (from the som) is Entry, and the symbol is
337 in a shared library, then it can also be a trampoline. This would be OK,
338 except that I believe the way they decide if we are ina shared library
339 does not work. SOOOO..., even if we have a regular function w/o
340 trampolines its minimal symbol can be assigned type mst_solib_trampoline.
341 Also, if we find that the symbol is a real stub, then we fix the unwind
342 descriptor, and define the stub type to be EXPORT.
343 Hopefully this is correct most of the times. */
344 if (u
->stub_unwind
.stub_type
== 0)
347 /* elz: NOTE (FIXME!) once the problem with the unwind information is fixed
348 we can delete all the code which appears between the lines. */
349 /*--------------------------------------------------------------------------*/
350 msym
= lookup_minimal_symbol_by_pc (pc
);
352 if (msym
.minsym
== NULL
353 || MSYMBOL_TYPE (msym
.minsym
) != mst_solib_trampoline
)
354 return orig_pc
== pc
? 0 : pc
& ~0x3;
356 else if (msym
.minsym
!= NULL
357 && MSYMBOL_TYPE (msym
.minsym
) == mst_solib_trampoline
)
359 struct objfile
*objfile
;
360 struct minimal_symbol
*msymbol
;
361 int function_found
= 0;
363 /* Go look if there is another minimal symbol with the same name as
364 this one, but with type mst_text. This would happen if the msym
365 is an actual trampoline, in which case there would be another
366 symbol with the same name corresponding to the real function. */
368 ALL_MSYMBOLS (objfile
, msymbol
)
370 if (MSYMBOL_TYPE (msymbol
) == mst_text
371 && strcmp (MSYMBOL_LINKAGE_NAME (msymbol
),
372 MSYMBOL_LINKAGE_NAME (msym
.minsym
)) == 0)
380 /* The type of msym is correct (mst_solib_trampoline), but
381 the unwind info is wrong, so set it to the correct value. */
382 u
->stub_unwind
.stub_type
= EXPORT
;
384 /* The stub type info in the unwind is correct (this is not a
385 trampoline), but the msym type information is wrong, it
386 should be mst_text. So we need to fix the msym, and also
387 get out of this function. */
389 MSYMBOL_TYPE (msym
.minsym
) = mst_text
;
390 return orig_pc
== pc
? 0 : pc
& ~0x3;
394 /*--------------------------------------------------------------------------*/
397 /* It's a stub. Search for a branch and figure out where it goes.
398 Note we have to handle multi insn branch sequences like ldil;ble.
399 Most (all?) other branches can be determined by examining the contents
400 of certain registers and the stack. */
407 /* Make sure we haven't walked outside the range of this stub. */
408 if (u
!= find_unwind_entry (loc
))
410 warning (_("Unable to find branch in linker stub"));
411 return orig_pc
== pc
? 0 : pc
& ~0x3;
414 prev_inst
= curr_inst
;
415 curr_inst
= read_memory_integer (loc
, 4, byte_order
);
417 /* Does it look like a branch external using %r1? Then it's the
418 branch from the stub to the actual function. */
419 if ((curr_inst
& 0xffe0e000) == 0xe0202000)
421 /* Yup. See if the previous instruction loaded
422 a value into %r1. If so compute and return the jump address. */
423 if ((prev_inst
& 0xffe00000) == 0x20200000)
424 return (hppa_extract_21 (prev_inst
)
425 + hppa_extract_17 (curr_inst
)) & ~0x3;
428 warning (_("Unable to find ldil X,%%r1 "
429 "before ble Y(%%sr4,%%r1)."));
430 return orig_pc
== pc
? 0 : pc
& ~0x3;
434 /* Does it look like a be 0(sr0,%r21)? OR
435 Does it look like a be, n 0(sr0,%r21)? OR
436 Does it look like a bve (r21)? (this is on PA2.0)
437 Does it look like a bve, n(r21)? (this is also on PA2.0)
438 That's the branch from an
439 import stub to an export stub.
441 It is impossible to determine the target of the branch via
442 simple examination of instructions and/or data (consider
443 that the address in the plabel may be the address of the
444 bind-on-reference routine in the dynamic loader).
446 So we have try an alternative approach.
448 Get the name of the symbol at our current location; it should
449 be a stub symbol with the same name as the symbol in the
452 Then lookup a minimal symbol with the same name; we should
453 get the minimal symbol for the target routine in the shared
454 library as those take precedence of import/export stubs. */
455 if ((curr_inst
== 0xe2a00000) ||
456 (curr_inst
== 0xe2a00002) ||
457 (curr_inst
== 0xeaa0d000) ||
458 (curr_inst
== 0xeaa0d002))
460 struct bound_minimal_symbol stubsym
;
461 struct bound_minimal_symbol libsym
;
463 stubsym
= lookup_minimal_symbol_by_pc (loc
);
464 if (stubsym
.minsym
== NULL
)
466 warning (_("Unable to find symbol for 0x%lx"), loc
);
467 return orig_pc
== pc
? 0 : pc
& ~0x3;
470 libsym
= lookup_minimal_symbol (MSYMBOL_LINKAGE_NAME (stubsym
.minsym
),
472 if (libsym
.minsym
== NULL
)
474 warning (_("Unable to find library symbol for %s."),
475 MSYMBOL_PRINT_NAME (stubsym
.minsym
));
476 return orig_pc
== pc
? 0 : pc
& ~0x3;
479 return MSYMBOL_VALUE (libsym
.minsym
);
482 /* Does it look like bl X,%rp or bl X,%r0? Another way to do a
483 branch from the stub to the actual function. */
485 else if ((curr_inst
& 0xffe0e000) == 0xe8400000
486 || (curr_inst
& 0xffe0e000) == 0xe8000000
487 || (curr_inst
& 0xffe0e000) == 0xe800A000)
488 return (loc
+ hppa_extract_17 (curr_inst
) + 8) & ~0x3;
490 /* Does it look like bv (rp)? Note this depends on the
491 current stack pointer being the same as the stack
492 pointer in the stub itself! This is a branch on from the
493 stub back to the original caller. */
494 /*else if ((curr_inst & 0xffe0e000) == 0xe840c000) */
495 else if ((curr_inst
& 0xffe0f000) == 0xe840c000)
497 /* Yup. See if the previous instruction loaded
499 if (prev_inst
== 0x4bc23ff1)
502 sp
= get_frame_register_unsigned (frame
, HPPA_SP_REGNUM
);
503 return read_memory_integer (sp
- 8, 4, byte_order
) & ~0x3;
507 warning (_("Unable to find restore of %%rp before bv (%%rp)."));
508 return orig_pc
== pc
? 0 : pc
& ~0x3;
512 /* elz: added this case to capture the new instruction
513 at the end of the return part of an export stub used by
514 the PA2.0: BVE, n (rp) */
515 else if ((curr_inst
& 0xffe0f000) == 0xe840d000)
517 return (read_memory_integer
518 (get_frame_register_unsigned (frame
, HPPA_SP_REGNUM
) - 24,
519 word_size
, byte_order
)) & ~0x3;
522 /* What about be,n 0(sr0,%rp)? It's just another way we return to
523 the original caller from the stub. Used in dynamic executables. */
524 else if (curr_inst
== 0xe0400002)
526 /* The value we jump to is sitting in sp - 24. But that's
527 loaded several instructions before the be instruction.
528 I guess we could check for the previous instruction being
529 mtsp %r1,%sr0 if we want to do sanity checking. */
530 return (read_memory_integer
531 (get_frame_register_unsigned (frame
, HPPA_SP_REGNUM
) - 24,
532 word_size
, byte_order
)) & ~0x3;
535 /* Haven't found the branch yet, but we're still in the stub.
542 hppa_skip_permanent_breakpoint (struct regcache
*regcache
)
544 /* To step over a breakpoint instruction on the PA takes some
545 fiddling with the instruction address queue.
547 When we stop at a breakpoint, the IA queue front (the instruction
548 we're executing now) points at the breakpoint instruction, and
549 the IA queue back (the next instruction to execute) points to
550 whatever instruction we would execute after the breakpoint, if it
551 were an ordinary instruction. This is the case even if the
552 breakpoint is in the delay slot of a branch instruction.
554 Clearly, to step past the breakpoint, we need to set the queue
555 front to the back. But what do we put in the back? What
556 instruction comes after that one? Because of the branch delay
557 slot, the next insn is always at the back + 4. */
559 ULONGEST pcoq_tail
, pcsq_tail
;
560 regcache_cooked_read_unsigned (regcache
, HPPA_PCOQ_TAIL_REGNUM
, &pcoq_tail
);
561 regcache_cooked_read_unsigned (regcache
, HPPA_PCSQ_TAIL_REGNUM
, &pcsq_tail
);
563 regcache_cooked_write_unsigned (regcache
, HPPA_PCOQ_HEAD_REGNUM
, pcoq_tail
);
564 regcache_cooked_write_unsigned (regcache
, HPPA_PCSQ_HEAD_REGNUM
, pcsq_tail
);
566 regcache_cooked_write_unsigned (regcache
,
567 HPPA_PCOQ_TAIL_REGNUM
, pcoq_tail
+ 4);
568 /* We can leave the tail's space the same, since there's no jump. */
573 struct hppa_hpux_sigtramp_unwind_cache
576 struct trad_frame_saved_reg
*saved_regs
;
579 static int hppa_hpux_tramp_reg
[] = {
581 HPPA_PCOQ_HEAD_REGNUM
,
582 HPPA_PCSQ_HEAD_REGNUM
,
583 HPPA_PCOQ_TAIL_REGNUM
,
584 HPPA_PCSQ_TAIL_REGNUM
,
611 static struct hppa_hpux_sigtramp_unwind_cache
*
612 hppa_hpux_sigtramp_frame_unwind_cache (struct frame_info
*this_frame
,
616 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
617 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
618 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
619 struct hppa_hpux_sigtramp_unwind_cache
*info
;
621 CORE_ADDR sp
, scptr
, off
;
627 info
= FRAME_OBSTACK_ZALLOC (struct hppa_hpux_sigtramp_unwind_cache
);
629 info
->saved_regs
= trad_frame_alloc_saved_regs (this_frame
);
631 sp
= get_frame_register_unsigned (this_frame
, HPPA_SP_REGNUM
);
633 if (IS_32BIT_TARGET (gdbarch
))
640 /* See /usr/include/machine/save_state.h for the structure of the
641 save_state_t structure. */
643 flag
= read_memory_unsigned_integer (scptr
+ HPPA_HPUX_SS_FLAGS_OFFSET
,
646 if (!(flag
& HPPA_HPUX_SS_WIDEREGS
))
648 /* Narrow registers. */
649 off
= scptr
+ HPPA_HPUX_SS_NARROW_OFFSET
;
655 /* Wide registers. */
656 off
= scptr
+ HPPA_HPUX_SS_WIDE_OFFSET
+ 8;
658 szoff
= (tdep
->bytes_per_address
== 4 ? 4 : 0);
661 for (i
= 1; i
< 32; i
++)
663 info
->saved_regs
[HPPA_R0_REGNUM
+ i
].addr
= off
+ szoff
;
667 for (i
= 0; i
< ARRAY_SIZE (hppa_hpux_tramp_reg
); i
++)
669 if (hppa_hpux_tramp_reg
[i
] > 0)
670 info
->saved_regs
[hppa_hpux_tramp_reg
[i
]].addr
= off
+ szoff
;
677 info
->base
= get_frame_register_unsigned (this_frame
, HPPA_SP_REGNUM
);
683 hppa_hpux_sigtramp_frame_this_id (struct frame_info
*this_frame
,
684 void **this_prologue_cache
,
685 struct frame_id
*this_id
)
687 struct hppa_hpux_sigtramp_unwind_cache
*info
688 = hppa_hpux_sigtramp_frame_unwind_cache (this_frame
, this_prologue_cache
);
690 *this_id
= frame_id_build (info
->base
, get_frame_pc (this_frame
));
693 static struct value
*
694 hppa_hpux_sigtramp_frame_prev_register (struct frame_info
*this_frame
,
695 void **this_prologue_cache
,
698 struct hppa_hpux_sigtramp_unwind_cache
*info
699 = hppa_hpux_sigtramp_frame_unwind_cache (this_frame
, this_prologue_cache
);
701 return hppa_frame_prev_register_helper (this_frame
,
702 info
->saved_regs
, regnum
);
706 hppa_hpux_sigtramp_unwind_sniffer (const struct frame_unwind
*self
,
707 struct frame_info
*this_frame
,
710 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
711 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
712 struct unwind_table_entry
*u
;
713 CORE_ADDR pc
= get_frame_pc (this_frame
);
715 u
= find_unwind_entry (pc
);
717 /* If this is an export stub, try to get the unwind descriptor for
718 the actual function itself. */
719 if (u
&& u
->stub_unwind
.stub_type
== EXPORT
)
721 gdb_byte buf
[HPPA_INSN_SIZE
];
724 if (!safe_frame_unwind_memory (this_frame
, u
->region_start
,
728 insn
= extract_unsigned_integer (buf
, sizeof buf
, byte_order
);
729 if ((insn
& 0xffe0e000) == 0xe8400000)
730 u
= find_unwind_entry(u
->region_start
+ hppa_extract_17 (insn
) + 8);
733 if (u
&& u
->HP_UX_interrupt_marker
)
739 static const struct frame_unwind hppa_hpux_sigtramp_frame_unwind
= {
741 default_frame_unwind_stop_reason
,
742 hppa_hpux_sigtramp_frame_this_id
,
743 hppa_hpux_sigtramp_frame_prev_register
,
745 hppa_hpux_sigtramp_unwind_sniffer
749 hppa32_hpux_find_global_pointer (struct gdbarch
*gdbarch
,
750 struct value
*function
)
752 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
755 faddr
= value_as_address (function
);
757 /* Is this a plabel? If so, dereference it to get the gp value. */
765 status
= target_read_memory (faddr
+ 4, buf
, sizeof (buf
));
767 return extract_unsigned_integer (buf
, sizeof (buf
), byte_order
);
770 return gdbarch_tdep (gdbarch
)->solib_get_got_by_pc (faddr
);
774 hppa64_hpux_find_global_pointer (struct gdbarch
*gdbarch
,
775 struct value
*function
)
777 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
781 faddr
= value_as_address (function
);
783 if (pc_in_section (faddr
, ".opd"))
785 target_read_memory (faddr
, buf
, sizeof (buf
));
786 return extract_unsigned_integer (&buf
[24], 8, byte_order
);
790 return gdbarch_tdep (gdbarch
)->solib_get_got_by_pc (faddr
);
794 static unsigned int ldsid_pattern
[] = {
795 0x000010a0, /* ldsid (rX),rY */
796 0x00001820, /* mtsp rY,sr0 */
797 0xe0000000 /* be,n (sr0,rX) */
801 hppa_hpux_search_pattern (struct gdbarch
*gdbarch
,
802 CORE_ADDR start
, CORE_ADDR end
,
803 unsigned int *patterns
, int count
)
805 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
806 int num_insns
= (end
- start
+ HPPA_INSN_SIZE
) / HPPA_INSN_SIZE
;
811 buf
= alloca (num_insns
* HPPA_INSN_SIZE
);
812 insns
= alloca (num_insns
* sizeof (unsigned int));
814 read_memory (start
, buf
, num_insns
* HPPA_INSN_SIZE
);
815 for (i
= 0; i
< num_insns
; i
++, buf
+= HPPA_INSN_SIZE
)
816 insns
[i
] = extract_unsigned_integer (buf
, HPPA_INSN_SIZE
, byte_order
);
818 for (offset
= 0; offset
<= num_insns
- count
; offset
++)
820 for (i
= 0; i
< count
; i
++)
822 if ((insns
[offset
+ i
] & patterns
[i
]) != patterns
[i
])
829 if (offset
<= num_insns
- count
)
830 return start
+ offset
* HPPA_INSN_SIZE
;
836 hppa32_hpux_search_dummy_call_sequence (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
839 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
841 struct obj_section
*sec
;
842 struct hppa_objfile_private
*priv
;
843 struct frame_info
*frame
;
844 struct unwind_table_entry
*u
;
849 sec
= find_pc_section (pc
);
851 priv
= objfile_data (obj
, hppa_objfile_priv_data
);
854 priv
= hppa_init_objfile_priv_data (obj
);
856 error (_("Internal error creating objfile private data."));
858 /* Use the cached value if we have one. */
859 if (priv
->dummy_call_sequence_addr
!= 0)
861 *argreg
= priv
->dummy_call_sequence_reg
;
862 return priv
->dummy_call_sequence_addr
;
865 /* First try a heuristic; if we are in a shared library call, our return
866 pointer is likely to point at an export stub. */
867 frame
= get_current_frame ();
868 rp
= frame_unwind_register_unsigned (frame
, 2);
869 u
= find_unwind_entry (rp
);
870 if (u
&& u
->stub_unwind
.stub_type
== EXPORT
)
872 addr
= hppa_hpux_search_pattern (gdbarch
,
873 u
->region_start
, u
->region_end
,
875 ARRAY_SIZE (ldsid_pattern
));
880 /* Next thing to try is to look for an export stub. */
881 if (priv
->unwind_info
)
885 for (i
= 0; i
< priv
->unwind_info
->last
; i
++)
887 struct unwind_table_entry
*u
;
888 u
= &priv
->unwind_info
->table
[i
];
889 if (u
->stub_unwind
.stub_type
== EXPORT
)
891 addr
= hppa_hpux_search_pattern (gdbarch
,
892 u
->region_start
, u
->region_end
,
894 ARRAY_SIZE (ldsid_pattern
));
903 /* Finally, if this is the main executable, try to locate a sequence
905 addr
= hppa_symbol_address ("noshlibs");
906 sec
= find_pc_section (addr
);
908 if (sec
&& sec
->objfile
== obj
)
910 CORE_ADDR start
, end
;
912 find_pc_partial_function (addr
, NULL
, &start
, &end
);
913 if (start
!= 0 && end
!= 0)
915 addr
= hppa_hpux_search_pattern (gdbarch
, start
, end
, ldsid_pattern
,
916 ARRAY_SIZE (ldsid_pattern
));
922 /* Can't find a suitable sequence. */
926 target_read_memory (addr
, buf
, sizeof (buf
));
927 insn
= extract_unsigned_integer (buf
, sizeof (buf
), byte_order
);
928 priv
->dummy_call_sequence_addr
= addr
;
929 priv
->dummy_call_sequence_reg
= (insn
>> 21) & 0x1f;
931 *argreg
= priv
->dummy_call_sequence_reg
;
932 return priv
->dummy_call_sequence_addr
;
936 hppa64_hpux_search_dummy_call_sequence (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
939 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
941 struct obj_section
*sec
;
942 struct hppa_objfile_private
*priv
;
944 struct minimal_symbol
*msym
;
946 sec
= find_pc_section (pc
);
948 priv
= objfile_data (obj
, hppa_objfile_priv_data
);
951 priv
= hppa_init_objfile_priv_data (obj
);
953 error (_("Internal error creating objfile private data."));
955 /* Use the cached value if we have one. */
956 if (priv
->dummy_call_sequence_addr
!= 0)
958 *argreg
= priv
->dummy_call_sequence_reg
;
959 return priv
->dummy_call_sequence_addr
;
962 /* FIXME: Without stub unwind information, locating a suitable sequence is
963 fairly difficult. For now, we implement a very naive and inefficient
964 scheme; try to read in blocks of code, and look for a "bve,n (rp)"
965 instruction. These are likely to occur at the end of functions, so
966 we only look at the last two instructions of each function. */
967 ALL_OBJFILE_MSYMBOLS (obj
, msym
)
969 CORE_ADDR begin
, end
;
971 gdb_byte buf
[2 * HPPA_INSN_SIZE
];
974 find_pc_partial_function (MSYMBOL_VALUE_ADDRESS (obj
, msym
), &name
,
977 if (name
== NULL
|| begin
== 0 || end
== 0)
980 if (target_read_memory (end
- sizeof (buf
), buf
, sizeof (buf
)) == 0)
982 for (offset
= 0; offset
< sizeof (buf
); offset
++)
986 insn
= extract_unsigned_integer (buf
+ offset
,
987 HPPA_INSN_SIZE
, byte_order
);
988 if (insn
== 0xe840d002) /* bve,n (rp) */
990 addr
= (end
- sizeof (buf
)) + offset
;
997 /* Can't find a suitable sequence. */
1001 priv
->dummy_call_sequence_addr
= addr
;
1002 /* Right now we only look for a "bve,l (rp)" sequence, so the register is
1003 always HPPA_RP_REGNUM. */
1004 priv
->dummy_call_sequence_reg
= HPPA_RP_REGNUM
;
1006 *argreg
= priv
->dummy_call_sequence_reg
;
1007 return priv
->dummy_call_sequence_addr
;
1011 hppa_hpux_find_import_stub_for_addr (CORE_ADDR funcaddr
)
1013 struct objfile
*objfile
;
1014 struct bound_minimal_symbol funsym
;
1015 struct bound_minimal_symbol stubsym
;
1018 funsym
= lookup_minimal_symbol_by_pc (funcaddr
);
1021 ALL_OBJFILES (objfile
)
1023 stubsym
= lookup_minimal_symbol_solib_trampoline
1024 (MSYMBOL_LINKAGE_NAME (funsym
.minsym
), objfile
);
1028 struct unwind_table_entry
*u
;
1030 u
= find_unwind_entry (MSYMBOL_VALUE (stubsym
.minsym
));
1032 || (u
->stub_unwind
.stub_type
!= IMPORT
1033 && u
->stub_unwind
.stub_type
!= IMPORT_SHLIB
))
1036 stubaddr
= MSYMBOL_VALUE (stubsym
.minsym
);
1038 /* If we found an IMPORT stub, then we can stop searching;
1039 if we found an IMPORT_SHLIB, we want to continue the search
1040 in the hopes that we will find an IMPORT stub. */
1041 if (u
->stub_unwind
.stub_type
== IMPORT
)
1050 hppa_hpux_sr_for_addr (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
1053 /* The space register to use is encoded in the top 2 bits of the address. */
1054 sr
= addr
>> (gdbarch_tdep (gdbarch
)->bytes_per_address
* 8 - 2);
1059 hppa_hpux_find_dummy_bpaddr (CORE_ADDR addr
)
1061 /* In order for us to restore the space register to its starting state,
1062 we need the dummy trampoline to return to an instruction address in
1063 the same space as where we started the call. We used to place the
1064 breakpoint near the current pc, however, this breaks nested dummy calls
1065 as the nested call will hit the breakpoint address and terminate
1066 prematurely. Instead, we try to look for an address in the same space to
1069 This is similar in spirit to putting the breakpoint at the "entry point"
1070 of an executable. */
1072 struct obj_section
*sec
;
1073 struct unwind_table_entry
*u
;
1074 struct minimal_symbol
*msym
;
1077 sec
= find_pc_section (addr
);
1080 /* First try the lowest address in the section; we can use it as long
1081 as it is "regular" code (i.e. not a stub). */
1082 u
= find_unwind_entry (obj_section_addr (sec
));
1083 if (!u
|| u
->stub_unwind
.stub_type
== 0)
1084 return obj_section_addr (sec
);
1086 /* Otherwise, we need to find a symbol for a regular function. We
1087 do this by walking the list of msymbols in the objfile. The symbol
1088 we find should not be the same as the function that was passed in. */
1090 /* FIXME: this is broken, because we can find a function that will be
1091 called by the dummy call target function, which will still not
1094 find_pc_partial_function (addr
, NULL
, &func
, NULL
);
1095 ALL_OBJFILE_MSYMBOLS (sec
->objfile
, msym
)
1097 u
= find_unwind_entry (MSYMBOL_VALUE_ADDRESS (sec
->objfile
, msym
));
1098 if (func
!= MSYMBOL_VALUE_ADDRESS (sec
->objfile
, msym
)
1099 && (!u
|| u
->stub_unwind
.stub_type
== 0))
1100 return MSYMBOL_VALUE_ADDRESS (sec
->objfile
, msym
);
1104 warning (_("Cannot find suitable address to place dummy breakpoint; nested "
1105 "calls may fail."));
1110 hppa_hpux_push_dummy_code (struct gdbarch
*gdbarch
, CORE_ADDR sp
,
1112 struct value
**args
, int nargs
,
1113 struct type
*value_type
,
1114 CORE_ADDR
*real_pc
, CORE_ADDR
*bp_addr
,
1115 struct regcache
*regcache
)
1117 CORE_ADDR pc
, stubaddr
;
1120 pc
= regcache_read_pc (regcache
);
1122 /* Note: we don't want to pass a function descriptor here; push_dummy_call
1123 fills in the PIC register for us. */
1124 funcaddr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, funcaddr
, NULL
);
1126 /* The simple case is where we call a function in the same space that we are
1127 currently in; in that case we don't really need to do anything. */
1128 if (hppa_hpux_sr_for_addr (gdbarch
, pc
)
1129 == hppa_hpux_sr_for_addr (gdbarch
, funcaddr
))
1131 /* Intraspace call. */
1132 *bp_addr
= hppa_hpux_find_dummy_bpaddr (pc
);
1133 *real_pc
= funcaddr
;
1134 regcache_cooked_write_unsigned (regcache
, HPPA_RP_REGNUM
, *bp_addr
);
1139 /* In order to make an interspace call, we need to go through a stub.
1140 gcc supplies an appropriate stub called "__gcc_plt_call", however, if
1141 an application is compiled with HP compilers then this stub is not
1142 available. We used to fallback to "__d_plt_call", however that stub
1143 is not entirely useful for us because it doesn't do an interspace
1144 return back to the caller. Also, on hppa64-hpux, there is no
1145 __gcc_plt_call available. In order to keep the code uniform, we
1146 instead don't use either of these stubs, but instead write our own
1149 A problem arises since the stack is located in a different space than
1150 code, so in order to branch to a stack stub, we will need to do an
1151 interspace branch. Previous versions of gdb did this by modifying code
1152 at the current pc and doing single-stepping to set the pcsq. Since this
1153 is highly undesirable, we use a different scheme:
1155 All we really need to do the branch to the stub is a short instruction
1166 Instead of writing these sequences ourselves, we can find it in
1167 the instruction stream that belongs to the current space. While this
1168 seems difficult at first, we are actually guaranteed to find the sequences
1172 - in export stubs for shared libraries
1173 - in the "noshlibs" routine in the main module
1176 - at the end of each "regular" function
1178 We cache the address of these sequences in the objfile's private data
1179 since these operations can potentially be quite expensive.
1182 - write a stack trampoline
1183 - look for a suitable instruction sequence in the current space
1184 - point the sequence at the trampoline
1185 - set the return address of the trampoline to the current space
1186 (see hppa_hpux_find_dummy_call_bpaddr)
1187 - set the continuing address of the "dummy code" as the sequence. */
1189 if (IS_32BIT_TARGET (gdbarch
))
1191 #define INSN(I1, I2, I3, I4) 0x ## I1, 0x ## I2, 0x ## I3, 0x ## I4
1192 static const gdb_byte hppa32_tramp
[] = {
1193 INSN(0f
,df
,12,91), /* stw r31,-8(,sp) */
1194 INSN(02,c0
,10,a1
), /* ldsid (,r22),r1 */
1195 INSN(00,01,18,20), /* mtsp r1,sr0 */
1196 INSN(e6
,c0
,00,00), /* be,l 0(sr0,r22),%sr0,%r31 */
1197 INSN(08,1f
,02,42), /* copy r31,rp */
1198 INSN(0f
,d1
,10,82), /* ldw -8(,sp),rp */
1199 INSN(00,40,10,a1
), /* ldsid (,rp),r1 */
1200 INSN(00,01,18,20), /* mtsp r1,sr0 */
1201 INSN(e0
,40,00,00), /* be 0(sr0,rp) */
1202 INSN(08,00,02,40) /* nop */
1205 /* for hppa32, we must call the function through a stub so that on
1206 return it can return to the space of our trampoline. */
1207 stubaddr
= hppa_hpux_find_import_stub_for_addr (funcaddr
);
1209 error (_("Cannot call external function not referenced by application "
1210 "(no import stub).\n"));
1211 regcache_cooked_write_unsigned (regcache
, 22, stubaddr
);
1213 write_memory (sp
, hppa32_tramp
, sizeof (hppa32_tramp
));
1215 *bp_addr
= hppa_hpux_find_dummy_bpaddr (pc
);
1216 regcache_cooked_write_unsigned (regcache
, 31, *bp_addr
);
1218 *real_pc
= hppa32_hpux_search_dummy_call_sequence (gdbarch
, pc
, &argreg
);
1220 error (_("Cannot make interspace call from here."));
1222 regcache_cooked_write_unsigned (regcache
, argreg
, sp
);
1224 sp
+= sizeof (hppa32_tramp
);
1228 static const gdb_byte hppa64_tramp
[] = {
1229 INSN(ea
,c0
,f0
,00), /* bve,l (r22),%r2 */
1230 INSN(0f
,df
,12,d1
), /* std r31,-8(,sp) */
1231 INSN(0f
,d1
,10,c2
), /* ldd -8(,sp),rp */
1232 INSN(e8
,40,d0
,02), /* bve,n (rp) */
1233 INSN(08,00,02,40) /* nop */
1237 /* for hppa64, we don't need to call through a stub; all functions
1238 return via a bve. */
1239 regcache_cooked_write_unsigned (regcache
, 22, funcaddr
);
1240 write_memory (sp
, hppa64_tramp
, sizeof (hppa64_tramp
));
1243 regcache_cooked_write_unsigned (regcache
, 31, *bp_addr
);
1245 *real_pc
= hppa64_hpux_search_dummy_call_sequence (gdbarch
, pc
, &argreg
);
1247 error (_("Cannot make interspace call from here."));
1249 regcache_cooked_write_unsigned (regcache
, argreg
, sp
);
1251 sp
+= sizeof (hppa64_tramp
);
1254 sp
= gdbarch_frame_align (gdbarch
, sp
);
1262 hppa_hpux_supply_ss_narrow (struct regcache
*regcache
,
1263 int regnum
, const gdb_byte
*save_state
)
1265 const gdb_byte
*ss_narrow
= save_state
+ HPPA_HPUX_SS_NARROW_OFFSET
;
1268 for (i
= HPPA_R1_REGNUM
; i
< HPPA_FP0_REGNUM
; i
++)
1270 if (regnum
== i
|| regnum
== -1)
1271 regcache_raw_supply (regcache
, i
, ss_narrow
+ offset
);
1278 hppa_hpux_supply_ss_fpblock (struct regcache
*regcache
,
1279 int regnum
, const gdb_byte
*save_state
)
1281 const gdb_byte
*ss_fpblock
= save_state
+ HPPA_HPUX_SS_FPBLOCK_OFFSET
;
1284 /* FIXME: We view the floating-point state as 64 single-precision
1285 registers for 32-bit code, and 32 double-precision register for
1286 64-bit code. This distinction is artificial and should be
1287 eliminated. If that ever happens, we should remove the if-clause
1290 if (register_size (get_regcache_arch (regcache
), HPPA_FP0_REGNUM
) == 4)
1292 for (i
= HPPA_FP0_REGNUM
; i
< HPPA_FP0_REGNUM
+ 64; i
++)
1294 if (regnum
== i
|| regnum
== -1)
1295 regcache_raw_supply (regcache
, i
, ss_fpblock
+ offset
);
1302 for (i
= HPPA_FP0_REGNUM
; i
< HPPA_FP0_REGNUM
+ 32; i
++)
1304 if (regnum
== i
|| regnum
== -1)
1305 regcache_raw_supply (regcache
, i
, ss_fpblock
+ offset
);
1313 hppa_hpux_supply_ss_wide (struct regcache
*regcache
,
1314 int regnum
, const gdb_byte
*save_state
)
1316 const gdb_byte
*ss_wide
= save_state
+ HPPA_HPUX_SS_WIDE_OFFSET
;
1319 if (register_size (get_regcache_arch (regcache
), HPPA_R1_REGNUM
) == 4)
1322 for (i
= HPPA_R1_REGNUM
; i
< HPPA_FP0_REGNUM
; i
++)
1324 if (regnum
== i
|| regnum
== -1)
1325 regcache_raw_supply (regcache
, i
, ss_wide
+ offset
);
1332 hppa_hpux_supply_save_state (const struct regset
*regset
,
1333 struct regcache
*regcache
,
1334 int regnum
, const void *regs
, size_t len
)
1336 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1337 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1338 const gdb_byte
*proc_info
= regs
;
1339 const gdb_byte
*save_state
= proc_info
+ 8;
1342 flags
= extract_unsigned_integer (save_state
+ HPPA_HPUX_SS_FLAGS_OFFSET
,
1344 if (regnum
== -1 || regnum
== HPPA_FLAGS_REGNUM
)
1346 size_t size
= register_size (gdbarch
, HPPA_FLAGS_REGNUM
);
1349 store_unsigned_integer (buf
, size
, byte_order
, flags
);
1350 regcache_raw_supply (regcache
, HPPA_FLAGS_REGNUM
, buf
);
1353 /* If the SS_WIDEREGS flag is set, we really do need the full
1354 `struct save_state'. */
1355 if (flags
& HPPA_HPUX_SS_WIDEREGS
&& len
< HPPA_HPUX_SAVE_STATE_SIZE
)
1356 error (_("Register set contents too small"));
1358 if (flags
& HPPA_HPUX_SS_WIDEREGS
)
1359 hppa_hpux_supply_ss_wide (regcache
, regnum
, save_state
);
1361 hppa_hpux_supply_ss_narrow (regcache
, regnum
, save_state
);
1363 hppa_hpux_supply_ss_fpblock (regcache
, regnum
, save_state
);
1366 /* HP-UX register set. */
1368 static const struct regset hppa_hpux_regset
=
1371 hppa_hpux_supply_save_state
1375 hppa_hpux_iterate_over_regset_sections (struct gdbarch
*gdbarch
,
1376 iterate_over_regset_sections_cb
*cb
,
1378 const struct regcache
*regcache
)
1380 cb (".reg", HPPA_HPUX_PA89_SAVE_STATE_SIZE
+ 8, &hppa_hpux_regset
,
1385 /* Bit in the `ss_flag' member of `struct save_state' that indicates
1386 the state was saved from a system call. From
1387 <machine/save_state.h>. */
1388 #define HPPA_HPUX_SS_INSYSCALL 0x02
1391 hppa_hpux_read_pc (struct regcache
*regcache
)
1395 /* If we're currently in a system call return the contents of %r31. */
1396 regcache_cooked_read_unsigned (regcache
, HPPA_FLAGS_REGNUM
, &flags
);
1397 if (flags
& HPPA_HPUX_SS_INSYSCALL
)
1400 regcache_cooked_read_unsigned (regcache
, HPPA_R31_REGNUM
, &pc
);
1404 return hppa_read_pc (regcache
);
1408 hppa_hpux_write_pc (struct regcache
*regcache
, CORE_ADDR pc
)
1412 /* If we're currently in a system call also write PC into %r31. */
1413 regcache_cooked_read_unsigned (regcache
, HPPA_FLAGS_REGNUM
, &flags
);
1414 if (flags
& HPPA_HPUX_SS_INSYSCALL
)
1415 regcache_cooked_write_unsigned (regcache
, HPPA_R31_REGNUM
, pc
| 0x3);
1417 hppa_write_pc (regcache
, pc
);
1421 hppa_hpux_unwind_pc (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
1425 /* If we're currently in a system call return the contents of %r31. */
1426 flags
= frame_unwind_register_unsigned (next_frame
, HPPA_FLAGS_REGNUM
);
1427 if (flags
& HPPA_HPUX_SS_INSYSCALL
)
1428 return frame_unwind_register_unsigned (next_frame
, HPPA_R31_REGNUM
) & ~0x3;
1430 return hppa_unwind_pc (gdbarch
, next_frame
);
1434 /* Given the current value of the pc, check to see if it is inside a stub, and
1435 if so, change the value of the pc to point to the caller of the stub.
1436 THIS_FRAME is the current frame in the current list of frames.
1437 BASE contains to stack frame base of the current frame.
1438 SAVE_REGS is the register file stored in the frame cache. */
1440 hppa_hpux_unwind_adjust_stub (struct frame_info
*this_frame
, CORE_ADDR base
,
1441 struct trad_frame_saved_reg
*saved_regs
)
1443 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
1444 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1445 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
1446 struct value
*pcoq_head_val
;
1449 struct unwind_table_entry
*u
;
1451 pcoq_head_val
= trad_frame_get_prev_register (this_frame
, saved_regs
,
1452 HPPA_PCOQ_HEAD_REGNUM
);
1454 extract_unsigned_integer (value_contents_all (pcoq_head_val
),
1455 register_size (gdbarch
, HPPA_PCOQ_HEAD_REGNUM
),
1458 u
= find_unwind_entry (pcoq_head
);
1459 if (u
&& u
->stub_unwind
.stub_type
== EXPORT
)
1461 stubpc
= read_memory_integer (base
- 24, word_size
, byte_order
);
1462 trad_frame_set_value (saved_regs
, HPPA_PCOQ_HEAD_REGNUM
, stubpc
);
1464 else if (hppa_symbol_address ("__gcc_plt_call")
1465 == get_pc_function_start (pcoq_head
))
1467 stubpc
= read_memory_integer (base
- 8, word_size
, byte_order
);
1468 trad_frame_set_value (saved_regs
, HPPA_PCOQ_HEAD_REGNUM
, stubpc
);
1473 hppa_hpux_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
1475 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1477 if (IS_32BIT_TARGET (gdbarch
))
1478 tdep
->in_solib_call_trampoline
= hppa32_hpux_in_solib_call_trampoline
;
1480 tdep
->in_solib_call_trampoline
= hppa64_hpux_in_solib_call_trampoline
;
1482 tdep
->unwind_adjust_stub
= hppa_hpux_unwind_adjust_stub
;
1484 set_gdbarch_in_solib_return_trampoline
1485 (gdbarch
, hppa_hpux_in_solib_return_trampoline
);
1486 set_gdbarch_skip_trampoline_code (gdbarch
, hppa_hpux_skip_trampoline_code
);
1488 set_gdbarch_push_dummy_code (gdbarch
, hppa_hpux_push_dummy_code
);
1489 set_gdbarch_call_dummy_location (gdbarch
, ON_STACK
);
1491 set_gdbarch_read_pc (gdbarch
, hppa_hpux_read_pc
);
1492 set_gdbarch_write_pc (gdbarch
, hppa_hpux_write_pc
);
1493 set_gdbarch_unwind_pc (gdbarch
, hppa_hpux_unwind_pc
);
1494 set_gdbarch_skip_permanent_breakpoint
1495 (gdbarch
, hppa_skip_permanent_breakpoint
);
1497 set_gdbarch_iterate_over_regset_sections
1498 (gdbarch
, hppa_hpux_iterate_over_regset_sections
);
1500 frame_unwind_append_unwinder (gdbarch
, &hppa_hpux_sigtramp_frame_unwind
);
1504 hppa_hpux_som_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
1506 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1510 tdep
->find_global_pointer
= hppa32_hpux_find_global_pointer
;
1512 hppa_hpux_init_abi (info
, gdbarch
);
1513 som_solib_select (gdbarch
);
1517 hppa_hpux_elf_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
1519 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1522 tdep
->find_global_pointer
= hppa64_hpux_find_global_pointer
;
1524 hppa_hpux_init_abi (info
, gdbarch
);
1525 pa64_solib_select (gdbarch
);
1528 static enum gdb_osabi
1529 hppa_hpux_core_osabi_sniffer (bfd
*abfd
)
1531 if (strcmp (bfd_get_target (abfd
), "hpux-core") == 0)
1532 return GDB_OSABI_HPUX_SOM
;
1533 else if (strcmp (bfd_get_target (abfd
), "elf64-hppa") == 0)
1537 section
= bfd_get_section_by_name (abfd
, ".kernel");
1543 size
= bfd_section_size (abfd
, section
);
1544 contents
= alloca (size
);
1545 if (bfd_get_section_contents (abfd
, section
, contents
,
1547 && strcmp (contents
, "HP-UX") == 0)
1548 return GDB_OSABI_HPUX_ELF
;
1552 return GDB_OSABI_UNKNOWN
;
1556 _initialize_hppa_hpux_tdep (void)
1558 /* BFD doesn't set a flavour for HP-UX style core files. It doesn't
1559 set the architecture either. */
1560 gdbarch_register_osabi_sniffer (bfd_arch_unknown
,
1561 bfd_target_unknown_flavour
,
1562 hppa_hpux_core_osabi_sniffer
);
1563 gdbarch_register_osabi_sniffer (bfd_arch_hppa
,
1564 bfd_target_elf_flavour
,
1565 hppa_hpux_core_osabi_sniffer
);
1567 gdbarch_register_osabi (bfd_arch_hppa
, 0, GDB_OSABI_HPUX_SOM
,
1568 hppa_hpux_som_init_abi
);
1569 gdbarch_register_osabi (bfd_arch_hppa
, bfd_mach_hppa20w
, GDB_OSABI_HPUX_ELF
,
1570 hppa_hpux_elf_init_abi
);