1 /* Target-dependent code for HPUX running on PA-RISC, for GDB.
3 Copyright 2002, 2003 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 #include "arch-utils.h"
25 #include "gdb_string.h"
27 #include "frame-unwind.h"
28 #include "trad-frame.h"
33 #include "hppa-tdep.h"
36 #include <machine/save_state.h>
39 #define offsetof(TYPE, MEMBER) ((unsigned long) &((TYPE *)0)->MEMBER)
42 /* Forward declarations. */
43 extern void _initialize_hppa_hpux_tdep (void);
44 extern initialize_file_ftype _initialize_hppa_hpux_tdep
;
48 struct minimal_symbol
*msym
;
49 CORE_ADDR solib_handle
;
54 /* Return one if PC is in the call path of a trampoline, else return zero.
56 Note we return one for *any* call trampoline (long-call, arg-reloc), not
57 just shared library trampolines (import, export). */
60 hppa32_hpux_in_solib_call_trampoline (CORE_ADDR pc
, char *name
)
62 struct minimal_symbol
*minsym
;
63 struct unwind_table_entry
*u
;
65 /* First see if PC is in one of the two C-library trampolines. */
66 if (pc
== hppa_symbol_address("$$dyncall")
67 || pc
== hppa_symbol_address("_sr4export"))
70 minsym
= lookup_minimal_symbol_by_pc (pc
);
71 if (minsym
&& strcmp (DEPRECATED_SYMBOL_NAME (minsym
), ".stub") == 0)
74 /* Get the unwind descriptor corresponding to PC, return zero
75 if no unwind was found. */
76 u
= find_unwind_entry (pc
);
80 /* If this isn't a linker stub, then return now. */
81 if (u
->stub_unwind
.stub_type
== 0)
84 /* By definition a long-branch stub is a call stub. */
85 if (u
->stub_unwind
.stub_type
== LONG_BRANCH
)
88 /* The call and return path execute the same instructions within
89 an IMPORT stub! So an IMPORT stub is both a call and return
91 if (u
->stub_unwind
.stub_type
== IMPORT
)
94 /* Parameter relocation stubs always have a call path and may have a
96 if (u
->stub_unwind
.stub_type
== PARAMETER_RELOCATION
97 || u
->stub_unwind
.stub_type
== EXPORT
)
101 /* Search forward from the current PC until we hit a branch
102 or the end of the stub. */
103 for (addr
= pc
; addr
<= u
->region_end
; addr
+= 4)
107 insn
= read_memory_integer (addr
, 4);
109 /* Does it look like a bl? If so then it's the call path, if
110 we find a bv or be first, then we're on the return path. */
111 if ((insn
& 0xfc00e000) == 0xe8000000)
113 else if ((insn
& 0xfc00e001) == 0xe800c000
114 || (insn
& 0xfc000000) == 0xe0000000)
118 /* Should never happen. */
119 warning ("Unable to find branch in parameter relocation stub.\n");
123 /* Unknown stub type. For now, just return zero. */
128 hppa64_hpux_in_solib_call_trampoline (CORE_ADDR pc
, char *name
)
130 /* PA64 has a completely different stub/trampoline scheme. Is it
131 better? Maybe. It's certainly harder to determine with any
132 certainty that we are in a stub because we can not refer to the
135 The heuristic is simple. Try to lookup the current PC value in th
136 minimal symbol table. If that fails, then assume we are not in a
139 Then see if the PC value falls within the section bounds for the
140 section containing the minimal symbol we found in the first
141 step. If it does, then assume we are not in a stub and return.
143 Finally peek at the instructions to see if they look like a stub. */
144 struct minimal_symbol
*minsym
;
149 minsym
= lookup_minimal_symbol_by_pc (pc
);
153 sec
= SYMBOL_BFD_SECTION (minsym
);
155 if (bfd_get_section_vma (sec
->owner
, sec
) <= pc
156 && pc
< (bfd_get_section_vma (sec
->owner
, sec
)
157 + bfd_section_size (sec
->owner
, sec
)))
160 /* We might be in a stub. Peek at the instructions. Stubs are 3
161 instructions long. */
162 insn
= read_memory_integer (pc
, 4);
164 /* Find out where we think we are within the stub. */
165 if ((insn
& 0xffffc00e) == 0x53610000)
167 else if ((insn
& 0xffffffff) == 0xe820d000)
169 else if ((insn
& 0xffffc00e) == 0x537b0000)
174 /* Now verify each insn in the range looks like a stub instruction. */
175 insn
= read_memory_integer (addr
, 4);
176 if ((insn
& 0xffffc00e) != 0x53610000)
179 /* Now verify each insn in the range looks like a stub instruction. */
180 insn
= read_memory_integer (addr
+ 4, 4);
181 if ((insn
& 0xffffffff) != 0xe820d000)
184 /* Now verify each insn in the range looks like a stub instruction. */
185 insn
= read_memory_integer (addr
+ 8, 4);
186 if ((insn
& 0xffffc00e) != 0x537b0000)
189 /* Looks like a stub. */
193 /* Return one if PC is in the return path of a trampoline, else return zero.
195 Note we return one for *any* call trampoline (long-call, arg-reloc), not
196 just shared library trampolines (import, export). */
199 hppa_hpux_in_solib_return_trampoline (CORE_ADDR pc
, char *name
)
201 struct unwind_table_entry
*u
;
203 /* Get the unwind descriptor corresponding to PC, return zero
204 if no unwind was found. */
205 u
= find_unwind_entry (pc
);
209 /* If this isn't a linker stub or it's just a long branch stub, then
211 if (u
->stub_unwind
.stub_type
== 0 || u
->stub_unwind
.stub_type
== LONG_BRANCH
)
214 /* The call and return path execute the same instructions within
215 an IMPORT stub! So an IMPORT stub is both a call and return
217 if (u
->stub_unwind
.stub_type
== IMPORT
)
220 /* Parameter relocation stubs always have a call path and may have a
222 if (u
->stub_unwind
.stub_type
== PARAMETER_RELOCATION
223 || u
->stub_unwind
.stub_type
== EXPORT
)
227 /* Search forward from the current PC until we hit a branch
228 or the end of the stub. */
229 for (addr
= pc
; addr
<= u
->region_end
; addr
+= 4)
233 insn
= read_memory_integer (addr
, 4);
235 /* Does it look like a bl? If so then it's the call path, if
236 we find a bv or be first, then we're on the return path. */
237 if ((insn
& 0xfc00e000) == 0xe8000000)
239 else if ((insn
& 0xfc00e001) == 0xe800c000
240 || (insn
& 0xfc000000) == 0xe0000000)
244 /* Should never happen. */
245 warning ("Unable to find branch in parameter relocation stub.\n");
249 /* Unknown stub type. For now, just return zero. */
254 /* Figure out if PC is in a trampoline, and if so find out where
255 the trampoline will jump to. If not in a trampoline, return zero.
257 Simple code examination probably is not a good idea since the code
258 sequences in trampolines can also appear in user code.
260 We use unwinds and information from the minimal symbol table to
261 determine when we're in a trampoline. This won't work for ELF
262 (yet) since it doesn't create stub unwind entries. Whether or
263 not ELF will create stub unwinds or normal unwinds for linker
264 stubs is still being debated.
266 This should handle simple calls through dyncall or sr4export,
267 long calls, argument relocation stubs, and dyncall/sr4export
268 calling an argument relocation stub. It even handles some stubs
269 used in dynamic executables. */
272 hppa_hpux_skip_trampoline_code (CORE_ADDR pc
)
275 long prev_inst
, curr_inst
, loc
;
276 struct minimal_symbol
*msym
;
277 struct unwind_table_entry
*u
;
279 /* Addresses passed to dyncall may *NOT* be the actual address
280 of the function. So we may have to do something special. */
281 if (pc
== hppa_symbol_address("$$dyncall"))
283 pc
= (CORE_ADDR
) read_register (22);
285 /* If bit 30 (counting from the left) is on, then pc is the address of
286 the PLT entry for this function, not the address of the function
287 itself. Bit 31 has meaning too, but only for MPE. */
289 pc
= (CORE_ADDR
) read_memory_integer (pc
& ~0x3, TARGET_PTR_BIT
/ 8);
291 if (pc
== hppa_symbol_address("$$dyncall_external"))
293 pc
= (CORE_ADDR
) read_register (22);
294 pc
= (CORE_ADDR
) read_memory_integer (pc
& ~0x3, TARGET_PTR_BIT
/ 8);
296 else if (pc
== hppa_symbol_address("_sr4export"))
297 pc
= (CORE_ADDR
) (read_register (22));
299 /* Get the unwind descriptor corresponding to PC, return zero
300 if no unwind was found. */
301 u
= find_unwind_entry (pc
);
305 /* If this isn't a linker stub, then return now. */
306 /* elz: attention here! (FIXME) because of a compiler/linker
307 error, some stubs which should have a non zero stub_unwind.stub_type
308 have unfortunately a value of zero. So this function would return here
309 as if we were not in a trampoline. To fix this, we go look at the partial
310 symbol information, which reports this guy as a stub.
311 (FIXME): Unfortunately, we are not that lucky: it turns out that the
312 partial symbol information is also wrong sometimes. This is because
313 when it is entered (somread.c::som_symtab_read()) it can happen that
314 if the type of the symbol (from the som) is Entry, and the symbol is
315 in a shared library, then it can also be a trampoline. This would
316 be OK, except that I believe the way they decide if we are ina shared library
317 does not work. SOOOO..., even if we have a regular function w/o trampolines
318 its minimal symbol can be assigned type mst_solib_trampoline.
319 Also, if we find that the symbol is a real stub, then we fix the unwind
320 descriptor, and define the stub type to be EXPORT.
321 Hopefully this is correct most of the times. */
322 if (u
->stub_unwind
.stub_type
== 0)
325 /* elz: NOTE (FIXME!) once the problem with the unwind information is fixed
326 we can delete all the code which appears between the lines */
327 /*--------------------------------------------------------------------------*/
328 msym
= lookup_minimal_symbol_by_pc (pc
);
330 if (msym
== NULL
|| MSYMBOL_TYPE (msym
) != mst_solib_trampoline
)
331 return orig_pc
== pc
? 0 : pc
& ~0x3;
333 else if (msym
!= NULL
&& MSYMBOL_TYPE (msym
) == mst_solib_trampoline
)
335 struct objfile
*objfile
;
336 struct minimal_symbol
*msymbol
;
337 int function_found
= 0;
339 /* go look if there is another minimal symbol with the same name as
340 this one, but with type mst_text. This would happen if the msym
341 is an actual trampoline, in which case there would be another
342 symbol with the same name corresponding to the real function */
344 ALL_MSYMBOLS (objfile
, msymbol
)
346 if (MSYMBOL_TYPE (msymbol
) == mst_text
347 && DEPRECATED_STREQ (DEPRECATED_SYMBOL_NAME (msymbol
), DEPRECATED_SYMBOL_NAME (msym
)))
355 /* the type of msym is correct (mst_solib_trampoline), but
356 the unwind info is wrong, so set it to the correct value */
357 u
->stub_unwind
.stub_type
= EXPORT
;
359 /* the stub type info in the unwind is correct (this is not a
360 trampoline), but the msym type information is wrong, it
361 should be mst_text. So we need to fix the msym, and also
362 get out of this function */
364 MSYMBOL_TYPE (msym
) = mst_text
;
365 return orig_pc
== pc
? 0 : pc
& ~0x3;
369 /*--------------------------------------------------------------------------*/
372 /* It's a stub. Search for a branch and figure out where it goes.
373 Note we have to handle multi insn branch sequences like ldil;ble.
374 Most (all?) other branches can be determined by examining the contents
375 of certain registers and the stack. */
382 /* Make sure we haven't walked outside the range of this stub. */
383 if (u
!= find_unwind_entry (loc
))
385 warning ("Unable to find branch in linker stub");
386 return orig_pc
== pc
? 0 : pc
& ~0x3;
389 prev_inst
= curr_inst
;
390 curr_inst
= read_memory_integer (loc
, 4);
392 /* Does it look like a branch external using %r1? Then it's the
393 branch from the stub to the actual function. */
394 if ((curr_inst
& 0xffe0e000) == 0xe0202000)
396 /* Yup. See if the previous instruction loaded
397 a value into %r1. If so compute and return the jump address. */
398 if ((prev_inst
& 0xffe00000) == 0x20200000)
399 return (hppa_extract_21 (prev_inst
) + hppa_extract_17 (curr_inst
)) & ~0x3;
402 warning ("Unable to find ldil X,%%r1 before ble Y(%%sr4,%%r1).");
403 return orig_pc
== pc
? 0 : pc
& ~0x3;
407 /* Does it look like a be 0(sr0,%r21)? OR
408 Does it look like a be, n 0(sr0,%r21)? OR
409 Does it look like a bve (r21)? (this is on PA2.0)
410 Does it look like a bve, n(r21)? (this is also on PA2.0)
411 That's the branch from an
412 import stub to an export stub.
414 It is impossible to determine the target of the branch via
415 simple examination of instructions and/or data (consider
416 that the address in the plabel may be the address of the
417 bind-on-reference routine in the dynamic loader).
419 So we have try an alternative approach.
421 Get the name of the symbol at our current location; it should
422 be a stub symbol with the same name as the symbol in the
425 Then lookup a minimal symbol with the same name; we should
426 get the minimal symbol for the target routine in the shared
427 library as those take precedence of import/export stubs. */
428 if ((curr_inst
== 0xe2a00000) ||
429 (curr_inst
== 0xe2a00002) ||
430 (curr_inst
== 0xeaa0d000) ||
431 (curr_inst
== 0xeaa0d002))
433 struct minimal_symbol
*stubsym
, *libsym
;
435 stubsym
= lookup_minimal_symbol_by_pc (loc
);
438 warning ("Unable to find symbol for 0x%lx", loc
);
439 return orig_pc
== pc
? 0 : pc
& ~0x3;
442 libsym
= lookup_minimal_symbol (DEPRECATED_SYMBOL_NAME (stubsym
), NULL
, NULL
);
445 warning ("Unable to find library symbol for %s\n",
446 DEPRECATED_SYMBOL_NAME (stubsym
));
447 return orig_pc
== pc
? 0 : pc
& ~0x3;
450 return SYMBOL_VALUE (libsym
);
453 /* Does it look like bl X,%rp or bl X,%r0? Another way to do a
454 branch from the stub to the actual function. */
456 else if ((curr_inst
& 0xffe0e000) == 0xe8400000
457 || (curr_inst
& 0xffe0e000) == 0xe8000000
458 || (curr_inst
& 0xffe0e000) == 0xe800A000)
459 return (loc
+ hppa_extract_17 (curr_inst
) + 8) & ~0x3;
461 /* Does it look like bv (rp)? Note this depends on the
462 current stack pointer being the same as the stack
463 pointer in the stub itself! This is a branch on from the
464 stub back to the original caller. */
465 /*else if ((curr_inst & 0xffe0e000) == 0xe840c000) */
466 else if ((curr_inst
& 0xffe0f000) == 0xe840c000)
468 /* Yup. See if the previous instruction loaded
470 if (prev_inst
== 0x4bc23ff1)
471 return (read_memory_integer
472 (read_register (HPPA_SP_REGNUM
) - 8, 4)) & ~0x3;
475 warning ("Unable to find restore of %%rp before bv (%%rp).");
476 return orig_pc
== pc
? 0 : pc
& ~0x3;
480 /* elz: added this case to capture the new instruction
481 at the end of the return part of an export stub used by
482 the PA2.0: BVE, n (rp) */
483 else if ((curr_inst
& 0xffe0f000) == 0xe840d000)
485 return (read_memory_integer
486 (read_register (HPPA_SP_REGNUM
) - 24, TARGET_PTR_BIT
/ 8)) & ~0x3;
489 /* What about be,n 0(sr0,%rp)? It's just another way we return to
490 the original caller from the stub. Used in dynamic executables. */
491 else if (curr_inst
== 0xe0400002)
493 /* The value we jump to is sitting in sp - 24. But that's
494 loaded several instructions before the be instruction.
495 I guess we could check for the previous instruction being
496 mtsp %r1,%sr0 if we want to do sanity checking. */
497 return (read_memory_integer
498 (read_register (HPPA_SP_REGNUM
) - 24, TARGET_PTR_BIT
/ 8)) & ~0x3;
501 /* Haven't found the branch yet, but we're still in the stub.
508 /* Exception handling support for the HP-UX ANSI C++ compiler.
509 The compiler (aCC) provides a callback for exception events;
510 GDB can set a breakpoint on this callback and find out what
511 exception event has occurred. */
513 /* The name of the hook to be set to point to the callback function */
514 static char HP_ACC_EH_notify_hook
[] = "__eh_notify_hook";
515 /* The name of the function to be used to set the hook value */
516 static char HP_ACC_EH_set_hook_value
[] = "__eh_set_hook_value";
517 /* The name of the callback function in end.o */
518 static char HP_ACC_EH_notify_callback
[] = "__d_eh_notify_callback";
519 /* Name of function in end.o on which a break is set (called by above) */
520 static char HP_ACC_EH_break
[] = "__d_eh_break";
521 /* Name of flag (in end.o) that enables catching throws */
522 static char HP_ACC_EH_catch_throw
[] = "__d_eh_catch_throw";
523 /* Name of flag (in end.o) that enables catching catching */
524 static char HP_ACC_EH_catch_catch
[] = "__d_eh_catch_catch";
525 /* The enum used by aCC */
533 /* Is exception-handling support available with this executable? */
534 static int hp_cxx_exception_support
= 0;
535 /* Has the initialize function been run? */
536 int hp_cxx_exception_support_initialized
= 0;
537 /* Address of __eh_notify_hook */
538 static CORE_ADDR eh_notify_hook_addr
= 0;
539 /* Address of __d_eh_notify_callback */
540 static CORE_ADDR eh_notify_callback_addr
= 0;
541 /* Address of __d_eh_break */
542 static CORE_ADDR eh_break_addr
= 0;
543 /* Address of __d_eh_catch_catch */
544 static CORE_ADDR eh_catch_catch_addr
= 0;
545 /* Address of __d_eh_catch_throw */
546 static CORE_ADDR eh_catch_throw_addr
= 0;
547 /* Sal for __d_eh_break */
548 static struct symtab_and_line
*break_callback_sal
= 0;
550 /* Code in end.c expects __d_pid to be set in the inferior,
551 otherwise __d_eh_notify_callback doesn't bother to call
552 __d_eh_break! So we poke the pid into this symbol
557 setup_d_pid_in_inferior (void)
560 struct minimal_symbol
*msymbol
;
561 char buf
[4]; /* FIXME 32x64? */
563 /* Slam the pid of the process into __d_pid; failing is only a warning! */
564 msymbol
= lookup_minimal_symbol ("__d_pid", NULL
, symfile_objfile
);
567 warning ("Unable to find __d_pid symbol in object file.");
568 warning ("Suggest linking executable with -g (links in /opt/langtools/lib/end.o).");
572 anaddr
= SYMBOL_VALUE_ADDRESS (msymbol
);
573 store_unsigned_integer (buf
, 4, PIDGET (inferior_ptid
)); /* FIXME 32x64? */
574 if (target_write_memory (anaddr
, buf
, 4)) /* FIXME 32x64? */
576 warning ("Unable to write __d_pid");
577 warning ("Suggest linking executable with -g (links in /opt/langtools/lib/end.o).");
583 /* elz: Used to lookup a symbol in the shared libraries.
584 This function calls shl_findsym, indirectly through a
585 call to __d_shl_get. __d_shl_get is in end.c, which is always
586 linked in by the hp compilers/linkers.
587 The call to shl_findsym cannot be made directly because it needs
588 to be active in target address space.
589 inputs: - minimal symbol pointer for the function we want to look up
590 - address in target space of the descriptor for the library
591 where we want to look the symbol up.
592 This address is retrieved using the
593 som_solib_get_solib_by_pc function (somsolib.c).
594 output: - real address in the library of the function.
595 note: the handle can be null, in which case shl_findsym will look for
596 the symbol in all the loaded shared libraries.
597 files to look at if you need reference on this stuff:
598 dld.c, dld_shl_findsym.c
600 man entry for shl_findsym */
603 find_stub_with_shl_get (struct minimal_symbol
*function
, CORE_ADDR handle
)
605 struct symbol
*get_sym
, *symbol2
;
606 struct minimal_symbol
*buff_minsym
, *msymbol
;
609 struct value
*funcval
;
612 int x
, namelen
, err_value
, tmp
= -1;
613 CORE_ADDR endo_buff_addr
, value_return_addr
, errno_return_addr
;
617 args
= alloca (sizeof (struct value
*) * 8); /* 6 for the arguments and one null one??? */
618 funcval
= find_function_in_inferior ("__d_shl_get");
619 get_sym
= lookup_symbol ("__d_shl_get", NULL
, VAR_DOMAIN
, NULL
, NULL
);
620 buff_minsym
= lookup_minimal_symbol ("__buffer", NULL
, NULL
);
621 msymbol
= lookup_minimal_symbol ("__shldp", NULL
, NULL
);
622 symbol2
= lookup_symbol ("__shldp", NULL
, VAR_DOMAIN
, NULL
, NULL
);
623 endo_buff_addr
= SYMBOL_VALUE_ADDRESS (buff_minsym
);
624 namelen
= strlen (DEPRECATED_SYMBOL_NAME (function
));
625 value_return_addr
= endo_buff_addr
+ namelen
;
626 ftype
= check_typedef (SYMBOL_TYPE (get_sym
));
629 if ((x
= value_return_addr
% 64) != 0)
630 value_return_addr
= value_return_addr
+ 64 - x
;
632 errno_return_addr
= value_return_addr
+ 64;
635 /* set up stuff needed by __d_shl_get in buffer in end.o */
637 target_write_memory (endo_buff_addr
, DEPRECATED_SYMBOL_NAME (function
), namelen
);
639 target_write_memory (value_return_addr
, (char *) &tmp
, 4);
641 target_write_memory (errno_return_addr
, (char *) &tmp
, 4);
643 target_write_memory (SYMBOL_VALUE_ADDRESS (msymbol
),
644 (char *) &handle
, 4);
646 /* now prepare the arguments for the call */
648 args
[0] = value_from_longest (TYPE_FIELD_TYPE (ftype
, 0), 12);
649 args
[1] = value_from_pointer (TYPE_FIELD_TYPE (ftype
, 1), SYMBOL_VALUE_ADDRESS (msymbol
));
650 args
[2] = value_from_pointer (TYPE_FIELD_TYPE (ftype
, 2), endo_buff_addr
);
651 args
[3] = value_from_longest (TYPE_FIELD_TYPE (ftype
, 3), TYPE_PROCEDURE
);
652 args
[4] = value_from_pointer (TYPE_FIELD_TYPE (ftype
, 4), value_return_addr
);
653 args
[5] = value_from_pointer (TYPE_FIELD_TYPE (ftype
, 5), errno_return_addr
);
655 /* now call the function */
657 val
= call_function_by_hand (funcval
, 6, args
);
659 /* now get the results */
661 target_read_memory (errno_return_addr
, (char *) &err_value
, sizeof (err_value
));
663 target_read_memory (value_return_addr
, (char *) &stub_addr
, sizeof (stub_addr
));
665 error ("call to __d_shl_get failed, error code is %d", err_value
);
670 /* Cover routine for find_stub_with_shl_get to pass to catch_errors */
672 cover_find_stub_with_shl_get (void *args_untyped
)
674 args_for_find_stub
*args
= args_untyped
;
675 args
->return_val
= find_stub_with_shl_get (args
->msym
, args
->solib_handle
);
679 /* Initialize exception catchpoint support by looking for the
680 necessary hooks/callbacks in end.o, etc., and set the hook value to
681 point to the required debug function
687 initialize_hp_cxx_exception_support (void)
689 struct symtabs_and_lines sals
;
690 struct cleanup
*old_chain
;
691 struct cleanup
*canonical_strings_chain
= NULL
;
694 char *addr_end
= NULL
;
695 char **canonical
= (char **) NULL
;
697 struct symbol
*sym
= NULL
;
698 struct minimal_symbol
*msym
= NULL
;
699 struct objfile
*objfile
;
700 asection
*shlib_info
;
702 /* Detect and disallow recursion. On HP-UX with aCC, infinite
703 recursion is a possibility because finding the hook for exception
704 callbacks involves making a call in the inferior, which means
705 re-inserting breakpoints which can re-invoke this code */
707 static int recurse
= 0;
710 hp_cxx_exception_support_initialized
= 0;
711 deprecated_exception_support_initialized
= 0;
715 hp_cxx_exception_support
= 0;
717 /* First check if we have seen any HP compiled objects; if not,
718 it is very unlikely that HP's idiosyncratic callback mechanism
719 for exception handling debug support will be available!
720 This will percolate back up to breakpoint.c, where our callers
721 will decide to try the g++ exception-handling support instead. */
722 if (!deprecated_hp_som_som_object_present
)
725 /* We have a SOM executable with SOM debug info; find the hooks */
727 /* First look for the notify hook provided by aCC runtime libs */
728 /* If we find this symbol, we conclude that the executable must
729 have HP aCC exception support built in. If this symbol is not
730 found, even though we're a HP SOM-SOM file, we may have been
731 built with some other compiler (not aCC). This results percolates
732 back up to our callers in breakpoint.c which can decide to
733 try the g++ style of exception support instead.
734 If this symbol is found but the other symbols we require are
735 not found, there is something weird going on, and g++ support
736 should *not* be tried as an alternative.
738 ASSUMPTION: Only HP aCC code will have __eh_notify_hook defined.
739 ASSUMPTION: HP aCC and g++ modules cannot be linked together. */
741 /* libCsup has this hook; it'll usually be non-debuggable */
742 msym
= lookup_minimal_symbol (HP_ACC_EH_notify_hook
, NULL
, NULL
);
745 eh_notify_hook_addr
= SYMBOL_VALUE_ADDRESS (msym
);
746 hp_cxx_exception_support
= 1;
750 warning ("Unable to find exception callback hook (%s).", HP_ACC_EH_notify_hook
);
751 warning ("Executable may not have been compiled debuggable with HP aCC.");
752 warning ("GDB will be unable to intercept exception events.");
753 eh_notify_hook_addr
= 0;
754 hp_cxx_exception_support
= 0;
758 /* Next look for the notify callback routine in end.o */
759 /* This is always available in the SOM symbol dictionary if end.o is linked in */
760 msym
= lookup_minimal_symbol (HP_ACC_EH_notify_callback
, NULL
, NULL
);
763 eh_notify_callback_addr
= SYMBOL_VALUE_ADDRESS (msym
);
764 hp_cxx_exception_support
= 1;
768 warning ("Unable to find exception callback routine (%s).", HP_ACC_EH_notify_callback
);
769 warning ("Suggest linking executable with -g (links in /opt/langtools/lib/end.o).");
770 warning ("GDB will be unable to intercept exception events.");
771 eh_notify_callback_addr
= 0;
775 #ifndef GDB_TARGET_IS_HPPA_20W
776 /* Check whether the executable is dynamically linked or archive bound */
777 /* With an archive-bound executable we can use the raw addresses we find
778 for the callback function, etc. without modification. For an executable
779 with shared libraries, we have to do more work to find the plabel, which
780 can be the target of a call through $$dyncall from the aCC runtime support
781 library (libCsup) which is linked shared by default by aCC. */
782 /* This test below was copied from somsolib.c/somread.c. It may not be a very
783 reliable one to test that an executable is linked shared. pai/1997-07-18 */
784 shlib_info
= bfd_get_section_by_name (symfile_objfile
->obfd
, "$SHLIB_INFO$");
785 if (shlib_info
&& (bfd_section_size (symfile_objfile
->obfd
, shlib_info
) != 0))
787 /* The minsym we have has the local code address, but that's not the
788 plabel that can be used by an inter-load-module call. */
789 /* Find solib handle for main image (which has end.o), and use that
790 and the min sym as arguments to __d_shl_get() (which does the equivalent
791 of shl_findsym()) to find the plabel. */
793 args_for_find_stub args
;
794 static char message
[] = "Error while finding exception callback hook:\n";
796 args
.solib_handle
= som_solib_get_solib_by_pc (eh_notify_callback_addr
);
801 catch_errors (cover_find_stub_with_shl_get
, &args
, message
,
803 eh_notify_callback_addr
= args
.return_val
;
806 deprecated_exception_catchpoints_are_fragile
= 1;
808 if (!eh_notify_callback_addr
)
810 /* We can get here either if there is no plabel in the export list
811 for the main image, or if something strange happened (?) */
812 warning ("Couldn't find a plabel (indirect function label) for the exception callback.");
813 warning ("GDB will not be able to intercept exception events.");
818 deprecated_exception_catchpoints_are_fragile
= 0;
821 /* Now, look for the breakpointable routine in end.o */
822 /* This should also be available in the SOM symbol dict. if end.o linked in */
823 msym
= lookup_minimal_symbol (HP_ACC_EH_break
, NULL
, NULL
);
826 eh_break_addr
= SYMBOL_VALUE_ADDRESS (msym
);
827 hp_cxx_exception_support
= 1;
831 warning ("Unable to find exception callback routine to set breakpoint (%s).", HP_ACC_EH_break
);
832 warning ("Suggest linking executable with -g (link in /opt/langtools/lib/end.o).");
833 warning ("GDB will be unable to intercept exception events.");
838 /* Next look for the catch enable flag provided in end.o */
839 sym
= lookup_symbol (HP_ACC_EH_catch_catch
, (struct block
*) NULL
,
840 VAR_DOMAIN
, 0, (struct symtab
**) NULL
);
841 if (sym
) /* sometimes present in debug info */
843 eh_catch_catch_addr
= SYMBOL_VALUE_ADDRESS (sym
);
844 hp_cxx_exception_support
= 1;
847 /* otherwise look in SOM symbol dict. */
849 msym
= lookup_minimal_symbol (HP_ACC_EH_catch_catch
, NULL
, NULL
);
852 eh_catch_catch_addr
= SYMBOL_VALUE_ADDRESS (msym
);
853 hp_cxx_exception_support
= 1;
857 warning ("Unable to enable interception of exception catches.");
858 warning ("Executable may not have been compiled debuggable with HP aCC.");
859 warning ("Suggest linking executable with -g (link in /opt/langtools/lib/end.o).");
864 /* Next look for the catch enable flag provided end.o */
865 sym
= lookup_symbol (HP_ACC_EH_catch_catch
, (struct block
*) NULL
,
866 VAR_DOMAIN
, 0, (struct symtab
**) NULL
);
867 if (sym
) /* sometimes present in debug info */
869 eh_catch_throw_addr
= SYMBOL_VALUE_ADDRESS (sym
);
870 hp_cxx_exception_support
= 1;
873 /* otherwise look in SOM symbol dict. */
875 msym
= lookup_minimal_symbol (HP_ACC_EH_catch_throw
, NULL
, NULL
);
878 eh_catch_throw_addr
= SYMBOL_VALUE_ADDRESS (msym
);
879 hp_cxx_exception_support
= 1;
883 warning ("Unable to enable interception of exception throws.");
884 warning ("Executable may not have been compiled debuggable with HP aCC.");
885 warning ("Suggest linking executable with -g (link in /opt/langtools/lib/end.o).");
891 hp_cxx_exception_support
= 2; /* everything worked so far */
892 hp_cxx_exception_support_initialized
= 1;
893 deprecated_exception_support_initialized
= 1;
898 /* Target operation for enabling or disabling interception of
900 KIND is either EX_EVENT_THROW or EX_EVENT_CATCH
901 ENABLE is either 0 (disable) or 1 (enable).
902 Return value is NULL if no support found;
903 -1 if something went wrong,
904 or a pointer to a symtab/line struct if the breakpointable
905 address was found. */
907 struct symtab_and_line
*
908 child_enable_exception_callback (enum exception_event_kind kind
, int enable
)
912 if (!deprecated_exception_support_initialized
913 || !hp_cxx_exception_support_initialized
)
914 if (!initialize_hp_cxx_exception_support ())
917 switch (hp_cxx_exception_support
)
920 /* Assuming no HP support at all */
923 /* HP support should be present, but something went wrong */
924 return (struct symtab_and_line
*) -1; /* yuck! */
925 /* there may be other cases in the future */
928 /* Set the EH hook to point to the callback routine */
929 store_unsigned_integer (buf
, 4, enable
? eh_notify_callback_addr
: 0); /* FIXME 32x64 problem */
930 /* pai: (temp) FIXME should there be a pack operation first? */
931 if (target_write_memory (eh_notify_hook_addr
, buf
, 4)) /* FIXME 32x64 problem */
933 warning ("Could not write to target memory for exception event callback.");
934 warning ("Interception of exception events may not work.");
935 return (struct symtab_and_line
*) -1;
939 /* Ensure that __d_pid is set up correctly -- end.c code checks this. :-( */
940 if (PIDGET (inferior_ptid
) > 0)
942 if (setup_d_pid_in_inferior ())
943 return (struct symtab_and_line
*) -1;
947 warning ("Internal error: Invalid inferior pid? Cannot intercept exception events.");
948 return (struct symtab_and_line
*) -1;
955 store_unsigned_integer (buf
, 4, enable
? 1 : 0);
956 if (target_write_memory (eh_catch_throw_addr
, buf
, 4)) /* FIXME 32x64? */
958 warning ("Couldn't enable exception throw interception.");
959 return (struct symtab_and_line
*) -1;
963 store_unsigned_integer (buf
, 4, enable
? 1 : 0);
964 if (target_write_memory (eh_catch_catch_addr
, buf
, 4)) /* FIXME 32x64? */
966 warning ("Couldn't enable exception catch interception.");
967 return (struct symtab_and_line
*) -1;
971 error ("Request to enable unknown or unsupported exception event.");
974 /* Copy break address into new sal struct, malloc'ing if needed. */
975 if (!break_callback_sal
)
977 break_callback_sal
= (struct symtab_and_line
*) xmalloc (sizeof (struct symtab_and_line
));
979 init_sal (break_callback_sal
);
980 break_callback_sal
->symtab
= NULL
;
981 break_callback_sal
->pc
= eh_break_addr
;
982 break_callback_sal
->line
= 0;
983 break_callback_sal
->end
= eh_break_addr
;
985 return break_callback_sal
;
988 /* Record some information about the current exception event */
989 static struct exception_event_record current_ex_event
;
990 /* Convenience struct */
991 static struct symtab_and_line null_symtab_and_line
=
994 /* Report current exception event. Returns a pointer to a record
995 that describes the kind of the event, where it was thrown from,
996 and where it will be caught. More information may be reported
998 struct exception_event_record
*
999 child_get_current_exception_event (void)
1001 CORE_ADDR event_kind
;
1002 CORE_ADDR throw_addr
;
1003 CORE_ADDR catch_addr
;
1004 struct frame_info
*fi
, *curr_frame
;
1007 curr_frame
= get_current_frame ();
1009 return (struct exception_event_record
*) NULL
;
1011 /* Go up one frame to __d_eh_notify_callback, because at the
1012 point when this code is executed, there's garbage in the
1013 arguments of __d_eh_break. */
1014 fi
= find_relative_frame (curr_frame
, &level
);
1016 return (struct exception_event_record
*) NULL
;
1020 /* Read in the arguments */
1021 /* __d_eh_notify_callback() is called with 3 arguments:
1022 1. event kind catch or throw
1023 2. the target address if known
1024 3. a flag -- not sure what this is. pai/1997-07-17 */
1025 event_kind
= read_register (HPPA_ARG0_REGNUM
);
1026 catch_addr
= read_register (HPPA_ARG1_REGNUM
);
1028 /* Now go down to a user frame */
1029 /* For a throw, __d_eh_break is called by
1030 __d_eh_notify_callback which is called by
1031 __notify_throw which is called
1033 For a catch, __d_eh_break is called by
1034 __d_eh_notify_callback which is called by
1035 <stackwalking stuff> which is called by
1036 __throw__<stuff> or __rethrow_<stuff> which is called
1038 /* FIXME: Don't use such magic numbers; search for the frames */
1039 level
= (event_kind
== EX_EVENT_THROW
) ? 3 : 4;
1040 fi
= find_relative_frame (curr_frame
, &level
);
1042 return (struct exception_event_record
*) NULL
;
1045 throw_addr
= get_frame_pc (fi
);
1047 /* Go back to original (top) frame */
1048 select_frame (curr_frame
);
1050 current_ex_event
.kind
= (enum exception_event_kind
) event_kind
;
1051 current_ex_event
.throw_sal
= find_pc_line (throw_addr
, 1);
1052 current_ex_event
.catch_sal
= find_pc_line (catch_addr
, 1);
1054 return ¤t_ex_event
;
1057 /* Signal frames. */
1058 struct hppa_hpux_sigtramp_unwind_cache
1061 struct trad_frame_saved_reg
*saved_regs
;
1064 static int hppa_hpux_tramp_reg
[] = {
1066 HPPA_PCOQ_HEAD_REGNUM
,
1067 HPPA_PCSQ_HEAD_REGNUM
,
1068 HPPA_PCOQ_TAIL_REGNUM
,
1069 HPPA_PCSQ_TAIL_REGNUM
,
1077 HPPA_SR4_REGNUM
+ 1,
1078 HPPA_SR4_REGNUM
+ 2,
1079 HPPA_SR4_REGNUM
+ 3,
1080 HPPA_SR4_REGNUM
+ 4,
1081 HPPA_SR4_REGNUM
+ 5,
1082 HPPA_SR4_REGNUM
+ 6,
1083 HPPA_SR4_REGNUM
+ 7,
1091 HPPA_TR0_REGNUM
+ 1,
1092 HPPA_TR0_REGNUM
+ 2,
1096 static struct hppa_hpux_sigtramp_unwind_cache
*
1097 hppa_hpux_sigtramp_frame_unwind_cache (struct frame_info
*next_frame
,
1101 struct gdbarch
*gdbarch
= get_frame_arch (next_frame
);
1102 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1103 struct hppa_hpux_sigtramp_unwind_cache
*info
;
1105 CORE_ADDR sp
, scptr
;
1106 int i
, incr
, off
, szoff
;
1111 info
= FRAME_OBSTACK_ZALLOC (struct hppa_hpux_sigtramp_unwind_cache
);
1113 info
->saved_regs
= trad_frame_alloc_saved_regs (next_frame
);
1115 sp
= frame_unwind_register_unsigned (next_frame
, HPPA_SP_REGNUM
);
1120 /* See /usr/include/machine/save_state.h for the structure of the save_state_t
1123 flag
= read_memory_unsigned_integer(scptr
, 4);
1127 /* Narrow registers. */
1128 off
= scptr
+ offsetof (save_state_t
, ss_narrow
);
1134 /* Wide registers. */
1135 off
= scptr
+ offsetof (save_state_t
, ss_wide
) + 8;
1137 szoff
= (tdep
->bytes_per_address
== 4 ? 4 : 0);
1140 for (i
= 1; i
< 32; i
++)
1142 info
->saved_regs
[HPPA_R0_REGNUM
+ i
].addr
= off
+ szoff
;
1147 i
< sizeof(hppa_hpux_tramp_reg
) / sizeof(hppa_hpux_tramp_reg
[0]);
1150 if (hppa_hpux_tramp_reg
[i
] > 0)
1151 info
->saved_regs
[hppa_hpux_tramp_reg
[i
]].addr
= off
+ szoff
;
1157 info
->base
= frame_unwind_register_unsigned (next_frame
, HPPA_SP_REGNUM
);
1163 hppa_hpux_sigtramp_frame_this_id (struct frame_info
*next_frame
,
1164 void **this_prologue_cache
,
1165 struct frame_id
*this_id
)
1167 struct hppa_hpux_sigtramp_unwind_cache
*info
1168 = hppa_hpux_sigtramp_frame_unwind_cache (next_frame
, this_prologue_cache
);
1169 *this_id
= frame_id_build (info
->base
, frame_pc_unwind (next_frame
));
1173 hppa_hpux_sigtramp_frame_prev_register (struct frame_info
*next_frame
,
1174 void **this_prologue_cache
,
1175 int regnum
, int *optimizedp
,
1176 enum lval_type
*lvalp
,
1178 int *realnump
, void *valuep
)
1180 struct hppa_hpux_sigtramp_unwind_cache
*info
1181 = hppa_hpux_sigtramp_frame_unwind_cache (next_frame
, this_prologue_cache
);
1182 hppa_frame_prev_register_helper (next_frame
, info
->saved_regs
, regnum
,
1183 optimizedp
, lvalp
, addrp
, realnump
, valuep
);
1186 static const struct frame_unwind hppa_hpux_sigtramp_frame_unwind
= {
1188 hppa_hpux_sigtramp_frame_this_id
,
1189 hppa_hpux_sigtramp_frame_prev_register
1192 static const struct frame_unwind
*
1193 hppa_hpux_sigtramp_unwind_sniffer (struct frame_info
*next_frame
)
1195 CORE_ADDR pc
= frame_pc_unwind (next_frame
);
1198 find_pc_partial_function (pc
, &name
, NULL
, NULL
);
1200 if (name
&& strcmp(name
, "_sigreturn") == 0)
1201 return &hppa_hpux_sigtramp_frame_unwind
;
1207 hppa_hpux_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
1209 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1211 if (tdep
->bytes_per_address
== 4)
1212 set_gdbarch_in_solib_call_trampoline (gdbarch
,
1213 hppa32_hpux_in_solib_call_trampoline
);
1215 set_gdbarch_in_solib_call_trampoline (gdbarch
,
1216 hppa64_hpux_in_solib_call_trampoline
);
1218 set_gdbarch_in_solib_return_trampoline (gdbarch
,
1219 hppa_hpux_in_solib_return_trampoline
);
1220 set_gdbarch_skip_trampoline_code (gdbarch
, hppa_hpux_skip_trampoline_code
);
1222 frame_unwind_append_sniffer (gdbarch
, hppa_hpux_sigtramp_unwind_sniffer
);
1226 hppa_hpux_som_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
1228 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1231 hppa_hpux_init_abi (info
, gdbarch
);
1235 hppa_hpux_elf_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
1237 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1240 hppa_hpux_init_abi (info
, gdbarch
);
1244 _initialize_hppa_hpux_tdep (void)
1246 gdbarch_register_osabi (bfd_arch_hppa
, 0, GDB_OSABI_HPUX_SOM
,
1247 hppa_hpux_som_init_abi
);
1248 gdbarch_register_osabi (bfd_arch_hppa
, bfd_mach_hppa20w
, GDB_OSABI_HPUX_ELF
,
1249 hppa_hpux_elf_init_abi
);