1 /* Target-dependent code for HP-UX on PA-RISC.
3 Copyright (C) 2002, 2003, 2004, 2005, 2007 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 2 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, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
23 #include "arch-utils.h"
27 #include "frame-unwind.h"
28 #include "trad-frame.h"
34 #include "hppa-tdep.h"
35 #include "solib-som.h"
36 #include "solib-pa64.h"
39 #include "exceptions.h"
41 #include "gdb_string.h"
43 #define IS_32BIT_TARGET(_gdbarch) \
44 ((gdbarch_tdep (_gdbarch))->bytes_per_address == 4)
46 /* Bit in the `ss_flag' member of `struct save_state' that indicates
47 that the 64-bit register values are live. From
48 <machine/save_state.h>. */
49 #define HPPA_HPUX_SS_WIDEREGS 0x40
51 /* Offsets of various parts of `struct save_state'. From
52 <machine/save_state.h>. */
53 #define HPPA_HPUX_SS_FLAGS_OFFSET 0
54 #define HPPA_HPUX_SS_NARROW_OFFSET 4
55 #define HPPA_HPUX_SS_FPBLOCK_OFFSET 256
56 #define HPPA_HPUX_SS_WIDE_OFFSET 640
58 /* The size of `struct save_state. */
59 #define HPPA_HPUX_SAVE_STATE_SIZE 1152
61 /* The size of `struct pa89_save_state', which corresponds to PA-RISC
62 1.1, the lowest common denominator that we support. */
63 #define HPPA_HPUX_PA89_SAVE_STATE_SIZE 512
66 /* Forward declarations. */
67 extern void _initialize_hppa_hpux_tdep (void);
68 extern initialize_file_ftype _initialize_hppa_hpux_tdep;
72 struct minimal_symbol *msym;
73 CORE_ADDR solib_handle;
79 in_opd_section (CORE_ADDR pc)
81 struct obj_section *s;
84 s = find_pc_section (pc);
87 && s->the_bfd_section->name != NULL
88 && strcmp (s->the_bfd_section->name, ".opd") == 0);
92 /* Return one if PC is in the call path of a trampoline, else return zero.
94 Note we return one for *any* call trampoline (long-call, arg-reloc), not
95 just shared library trampolines (import, export). */
98 hppa32_hpux_in_solib_call_trampoline (CORE_ADDR pc, char *name)
100 struct minimal_symbol *minsym;
101 struct unwind_table_entry *u;
103 /* First see if PC is in one of the two C-library trampolines. */
104 if (pc == hppa_symbol_address("$$dyncall")
105 || pc == hppa_symbol_address("_sr4export"))
108 minsym = lookup_minimal_symbol_by_pc (pc);
109 if (minsym && strcmp (DEPRECATED_SYMBOL_NAME (minsym), ".stub") == 0)
112 /* Get the unwind descriptor corresponding to PC, return zero
113 if no unwind was found. */
114 u = find_unwind_entry (pc);
118 /* If this isn't a linker stub, then return now. */
119 if (u->stub_unwind.stub_type == 0)
122 /* By definition a long-branch stub is a call stub. */
123 if (u->stub_unwind.stub_type == LONG_BRANCH)
126 /* The call and return path execute the same instructions within
127 an IMPORT stub! So an IMPORT stub is both a call and return
129 if (u->stub_unwind.stub_type == IMPORT)
132 /* Parameter relocation stubs always have a call path and may have a
134 if (u->stub_unwind.stub_type == PARAMETER_RELOCATION
135 || u->stub_unwind.stub_type == EXPORT)
139 /* Search forward from the current PC until we hit a branch
140 or the end of the stub. */
141 for (addr = pc; addr <= u->region_end; addr += 4)
145 insn = read_memory_integer (addr, 4);
147 /* Does it look like a bl? If so then it's the call path, if
148 we find a bv or be first, then we're on the return path. */
149 if ((insn & 0xfc00e000) == 0xe8000000)
151 else if ((insn & 0xfc00e001) == 0xe800c000
152 || (insn & 0xfc000000) == 0xe0000000)
156 /* Should never happen. */
157 warning (_("Unable to find branch in parameter relocation stub."));
161 /* Unknown stub type. For now, just return zero. */
166 hppa64_hpux_in_solib_call_trampoline (CORE_ADDR pc, char *name)
168 /* PA64 has a completely different stub/trampoline scheme. Is it
169 better? Maybe. It's certainly harder to determine with any
170 certainty that we are in a stub because we can not refer to the
173 The heuristic is simple. Try to lookup the current PC value in th
174 minimal symbol table. If that fails, then assume we are not in a
177 Then see if the PC value falls within the section bounds for the
178 section containing the minimal symbol we found in the first
179 step. If it does, then assume we are not in a stub and return.
181 Finally peek at the instructions to see if they look like a stub. */
182 struct minimal_symbol *minsym;
187 minsym = lookup_minimal_symbol_by_pc (pc);
191 sec = SYMBOL_BFD_SECTION (minsym);
193 if (bfd_get_section_vma (sec->owner, sec) <= pc
194 && pc < (bfd_get_section_vma (sec->owner, sec)
195 + bfd_section_size (sec->owner, sec)))
198 /* We might be in a stub. Peek at the instructions. Stubs are 3
199 instructions long. */
200 insn = read_memory_integer (pc, 4);
202 /* Find out where we think we are within the stub. */
203 if ((insn & 0xffffc00e) == 0x53610000)
205 else if ((insn & 0xffffffff) == 0xe820d000)
207 else if ((insn & 0xffffc00e) == 0x537b0000)
212 /* Now verify each insn in the range looks like a stub instruction. */
213 insn = read_memory_integer (addr, 4);
214 if ((insn & 0xffffc00e) != 0x53610000)
217 /* Now verify each insn in the range looks like a stub instruction. */
218 insn = read_memory_integer (addr + 4, 4);
219 if ((insn & 0xffffffff) != 0xe820d000)
222 /* Now verify each insn in the range looks like a stub instruction. */
223 insn = read_memory_integer (addr + 8, 4);
224 if ((insn & 0xffffc00e) != 0x537b0000)
227 /* Looks like a stub. */
231 /* Return one if PC is in the return path of a trampoline, else return zero.
233 Note we return one for *any* call trampoline (long-call, arg-reloc), not
234 just shared library trampolines (import, export). */
237 hppa_hpux_in_solib_return_trampoline (CORE_ADDR pc, char *name)
239 struct unwind_table_entry *u;
241 /* Get the unwind descriptor corresponding to PC, return zero
242 if no unwind was found. */
243 u = find_unwind_entry (pc);
247 /* If this isn't a linker stub or it's just a long branch stub, then
249 if (u->stub_unwind.stub_type == 0 || u->stub_unwind.stub_type == LONG_BRANCH)
252 /* The call and return path execute the same instructions within
253 an IMPORT stub! So an IMPORT stub is both a call and return
255 if (u->stub_unwind.stub_type == IMPORT)
258 /* Parameter relocation stubs always have a call path and may have a
260 if (u->stub_unwind.stub_type == PARAMETER_RELOCATION
261 || u->stub_unwind.stub_type == EXPORT)
265 /* Search forward from the current PC until we hit a branch
266 or the end of the stub. */
267 for (addr = pc; addr <= u->region_end; addr += 4)
271 insn = read_memory_integer (addr, 4);
273 /* Does it look like a bl? If so then it's the call path, if
274 we find a bv or be first, then we're on the return path. */
275 if ((insn & 0xfc00e000) == 0xe8000000)
277 else if ((insn & 0xfc00e001) == 0xe800c000
278 || (insn & 0xfc000000) == 0xe0000000)
282 /* Should never happen. */
283 warning (_("Unable to find branch in parameter relocation stub."));
287 /* Unknown stub type. For now, just return zero. */
292 /* Figure out if PC is in a trampoline, and if so find out where
293 the trampoline will jump to. If not in a trampoline, return zero.
295 Simple code examination probably is not a good idea since the code
296 sequences in trampolines can also appear in user code.
298 We use unwinds and information from the minimal symbol table to
299 determine when we're in a trampoline. This won't work for ELF
300 (yet) since it doesn't create stub unwind entries. Whether or
301 not ELF will create stub unwinds or normal unwinds for linker
302 stubs is still being debated.
304 This should handle simple calls through dyncall or sr4export,
305 long calls, argument relocation stubs, and dyncall/sr4export
306 calling an argument relocation stub. It even handles some stubs
307 used in dynamic executables. */
310 hppa_hpux_skip_trampoline_code (CORE_ADDR pc)
313 long prev_inst, curr_inst, loc;
314 struct minimal_symbol *msym;
315 struct unwind_table_entry *u;
317 /* Addresses passed to dyncall may *NOT* be the actual address
318 of the function. So we may have to do something special. */
319 if (pc == hppa_symbol_address("$$dyncall"))
321 pc = (CORE_ADDR) read_register (22);
323 /* If bit 30 (counting from the left) is on, then pc is the address of
324 the PLT entry for this function, not the address of the function
325 itself. Bit 31 has meaning too, but only for MPE. */
327 pc = (CORE_ADDR) read_memory_integer (pc & ~0x3, TARGET_PTR_BIT / 8);
329 if (pc == hppa_symbol_address("$$dyncall_external"))
331 pc = (CORE_ADDR) read_register (22);
332 pc = (CORE_ADDR) read_memory_integer (pc & ~0x3, TARGET_PTR_BIT / 8);
334 else if (pc == hppa_symbol_address("_sr4export"))
335 pc = (CORE_ADDR) (read_register (22));
337 /* Get the unwind descriptor corresponding to PC, return zero
338 if no unwind was found. */
339 u = find_unwind_entry (pc);
343 /* If this isn't a linker stub, then return now. */
344 /* elz: attention here! (FIXME) because of a compiler/linker
345 error, some stubs which should have a non zero stub_unwind.stub_type
346 have unfortunately a value of zero. So this function would return here
347 as if we were not in a trampoline. To fix this, we go look at the partial
348 symbol information, which reports this guy as a stub.
349 (FIXME): Unfortunately, we are not that lucky: it turns out that the
350 partial symbol information is also wrong sometimes. This is because
351 when it is entered (somread.c::som_symtab_read()) it can happen that
352 if the type of the symbol (from the som) is Entry, and the symbol is
353 in a shared library, then it can also be a trampoline. This would
354 be OK, except that I believe the way they decide if we are ina shared library
355 does not work. SOOOO..., even if we have a regular function w/o trampolines
356 its minimal symbol can be assigned type mst_solib_trampoline.
357 Also, if we find that the symbol is a real stub, then we fix the unwind
358 descriptor, and define the stub type to be EXPORT.
359 Hopefully this is correct most of the times. */
360 if (u->stub_unwind.stub_type == 0)
363 /* elz: NOTE (FIXME!) once the problem with the unwind information is fixed
364 we can delete all the code which appears between the lines */
365 /*--------------------------------------------------------------------------*/
366 msym = lookup_minimal_symbol_by_pc (pc);
368 if (msym == NULL || MSYMBOL_TYPE (msym) != mst_solib_trampoline)
369 return orig_pc == pc ? 0 : pc & ~0x3;
371 else if (msym != NULL && MSYMBOL_TYPE (msym) == mst_solib_trampoline)
373 struct objfile *objfile;
374 struct minimal_symbol *msymbol;
375 int function_found = 0;
377 /* go look if there is another minimal symbol with the same name as
378 this one, but with type mst_text. This would happen if the msym
379 is an actual trampoline, in which case there would be another
380 symbol with the same name corresponding to the real function */
382 ALL_MSYMBOLS (objfile, msymbol)
384 if (MSYMBOL_TYPE (msymbol) == mst_text
385 && DEPRECATED_STREQ (DEPRECATED_SYMBOL_NAME (msymbol), DEPRECATED_SYMBOL_NAME (msym)))
393 /* the type of msym is correct (mst_solib_trampoline), but
394 the unwind info is wrong, so set it to the correct value */
395 u->stub_unwind.stub_type = EXPORT;
397 /* the stub type info in the unwind is correct (this is not a
398 trampoline), but the msym type information is wrong, it
399 should be mst_text. So we need to fix the msym, and also
400 get out of this function */
402 MSYMBOL_TYPE (msym) = mst_text;
403 return orig_pc == pc ? 0 : pc & ~0x3;
407 /*--------------------------------------------------------------------------*/
410 /* It's a stub. Search for a branch and figure out where it goes.
411 Note we have to handle multi insn branch sequences like ldil;ble.
412 Most (all?) other branches can be determined by examining the contents
413 of certain registers and the stack. */
420 /* Make sure we haven't walked outside the range of this stub. */
421 if (u != find_unwind_entry (loc))
423 warning (_("Unable to find branch in linker stub"));
424 return orig_pc == pc ? 0 : pc & ~0x3;
427 prev_inst = curr_inst;
428 curr_inst = read_memory_integer (loc, 4);
430 /* Does it look like a branch external using %r1? Then it's the
431 branch from the stub to the actual function. */
432 if ((curr_inst & 0xffe0e000) == 0xe0202000)
434 /* Yup. See if the previous instruction loaded
435 a value into %r1. If so compute and return the jump address. */
436 if ((prev_inst & 0xffe00000) == 0x20200000)
437 return (hppa_extract_21 (prev_inst) + hppa_extract_17 (curr_inst)) & ~0x3;
440 warning (_("Unable to find ldil X,%%r1 before ble Y(%%sr4,%%r1)."));
441 return orig_pc == pc ? 0 : pc & ~0x3;
445 /* Does it look like a be 0(sr0,%r21)? OR
446 Does it look like a be, n 0(sr0,%r21)? OR
447 Does it look like a bve (r21)? (this is on PA2.0)
448 Does it look like a bve, n(r21)? (this is also on PA2.0)
449 That's the branch from an
450 import stub to an export stub.
452 It is impossible to determine the target of the branch via
453 simple examination of instructions and/or data (consider
454 that the address in the plabel may be the address of the
455 bind-on-reference routine in the dynamic loader).
457 So we have try an alternative approach.
459 Get the name of the symbol at our current location; it should
460 be a stub symbol with the same name as the symbol in the
463 Then lookup a minimal symbol with the same name; we should
464 get the minimal symbol for the target routine in the shared
465 library as those take precedence of import/export stubs. */
466 if ((curr_inst == 0xe2a00000) ||
467 (curr_inst == 0xe2a00002) ||
468 (curr_inst == 0xeaa0d000) ||
469 (curr_inst == 0xeaa0d002))
471 struct minimal_symbol *stubsym, *libsym;
473 stubsym = lookup_minimal_symbol_by_pc (loc);
476 warning (_("Unable to find symbol for 0x%lx"), loc);
477 return orig_pc == pc ? 0 : pc & ~0x3;
480 libsym = lookup_minimal_symbol (DEPRECATED_SYMBOL_NAME (stubsym), NULL, NULL);
483 warning (_("Unable to find library symbol for %s."),
484 DEPRECATED_SYMBOL_NAME (stubsym));
485 return orig_pc == pc ? 0 : pc & ~0x3;
488 return SYMBOL_VALUE (libsym);
491 /* Does it look like bl X,%rp or bl X,%r0? Another way to do a
492 branch from the stub to the actual function. */
494 else if ((curr_inst & 0xffe0e000) == 0xe8400000
495 || (curr_inst & 0xffe0e000) == 0xe8000000
496 || (curr_inst & 0xffe0e000) == 0xe800A000)
497 return (loc + hppa_extract_17 (curr_inst) + 8) & ~0x3;
499 /* Does it look like bv (rp)? Note this depends on the
500 current stack pointer being the same as the stack
501 pointer in the stub itself! This is a branch on from the
502 stub back to the original caller. */
503 /*else if ((curr_inst & 0xffe0e000) == 0xe840c000) */
504 else if ((curr_inst & 0xffe0f000) == 0xe840c000)
506 /* Yup. See if the previous instruction loaded
508 if (prev_inst == 0x4bc23ff1)
509 return (read_memory_integer
510 (read_register (HPPA_SP_REGNUM) - 8, 4)) & ~0x3;
513 warning (_("Unable to find restore of %%rp before bv (%%rp)."));
514 return orig_pc == pc ? 0 : pc & ~0x3;
518 /* elz: added this case to capture the new instruction
519 at the end of the return part of an export stub used by
520 the PA2.0: BVE, n (rp) */
521 else if ((curr_inst & 0xffe0f000) == 0xe840d000)
523 return (read_memory_integer
524 (read_register (HPPA_SP_REGNUM) - 24, TARGET_PTR_BIT / 8)) & ~0x3;
527 /* What about be,n 0(sr0,%rp)? It's just another way we return to
528 the original caller from the stub. Used in dynamic executables. */
529 else if (curr_inst == 0xe0400002)
531 /* The value we jump to is sitting in sp - 24. But that's
532 loaded several instructions before the be instruction.
533 I guess we could check for the previous instruction being
534 mtsp %r1,%sr0 if we want to do sanity checking. */
535 return (read_memory_integer
536 (read_register (HPPA_SP_REGNUM) - 24, TARGET_PTR_BIT / 8)) & ~0x3;
539 /* Haven't found the branch yet, but we're still in the stub.
546 hppa_skip_permanent_breakpoint (struct regcache *regcache)
548 /* To step over a breakpoint instruction on the PA takes some
549 fiddling with the instruction address queue.
551 When we stop at a breakpoint, the IA queue front (the instruction
552 we're executing now) points at the breakpoint instruction, and
553 the IA queue back (the next instruction to execute) points to
554 whatever instruction we would execute after the breakpoint, if it
555 were an ordinary instruction. This is the case even if the
556 breakpoint is in the delay slot of a branch instruction.
558 Clearly, to step past the breakpoint, we need to set the queue
559 front to the back. But what do we put in the back? What
560 instruction comes after that one? Because of the branch delay
561 slot, the next insn is always at the back + 4. */
563 ULONGEST pcoq_tail, pcsq_tail;
564 regcache_cooked_read_unsigned (regcache, HPPA_PCOQ_TAIL_REGNUM, &pcoq_tail);
565 regcache_cooked_read_unsigned (regcache, HPPA_PCSQ_TAIL_REGNUM, &pcsq_tail);
567 regcache_cooked_write_unsigned (regcache, HPPA_PCOQ_HEAD_REGNUM, pcoq_tail);
568 regcache_cooked_write_unsigned (regcache, HPPA_PCSQ_HEAD_REGNUM, pcsq_tail);
570 regcache_cooked_write_unsigned (regcache, HPPA_PCOQ_TAIL_REGNUM, pcoq_tail + 4);
571 /* We can leave the tail's space the same, since there's no jump. */
574 /* Exception handling support for the HP-UX ANSI C++ compiler.
575 The compiler (aCC) provides a callback for exception events;
576 GDB can set a breakpoint on this callback and find out what
577 exception event has occurred. */
579 /* The name of the hook to be set to point to the callback function. */
580 static char HP_ACC_EH_notify_hook[] = "__eh_notify_hook";
581 /* The name of the function to be used to set the hook value. */
582 static char HP_ACC_EH_set_hook_value[] = "__eh_set_hook_value";
583 /* The name of the callback function in end.o */
584 static char HP_ACC_EH_notify_callback[] = "__d_eh_notify_callback";
585 /* Name of function in end.o on which a break is set (called by above). */
586 static char HP_ACC_EH_break[] = "__d_eh_break";
587 /* Name of flag (in end.o) that enables catching throws. */
588 static char HP_ACC_EH_catch_throw[] = "__d_eh_catch_throw";
589 /* Name of flag (in end.o) that enables catching catching. */
590 static char HP_ACC_EH_catch_catch[] = "__d_eh_catch_catch";
591 /* The enum used by aCC. */
599 /* Is exception-handling support available with this executable? */
600 static int hp_cxx_exception_support = 0;
601 /* Has the initialize function been run? */
602 static int hp_cxx_exception_support_initialized = 0;
603 /* Address of __eh_notify_hook */
604 static CORE_ADDR eh_notify_hook_addr = 0;
605 /* Address of __d_eh_notify_callback */
606 static CORE_ADDR eh_notify_callback_addr = 0;
607 /* Address of __d_eh_break */
608 static CORE_ADDR eh_break_addr = 0;
609 /* Address of __d_eh_catch_catch */
610 static CORE_ADDR eh_catch_catch_addr = 0;
611 /* Address of __d_eh_catch_throw */
612 static CORE_ADDR eh_catch_throw_addr = 0;
613 /* Sal for __d_eh_break */
614 static struct symtab_and_line *break_callback_sal = 0;
616 /* Code in end.c expects __d_pid to be set in the inferior,
617 otherwise __d_eh_notify_callback doesn't bother to call
618 __d_eh_break! So we poke the pid into this symbol
623 setup_d_pid_in_inferior (void)
626 struct minimal_symbol *msymbol;
627 char buf[4]; /* FIXME 32x64? */
629 /* Slam the pid of the process into __d_pid; failing is only a warning! */
630 msymbol = lookup_minimal_symbol ("__d_pid", NULL, symfile_objfile);
633 warning (_("Unable to find __d_pid symbol in object file.\n"
634 "Suggest linking executable with -g (links in /opt/langtools/lib/end.o)."));
638 anaddr = SYMBOL_VALUE_ADDRESS (msymbol);
639 store_unsigned_integer (buf, 4, PIDGET (inferior_ptid)); /* FIXME 32x64? */
640 if (target_write_memory (anaddr, buf, 4)) /* FIXME 32x64? */
642 warning (_("Unable to write __d_pid.\n"
643 "Suggest linking executable with -g (links in /opt/langtools/lib/end.o)."));
649 /* elz: Used to lookup a symbol in the shared libraries.
650 This function calls shl_findsym, indirectly through a
651 call to __d_shl_get. __d_shl_get is in end.c, which is always
652 linked in by the hp compilers/linkers.
653 The call to shl_findsym cannot be made directly because it needs
654 to be active in target address space.
655 inputs: - minimal symbol pointer for the function we want to look up
656 - address in target space of the descriptor for the library
657 where we want to look the symbol up.
658 This address is retrieved using the
659 som_solib_get_solib_by_pc function (somsolib.c).
660 output: - real address in the library of the function.
661 note: the handle can be null, in which case shl_findsym will look for
662 the symbol in all the loaded shared libraries.
663 files to look at if you need reference on this stuff:
664 dld.c, dld_shl_findsym.c
666 man entry for shl_findsym */
669 find_stub_with_shl_get (struct minimal_symbol *function, CORE_ADDR handle)
671 struct symbol *get_sym, *symbol2;
672 struct minimal_symbol *buff_minsym, *msymbol;
675 struct value *funcval;
678 int x, namelen, err_value, tmp = -1;
679 CORE_ADDR endo_buff_addr, value_return_addr, errno_return_addr;
683 args = alloca (sizeof (struct value *) * 8); /* 6 for the arguments and one null one??? */
684 funcval = find_function_in_inferior ("__d_shl_get");
685 get_sym = lookup_symbol ("__d_shl_get", NULL, VAR_DOMAIN, NULL, NULL);
686 buff_minsym = lookup_minimal_symbol ("__buffer", NULL, NULL);
687 msymbol = lookup_minimal_symbol ("__shldp", NULL, NULL);
688 symbol2 = lookup_symbol ("__shldp", NULL, VAR_DOMAIN, NULL, NULL);
689 endo_buff_addr = SYMBOL_VALUE_ADDRESS (buff_minsym);
690 namelen = strlen (DEPRECATED_SYMBOL_NAME (function));
691 value_return_addr = endo_buff_addr + namelen;
692 ftype = check_typedef (SYMBOL_TYPE (get_sym));
695 if ((x = value_return_addr % 64) != 0)
696 value_return_addr = value_return_addr + 64 - x;
698 errno_return_addr = value_return_addr + 64;
701 /* set up stuff needed by __d_shl_get in buffer in end.o */
703 target_write_memory (endo_buff_addr, DEPRECATED_SYMBOL_NAME (function), namelen);
705 target_write_memory (value_return_addr, (char *) &tmp, 4);
707 target_write_memory (errno_return_addr, (char *) &tmp, 4);
709 target_write_memory (SYMBOL_VALUE_ADDRESS (msymbol),
710 (char *) &handle, 4);
712 /* now prepare the arguments for the call */
714 args[0] = value_from_longest (TYPE_FIELD_TYPE (ftype, 0), 12);
715 args[1] = value_from_pointer (TYPE_FIELD_TYPE (ftype, 1), SYMBOL_VALUE_ADDRESS (msymbol));
716 args[2] = value_from_pointer (TYPE_FIELD_TYPE (ftype, 2), endo_buff_addr);
717 args[3] = value_from_longest (TYPE_FIELD_TYPE (ftype, 3), 3 /* TYPE_PROCEDURE */);
718 args[4] = value_from_pointer (TYPE_FIELD_TYPE (ftype, 4), value_return_addr);
719 args[5] = value_from_pointer (TYPE_FIELD_TYPE (ftype, 5), errno_return_addr);
721 /* now call the function */
723 val = call_function_by_hand (funcval, 6, args);
725 /* now get the results */
727 target_read_memory (errno_return_addr, (char *) &err_value, sizeof (err_value));
729 target_read_memory (value_return_addr, (char *) &stub_addr, sizeof (stub_addr));
731 error (_("call to __d_shl_get failed, error code is %d"), err_value);
736 /* Cover routine for find_stub_with_shl_get to pass to catch_errors */
738 cover_find_stub_with_shl_get (void *args_untyped)
740 args_for_find_stub *args = args_untyped;
741 args->return_val = find_stub_with_shl_get (args->msym, args->solib_handle);
745 /* Initialize exception catchpoint support by looking for the
746 necessary hooks/callbacks in end.o, etc., and set the hook value
747 to point to the required debug function.
753 initialize_hp_cxx_exception_support (void)
755 struct symtabs_and_lines sals;
756 struct cleanup *old_chain;
757 struct cleanup *canonical_strings_chain = NULL;
760 char *addr_end = NULL;
761 char **canonical = (char **) NULL;
763 struct symbol *sym = NULL;
764 struct minimal_symbol *msym = NULL;
765 struct objfile *objfile;
766 asection *shlib_info;
768 /* Detect and disallow recursion. On HP-UX with aCC, infinite
769 recursion is a possibility because finding the hook for exception
770 callbacks involves making a call in the inferior, which means
771 re-inserting breakpoints which can re-invoke this code. */
773 static int recurse = 0;
776 hp_cxx_exception_support_initialized = 0;
777 deprecated_exception_support_initialized = 0;
781 hp_cxx_exception_support = 0;
783 /* First check if we have seen any HP compiled objects; if not,
784 it is very unlikely that HP's idiosyncratic callback mechanism
785 for exception handling debug support will be available!
786 This will percolate back up to breakpoint.c, where our callers
787 will decide to try the g++ exception-handling support instead. */
788 if (!deprecated_hp_som_som_object_present)
791 /* We have a SOM executable with SOM debug info; find the hooks. */
793 /* First look for the notify hook provided by aCC runtime libs */
794 /* If we find this symbol, we conclude that the executable must
795 have HP aCC exception support built in. If this symbol is not
796 found, even though we're a HP SOM-SOM file, we may have been
797 built with some other compiler (not aCC). This results percolates
798 back up to our callers in breakpoint.c which can decide to
799 try the g++ style of exception support instead.
800 If this symbol is found but the other symbols we require are
801 not found, there is something weird going on, and g++ support
802 should *not* be tried as an alternative.
804 ASSUMPTION: Only HP aCC code will have __eh_notify_hook defined.
805 ASSUMPTION: HP aCC and g++ modules cannot be linked together. */
807 /* libCsup has this hook; it'll usually be non-debuggable */
808 msym = lookup_minimal_symbol (HP_ACC_EH_notify_hook, NULL, NULL);
811 eh_notify_hook_addr = SYMBOL_VALUE_ADDRESS (msym);
812 hp_cxx_exception_support = 1;
817 Unable to find exception callback hook (%s).\n\
818 Executable may not have been compiled debuggable with HP aCC.\n\
819 GDB will be unable to intercept exception events."),
820 HP_ACC_EH_notify_hook);
821 eh_notify_hook_addr = 0;
822 hp_cxx_exception_support = 0;
826 /* Next look for the notify callback routine in end.o */
827 /* This is always available in the SOM symbol dictionary if end.o is
829 msym = lookup_minimal_symbol (HP_ACC_EH_notify_callback, NULL, NULL);
832 eh_notify_callback_addr = SYMBOL_VALUE_ADDRESS (msym);
833 hp_cxx_exception_support = 1;
838 Unable to find exception callback routine (%s).\n\
839 Suggest linking executable with -g (links in /opt/langtools/lib/end.o).\n\
840 GDB will be unable to intercept exception events."),
841 HP_ACC_EH_notify_callback);
842 eh_notify_callback_addr = 0;
846 if (!gdbarch_tdep (current_gdbarch)->is_elf)
848 /* Check whether the executable is dynamically linked or archive bound */
849 /* With an archive-bound executable we can use the raw addresses we find
850 for the callback function, etc. without modification. For an executable
851 with shared libraries, we have to do more work to find the plabel, which
852 can be the target of a call through $$dyncall from the aCC runtime
853 support library (libCsup) which is linked shared by default by aCC. */
854 /* This test below was copied from somsolib.c/somread.c. It may not be a very
855 reliable one to test that an executable is linked shared.
857 shlib_info = bfd_get_section_by_name (symfile_objfile->obfd, "$SHLIB_INFO$");
858 if (shlib_info && (bfd_section_size (symfile_objfile->obfd, shlib_info) != 0))
860 /* The minsym we have has the local code address, but that's not
861 the plabel that can be used by an inter-load-module call. */
862 /* Find solib handle for main image (which has end.o), and use
863 that and the min sym as arguments to __d_shl_get() (which
864 does the equivalent of shl_findsym()) to find the plabel. */
866 args_for_find_stub args;
868 args.solib_handle = gdbarch_tdep (current_gdbarch)->solib_get_solib_by_pc (eh_notify_callback_addr);
873 catch_errors (cover_find_stub_with_shl_get, &args,
874 _("Error while finding exception callback hook:\n"),
876 eh_notify_callback_addr = args.return_val;
879 deprecated_exception_catchpoints_are_fragile = 1;
881 if (!eh_notify_callback_addr)
883 /* We can get here either if there is no plabel in the export list
884 for the main image, or if something strange happened (?) */
886 Couldn't find a plabel (indirect function label) for the exception callback.\n\
887 GDB will not be able to intercept exception events."));
892 deprecated_exception_catchpoints_are_fragile = 0;
895 /* Now, look for the breakpointable routine in end.o */
896 /* This should also be available in the SOM symbol dict. if end.o linked in */
897 msym = lookup_minimal_symbol (HP_ACC_EH_break, NULL, NULL);
900 eh_break_addr = SYMBOL_VALUE_ADDRESS (msym);
901 hp_cxx_exception_support = 1;
906 Unable to find exception callback routine to set breakpoint (%s).\n\
907 Suggest linking executable with -g (link in /opt/langtools/lib/end.o).\n\
908 GDB will be unable to intercept exception events."),
914 /* Next look for the catch enable flag provided in end.o */
915 sym = lookup_symbol (HP_ACC_EH_catch_catch, (struct block *) NULL,
916 VAR_DOMAIN, 0, (struct symtab **) NULL);
917 if (sym) /* sometimes present in debug info */
919 eh_catch_catch_addr = SYMBOL_VALUE_ADDRESS (sym);
920 hp_cxx_exception_support = 1;
923 /* otherwise look in SOM symbol dict. */
925 msym = lookup_minimal_symbol (HP_ACC_EH_catch_catch, NULL, NULL);
928 eh_catch_catch_addr = SYMBOL_VALUE_ADDRESS (msym);
929 hp_cxx_exception_support = 1;
934 Unable to enable interception of exception catches.\n\
935 Executable may not have been compiled debuggable with HP aCC.\n\
936 Suggest linking executable with -g (link in /opt/langtools/lib/end.o)."));
941 /* Next look for the catch enable flag provided end.o */
942 sym = lookup_symbol (HP_ACC_EH_catch_catch, (struct block *) NULL,
943 VAR_DOMAIN, 0, (struct symtab **) NULL);
944 if (sym) /* sometimes present in debug info */
946 eh_catch_throw_addr = SYMBOL_VALUE_ADDRESS (sym);
947 hp_cxx_exception_support = 1;
950 /* otherwise look in SOM symbol dict. */
952 msym = lookup_minimal_symbol (HP_ACC_EH_catch_throw, NULL, NULL);
955 eh_catch_throw_addr = SYMBOL_VALUE_ADDRESS (msym);
956 hp_cxx_exception_support = 1;
961 Unable to enable interception of exception throws.\n\
962 Executable may not have been compiled debuggable with HP aCC.\n\
963 Suggest linking executable with -g (link in /opt/langtools/lib/end.o)."));
969 hp_cxx_exception_support = 2; /* everything worked so far */
970 hp_cxx_exception_support_initialized = 1;
971 deprecated_exception_support_initialized = 1;
976 /* Target operation for enabling or disabling interception of
978 KIND is either EX_EVENT_THROW or EX_EVENT_CATCH
979 ENABLE is either 0 (disable) or 1 (enable).
980 Return value is NULL if no support found;
981 -1 if something went wrong,
982 or a pointer to a symtab/line struct if the breakpointable
983 address was found. */
985 struct symtab_and_line *
986 child_enable_exception_callback (enum exception_event_kind kind, int enable)
990 if (!deprecated_exception_support_initialized
991 || !hp_cxx_exception_support_initialized)
992 if (!initialize_hp_cxx_exception_support ())
995 switch (hp_cxx_exception_support)
998 /* Assuming no HP support at all */
1001 /* HP support should be present, but something went wrong */
1002 return (struct symtab_and_line *) -1; /* yuck! */
1003 /* there may be other cases in the future */
1006 /* Set the EH hook to point to the callback routine. */
1007 store_unsigned_integer (buf, 4, enable ? eh_notify_callback_addr : 0); /* FIXME 32x64 problem */
1008 /* pai: (temp) FIXME should there be a pack operation first? */
1009 if (target_write_memory (eh_notify_hook_addr, buf, 4)) /* FIXME 32x64 problem */
1012 Could not write to target memory for exception event callback.\n\
1013 Interception of exception events may not work."));
1014 return (struct symtab_and_line *) -1;
1018 /* Ensure that __d_pid is set up correctly -- end.c code checks this. :-( */
1019 if (PIDGET (inferior_ptid) > 0)
1021 if (setup_d_pid_in_inferior ())
1022 return (struct symtab_and_line *) -1;
1026 warning (_("Internal error: Invalid inferior pid? Cannot intercept exception events."));
1027 return (struct symtab_and_line *) -1;
1033 case EX_EVENT_THROW:
1034 store_unsigned_integer (buf, 4, enable ? 1 : 0);
1035 if (target_write_memory (eh_catch_throw_addr, buf, 4)) /* FIXME 32x64? */
1037 warning (_("Couldn't enable exception throw interception."));
1038 return (struct symtab_and_line *) -1;
1041 case EX_EVENT_CATCH:
1042 store_unsigned_integer (buf, 4, enable ? 1 : 0);
1043 if (target_write_memory (eh_catch_catch_addr, buf, 4)) /* FIXME 32x64? */
1045 warning (_("Couldn't enable exception catch interception."));
1046 return (struct symtab_and_line *) -1;
1050 error (_("Request to enable unknown or unsupported exception event."));
1053 /* Copy break address into new sal struct, malloc'ing if needed. */
1054 if (!break_callback_sal)
1055 break_callback_sal = XMALLOC (struct symtab_and_line);
1056 init_sal (break_callback_sal);
1057 break_callback_sal->symtab = NULL;
1058 break_callback_sal->pc = eh_break_addr;
1059 break_callback_sal->line = 0;
1060 break_callback_sal->end = eh_break_addr;
1062 return break_callback_sal;
1065 /* Record some information about the current exception event */
1066 static struct exception_event_record current_ex_event;
1068 /* Report current exception event. Returns a pointer to a record
1069 that describes the kind of the event, where it was thrown from,
1070 and where it will be caught. More information may be reported
1072 struct exception_event_record *
1073 child_get_current_exception_event (void)
1075 CORE_ADDR event_kind;
1076 CORE_ADDR throw_addr;
1077 CORE_ADDR catch_addr;
1078 struct frame_info *fi, *curr_frame;
1081 curr_frame = get_current_frame ();
1083 return (struct exception_event_record *) NULL;
1085 /* Go up one frame to __d_eh_notify_callback, because at the
1086 point when this code is executed, there's garbage in the
1087 arguments of __d_eh_break. */
1088 fi = find_relative_frame (curr_frame, &level);
1090 return (struct exception_event_record *) NULL;
1094 /* Read in the arguments */
1095 /* __d_eh_notify_callback() is called with 3 arguments:
1096 1. event kind catch or throw
1097 2. the target address if known
1098 3. a flag -- not sure what this is. pai/1997-07-17 */
1099 event_kind = read_register (HPPA_ARG0_REGNUM);
1100 catch_addr = read_register (HPPA_ARG1_REGNUM);
1102 /* Now go down to a user frame */
1103 /* For a throw, __d_eh_break is called by
1104 __d_eh_notify_callback which is called by
1105 __notify_throw which is called
1107 For a catch, __d_eh_break is called by
1108 __d_eh_notify_callback which is called by
1109 <stackwalking stuff> which is called by
1110 __throw__<stuff> or __rethrow_<stuff> which is called
1112 /* FIXME: Don't use such magic numbers; search for the frames */
1113 level = (event_kind == EX_EVENT_THROW) ? 3 : 4;
1114 fi = find_relative_frame (curr_frame, &level);
1116 return (struct exception_event_record *) NULL;
1119 throw_addr = get_frame_pc (fi);
1121 /* Go back to original (top) frame */
1122 select_frame (curr_frame);
1124 current_ex_event.kind = (enum exception_event_kind) event_kind;
1125 current_ex_event.throw_sal = find_pc_line (throw_addr, 1);
1126 current_ex_event.catch_sal = find_pc_line (catch_addr, 1);
1128 return ¤t_ex_event;
1131 /* Signal frames. */
1132 struct hppa_hpux_sigtramp_unwind_cache
1135 struct trad_frame_saved_reg *saved_regs;
1138 static int hppa_hpux_tramp_reg[] = {
1140 HPPA_PCOQ_HEAD_REGNUM,
1141 HPPA_PCSQ_HEAD_REGNUM,
1142 HPPA_PCOQ_TAIL_REGNUM,
1143 HPPA_PCSQ_TAIL_REGNUM,
1151 HPPA_SR4_REGNUM + 1,
1152 HPPA_SR4_REGNUM + 2,
1153 HPPA_SR4_REGNUM + 3,
1154 HPPA_SR4_REGNUM + 4,
1155 HPPA_SR4_REGNUM + 5,
1156 HPPA_SR4_REGNUM + 6,
1157 HPPA_SR4_REGNUM + 7,
1165 HPPA_TR0_REGNUM + 1,
1166 HPPA_TR0_REGNUM + 2,
1170 static struct hppa_hpux_sigtramp_unwind_cache *
1171 hppa_hpux_sigtramp_frame_unwind_cache (struct frame_info *next_frame,
1175 struct gdbarch *gdbarch = get_frame_arch (next_frame);
1176 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1177 struct hppa_hpux_sigtramp_unwind_cache *info;
1179 CORE_ADDR sp, scptr, off;
1185 info = FRAME_OBSTACK_ZALLOC (struct hppa_hpux_sigtramp_unwind_cache);
1187 info->saved_regs = trad_frame_alloc_saved_regs (next_frame);
1189 sp = frame_unwind_register_unsigned (next_frame, HPPA_SP_REGNUM);
1191 if (IS_32BIT_TARGET (gdbarch))
1198 /* See /usr/include/machine/save_state.h for the structure of the save_state_t
1201 flag = read_memory_unsigned_integer(scptr + HPPA_HPUX_SS_FLAGS_OFFSET, 4);
1203 if (!(flag & HPPA_HPUX_SS_WIDEREGS))
1205 /* Narrow registers. */
1206 off = scptr + HPPA_HPUX_SS_NARROW_OFFSET;
1212 /* Wide registers. */
1213 off = scptr + HPPA_HPUX_SS_WIDE_OFFSET + 8;
1215 szoff = (tdep->bytes_per_address == 4 ? 4 : 0);
1218 for (i = 1; i < 32; i++)
1220 info->saved_regs[HPPA_R0_REGNUM + i].addr = off + szoff;
1224 for (i = 0; i < ARRAY_SIZE (hppa_hpux_tramp_reg); i++)
1226 if (hppa_hpux_tramp_reg[i] > 0)
1227 info->saved_regs[hppa_hpux_tramp_reg[i]].addr = off + szoff;
1234 info->base = frame_unwind_register_unsigned (next_frame, HPPA_SP_REGNUM);
1240 hppa_hpux_sigtramp_frame_this_id (struct frame_info *next_frame,
1241 void **this_prologue_cache,
1242 struct frame_id *this_id)
1244 struct hppa_hpux_sigtramp_unwind_cache *info
1245 = hppa_hpux_sigtramp_frame_unwind_cache (next_frame, this_prologue_cache);
1246 *this_id = frame_id_build (info->base, frame_pc_unwind (next_frame));
1250 hppa_hpux_sigtramp_frame_prev_register (struct frame_info *next_frame,
1251 void **this_prologue_cache,
1252 int regnum, int *optimizedp,
1253 enum lval_type *lvalp,
1255 int *realnump, gdb_byte *valuep)
1257 struct hppa_hpux_sigtramp_unwind_cache *info
1258 = hppa_hpux_sigtramp_frame_unwind_cache (next_frame, this_prologue_cache);
1259 hppa_frame_prev_register_helper (next_frame, info->saved_regs, regnum,
1260 optimizedp, lvalp, addrp, realnump, valuep);
1263 static const struct frame_unwind hppa_hpux_sigtramp_frame_unwind = {
1265 hppa_hpux_sigtramp_frame_this_id,
1266 hppa_hpux_sigtramp_frame_prev_register
1269 static const struct frame_unwind *
1270 hppa_hpux_sigtramp_unwind_sniffer (struct frame_info *next_frame)
1272 struct unwind_table_entry *u;
1273 CORE_ADDR pc = frame_pc_unwind (next_frame);
1275 u = find_unwind_entry (pc);
1277 /* If this is an export stub, try to get the unwind descriptor for
1278 the actual function itself. */
1279 if (u && u->stub_unwind.stub_type == EXPORT)
1281 gdb_byte buf[HPPA_INSN_SIZE];
1284 if (!safe_frame_unwind_memory (next_frame, u->region_start,
1288 insn = extract_unsigned_integer (buf, sizeof buf);
1289 if ((insn & 0xffe0e000) == 0xe8400000)
1290 u = find_unwind_entry(u->region_start + hppa_extract_17 (insn) + 8);
1293 if (u && u->HP_UX_interrupt_marker)
1294 return &hppa_hpux_sigtramp_frame_unwind;
1300 hppa32_hpux_find_global_pointer (struct value *function)
1304 faddr = value_as_address (function);
1306 /* Is this a plabel? If so, dereference it to get the gp value. */
1314 status = target_read_memory (faddr + 4, buf, sizeof (buf));
1316 return extract_unsigned_integer (buf, sizeof (buf));
1319 return gdbarch_tdep (current_gdbarch)->solib_get_got_by_pc (faddr);
1323 hppa64_hpux_find_global_pointer (struct value *function)
1328 faddr = value_as_address (function);
1330 if (in_opd_section (faddr))
1332 target_read_memory (faddr, buf, sizeof (buf));
1333 return extract_unsigned_integer (&buf[24], 8);
1337 return gdbarch_tdep (current_gdbarch)->solib_get_got_by_pc (faddr);
1341 static unsigned int ldsid_pattern[] = {
1342 0x000010a0, /* ldsid (rX),rY */
1343 0x00001820, /* mtsp rY,sr0 */
1344 0xe0000000 /* be,n (sr0,rX) */
1348 hppa_hpux_search_pattern (CORE_ADDR start, CORE_ADDR end,
1349 unsigned int *patterns, int count)
1351 int num_insns = (end - start + HPPA_INSN_SIZE) / HPPA_INSN_SIZE;
1352 unsigned int *insns;
1356 buf = alloca (num_insns * HPPA_INSN_SIZE);
1357 insns = alloca (num_insns * sizeof (unsigned int));
1359 read_memory (start, buf, num_insns * HPPA_INSN_SIZE);
1360 for (i = 0; i < num_insns; i++, buf += HPPA_INSN_SIZE)
1361 insns[i] = extract_unsigned_integer (buf, HPPA_INSN_SIZE);
1363 for (offset = 0; offset <= num_insns - count; offset++)
1365 for (i = 0; i < count; i++)
1367 if ((insns[offset + i] & patterns[i]) != patterns[i])
1374 if (offset <= num_insns - count)
1375 return start + offset * HPPA_INSN_SIZE;
1381 hppa32_hpux_search_dummy_call_sequence (struct gdbarch *gdbarch, CORE_ADDR pc,
1384 struct objfile *obj;
1385 struct obj_section *sec;
1386 struct hppa_objfile_private *priv;
1387 struct frame_info *frame;
1388 struct unwind_table_entry *u;
1393 sec = find_pc_section (pc);
1395 priv = objfile_data (obj, hppa_objfile_priv_data);
1398 priv = hppa_init_objfile_priv_data (obj);
1400 error (_("Internal error creating objfile private data."));
1402 /* Use the cached value if we have one. */
1403 if (priv->dummy_call_sequence_addr != 0)
1405 *argreg = priv->dummy_call_sequence_reg;
1406 return priv->dummy_call_sequence_addr;
1409 /* First try a heuristic; if we are in a shared library call, our return
1410 pointer is likely to point at an export stub. */
1411 frame = get_current_frame ();
1412 rp = frame_unwind_register_unsigned (frame, 2);
1413 u = find_unwind_entry (rp);
1414 if (u && u->stub_unwind.stub_type == EXPORT)
1416 addr = hppa_hpux_search_pattern (u->region_start, u->region_end,
1418 ARRAY_SIZE (ldsid_pattern));
1423 /* Next thing to try is to look for an export stub. */
1424 if (priv->unwind_info)
1428 for (i = 0; i < priv->unwind_info->last; i++)
1430 struct unwind_table_entry *u;
1431 u = &priv->unwind_info->table[i];
1432 if (u->stub_unwind.stub_type == EXPORT)
1434 addr = hppa_hpux_search_pattern (u->region_start, u->region_end,
1436 ARRAY_SIZE (ldsid_pattern));
1445 /* Finally, if this is the main executable, try to locate a sequence
1447 addr = hppa_symbol_address ("noshlibs");
1448 sec = find_pc_section (addr);
1450 if (sec && sec->objfile == obj)
1452 CORE_ADDR start, end;
1454 find_pc_partial_function (addr, NULL, &start, &end);
1455 if (start != 0 && end != 0)
1457 addr = hppa_hpux_search_pattern (start, end, ldsid_pattern,
1458 ARRAY_SIZE (ldsid_pattern));
1464 /* Can't find a suitable sequence. */
1468 target_read_memory (addr, buf, sizeof (buf));
1469 insn = extract_unsigned_integer (buf, sizeof (buf));
1470 priv->dummy_call_sequence_addr = addr;
1471 priv->dummy_call_sequence_reg = (insn >> 21) & 0x1f;
1473 *argreg = priv->dummy_call_sequence_reg;
1474 return priv->dummy_call_sequence_addr;
1478 hppa64_hpux_search_dummy_call_sequence (struct gdbarch *gdbarch, CORE_ADDR pc,
1481 struct objfile *obj;
1482 struct obj_section *sec;
1483 struct hppa_objfile_private *priv;
1485 struct minimal_symbol *msym;
1488 sec = find_pc_section (pc);
1490 priv = objfile_data (obj, hppa_objfile_priv_data);
1493 priv = hppa_init_objfile_priv_data (obj);
1495 error (_("Internal error creating objfile private data."));
1497 /* Use the cached value if we have one. */
1498 if (priv->dummy_call_sequence_addr != 0)
1500 *argreg = priv->dummy_call_sequence_reg;
1501 return priv->dummy_call_sequence_addr;
1504 /* FIXME: Without stub unwind information, locating a suitable sequence is
1505 fairly difficult. For now, we implement a very naive and inefficient
1506 scheme; try to read in blocks of code, and look for a "bve,n (rp)"
1507 instruction. These are likely to occur at the end of functions, so
1508 we only look at the last two instructions of each function. */
1509 for (i = 0, msym = obj->msymbols; i < obj->minimal_symbol_count; i++, msym++)
1511 CORE_ADDR begin, end;
1513 gdb_byte buf[2 * HPPA_INSN_SIZE];
1516 find_pc_partial_function (SYMBOL_VALUE_ADDRESS (msym), &name,
1519 if (name == NULL || begin == 0 || end == 0)
1522 if (target_read_memory (end - sizeof (buf), buf, sizeof (buf)) == 0)
1524 for (offset = 0; offset < sizeof (buf); offset++)
1528 insn = extract_unsigned_integer (buf + offset, HPPA_INSN_SIZE);
1529 if (insn == 0xe840d002) /* bve,n (rp) */
1531 addr = (end - sizeof (buf)) + offset;
1538 /* Can't find a suitable sequence. */
1542 priv->dummy_call_sequence_addr = addr;
1543 /* Right now we only look for a "bve,l (rp)" sequence, so the register is
1544 always HPPA_RP_REGNUM. */
1545 priv->dummy_call_sequence_reg = HPPA_RP_REGNUM;
1547 *argreg = priv->dummy_call_sequence_reg;
1548 return priv->dummy_call_sequence_addr;
1552 hppa_hpux_find_import_stub_for_addr (CORE_ADDR funcaddr)
1554 struct objfile *objfile;
1555 struct minimal_symbol *funsym, *stubsym;
1558 funsym = lookup_minimal_symbol_by_pc (funcaddr);
1561 ALL_OBJFILES (objfile)
1563 stubsym = lookup_minimal_symbol_solib_trampoline
1564 (SYMBOL_LINKAGE_NAME (funsym), objfile);
1568 struct unwind_table_entry *u;
1570 u = find_unwind_entry (SYMBOL_VALUE (stubsym));
1572 || (u->stub_unwind.stub_type != IMPORT
1573 && u->stub_unwind.stub_type != IMPORT_SHLIB))
1576 stubaddr = SYMBOL_VALUE (stubsym);
1578 /* If we found an IMPORT stub, then we can stop searching;
1579 if we found an IMPORT_SHLIB, we want to continue the search
1580 in the hopes that we will find an IMPORT stub. */
1581 if (u->stub_unwind.stub_type == IMPORT)
1590 hppa_hpux_sr_for_addr (CORE_ADDR addr)
1593 /* The space register to use is encoded in the top 2 bits of the address. */
1594 sr = addr >> (gdbarch_tdep (current_gdbarch)->bytes_per_address * 8 - 2);
1599 hppa_hpux_find_dummy_bpaddr (CORE_ADDR addr)
1601 /* In order for us to restore the space register to its starting state,
1602 we need the dummy trampoline to return to the an instruction address in
1603 the same space as where we started the call. We used to place the
1604 breakpoint near the current pc, however, this breaks nested dummy calls
1605 as the nested call will hit the breakpoint address and terminate
1606 prematurely. Instead, we try to look for an address in the same space to
1609 This is similar in spirit to putting the breakpoint at the "entry point"
1610 of an executable. */
1612 struct obj_section *sec;
1613 struct unwind_table_entry *u;
1614 struct minimal_symbol *msym;
1618 sec = find_pc_section (addr);
1621 /* First try the lowest address in the section; we can use it as long
1622 as it is "regular" code (i.e. not a stub) */
1623 u = find_unwind_entry (sec->addr);
1624 if (!u || u->stub_unwind.stub_type == 0)
1627 /* Otherwise, we need to find a symbol for a regular function. We
1628 do this by walking the list of msymbols in the objfile. The symbol
1629 we find should not be the same as the function that was passed in. */
1631 /* FIXME: this is broken, because we can find a function that will be
1632 called by the dummy call target function, which will still not
1635 find_pc_partial_function (addr, NULL, &func, NULL);
1636 for (i = 0, msym = sec->objfile->msymbols;
1637 i < sec->objfile->minimal_symbol_count;
1640 u = find_unwind_entry (SYMBOL_VALUE_ADDRESS (msym));
1641 if (func != SYMBOL_VALUE_ADDRESS (msym)
1642 && (!u || u->stub_unwind.stub_type == 0))
1643 return SYMBOL_VALUE_ADDRESS (msym);
1647 warning (_("Cannot find suitable address to place dummy breakpoint; nested "
1648 "calls may fail."));
1653 hppa_hpux_push_dummy_code (struct gdbarch *gdbarch, CORE_ADDR sp,
1654 CORE_ADDR funcaddr, int using_gcc,
1655 struct value **args, int nargs,
1656 struct type *value_type,
1657 CORE_ADDR *real_pc, CORE_ADDR *bp_addr)
1659 CORE_ADDR pc, stubaddr;
1664 /* Note: we don't want to pass a function descriptor here; push_dummy_call
1665 fills in the PIC register for us. */
1666 funcaddr = gdbarch_convert_from_func_ptr_addr (gdbarch, funcaddr, NULL);
1668 /* The simple case is where we call a function in the same space that we are
1669 currently in; in that case we don't really need to do anything. */
1670 if (hppa_hpux_sr_for_addr (pc) == hppa_hpux_sr_for_addr (funcaddr))
1672 /* Intraspace call. */
1673 *bp_addr = hppa_hpux_find_dummy_bpaddr (pc);
1674 *real_pc = funcaddr;
1675 regcache_cooked_write_unsigned (current_regcache, HPPA_RP_REGNUM, *bp_addr);
1680 /* In order to make an interspace call, we need to go through a stub.
1681 gcc supplies an appropriate stub called "__gcc_plt_call", however, if
1682 an application is compiled with HP compilers then this stub is not
1683 available. We used to fallback to "__d_plt_call", however that stub
1684 is not entirely useful for us because it doesn't do an interspace
1685 return back to the caller. Also, on hppa64-hpux, there is no
1686 __gcc_plt_call available. In order to keep the code uniform, we
1687 instead don't use either of these stubs, but instead write our own
1690 A problem arises since the stack is located in a different space than
1691 code, so in order to branch to a stack stub, we will need to do an
1692 interspace branch. Previous versions of gdb did this by modifying code
1693 at the current pc and doing single-stepping to set the pcsq. Since this
1694 is highly undesirable, we use a different scheme:
1696 All we really need to do the branch to the stub is a short instruction
1707 Instead of writing these sequences ourselves, we can find it in
1708 the instruction stream that belongs to the current space. While this
1709 seems difficult at first, we are actually guaranteed to find the sequences
1713 - in export stubs for shared libraries
1714 - in the "noshlibs" routine in the main module
1717 - at the end of each "regular" function
1719 We cache the address of these sequences in the objfile's private data
1720 since these operations can potentially be quite expensive.
1723 - write a stack trampoline
1724 - look for a suitable instruction sequence in the current space
1725 - point the sequence at the trampoline
1726 - set the return address of the trampoline to the current space
1727 (see hppa_hpux_find_dummy_call_bpaddr)
1728 - set the continuing address of the "dummy code" as the sequence.
1732 if (IS_32BIT_TARGET (gdbarch))
1734 static unsigned int hppa32_tramp[] = {
1735 0x0fdf1291, /* stw r31,-8(,sp) */
1736 0x02c010a1, /* ldsid (,r22),r1 */
1737 0x00011820, /* mtsp r1,sr0 */
1738 0xe6c00000, /* be,l 0(sr0,r22),%sr0,%r31 */
1739 0x081f0242, /* copy r31,rp */
1740 0x0fd11082, /* ldw -8(,sp),rp */
1741 0x004010a1, /* ldsid (,rp),r1 */
1742 0x00011820, /* mtsp r1,sr0 */
1743 0xe0400000, /* be 0(sr0,rp) */
1744 0x08000240 /* nop */
1747 /* for hppa32, we must call the function through a stub so that on
1748 return it can return to the space of our trampoline. */
1749 stubaddr = hppa_hpux_find_import_stub_for_addr (funcaddr);
1751 error (_("Cannot call external function not referenced by application "
1752 "(no import stub).\n"));
1753 regcache_cooked_write_unsigned (current_regcache, 22, stubaddr);
1755 write_memory (sp, (char *)&hppa32_tramp, sizeof (hppa32_tramp));
1757 *bp_addr = hppa_hpux_find_dummy_bpaddr (pc);
1758 regcache_cooked_write_unsigned (current_regcache, 31, *bp_addr);
1760 *real_pc = hppa32_hpux_search_dummy_call_sequence (gdbarch, pc, &argreg);
1762 error (_("Cannot make interspace call from here."));
1764 regcache_cooked_write_unsigned (current_regcache, argreg, sp);
1766 sp += sizeof (hppa32_tramp);
1770 static unsigned int hppa64_tramp[] = {
1771 0xeac0f000, /* bve,l (r22),%r2 */
1772 0x0fdf12d1, /* std r31,-8(,sp) */
1773 0x0fd110c2, /* ldd -8(,sp),rp */
1774 0xe840d002, /* bve,n (rp) */
1775 0x08000240 /* nop */
1778 /* for hppa64, we don't need to call through a stub; all functions
1779 return via a bve. */
1780 regcache_cooked_write_unsigned (current_regcache, 22, funcaddr);
1781 write_memory (sp, (char *)&hppa64_tramp, sizeof (hppa64_tramp));
1784 regcache_cooked_write_unsigned (current_regcache, 31, *bp_addr);
1786 *real_pc = hppa64_hpux_search_dummy_call_sequence (gdbarch, pc, &argreg);
1788 error (_("Cannot make interspace call from here."));
1790 regcache_cooked_write_unsigned (current_regcache, argreg, sp);
1792 sp += sizeof (hppa64_tramp);
1795 sp = gdbarch_frame_align (gdbarch, sp);
1803 hppa_hpux_supply_ss_narrow (struct regcache *regcache,
1804 int regnum, const char *save_state)
1806 const char *ss_narrow = save_state + HPPA_HPUX_SS_NARROW_OFFSET;
1809 for (i = HPPA_R1_REGNUM; i < HPPA_FP0_REGNUM; i++)
1811 if (regnum == i || regnum == -1)
1812 regcache_raw_supply (regcache, i, ss_narrow + offset);
1819 hppa_hpux_supply_ss_fpblock (struct regcache *regcache,
1820 int regnum, const char *save_state)
1822 const char *ss_fpblock = save_state + HPPA_HPUX_SS_FPBLOCK_OFFSET;
1825 /* FIXME: We view the floating-point state as 64 single-precision
1826 registers for 32-bit code, and 32 double-precision register for
1827 64-bit code. This distinction is artificial and should be
1828 eliminated. If that ever happens, we should remove the if-clause
1831 if (register_size (get_regcache_arch (regcache), HPPA_FP0_REGNUM) == 4)
1833 for (i = HPPA_FP0_REGNUM; i < HPPA_FP0_REGNUM + 64; i++)
1835 if (regnum == i || regnum == -1)
1836 regcache_raw_supply (regcache, i, ss_fpblock + offset);
1843 for (i = HPPA_FP0_REGNUM; i < HPPA_FP0_REGNUM + 32; i++)
1845 if (regnum == i || regnum == -1)
1846 regcache_raw_supply (regcache, i, ss_fpblock + offset);
1854 hppa_hpux_supply_ss_wide (struct regcache *regcache,
1855 int regnum, const char *save_state)
1857 const char *ss_wide = save_state + HPPA_HPUX_SS_WIDE_OFFSET;
1860 if (register_size (get_regcache_arch (regcache), HPPA_R1_REGNUM) == 4)
1863 for (i = HPPA_R1_REGNUM; i < HPPA_FP0_REGNUM; i++)
1865 if (regnum == i || regnum == -1)
1866 regcache_raw_supply (regcache, i, ss_wide + offset);
1873 hppa_hpux_supply_save_state (const struct regset *regset,
1874 struct regcache *regcache,
1875 int regnum, const void *regs, size_t len)
1877 const char *proc_info = regs;
1878 const char *save_state = proc_info + 8;
1881 flags = extract_unsigned_integer (save_state + HPPA_HPUX_SS_FLAGS_OFFSET, 4);
1882 if (regnum == -1 || regnum == HPPA_FLAGS_REGNUM)
1884 struct gdbarch *arch = get_regcache_arch (regcache);
1885 size_t size = register_size (arch, HPPA_FLAGS_REGNUM);
1888 store_unsigned_integer (buf, size, flags);
1889 regcache_raw_supply (regcache, HPPA_FLAGS_REGNUM, buf);
1892 /* If the SS_WIDEREGS flag is set, we really do need the full
1893 `struct save_state'. */
1894 if (flags & HPPA_HPUX_SS_WIDEREGS && len < HPPA_HPUX_SAVE_STATE_SIZE)
1895 error (_("Register set contents too small"));
1897 if (flags & HPPA_HPUX_SS_WIDEREGS)
1898 hppa_hpux_supply_ss_wide (regcache, regnum, save_state);
1900 hppa_hpux_supply_ss_narrow (regcache, regnum, save_state);
1902 hppa_hpux_supply_ss_fpblock (regcache, regnum, save_state);
1905 /* HP-UX register set. */
1907 static struct regset hppa_hpux_regset =
1910 hppa_hpux_supply_save_state
1913 static const struct regset *
1914 hppa_hpux_regset_from_core_section (struct gdbarch *gdbarch,
1915 const char *sect_name, size_t sect_size)
1917 if (strcmp (sect_name, ".reg") == 0
1918 && sect_size >= HPPA_HPUX_PA89_SAVE_STATE_SIZE + 8)
1919 return &hppa_hpux_regset;
1925 /* Bit in the `ss_flag' member of `struct save_state' that indicates
1926 the state was saved from a system call. From
1927 <machine/save_state.h>. */
1928 #define HPPA_HPUX_SS_INSYSCALL 0x02
1931 hppa_hpux_read_pc (ptid_t ptid)
1935 /* If we're currently in a system call return the contents of %r31. */
1936 flags = read_register_pid (HPPA_FLAGS_REGNUM, ptid);
1937 if (flags & HPPA_HPUX_SS_INSYSCALL)
1938 return read_register_pid (HPPA_R31_REGNUM, ptid) & ~0x3;
1940 return hppa_read_pc (ptid);
1944 hppa_hpux_write_pc (CORE_ADDR pc, ptid_t ptid)
1948 /* If we're currently in a system call also write PC into %r31. */
1949 flags = read_register_pid (HPPA_FLAGS_REGNUM, ptid);
1950 if (flags & HPPA_HPUX_SS_INSYSCALL)
1951 write_register_pid (HPPA_R31_REGNUM, pc | 0x3, ptid);
1953 return hppa_write_pc (pc, ptid);
1957 hppa_hpux_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
1961 /* If we're currently in a system call return the contents of %r31. */
1962 flags = frame_unwind_register_unsigned (next_frame, HPPA_FLAGS_REGNUM);
1963 if (flags & HPPA_HPUX_SS_INSYSCALL)
1964 return frame_unwind_register_unsigned (next_frame, HPPA_R31_REGNUM) & ~0x3;
1966 return hppa_unwind_pc (gdbarch, next_frame);
1971 hppa_hpux_inferior_created (struct target_ops *objfile, int from_tty)
1973 /* Some HP-UX related globals to clear when a new "main"
1974 symbol file is loaded. HP-specific. */
1975 deprecated_hp_som_som_object_present = 0;
1976 hp_cxx_exception_support_initialized = 0;
1979 /* Given the current value of the pc, check to see if it is inside a stub, and
1980 if so, change the value of the pc to point to the caller of the stub.
1981 NEXT_FRAME is the next frame in the current list of frames.
1982 BASE contains to stack frame base of the current frame.
1983 SAVE_REGS is the register file stored in the frame cache. */
1985 hppa_hpux_unwind_adjust_stub (struct frame_info *next_frame, CORE_ADDR base,
1986 struct trad_frame_saved_reg *saved_regs)
1988 int optimized, realreg;
1989 enum lval_type lval;
1991 char buffer[sizeof(ULONGEST)];
1994 struct unwind_table_entry *u;
1996 trad_frame_get_prev_register (next_frame, saved_regs,
1997 HPPA_PCOQ_HEAD_REGNUM,
1998 &optimized, &lval, &addr, &realreg, buffer);
1999 val = extract_unsigned_integer (buffer,
2000 register_size (get_frame_arch (next_frame),
2001 HPPA_PCOQ_HEAD_REGNUM));
2003 u = find_unwind_entry (val);
2004 if (u && u->stub_unwind.stub_type == EXPORT)
2006 stubpc = read_memory_integer (base - 24, TARGET_PTR_BIT / 8);
2007 trad_frame_set_value (saved_regs, HPPA_PCOQ_HEAD_REGNUM, stubpc);
2009 else if (hppa_symbol_address ("__gcc_plt_call")
2010 == get_pc_function_start (val))
2012 stubpc = read_memory_integer (base - 8, TARGET_PTR_BIT / 8);
2013 trad_frame_set_value (saved_regs, HPPA_PCOQ_HEAD_REGNUM, stubpc);
2018 hppa_hpux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
2020 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2022 if (IS_32BIT_TARGET (gdbarch))
2023 tdep->in_solib_call_trampoline = hppa32_hpux_in_solib_call_trampoline;
2025 tdep->in_solib_call_trampoline = hppa64_hpux_in_solib_call_trampoline;
2027 tdep->unwind_adjust_stub = hppa_hpux_unwind_adjust_stub;
2029 set_gdbarch_in_solib_return_trampoline
2030 (gdbarch, hppa_hpux_in_solib_return_trampoline);
2031 set_gdbarch_skip_trampoline_code (gdbarch, hppa_hpux_skip_trampoline_code);
2033 set_gdbarch_push_dummy_code (gdbarch, hppa_hpux_push_dummy_code);
2034 set_gdbarch_call_dummy_location (gdbarch, ON_STACK);
2036 set_gdbarch_read_pc (gdbarch, hppa_hpux_read_pc);
2037 set_gdbarch_write_pc (gdbarch, hppa_hpux_write_pc);
2038 set_gdbarch_unwind_pc (gdbarch, hppa_hpux_unwind_pc);
2039 set_gdbarch_skip_permanent_breakpoint
2040 (gdbarch, hppa_skip_permanent_breakpoint);
2042 set_gdbarch_regset_from_core_section
2043 (gdbarch, hppa_hpux_regset_from_core_section);
2045 frame_unwind_append_sniffer (gdbarch, hppa_hpux_sigtramp_unwind_sniffer);
2047 observer_attach_inferior_created (hppa_hpux_inferior_created);
2051 hppa_hpux_som_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
2053 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2057 tdep->find_global_pointer = hppa32_hpux_find_global_pointer;
2059 hppa_hpux_init_abi (info, gdbarch);
2060 som_solib_select (tdep);
2064 hppa_hpux_elf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
2066 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2069 tdep->find_global_pointer = hppa64_hpux_find_global_pointer;
2071 hppa_hpux_init_abi (info, gdbarch);
2072 pa64_solib_select (tdep);
2075 static enum gdb_osabi
2076 hppa_hpux_core_osabi_sniffer (bfd *abfd)
2078 if (strcmp (bfd_get_target (abfd), "hpux-core") == 0)
2079 return GDB_OSABI_HPUX_SOM;
2080 else if (strcmp (bfd_get_target (abfd), "elf64-hppa") == 0)
2084 section = bfd_get_section_by_name (abfd, ".kernel");
2090 size = bfd_section_size (abfd, section);
2091 contents = alloca (size);
2092 if (bfd_get_section_contents (abfd, section, contents,
2094 && strcmp (contents, "HP-UX") == 0)
2095 return GDB_OSABI_HPUX_ELF;
2099 return GDB_OSABI_UNKNOWN;
2103 _initialize_hppa_hpux_tdep (void)
2105 /* BFD doesn't set a flavour for HP-UX style core files. It doesn't
2106 set the architecture either. */
2107 gdbarch_register_osabi_sniffer (bfd_arch_unknown,
2108 bfd_target_unknown_flavour,
2109 hppa_hpux_core_osabi_sniffer);
2110 gdbarch_register_osabi_sniffer (bfd_arch_hppa,
2111 bfd_target_elf_flavour,
2112 hppa_hpux_core_osabi_sniffer);
2114 gdbarch_register_osabi (bfd_arch_hppa, 0, GDB_OSABI_HPUX_SOM,
2115 hppa_hpux_som_init_abi);
2116 gdbarch_register_osabi (bfd_arch_hppa, bfd_mach_hppa20w, GDB_OSABI_HPUX_ELF,
2117 hppa_hpux_elf_init_abi);