1 /* Target-dependent code for HP-UX on PA-RISC.
3 Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "arch-utils.h"
26 #include "frame-unwind.h"
27 #include "trad-frame.h"
33 #include "hppa-tdep.h"
34 #include "solib-som.h"
35 #include "solib-pa64.h"
38 #include "exceptions.h"
40 #include "gdb_string.h"
42 #define IS_32BIT_TARGET(_gdbarch) \
43 ((gdbarch_tdep (_gdbarch))->bytes_per_address == 4)
45 /* Bit in the `ss_flag' member of `struct save_state' that indicates
46 that the 64-bit register values are live. From
47 <machine/save_state.h>. */
48 #define HPPA_HPUX_SS_WIDEREGS 0x40
50 /* Offsets of various parts of `struct save_state'. From
51 <machine/save_state.h>. */
52 #define HPPA_HPUX_SS_FLAGS_OFFSET 0
53 #define HPPA_HPUX_SS_NARROW_OFFSET 4
54 #define HPPA_HPUX_SS_FPBLOCK_OFFSET 256
55 #define HPPA_HPUX_SS_WIDE_OFFSET 640
57 /* The size of `struct save_state. */
58 #define HPPA_HPUX_SAVE_STATE_SIZE 1152
60 /* The size of `struct pa89_save_state', which corresponds to PA-RISC
61 1.1, the lowest common denominator that we support. */
62 #define HPPA_HPUX_PA89_SAVE_STATE_SIZE 512
65 /* Forward declarations. */
66 extern void _initialize_hppa_hpux_tdep (void);
67 extern initialize_file_ftype _initialize_hppa_hpux_tdep;
70 in_opd_section (CORE_ADDR pc)
72 struct obj_section *s;
75 s = find_pc_section (pc);
78 && s->the_bfd_section->name != NULL
79 && strcmp (s->the_bfd_section->name, ".opd") == 0);
83 /* Return one if PC is in the call path of a trampoline, else return zero.
85 Note we return one for *any* call trampoline (long-call, arg-reloc), not
86 just shared library trampolines (import, export). */
89 hppa32_hpux_in_solib_call_trampoline (struct gdbarch *gdbarch,
90 CORE_ADDR pc, char *name)
92 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
93 struct minimal_symbol *minsym;
94 struct unwind_table_entry *u;
96 /* First see if PC is in one of the two C-library trampolines. */
97 if (pc == hppa_symbol_address("$$dyncall")
98 || pc == hppa_symbol_address("_sr4export"))
101 minsym = lookup_minimal_symbol_by_pc (pc);
102 if (minsym && strcmp (SYMBOL_LINKAGE_NAME (minsym), ".stub") == 0)
105 /* Get the unwind descriptor corresponding to PC, return zero
106 if no unwind was found. */
107 u = find_unwind_entry (pc);
111 /* If this isn't a linker stub, then return now. */
112 if (u->stub_unwind.stub_type == 0)
115 /* By definition a long-branch stub is a call stub. */
116 if (u->stub_unwind.stub_type == LONG_BRANCH)
119 /* The call and return path execute the same instructions within
120 an IMPORT stub! So an IMPORT stub is both a call and return
122 if (u->stub_unwind.stub_type == IMPORT)
125 /* Parameter relocation stubs always have a call path and may have a
127 if (u->stub_unwind.stub_type == PARAMETER_RELOCATION
128 || u->stub_unwind.stub_type == EXPORT)
132 /* Search forward from the current PC until we hit a branch
133 or the end of the stub. */
134 for (addr = pc; addr <= u->region_end; addr += 4)
138 insn = read_memory_integer (addr, 4, byte_order);
140 /* Does it look like a bl? If so then it's the call path, if
141 we find a bv or be first, then we're on the return path. */
142 if ((insn & 0xfc00e000) == 0xe8000000)
144 else if ((insn & 0xfc00e001) == 0xe800c000
145 || (insn & 0xfc000000) == 0xe0000000)
149 /* Should never happen. */
150 warning (_("Unable to find branch in parameter relocation stub."));
154 /* Unknown stub type. For now, just return zero. */
159 hppa64_hpux_in_solib_call_trampoline (struct gdbarch *gdbarch,
160 CORE_ADDR pc, char *name)
162 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
164 /* PA64 has a completely different stub/trampoline scheme. Is it
165 better? Maybe. It's certainly harder to determine with any
166 certainty that we are in a stub because we can not refer to the
169 The heuristic is simple. Try to lookup the current PC value in th
170 minimal symbol table. If that fails, then assume we are not in a
173 Then see if the PC value falls within the section bounds for the
174 section containing the minimal symbol we found in the first
175 step. If it does, then assume we are not in a stub and return.
177 Finally peek at the instructions to see if they look like a stub. */
178 struct minimal_symbol *minsym;
183 minsym = lookup_minimal_symbol_by_pc (pc);
187 sec = SYMBOL_OBJ_SECTION (minsym)->the_bfd_section;
189 if (bfd_get_section_vma (sec->owner, sec) <= pc
190 && pc < (bfd_get_section_vma (sec->owner, sec)
191 + bfd_section_size (sec->owner, sec)))
194 /* We might be in a stub. Peek at the instructions. Stubs are 3
195 instructions long. */
196 insn = read_memory_integer (pc, 4, byte_order);
198 /* Find out where we think we are within the stub. */
199 if ((insn & 0xffffc00e) == 0x53610000)
201 else if ((insn & 0xffffffff) == 0xe820d000)
203 else if ((insn & 0xffffc00e) == 0x537b0000)
208 /* Now verify each insn in the range looks like a stub instruction. */
209 insn = read_memory_integer (addr, 4, byte_order);
210 if ((insn & 0xffffc00e) != 0x53610000)
213 /* Now verify each insn in the range looks like a stub instruction. */
214 insn = read_memory_integer (addr + 4, 4, byte_order);
215 if ((insn & 0xffffffff) != 0xe820d000)
218 /* Now verify each insn in the range looks like a stub instruction. */
219 insn = read_memory_integer (addr + 8, 4, byte_order);
220 if ((insn & 0xffffc00e) != 0x537b0000)
223 /* Looks like a stub. */
227 /* Return one if PC is in the return path of a trampoline, else return zero.
229 Note we return one for *any* call trampoline (long-call, arg-reloc), not
230 just shared library trampolines (import, export). */
233 hppa_hpux_in_solib_return_trampoline (struct gdbarch *gdbarch,
234 CORE_ADDR pc, char *name)
236 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
237 struct unwind_table_entry *u;
239 /* Get the unwind descriptor corresponding to PC, return zero
240 if no unwind was found. */
241 u = find_unwind_entry (pc);
245 /* If this isn't a linker stub or it's just a long branch stub, then
247 if (u->stub_unwind.stub_type == 0 || u->stub_unwind.stub_type == LONG_BRANCH)
250 /* The call and return path execute the same instructions within
251 an IMPORT stub! So an IMPORT stub is both a call and return
253 if (u->stub_unwind.stub_type == IMPORT)
256 /* Parameter relocation stubs always have a call path and may have a
258 if (u->stub_unwind.stub_type == PARAMETER_RELOCATION
259 || u->stub_unwind.stub_type == EXPORT)
263 /* Search forward from the current PC until we hit a branch
264 or the end of the stub. */
265 for (addr = pc; addr <= u->region_end; addr += 4)
269 insn = read_memory_integer (addr, 4, byte_order);
271 /* Does it look like a bl? If so then it's the call path, if
272 we find a bv or be first, then we're on the return path. */
273 if ((insn & 0xfc00e000) == 0xe8000000)
275 else if ((insn & 0xfc00e001) == 0xe800c000
276 || (insn & 0xfc000000) == 0xe0000000)
280 /* Should never happen. */
281 warning (_("Unable to find branch in parameter relocation stub."));
285 /* Unknown stub type. For now, just return zero. */
290 /* Figure out if PC is in a trampoline, and if so find out where
291 the trampoline will jump to. If not in a trampoline, return zero.
293 Simple code examination probably is not a good idea since the code
294 sequences in trampolines can also appear in user code.
296 We use unwinds and information from the minimal symbol table to
297 determine when we're in a trampoline. This won't work for ELF
298 (yet) since it doesn't create stub unwind entries. Whether or
299 not ELF will create stub unwinds or normal unwinds for linker
300 stubs is still being debated.
302 This should handle simple calls through dyncall or sr4export,
303 long calls, argument relocation stubs, and dyncall/sr4export
304 calling an argument relocation stub. It even handles some stubs
305 used in dynamic executables. */
308 hppa_hpux_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
310 struct gdbarch *gdbarch = get_frame_arch (frame);
311 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
312 int word_size = gdbarch_ptr_bit (gdbarch) / 8;
314 long prev_inst, curr_inst, loc;
315 struct minimal_symbol *msym;
316 struct unwind_table_entry *u;
318 /* Addresses passed to dyncall may *NOT* be the actual address
319 of the function. So we may have to do something special. */
320 if (pc == hppa_symbol_address("$$dyncall"))
322 pc = (CORE_ADDR) get_frame_register_unsigned (frame, 22);
324 /* If bit 30 (counting from the left) is on, then pc is the address of
325 the PLT entry for this function, not the address of the function
326 itself. Bit 31 has meaning too, but only for MPE. */
328 pc = (CORE_ADDR) read_memory_integer (pc & ~0x3, word_size,
331 if (pc == hppa_symbol_address("$$dyncall_external"))
333 pc = (CORE_ADDR) get_frame_register_unsigned (frame, 22);
334 pc = (CORE_ADDR) read_memory_integer (pc & ~0x3, word_size, byte_order);
336 else if (pc == hppa_symbol_address("_sr4export"))
337 pc = (CORE_ADDR) get_frame_register_unsigned (frame, 22);
339 /* Get the unwind descriptor corresponding to PC, return zero
340 if no unwind was found. */
341 u = find_unwind_entry (pc);
345 /* If this isn't a linker stub, then return now. */
346 /* elz: attention here! (FIXME) because of a compiler/linker
347 error, some stubs which should have a non zero stub_unwind.stub_type
348 have unfortunately a value of zero. So this function would return here
349 as if we were not in a trampoline. To fix this, we go look at the partial
350 symbol information, which reports this guy as a stub.
351 (FIXME): Unfortunately, we are not that lucky: it turns out that the
352 partial symbol information is also wrong sometimes. This is because
353 when it is entered (somread.c::som_symtab_read()) it can happen that
354 if the type of the symbol (from the som) is Entry, and the symbol is
355 in a shared library, then it can also be a trampoline. This would be OK,
356 except that I believe the way they decide if we are ina shared library
357 does not work. SOOOO..., even if we have a regular function w/o
358 trampolines its minimal symbol can be assigned type mst_solib_trampoline.
359 Also, if we find that the symbol is a real stub, then we fix the unwind
360 descriptor, and define the stub type to be EXPORT.
361 Hopefully this is correct most of the times. */
362 if (u->stub_unwind.stub_type == 0)
365 /* elz: NOTE (FIXME!) once the problem with the unwind information is fixed
366 we can delete all the code which appears between the lines. */
367 /*--------------------------------------------------------------------------*/
368 msym = lookup_minimal_symbol_by_pc (pc);
370 if (msym == NULL || MSYMBOL_TYPE (msym) != mst_solib_trampoline)
371 return orig_pc == pc ? 0 : pc & ~0x3;
373 else if (msym != NULL && MSYMBOL_TYPE (msym) == mst_solib_trampoline)
375 struct objfile *objfile;
376 struct minimal_symbol *msymbol;
377 int function_found = 0;
379 /* Go look if there is another minimal symbol with the same name as
380 this one, but with type mst_text. This would happen if the msym
381 is an actual trampoline, in which case there would be another
382 symbol with the same name corresponding to the real function. */
384 ALL_MSYMBOLS (objfile, msymbol)
386 if (MSYMBOL_TYPE (msymbol) == mst_text
387 && strcmp (SYMBOL_LINKAGE_NAME (msymbol),
388 SYMBOL_LINKAGE_NAME (msym)) == 0)
396 /* The type of msym is correct (mst_solib_trampoline), but
397 the unwind info is wrong, so set it to the correct value. */
398 u->stub_unwind.stub_type = EXPORT;
400 /* The stub type info in the unwind is correct (this is not a
401 trampoline), but the msym type information is wrong, it
402 should be mst_text. So we need to fix the msym, and also
403 get out of this function. */
405 MSYMBOL_TYPE (msym) = mst_text;
406 return orig_pc == pc ? 0 : pc & ~0x3;
410 /*--------------------------------------------------------------------------*/
413 /* It's a stub. Search for a branch and figure out where it goes.
414 Note we have to handle multi insn branch sequences like ldil;ble.
415 Most (all?) other branches can be determined by examining the contents
416 of certain registers and the stack. */
423 /* Make sure we haven't walked outside the range of this stub. */
424 if (u != find_unwind_entry (loc))
426 warning (_("Unable to find branch in linker stub"));
427 return orig_pc == pc ? 0 : pc & ~0x3;
430 prev_inst = curr_inst;
431 curr_inst = read_memory_integer (loc, 4, byte_order);
433 /* Does it look like a branch external using %r1? Then it's the
434 branch from the stub to the actual function. */
435 if ((curr_inst & 0xffe0e000) == 0xe0202000)
437 /* Yup. See if the previous instruction loaded
438 a value into %r1. If so compute and return the jump address. */
439 if ((prev_inst & 0xffe00000) == 0x20200000)
440 return (hppa_extract_21 (prev_inst)
441 + hppa_extract_17 (curr_inst)) & ~0x3;
444 warning (_("Unable to find ldil X,%%r1 "
445 "before ble Y(%%sr4,%%r1)."));
446 return orig_pc == pc ? 0 : pc & ~0x3;
450 /* Does it look like a be 0(sr0,%r21)? OR
451 Does it look like a be, n 0(sr0,%r21)? OR
452 Does it look like a bve (r21)? (this is on PA2.0)
453 Does it look like a bve, n(r21)? (this is also on PA2.0)
454 That's the branch from an
455 import stub to an export stub.
457 It is impossible to determine the target of the branch via
458 simple examination of instructions and/or data (consider
459 that the address in the plabel may be the address of the
460 bind-on-reference routine in the dynamic loader).
462 So we have try an alternative approach.
464 Get the name of the symbol at our current location; it should
465 be a stub symbol with the same name as the symbol in the
468 Then lookup a minimal symbol with the same name; we should
469 get the minimal symbol for the target routine in the shared
470 library as those take precedence of import/export stubs. */
471 if ((curr_inst == 0xe2a00000) ||
472 (curr_inst == 0xe2a00002) ||
473 (curr_inst == 0xeaa0d000) ||
474 (curr_inst == 0xeaa0d002))
476 struct minimal_symbol *stubsym, *libsym;
478 stubsym = lookup_minimal_symbol_by_pc (loc);
481 warning (_("Unable to find symbol for 0x%lx"), loc);
482 return orig_pc == pc ? 0 : pc & ~0x3;
485 libsym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (stubsym),
489 warning (_("Unable to find library symbol for %s."),
490 SYMBOL_PRINT_NAME (stubsym));
491 return orig_pc == pc ? 0 : pc & ~0x3;
494 return SYMBOL_VALUE (libsym);
497 /* Does it look like bl X,%rp or bl X,%r0? Another way to do a
498 branch from the stub to the actual function. */
500 else if ((curr_inst & 0xffe0e000) == 0xe8400000
501 || (curr_inst & 0xffe0e000) == 0xe8000000
502 || (curr_inst & 0xffe0e000) == 0xe800A000)
503 return (loc + hppa_extract_17 (curr_inst) + 8) & ~0x3;
505 /* Does it look like bv (rp)? Note this depends on the
506 current stack pointer being the same as the stack
507 pointer in the stub itself! This is a branch on from the
508 stub back to the original caller. */
509 /*else if ((curr_inst & 0xffe0e000) == 0xe840c000) */
510 else if ((curr_inst & 0xffe0f000) == 0xe840c000)
512 /* Yup. See if the previous instruction loaded
514 if (prev_inst == 0x4bc23ff1)
517 sp = get_frame_register_unsigned (frame, HPPA_SP_REGNUM);
518 return read_memory_integer (sp - 8, 4, byte_order) & ~0x3;
522 warning (_("Unable to find restore of %%rp before bv (%%rp)."));
523 return orig_pc == pc ? 0 : pc & ~0x3;
527 /* elz: added this case to capture the new instruction
528 at the end of the return part of an export stub used by
529 the PA2.0: BVE, n (rp) */
530 else if ((curr_inst & 0xffe0f000) == 0xe840d000)
532 return (read_memory_integer
533 (get_frame_register_unsigned (frame, HPPA_SP_REGNUM) - 24,
534 word_size, byte_order)) & ~0x3;
537 /* What about be,n 0(sr0,%rp)? It's just another way we return to
538 the original caller from the stub. Used in dynamic executables. */
539 else if (curr_inst == 0xe0400002)
541 /* The value we jump to is sitting in sp - 24. But that's
542 loaded several instructions before the be instruction.
543 I guess we could check for the previous instruction being
544 mtsp %r1,%sr0 if we want to do sanity checking. */
545 return (read_memory_integer
546 (get_frame_register_unsigned (frame, HPPA_SP_REGNUM) - 24,
547 word_size, byte_order)) & ~0x3;
550 /* Haven't found the branch yet, but we're still in the stub.
557 hppa_skip_permanent_breakpoint (struct regcache *regcache)
559 /* To step over a breakpoint instruction on the PA takes some
560 fiddling with the instruction address queue.
562 When we stop at a breakpoint, the IA queue front (the instruction
563 we're executing now) points at the breakpoint instruction, and
564 the IA queue back (the next instruction to execute) points to
565 whatever instruction we would execute after the breakpoint, if it
566 were an ordinary instruction. This is the case even if the
567 breakpoint is in the delay slot of a branch instruction.
569 Clearly, to step past the breakpoint, we need to set the queue
570 front to the back. But what do we put in the back? What
571 instruction comes after that one? Because of the branch delay
572 slot, the next insn is always at the back + 4. */
574 ULONGEST pcoq_tail, pcsq_tail;
575 regcache_cooked_read_unsigned (regcache, HPPA_PCOQ_TAIL_REGNUM, &pcoq_tail);
576 regcache_cooked_read_unsigned (regcache, HPPA_PCSQ_TAIL_REGNUM, &pcsq_tail);
578 regcache_cooked_write_unsigned (regcache, HPPA_PCOQ_HEAD_REGNUM, pcoq_tail);
579 regcache_cooked_write_unsigned (regcache, HPPA_PCSQ_HEAD_REGNUM, pcsq_tail);
581 regcache_cooked_write_unsigned (regcache,
582 HPPA_PCOQ_TAIL_REGNUM, pcoq_tail + 4);
583 /* We can leave the tail's space the same, since there's no jump. */
588 struct hppa_hpux_sigtramp_unwind_cache
591 struct trad_frame_saved_reg *saved_regs;
594 static int hppa_hpux_tramp_reg[] = {
596 HPPA_PCOQ_HEAD_REGNUM,
597 HPPA_PCSQ_HEAD_REGNUM,
598 HPPA_PCOQ_TAIL_REGNUM,
599 HPPA_PCSQ_TAIL_REGNUM,
626 static struct hppa_hpux_sigtramp_unwind_cache *
627 hppa_hpux_sigtramp_frame_unwind_cache (struct frame_info *this_frame,
631 struct gdbarch *gdbarch = get_frame_arch (this_frame);
632 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
633 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
634 struct hppa_hpux_sigtramp_unwind_cache *info;
636 CORE_ADDR sp, scptr, off;
642 info = FRAME_OBSTACK_ZALLOC (struct hppa_hpux_sigtramp_unwind_cache);
644 info->saved_regs = trad_frame_alloc_saved_regs (this_frame);
646 sp = get_frame_register_unsigned (this_frame, HPPA_SP_REGNUM);
648 if (IS_32BIT_TARGET (gdbarch))
655 /* See /usr/include/machine/save_state.h for the structure of the
656 save_state_t structure. */
658 flag = read_memory_unsigned_integer (scptr + HPPA_HPUX_SS_FLAGS_OFFSET,
661 if (!(flag & HPPA_HPUX_SS_WIDEREGS))
663 /* Narrow registers. */
664 off = scptr + HPPA_HPUX_SS_NARROW_OFFSET;
670 /* Wide registers. */
671 off = scptr + HPPA_HPUX_SS_WIDE_OFFSET + 8;
673 szoff = (tdep->bytes_per_address == 4 ? 4 : 0);
676 for (i = 1; i < 32; i++)
678 info->saved_regs[HPPA_R0_REGNUM + i].addr = off + szoff;
682 for (i = 0; i < ARRAY_SIZE (hppa_hpux_tramp_reg); i++)
684 if (hppa_hpux_tramp_reg[i] > 0)
685 info->saved_regs[hppa_hpux_tramp_reg[i]].addr = off + szoff;
692 info->base = get_frame_register_unsigned (this_frame, HPPA_SP_REGNUM);
698 hppa_hpux_sigtramp_frame_this_id (struct frame_info *this_frame,
699 void **this_prologue_cache,
700 struct frame_id *this_id)
702 struct hppa_hpux_sigtramp_unwind_cache *info
703 = hppa_hpux_sigtramp_frame_unwind_cache (this_frame, this_prologue_cache);
705 *this_id = frame_id_build (info->base, get_frame_pc (this_frame));
708 static struct value *
709 hppa_hpux_sigtramp_frame_prev_register (struct frame_info *this_frame,
710 void **this_prologue_cache,
713 struct hppa_hpux_sigtramp_unwind_cache *info
714 = hppa_hpux_sigtramp_frame_unwind_cache (this_frame, this_prologue_cache);
716 return hppa_frame_prev_register_helper (this_frame,
717 info->saved_regs, regnum);
721 hppa_hpux_sigtramp_unwind_sniffer (const struct frame_unwind *self,
722 struct frame_info *this_frame,
725 struct gdbarch *gdbarch = get_frame_arch (this_frame);
726 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
727 struct unwind_table_entry *u;
728 CORE_ADDR pc = get_frame_pc (this_frame);
730 u = find_unwind_entry (pc);
732 /* If this is an export stub, try to get the unwind descriptor for
733 the actual function itself. */
734 if (u && u->stub_unwind.stub_type == EXPORT)
736 gdb_byte buf[HPPA_INSN_SIZE];
739 if (!safe_frame_unwind_memory (this_frame, u->region_start,
743 insn = extract_unsigned_integer (buf, sizeof buf, byte_order);
744 if ((insn & 0xffe0e000) == 0xe8400000)
745 u = find_unwind_entry(u->region_start + hppa_extract_17 (insn) + 8);
748 if (u && u->HP_UX_interrupt_marker)
754 static const struct frame_unwind hppa_hpux_sigtramp_frame_unwind = {
756 default_frame_unwind_stop_reason,
757 hppa_hpux_sigtramp_frame_this_id,
758 hppa_hpux_sigtramp_frame_prev_register,
760 hppa_hpux_sigtramp_unwind_sniffer
764 hppa32_hpux_find_global_pointer (struct gdbarch *gdbarch,
765 struct value *function)
767 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
770 faddr = value_as_address (function);
772 /* Is this a plabel? If so, dereference it to get the gp value. */
780 status = target_read_memory (faddr + 4, buf, sizeof (buf));
782 return extract_unsigned_integer (buf, sizeof (buf), byte_order);
785 return gdbarch_tdep (gdbarch)->solib_get_got_by_pc (faddr);
789 hppa64_hpux_find_global_pointer (struct gdbarch *gdbarch,
790 struct value *function)
792 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
796 faddr = value_as_address (function);
798 if (in_opd_section (faddr))
800 target_read_memory (faddr, buf, sizeof (buf));
801 return extract_unsigned_integer (&buf[24], 8, byte_order);
805 return gdbarch_tdep (gdbarch)->solib_get_got_by_pc (faddr);
809 static unsigned int ldsid_pattern[] = {
810 0x000010a0, /* ldsid (rX),rY */
811 0x00001820, /* mtsp rY,sr0 */
812 0xe0000000 /* be,n (sr0,rX) */
816 hppa_hpux_search_pattern (struct gdbarch *gdbarch,
817 CORE_ADDR start, CORE_ADDR end,
818 unsigned int *patterns, int count)
820 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
821 int num_insns = (end - start + HPPA_INSN_SIZE) / HPPA_INSN_SIZE;
826 buf = alloca (num_insns * HPPA_INSN_SIZE);
827 insns = alloca (num_insns * sizeof (unsigned int));
829 read_memory (start, buf, num_insns * HPPA_INSN_SIZE);
830 for (i = 0; i < num_insns; i++, buf += HPPA_INSN_SIZE)
831 insns[i] = extract_unsigned_integer (buf, HPPA_INSN_SIZE, byte_order);
833 for (offset = 0; offset <= num_insns - count; offset++)
835 for (i = 0; i < count; i++)
837 if ((insns[offset + i] & patterns[i]) != patterns[i])
844 if (offset <= num_insns - count)
845 return start + offset * HPPA_INSN_SIZE;
851 hppa32_hpux_search_dummy_call_sequence (struct gdbarch *gdbarch, CORE_ADDR pc,
854 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
856 struct obj_section *sec;
857 struct hppa_objfile_private *priv;
858 struct frame_info *frame;
859 struct unwind_table_entry *u;
864 sec = find_pc_section (pc);
866 priv = objfile_data (obj, hppa_objfile_priv_data);
869 priv = hppa_init_objfile_priv_data (obj);
871 error (_("Internal error creating objfile private data."));
873 /* Use the cached value if we have one. */
874 if (priv->dummy_call_sequence_addr != 0)
876 *argreg = priv->dummy_call_sequence_reg;
877 return priv->dummy_call_sequence_addr;
880 /* First try a heuristic; if we are in a shared library call, our return
881 pointer is likely to point at an export stub. */
882 frame = get_current_frame ();
883 rp = frame_unwind_register_unsigned (frame, 2);
884 u = find_unwind_entry (rp);
885 if (u && u->stub_unwind.stub_type == EXPORT)
887 addr = hppa_hpux_search_pattern (gdbarch,
888 u->region_start, u->region_end,
890 ARRAY_SIZE (ldsid_pattern));
895 /* Next thing to try is to look for an export stub. */
896 if (priv->unwind_info)
900 for (i = 0; i < priv->unwind_info->last; i++)
902 struct unwind_table_entry *u;
903 u = &priv->unwind_info->table[i];
904 if (u->stub_unwind.stub_type == EXPORT)
906 addr = hppa_hpux_search_pattern (gdbarch,
907 u->region_start, u->region_end,
909 ARRAY_SIZE (ldsid_pattern));
918 /* Finally, if this is the main executable, try to locate a sequence
920 addr = hppa_symbol_address ("noshlibs");
921 sec = find_pc_section (addr);
923 if (sec && sec->objfile == obj)
925 CORE_ADDR start, end;
927 find_pc_partial_function (addr, NULL, &start, &end);
928 if (start != 0 && end != 0)
930 addr = hppa_hpux_search_pattern (gdbarch, start, end, ldsid_pattern,
931 ARRAY_SIZE (ldsid_pattern));
937 /* Can't find a suitable sequence. */
941 target_read_memory (addr, buf, sizeof (buf));
942 insn = extract_unsigned_integer (buf, sizeof (buf), byte_order);
943 priv->dummy_call_sequence_addr = addr;
944 priv->dummy_call_sequence_reg = (insn >> 21) & 0x1f;
946 *argreg = priv->dummy_call_sequence_reg;
947 return priv->dummy_call_sequence_addr;
951 hppa64_hpux_search_dummy_call_sequence (struct gdbarch *gdbarch, CORE_ADDR pc,
954 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
956 struct obj_section *sec;
957 struct hppa_objfile_private *priv;
959 struct minimal_symbol *msym;
962 sec = find_pc_section (pc);
964 priv = objfile_data (obj, hppa_objfile_priv_data);
967 priv = hppa_init_objfile_priv_data (obj);
969 error (_("Internal error creating objfile private data."));
971 /* Use the cached value if we have one. */
972 if (priv->dummy_call_sequence_addr != 0)
974 *argreg = priv->dummy_call_sequence_reg;
975 return priv->dummy_call_sequence_addr;
978 /* FIXME: Without stub unwind information, locating a suitable sequence is
979 fairly difficult. For now, we implement a very naive and inefficient
980 scheme; try to read in blocks of code, and look for a "bve,n (rp)"
981 instruction. These are likely to occur at the end of functions, so
982 we only look at the last two instructions of each function. */
983 for (i = 0, msym = obj->msymbols; i < obj->minimal_symbol_count; i++, msym++)
985 CORE_ADDR begin, end;
987 gdb_byte buf[2 * HPPA_INSN_SIZE];
990 find_pc_partial_function (SYMBOL_VALUE_ADDRESS (msym), &name,
993 if (name == NULL || begin == 0 || end == 0)
996 if (target_read_memory (end - sizeof (buf), buf, sizeof (buf)) == 0)
998 for (offset = 0; offset < sizeof (buf); offset++)
1002 insn = extract_unsigned_integer (buf + offset,
1003 HPPA_INSN_SIZE, byte_order);
1004 if (insn == 0xe840d002) /* bve,n (rp) */
1006 addr = (end - sizeof (buf)) + offset;
1013 /* Can't find a suitable sequence. */
1017 priv->dummy_call_sequence_addr = addr;
1018 /* Right now we only look for a "bve,l (rp)" sequence, so the register is
1019 always HPPA_RP_REGNUM. */
1020 priv->dummy_call_sequence_reg = HPPA_RP_REGNUM;
1022 *argreg = priv->dummy_call_sequence_reg;
1023 return priv->dummy_call_sequence_addr;
1027 hppa_hpux_find_import_stub_for_addr (CORE_ADDR funcaddr)
1029 struct objfile *objfile;
1030 struct minimal_symbol *funsym, *stubsym;
1033 funsym = lookup_minimal_symbol_by_pc (funcaddr);
1036 ALL_OBJFILES (objfile)
1038 stubsym = lookup_minimal_symbol_solib_trampoline
1039 (SYMBOL_LINKAGE_NAME (funsym), objfile);
1043 struct unwind_table_entry *u;
1045 u = find_unwind_entry (SYMBOL_VALUE (stubsym));
1047 || (u->stub_unwind.stub_type != IMPORT
1048 && u->stub_unwind.stub_type != IMPORT_SHLIB))
1051 stubaddr = SYMBOL_VALUE (stubsym);
1053 /* If we found an IMPORT stub, then we can stop searching;
1054 if we found an IMPORT_SHLIB, we want to continue the search
1055 in the hopes that we will find an IMPORT stub. */
1056 if (u->stub_unwind.stub_type == IMPORT)
1065 hppa_hpux_sr_for_addr (struct gdbarch *gdbarch, CORE_ADDR addr)
1068 /* The space register to use is encoded in the top 2 bits of the address. */
1069 sr = addr >> (gdbarch_tdep (gdbarch)->bytes_per_address * 8 - 2);
1074 hppa_hpux_find_dummy_bpaddr (CORE_ADDR addr)
1076 /* In order for us to restore the space register to its starting state,
1077 we need the dummy trampoline to return to an instruction address in
1078 the same space as where we started the call. We used to place the
1079 breakpoint near the current pc, however, this breaks nested dummy calls
1080 as the nested call will hit the breakpoint address and terminate
1081 prematurely. Instead, we try to look for an address in the same space to
1084 This is similar in spirit to putting the breakpoint at the "entry point"
1085 of an executable. */
1087 struct obj_section *sec;
1088 struct unwind_table_entry *u;
1089 struct minimal_symbol *msym;
1093 sec = find_pc_section (addr);
1096 /* First try the lowest address in the section; we can use it as long
1097 as it is "regular" code (i.e. not a stub). */
1098 u = find_unwind_entry (obj_section_addr (sec));
1099 if (!u || u->stub_unwind.stub_type == 0)
1100 return obj_section_addr (sec);
1102 /* Otherwise, we need to find a symbol for a regular function. We
1103 do this by walking the list of msymbols in the objfile. The symbol
1104 we find should not be the same as the function that was passed in. */
1106 /* FIXME: this is broken, because we can find a function that will be
1107 called by the dummy call target function, which will still not
1110 find_pc_partial_function (addr, NULL, &func, NULL);
1111 for (i = 0, msym = sec->objfile->msymbols;
1112 i < sec->objfile->minimal_symbol_count;
1115 u = find_unwind_entry (SYMBOL_VALUE_ADDRESS (msym));
1116 if (func != SYMBOL_VALUE_ADDRESS (msym)
1117 && (!u || u->stub_unwind.stub_type == 0))
1118 return SYMBOL_VALUE_ADDRESS (msym);
1122 warning (_("Cannot find suitable address to place dummy breakpoint; nested "
1123 "calls may fail."));
1128 hppa_hpux_push_dummy_code (struct gdbarch *gdbarch, CORE_ADDR sp,
1130 struct value **args, int nargs,
1131 struct type *value_type,
1132 CORE_ADDR *real_pc, CORE_ADDR *bp_addr,
1133 struct regcache *regcache)
1135 CORE_ADDR pc, stubaddr;
1138 pc = regcache_read_pc (regcache);
1140 /* Note: we don't want to pass a function descriptor here; push_dummy_call
1141 fills in the PIC register for us. */
1142 funcaddr = gdbarch_convert_from_func_ptr_addr (gdbarch, funcaddr, NULL);
1144 /* The simple case is where we call a function in the same space that we are
1145 currently in; in that case we don't really need to do anything. */
1146 if (hppa_hpux_sr_for_addr (gdbarch, pc)
1147 == hppa_hpux_sr_for_addr (gdbarch, funcaddr))
1149 /* Intraspace call. */
1150 *bp_addr = hppa_hpux_find_dummy_bpaddr (pc);
1151 *real_pc = funcaddr;
1152 regcache_cooked_write_unsigned (regcache, HPPA_RP_REGNUM, *bp_addr);
1157 /* In order to make an interspace call, we need to go through a stub.
1158 gcc supplies an appropriate stub called "__gcc_plt_call", however, if
1159 an application is compiled with HP compilers then this stub is not
1160 available. We used to fallback to "__d_plt_call", however that stub
1161 is not entirely useful for us because it doesn't do an interspace
1162 return back to the caller. Also, on hppa64-hpux, there is no
1163 __gcc_plt_call available. In order to keep the code uniform, we
1164 instead don't use either of these stubs, but instead write our own
1167 A problem arises since the stack is located in a different space than
1168 code, so in order to branch to a stack stub, we will need to do an
1169 interspace branch. Previous versions of gdb did this by modifying code
1170 at the current pc and doing single-stepping to set the pcsq. Since this
1171 is highly undesirable, we use a different scheme:
1173 All we really need to do the branch to the stub is a short instruction
1184 Instead of writing these sequences ourselves, we can find it in
1185 the instruction stream that belongs to the current space. While this
1186 seems difficult at first, we are actually guaranteed to find the sequences
1190 - in export stubs for shared libraries
1191 - in the "noshlibs" routine in the main module
1194 - at the end of each "regular" function
1196 We cache the address of these sequences in the objfile's private data
1197 since these operations can potentially be quite expensive.
1200 - write a stack trampoline
1201 - look for a suitable instruction sequence in the current space
1202 - point the sequence at the trampoline
1203 - set the return address of the trampoline to the current space
1204 (see hppa_hpux_find_dummy_call_bpaddr)
1205 - set the continuing address of the "dummy code" as the sequence. */
1207 if (IS_32BIT_TARGET (gdbarch))
1209 static unsigned int hppa32_tramp[] = {
1210 0x0fdf1291, /* stw r31,-8(,sp) */
1211 0x02c010a1, /* ldsid (,r22),r1 */
1212 0x00011820, /* mtsp r1,sr0 */
1213 0xe6c00000, /* be,l 0(sr0,r22),%sr0,%r31 */
1214 0x081f0242, /* copy r31,rp */
1215 0x0fd11082, /* ldw -8(,sp),rp */
1216 0x004010a1, /* ldsid (,rp),r1 */
1217 0x00011820, /* mtsp r1,sr0 */
1218 0xe0400000, /* be 0(sr0,rp) */
1219 0x08000240 /* nop */
1222 /* for hppa32, we must call the function through a stub so that on
1223 return it can return to the space of our trampoline. */
1224 stubaddr = hppa_hpux_find_import_stub_for_addr (funcaddr);
1226 error (_("Cannot call external function not referenced by application "
1227 "(no import stub).\n"));
1228 regcache_cooked_write_unsigned (regcache, 22, stubaddr);
1230 write_memory (sp, (char *)&hppa32_tramp, sizeof (hppa32_tramp));
1232 *bp_addr = hppa_hpux_find_dummy_bpaddr (pc);
1233 regcache_cooked_write_unsigned (regcache, 31, *bp_addr);
1235 *real_pc = hppa32_hpux_search_dummy_call_sequence (gdbarch, pc, &argreg);
1237 error (_("Cannot make interspace call from here."));
1239 regcache_cooked_write_unsigned (regcache, argreg, sp);
1241 sp += sizeof (hppa32_tramp);
1245 static unsigned int hppa64_tramp[] = {
1246 0xeac0f000, /* bve,l (r22),%r2 */
1247 0x0fdf12d1, /* std r31,-8(,sp) */
1248 0x0fd110c2, /* ldd -8(,sp),rp */
1249 0xe840d002, /* bve,n (rp) */
1250 0x08000240 /* nop */
1253 /* for hppa64, we don't need to call through a stub; all functions
1254 return via a bve. */
1255 regcache_cooked_write_unsigned (regcache, 22, funcaddr);
1256 write_memory (sp, (char *)&hppa64_tramp, sizeof (hppa64_tramp));
1259 regcache_cooked_write_unsigned (regcache, 31, *bp_addr);
1261 *real_pc = hppa64_hpux_search_dummy_call_sequence (gdbarch, pc, &argreg);
1263 error (_("Cannot make interspace call from here."));
1265 regcache_cooked_write_unsigned (regcache, argreg, sp);
1267 sp += sizeof (hppa64_tramp);
1270 sp = gdbarch_frame_align (gdbarch, sp);
1278 hppa_hpux_supply_ss_narrow (struct regcache *regcache,
1279 int regnum, const char *save_state)
1281 const char *ss_narrow = save_state + HPPA_HPUX_SS_NARROW_OFFSET;
1284 for (i = HPPA_R1_REGNUM; i < HPPA_FP0_REGNUM; i++)
1286 if (regnum == i || regnum == -1)
1287 regcache_raw_supply (regcache, i, ss_narrow + offset);
1294 hppa_hpux_supply_ss_fpblock (struct regcache *regcache,
1295 int regnum, const char *save_state)
1297 const char *ss_fpblock = save_state + HPPA_HPUX_SS_FPBLOCK_OFFSET;
1300 /* FIXME: We view the floating-point state as 64 single-precision
1301 registers for 32-bit code, and 32 double-precision register for
1302 64-bit code. This distinction is artificial and should be
1303 eliminated. If that ever happens, we should remove the if-clause
1306 if (register_size (get_regcache_arch (regcache), HPPA_FP0_REGNUM) == 4)
1308 for (i = HPPA_FP0_REGNUM; i < HPPA_FP0_REGNUM + 64; i++)
1310 if (regnum == i || regnum == -1)
1311 regcache_raw_supply (regcache, i, ss_fpblock + offset);
1318 for (i = HPPA_FP0_REGNUM; i < HPPA_FP0_REGNUM + 32; i++)
1320 if (regnum == i || regnum == -1)
1321 regcache_raw_supply (regcache, i, ss_fpblock + offset);
1329 hppa_hpux_supply_ss_wide (struct regcache *regcache,
1330 int regnum, const char *save_state)
1332 const char *ss_wide = save_state + HPPA_HPUX_SS_WIDE_OFFSET;
1335 if (register_size (get_regcache_arch (regcache), HPPA_R1_REGNUM) == 4)
1338 for (i = HPPA_R1_REGNUM; i < HPPA_FP0_REGNUM; i++)
1340 if (regnum == i || regnum == -1)
1341 regcache_raw_supply (regcache, i, ss_wide + offset);
1348 hppa_hpux_supply_save_state (const struct regset *regset,
1349 struct regcache *regcache,
1350 int regnum, const void *regs, size_t len)
1352 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1353 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1354 const char *proc_info = regs;
1355 const char *save_state = proc_info + 8;
1358 flags = extract_unsigned_integer (save_state + HPPA_HPUX_SS_FLAGS_OFFSET,
1360 if (regnum == -1 || regnum == HPPA_FLAGS_REGNUM)
1362 size_t size = register_size (gdbarch, HPPA_FLAGS_REGNUM);
1365 store_unsigned_integer (buf, size, byte_order, flags);
1366 regcache_raw_supply (regcache, HPPA_FLAGS_REGNUM, buf);
1369 /* If the SS_WIDEREGS flag is set, we really do need the full
1370 `struct save_state'. */
1371 if (flags & HPPA_HPUX_SS_WIDEREGS && len < HPPA_HPUX_SAVE_STATE_SIZE)
1372 error (_("Register set contents too small"));
1374 if (flags & HPPA_HPUX_SS_WIDEREGS)
1375 hppa_hpux_supply_ss_wide (regcache, regnum, save_state);
1377 hppa_hpux_supply_ss_narrow (regcache, regnum, save_state);
1379 hppa_hpux_supply_ss_fpblock (regcache, regnum, save_state);
1382 /* HP-UX register set. */
1384 static struct regset hppa_hpux_regset =
1387 hppa_hpux_supply_save_state
1390 static const struct regset *
1391 hppa_hpux_regset_from_core_section (struct gdbarch *gdbarch,
1392 const char *sect_name, size_t sect_size)
1394 if (strcmp (sect_name, ".reg") == 0
1395 && sect_size >= HPPA_HPUX_PA89_SAVE_STATE_SIZE + 8)
1396 return &hppa_hpux_regset;
1402 /* Bit in the `ss_flag' member of `struct save_state' that indicates
1403 the state was saved from a system call. From
1404 <machine/save_state.h>. */
1405 #define HPPA_HPUX_SS_INSYSCALL 0x02
1408 hppa_hpux_read_pc (struct regcache *regcache)
1412 /* If we're currently in a system call return the contents of %r31. */
1413 regcache_cooked_read_unsigned (regcache, HPPA_FLAGS_REGNUM, &flags);
1414 if (flags & HPPA_HPUX_SS_INSYSCALL)
1417 regcache_cooked_read_unsigned (regcache, HPPA_R31_REGNUM, &pc);
1421 return hppa_read_pc (regcache);
1425 hppa_hpux_write_pc (struct regcache *regcache, CORE_ADDR pc)
1429 /* If we're currently in a system call also write PC into %r31. */
1430 regcache_cooked_read_unsigned (regcache, HPPA_FLAGS_REGNUM, &flags);
1431 if (flags & HPPA_HPUX_SS_INSYSCALL)
1432 regcache_cooked_write_unsigned (regcache, HPPA_R31_REGNUM, pc | 0x3);
1434 hppa_write_pc (regcache, pc);
1438 hppa_hpux_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
1442 /* If we're currently in a system call return the contents of %r31. */
1443 flags = frame_unwind_register_unsigned (next_frame, HPPA_FLAGS_REGNUM);
1444 if (flags & HPPA_HPUX_SS_INSYSCALL)
1445 return frame_unwind_register_unsigned (next_frame, HPPA_R31_REGNUM) & ~0x3;
1447 return hppa_unwind_pc (gdbarch, next_frame);
1451 /* Given the current value of the pc, check to see if it is inside a stub, and
1452 if so, change the value of the pc to point to the caller of the stub.
1453 THIS_FRAME is the current frame in the current list of frames.
1454 BASE contains to stack frame base of the current frame.
1455 SAVE_REGS is the register file stored in the frame cache. */
1457 hppa_hpux_unwind_adjust_stub (struct frame_info *this_frame, CORE_ADDR base,
1458 struct trad_frame_saved_reg *saved_regs)
1460 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1461 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1462 int word_size = gdbarch_ptr_bit (gdbarch) / 8;
1463 struct value *pcoq_head_val;
1466 struct unwind_table_entry *u;
1468 pcoq_head_val = trad_frame_get_prev_register (this_frame, saved_regs,
1469 HPPA_PCOQ_HEAD_REGNUM);
1471 extract_unsigned_integer (value_contents_all (pcoq_head_val),
1472 register_size (gdbarch, HPPA_PCOQ_HEAD_REGNUM),
1475 u = find_unwind_entry (pcoq_head);
1476 if (u && u->stub_unwind.stub_type == EXPORT)
1478 stubpc = read_memory_integer (base - 24, word_size, byte_order);
1479 trad_frame_set_value (saved_regs, HPPA_PCOQ_HEAD_REGNUM, stubpc);
1481 else if (hppa_symbol_address ("__gcc_plt_call")
1482 == get_pc_function_start (pcoq_head))
1484 stubpc = read_memory_integer (base - 8, word_size, byte_order);
1485 trad_frame_set_value (saved_regs, HPPA_PCOQ_HEAD_REGNUM, stubpc);
1490 hppa_hpux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
1492 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1494 if (IS_32BIT_TARGET (gdbarch))
1495 tdep->in_solib_call_trampoline = hppa32_hpux_in_solib_call_trampoline;
1497 tdep->in_solib_call_trampoline = hppa64_hpux_in_solib_call_trampoline;
1499 tdep->unwind_adjust_stub = hppa_hpux_unwind_adjust_stub;
1501 set_gdbarch_in_solib_return_trampoline
1502 (gdbarch, hppa_hpux_in_solib_return_trampoline);
1503 set_gdbarch_skip_trampoline_code (gdbarch, hppa_hpux_skip_trampoline_code);
1505 set_gdbarch_push_dummy_code (gdbarch, hppa_hpux_push_dummy_code);
1506 set_gdbarch_call_dummy_location (gdbarch, ON_STACK);
1508 set_gdbarch_read_pc (gdbarch, hppa_hpux_read_pc);
1509 set_gdbarch_write_pc (gdbarch, hppa_hpux_write_pc);
1510 set_gdbarch_unwind_pc (gdbarch, hppa_hpux_unwind_pc);
1511 set_gdbarch_skip_permanent_breakpoint
1512 (gdbarch, hppa_skip_permanent_breakpoint);
1514 set_gdbarch_regset_from_core_section
1515 (gdbarch, hppa_hpux_regset_from_core_section);
1517 frame_unwind_append_unwinder (gdbarch, &hppa_hpux_sigtramp_frame_unwind);
1521 hppa_hpux_som_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
1523 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1527 tdep->find_global_pointer = hppa32_hpux_find_global_pointer;
1529 hppa_hpux_init_abi (info, gdbarch);
1530 som_solib_select (gdbarch);
1534 hppa_hpux_elf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
1536 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1539 tdep->find_global_pointer = hppa64_hpux_find_global_pointer;
1541 hppa_hpux_init_abi (info, gdbarch);
1542 pa64_solib_select (gdbarch);
1545 static enum gdb_osabi
1546 hppa_hpux_core_osabi_sniffer (bfd *abfd)
1548 if (strcmp (bfd_get_target (abfd), "hpux-core") == 0)
1549 return GDB_OSABI_HPUX_SOM;
1550 else if (strcmp (bfd_get_target (abfd), "elf64-hppa") == 0)
1554 section = bfd_get_section_by_name (abfd, ".kernel");
1560 size = bfd_section_size (abfd, section);
1561 contents = alloca (size);
1562 if (bfd_get_section_contents (abfd, section, contents,
1564 && strcmp (contents, "HP-UX") == 0)
1565 return GDB_OSABI_HPUX_ELF;
1569 return GDB_OSABI_UNKNOWN;
1573 _initialize_hppa_hpux_tdep (void)
1575 /* BFD doesn't set a flavour for HP-UX style core files. It doesn't
1576 set the architecture either. */
1577 gdbarch_register_osabi_sniffer (bfd_arch_unknown,
1578 bfd_target_unknown_flavour,
1579 hppa_hpux_core_osabi_sniffer);
1580 gdbarch_register_osabi_sniffer (bfd_arch_hppa,
1581 bfd_target_elf_flavour,
1582 hppa_hpux_core_osabi_sniffer);
1584 gdbarch_register_osabi (bfd_arch_hppa, 0, GDB_OSABI_HPUX_SOM,
1585 hppa_hpux_som_init_abi);
1586 gdbarch_register_osabi (bfd_arch_hppa, bfd_mach_hppa20w, GDB_OSABI_HPUX_ELF,
1587 hppa_hpux_elf_init_abi);