* gdbarch.sh: Add skip_permanent_breakpoint callback.
[deliverable/binutils-gdb.git] / gdb / hppa-hpux-tdep.c
1 /* Target-dependent code for HP-UX on PA-RISC.
2
3 Copyright (C) 2002, 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
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.
11
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.
16
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. */
21
22 #include "defs.h"
23 #include "arch-utils.h"
24 #include "gdbcore.h"
25 #include "osabi.h"
26 #include "frame.h"
27 #include "frame-unwind.h"
28 #include "trad-frame.h"
29 #include "symtab.h"
30 #include "objfiles.h"
31 #include "inferior.h"
32 #include "infcall.h"
33 #include "observer.h"
34 #include "hppa-tdep.h"
35 #include "solib-som.h"
36 #include "solib-pa64.h"
37 #include "regset.h"
38 #include "exceptions.h"
39
40 #include "gdb_string.h"
41
42 #include <dl.h>
43 #include <machine/save_state.h>
44
45 #ifndef offsetof
46 #define offsetof(TYPE, MEMBER) ((unsigned long) &((TYPE *)0)->MEMBER)
47 #endif
48
49 #define IS_32BIT_TARGET(_gdbarch) \
50 ((gdbarch_tdep (_gdbarch))->bytes_per_address == 4)
51
52 /* Bit in the `ss_flag' member of `struct save_state' that indicates
53 that the 64-bit register values are live. From
54 <machine/save_state.h>. */
55 #define HPPA_HPUX_SS_WIDEREGS 0x40
56
57 /* Offsets of various parts of `struct save_state'. From
58 <machine/save_state.h>. */
59 #define HPPA_HPUX_SS_FLAGS_OFFSET 0
60 #define HPPA_HPUX_SS_NARROW_OFFSET 4
61 #define HPPA_HPUX_SS_FPBLOCK_OFFSET 256
62 #define HPPA_HPUX_SS_WIDE_OFFSET 640
63
64 /* The size of `struct save_state. */
65 #define HPPA_HPUX_SAVE_STATE_SIZE 1152
66
67 /* The size of `struct pa89_save_state', which corresponds to PA-RISC
68 1.1, the lowest common denominator that we support. */
69 #define HPPA_HPUX_PA89_SAVE_STATE_SIZE 512
70
71
72 /* Forward declarations. */
73 extern void _initialize_hppa_hpux_tdep (void);
74 extern initialize_file_ftype _initialize_hppa_hpux_tdep;
75
76 typedef struct
77 {
78 struct minimal_symbol *msym;
79 CORE_ADDR solib_handle;
80 CORE_ADDR return_val;
81 }
82 args_for_find_stub;
83
84 static int
85 in_opd_section (CORE_ADDR pc)
86 {
87 struct obj_section *s;
88 int retval = 0;
89
90 s = find_pc_section (pc);
91
92 retval = (s != NULL
93 && s->the_bfd_section->name != NULL
94 && strcmp (s->the_bfd_section->name, ".opd") == 0);
95 return (retval);
96 }
97
98 /* Return one if PC is in the call path of a trampoline, else return zero.
99
100 Note we return one for *any* call trampoline (long-call, arg-reloc), not
101 just shared library trampolines (import, export). */
102
103 static int
104 hppa32_hpux_in_solib_call_trampoline (CORE_ADDR pc, char *name)
105 {
106 struct minimal_symbol *minsym;
107 struct unwind_table_entry *u;
108
109 /* First see if PC is in one of the two C-library trampolines. */
110 if (pc == hppa_symbol_address("$$dyncall")
111 || pc == hppa_symbol_address("_sr4export"))
112 return 1;
113
114 minsym = lookup_minimal_symbol_by_pc (pc);
115 if (minsym && strcmp (DEPRECATED_SYMBOL_NAME (minsym), ".stub") == 0)
116 return 1;
117
118 /* Get the unwind descriptor corresponding to PC, return zero
119 if no unwind was found. */
120 u = find_unwind_entry (pc);
121 if (!u)
122 return 0;
123
124 /* If this isn't a linker stub, then return now. */
125 if (u->stub_unwind.stub_type == 0)
126 return 0;
127
128 /* By definition a long-branch stub is a call stub. */
129 if (u->stub_unwind.stub_type == LONG_BRANCH)
130 return 1;
131
132 /* The call and return path execute the same instructions within
133 an IMPORT stub! So an IMPORT stub is both a call and return
134 trampoline. */
135 if (u->stub_unwind.stub_type == IMPORT)
136 return 1;
137
138 /* Parameter relocation stubs always have a call path and may have a
139 return path. */
140 if (u->stub_unwind.stub_type == PARAMETER_RELOCATION
141 || u->stub_unwind.stub_type == EXPORT)
142 {
143 CORE_ADDR addr;
144
145 /* Search forward from the current PC until we hit a branch
146 or the end of the stub. */
147 for (addr = pc; addr <= u->region_end; addr += 4)
148 {
149 unsigned long insn;
150
151 insn = read_memory_integer (addr, 4);
152
153 /* Does it look like a bl? If so then it's the call path, if
154 we find a bv or be first, then we're on the return path. */
155 if ((insn & 0xfc00e000) == 0xe8000000)
156 return 1;
157 else if ((insn & 0xfc00e001) == 0xe800c000
158 || (insn & 0xfc000000) == 0xe0000000)
159 return 0;
160 }
161
162 /* Should never happen. */
163 warning (_("Unable to find branch in parameter relocation stub."));
164 return 0;
165 }
166
167 /* Unknown stub type. For now, just return zero. */
168 return 0;
169 }
170
171 static int
172 hppa64_hpux_in_solib_call_trampoline (CORE_ADDR pc, char *name)
173 {
174 /* PA64 has a completely different stub/trampoline scheme. Is it
175 better? Maybe. It's certainly harder to determine with any
176 certainty that we are in a stub because we can not refer to the
177 unwinders to help.
178
179 The heuristic is simple. Try to lookup the current PC value in th
180 minimal symbol table. If that fails, then assume we are not in a
181 stub and return.
182
183 Then see if the PC value falls within the section bounds for the
184 section containing the minimal symbol we found in the first
185 step. If it does, then assume we are not in a stub and return.
186
187 Finally peek at the instructions to see if they look like a stub. */
188 struct minimal_symbol *minsym;
189 asection *sec;
190 CORE_ADDR addr;
191 int insn, i;
192
193 minsym = lookup_minimal_symbol_by_pc (pc);
194 if (! minsym)
195 return 0;
196
197 sec = SYMBOL_BFD_SECTION (minsym);
198
199 if (bfd_get_section_vma (sec->owner, sec) <= pc
200 && pc < (bfd_get_section_vma (sec->owner, sec)
201 + bfd_section_size (sec->owner, sec)))
202 return 0;
203
204 /* We might be in a stub. Peek at the instructions. Stubs are 3
205 instructions long. */
206 insn = read_memory_integer (pc, 4);
207
208 /* Find out where we think we are within the stub. */
209 if ((insn & 0xffffc00e) == 0x53610000)
210 addr = pc;
211 else if ((insn & 0xffffffff) == 0xe820d000)
212 addr = pc - 4;
213 else if ((insn & 0xffffc00e) == 0x537b0000)
214 addr = pc - 8;
215 else
216 return 0;
217
218 /* Now verify each insn in the range looks like a stub instruction. */
219 insn = read_memory_integer (addr, 4);
220 if ((insn & 0xffffc00e) != 0x53610000)
221 return 0;
222
223 /* Now verify each insn in the range looks like a stub instruction. */
224 insn = read_memory_integer (addr + 4, 4);
225 if ((insn & 0xffffffff) != 0xe820d000)
226 return 0;
227
228 /* Now verify each insn in the range looks like a stub instruction. */
229 insn = read_memory_integer (addr + 8, 4);
230 if ((insn & 0xffffc00e) != 0x537b0000)
231 return 0;
232
233 /* Looks like a stub. */
234 return 1;
235 }
236
237 /* Return one if PC is in the return path of a trampoline, else return zero.
238
239 Note we return one for *any* call trampoline (long-call, arg-reloc), not
240 just shared library trampolines (import, export). */
241
242 static int
243 hppa_hpux_in_solib_return_trampoline (CORE_ADDR pc, char *name)
244 {
245 struct unwind_table_entry *u;
246
247 /* Get the unwind descriptor corresponding to PC, return zero
248 if no unwind was found. */
249 u = find_unwind_entry (pc);
250 if (!u)
251 return 0;
252
253 /* If this isn't a linker stub or it's just a long branch stub, then
254 return zero. */
255 if (u->stub_unwind.stub_type == 0 || u->stub_unwind.stub_type == LONG_BRANCH)
256 return 0;
257
258 /* The call and return path execute the same instructions within
259 an IMPORT stub! So an IMPORT stub is both a call and return
260 trampoline. */
261 if (u->stub_unwind.stub_type == IMPORT)
262 return 1;
263
264 /* Parameter relocation stubs always have a call path and may have a
265 return path. */
266 if (u->stub_unwind.stub_type == PARAMETER_RELOCATION
267 || u->stub_unwind.stub_type == EXPORT)
268 {
269 CORE_ADDR addr;
270
271 /* Search forward from the current PC until we hit a branch
272 or the end of the stub. */
273 for (addr = pc; addr <= u->region_end; addr += 4)
274 {
275 unsigned long insn;
276
277 insn = read_memory_integer (addr, 4);
278
279 /* Does it look like a bl? If so then it's the call path, if
280 we find a bv or be first, then we're on the return path. */
281 if ((insn & 0xfc00e000) == 0xe8000000)
282 return 0;
283 else if ((insn & 0xfc00e001) == 0xe800c000
284 || (insn & 0xfc000000) == 0xe0000000)
285 return 1;
286 }
287
288 /* Should never happen. */
289 warning (_("Unable to find branch in parameter relocation stub."));
290 return 0;
291 }
292
293 /* Unknown stub type. For now, just return zero. */
294 return 0;
295
296 }
297
298 /* Figure out if PC is in a trampoline, and if so find out where
299 the trampoline will jump to. If not in a trampoline, return zero.
300
301 Simple code examination probably is not a good idea since the code
302 sequences in trampolines can also appear in user code.
303
304 We use unwinds and information from the minimal symbol table to
305 determine when we're in a trampoline. This won't work for ELF
306 (yet) since it doesn't create stub unwind entries. Whether or
307 not ELF will create stub unwinds or normal unwinds for linker
308 stubs is still being debated.
309
310 This should handle simple calls through dyncall or sr4export,
311 long calls, argument relocation stubs, and dyncall/sr4export
312 calling an argument relocation stub. It even handles some stubs
313 used in dynamic executables. */
314
315 static CORE_ADDR
316 hppa_hpux_skip_trampoline_code (CORE_ADDR pc)
317 {
318 long orig_pc = pc;
319 long prev_inst, curr_inst, loc;
320 struct minimal_symbol *msym;
321 struct unwind_table_entry *u;
322
323 /* Addresses passed to dyncall may *NOT* be the actual address
324 of the function. So we may have to do something special. */
325 if (pc == hppa_symbol_address("$$dyncall"))
326 {
327 pc = (CORE_ADDR) read_register (22);
328
329 /* If bit 30 (counting from the left) is on, then pc is the address of
330 the PLT entry for this function, not the address of the function
331 itself. Bit 31 has meaning too, but only for MPE. */
332 if (pc & 0x2)
333 pc = (CORE_ADDR) read_memory_integer (pc & ~0x3, TARGET_PTR_BIT / 8);
334 }
335 if (pc == hppa_symbol_address("$$dyncall_external"))
336 {
337 pc = (CORE_ADDR) read_register (22);
338 pc = (CORE_ADDR) read_memory_integer (pc & ~0x3, TARGET_PTR_BIT / 8);
339 }
340 else if (pc == hppa_symbol_address("_sr4export"))
341 pc = (CORE_ADDR) (read_register (22));
342
343 /* Get the unwind descriptor corresponding to PC, return zero
344 if no unwind was found. */
345 u = find_unwind_entry (pc);
346 if (!u)
347 return 0;
348
349 /* If this isn't a linker stub, then return now. */
350 /* elz: attention here! (FIXME) because of a compiler/linker
351 error, some stubs which should have a non zero stub_unwind.stub_type
352 have unfortunately a value of zero. So this function would return here
353 as if we were not in a trampoline. To fix this, we go look at the partial
354 symbol information, which reports this guy as a stub.
355 (FIXME): Unfortunately, we are not that lucky: it turns out that the
356 partial symbol information is also wrong sometimes. This is because
357 when it is entered (somread.c::som_symtab_read()) it can happen that
358 if the type of the symbol (from the som) is Entry, and the symbol is
359 in a shared library, then it can also be a trampoline. This would
360 be OK, except that I believe the way they decide if we are ina shared library
361 does not work. SOOOO..., even if we have a regular function w/o trampolines
362 its minimal symbol can be assigned type mst_solib_trampoline.
363 Also, if we find that the symbol is a real stub, then we fix the unwind
364 descriptor, and define the stub type to be EXPORT.
365 Hopefully this is correct most of the times. */
366 if (u->stub_unwind.stub_type == 0)
367 {
368
369 /* elz: NOTE (FIXME!) once the problem with the unwind information is fixed
370 we can delete all the code which appears between the lines */
371 /*--------------------------------------------------------------------------*/
372 msym = lookup_minimal_symbol_by_pc (pc);
373
374 if (msym == NULL || MSYMBOL_TYPE (msym) != mst_solib_trampoline)
375 return orig_pc == pc ? 0 : pc & ~0x3;
376
377 else if (msym != NULL && MSYMBOL_TYPE (msym) == mst_solib_trampoline)
378 {
379 struct objfile *objfile;
380 struct minimal_symbol *msymbol;
381 int function_found = 0;
382
383 /* go look if there is another minimal symbol with the same name as
384 this one, but with type mst_text. This would happen if the msym
385 is an actual trampoline, in which case there would be another
386 symbol with the same name corresponding to the real function */
387
388 ALL_MSYMBOLS (objfile, msymbol)
389 {
390 if (MSYMBOL_TYPE (msymbol) == mst_text
391 && DEPRECATED_STREQ (DEPRECATED_SYMBOL_NAME (msymbol), DEPRECATED_SYMBOL_NAME (msym)))
392 {
393 function_found = 1;
394 break;
395 }
396 }
397
398 if (function_found)
399 /* the type of msym is correct (mst_solib_trampoline), but
400 the unwind info is wrong, so set it to the correct value */
401 u->stub_unwind.stub_type = EXPORT;
402 else
403 /* the stub type info in the unwind is correct (this is not a
404 trampoline), but the msym type information is wrong, it
405 should be mst_text. So we need to fix the msym, and also
406 get out of this function */
407 {
408 MSYMBOL_TYPE (msym) = mst_text;
409 return orig_pc == pc ? 0 : pc & ~0x3;
410 }
411 }
412
413 /*--------------------------------------------------------------------------*/
414 }
415
416 /* It's a stub. Search for a branch and figure out where it goes.
417 Note we have to handle multi insn branch sequences like ldil;ble.
418 Most (all?) other branches can be determined by examining the contents
419 of certain registers and the stack. */
420
421 loc = pc;
422 curr_inst = 0;
423 prev_inst = 0;
424 while (1)
425 {
426 /* Make sure we haven't walked outside the range of this stub. */
427 if (u != find_unwind_entry (loc))
428 {
429 warning (_("Unable to find branch in linker stub"));
430 return orig_pc == pc ? 0 : pc & ~0x3;
431 }
432
433 prev_inst = curr_inst;
434 curr_inst = read_memory_integer (loc, 4);
435
436 /* Does it look like a branch external using %r1? Then it's the
437 branch from the stub to the actual function. */
438 if ((curr_inst & 0xffe0e000) == 0xe0202000)
439 {
440 /* Yup. See if the previous instruction loaded
441 a value into %r1. If so compute and return the jump address. */
442 if ((prev_inst & 0xffe00000) == 0x20200000)
443 return (hppa_extract_21 (prev_inst) + hppa_extract_17 (curr_inst)) & ~0x3;
444 else
445 {
446 warning (_("Unable to find ldil X,%%r1 before ble Y(%%sr4,%%r1)."));
447 return orig_pc == pc ? 0 : pc & ~0x3;
448 }
449 }
450
451 /* Does it look like a be 0(sr0,%r21)? OR
452 Does it look like a be, n 0(sr0,%r21)? OR
453 Does it look like a bve (r21)? (this is on PA2.0)
454 Does it look like a bve, n(r21)? (this is also on PA2.0)
455 That's the branch from an
456 import stub to an export stub.
457
458 It is impossible to determine the target of the branch via
459 simple examination of instructions and/or data (consider
460 that the address in the plabel may be the address of the
461 bind-on-reference routine in the dynamic loader).
462
463 So we have try an alternative approach.
464
465 Get the name of the symbol at our current location; it should
466 be a stub symbol with the same name as the symbol in the
467 shared library.
468
469 Then lookup a minimal symbol with the same name; we should
470 get the minimal symbol for the target routine in the shared
471 library as those take precedence of import/export stubs. */
472 if ((curr_inst == 0xe2a00000) ||
473 (curr_inst == 0xe2a00002) ||
474 (curr_inst == 0xeaa0d000) ||
475 (curr_inst == 0xeaa0d002))
476 {
477 struct minimal_symbol *stubsym, *libsym;
478
479 stubsym = lookup_minimal_symbol_by_pc (loc);
480 if (stubsym == NULL)
481 {
482 warning (_("Unable to find symbol for 0x%lx"), loc);
483 return orig_pc == pc ? 0 : pc & ~0x3;
484 }
485
486 libsym = lookup_minimal_symbol (DEPRECATED_SYMBOL_NAME (stubsym), NULL, NULL);
487 if (libsym == NULL)
488 {
489 warning (_("Unable to find library symbol for %s."),
490 DEPRECATED_SYMBOL_NAME (stubsym));
491 return orig_pc == pc ? 0 : pc & ~0x3;
492 }
493
494 return SYMBOL_VALUE (libsym);
495 }
496
497 /* Does it look like bl X,%rp or bl X,%r0? Another way to do a
498 branch from the stub to the actual function. */
499 /*elz */
500 else if ((curr_inst & 0xffe0e000) == 0xe8400000
501 || (curr_inst & 0xffe0e000) == 0xe8000000
502 || (curr_inst & 0xffe0e000) == 0xe800A000)
503 return (loc + hppa_extract_17 (curr_inst) + 8) & ~0x3;
504
505 /* Does it look like bv (rp)? Note this depends on the
506 current stack pointer being the same as the stack
507 pointer in the stub itself! This is a branch on from the
508 stub back to the original caller. */
509 /*else if ((curr_inst & 0xffe0e000) == 0xe840c000) */
510 else if ((curr_inst & 0xffe0f000) == 0xe840c000)
511 {
512 /* Yup. See if the previous instruction loaded
513 rp from sp - 8. */
514 if (prev_inst == 0x4bc23ff1)
515 return (read_memory_integer
516 (read_register (HPPA_SP_REGNUM) - 8, 4)) & ~0x3;
517 else
518 {
519 warning (_("Unable to find restore of %%rp before bv (%%rp)."));
520 return orig_pc == pc ? 0 : pc & ~0x3;
521 }
522 }
523
524 /* elz: added this case to capture the new instruction
525 at the end of the return part of an export stub used by
526 the PA2.0: BVE, n (rp) */
527 else if ((curr_inst & 0xffe0f000) == 0xe840d000)
528 {
529 return (read_memory_integer
530 (read_register (HPPA_SP_REGNUM) - 24, TARGET_PTR_BIT / 8)) & ~0x3;
531 }
532
533 /* What about be,n 0(sr0,%rp)? It's just another way we return to
534 the original caller from the stub. Used in dynamic executables. */
535 else if (curr_inst == 0xe0400002)
536 {
537 /* The value we jump to is sitting in sp - 24. But that's
538 loaded several instructions before the be instruction.
539 I guess we could check for the previous instruction being
540 mtsp %r1,%sr0 if we want to do sanity checking. */
541 return (read_memory_integer
542 (read_register (HPPA_SP_REGNUM) - 24, TARGET_PTR_BIT / 8)) & ~0x3;
543 }
544
545 /* Haven't found the branch yet, but we're still in the stub.
546 Keep looking. */
547 loc += 4;
548 }
549 }
550
551 static void
552 hppa_skip_permanent_breakpoint (struct regcache *regcache)
553 {
554 /* To step over a breakpoint instruction on the PA takes some
555 fiddling with the instruction address queue.
556
557 When we stop at a breakpoint, the IA queue front (the instruction
558 we're executing now) points at the breakpoint instruction, and
559 the IA queue back (the next instruction to execute) points to
560 whatever instruction we would execute after the breakpoint, if it
561 were an ordinary instruction. This is the case even if the
562 breakpoint is in the delay slot of a branch instruction.
563
564 Clearly, to step past the breakpoint, we need to set the queue
565 front to the back. But what do we put in the back? What
566 instruction comes after that one? Because of the branch delay
567 slot, the next insn is always at the back + 4. */
568
569 ULONGEST pcoq_tail, pcsq_tail;
570 regcache_cooked_read_unsigned (regcache, HPPA_PCOQ_TAIL_REGNUM, &pcoq_tail);
571 regcache_cooked_read_unsigned (regcache, HPPA_PCSQ_TAIL_REGNUM, &pcsq_tail);
572
573 regcache_cooked_write_unsigned (regcache, HPPA_PCOQ_HEAD_REGNUM, pcoq_tail);
574 regcache_cooked_write_unsigned (regcache, HPPA_PCSQ_HEAD_REGNUM, pcsq_tail);
575
576 regcache_cooked_write_unsigned (regcache, HPPA_PCOQ_TAIL_REGNUM, pcoq_tail + 4);
577 /* We can leave the tail's space the same, since there's no jump. */
578 }
579
580 /* Exception handling support for the HP-UX ANSI C++ compiler.
581 The compiler (aCC) provides a callback for exception events;
582 GDB can set a breakpoint on this callback and find out what
583 exception event has occurred. */
584
585 /* The name of the hook to be set to point to the callback function. */
586 static char HP_ACC_EH_notify_hook[] = "__eh_notify_hook";
587 /* The name of the function to be used to set the hook value. */
588 static char HP_ACC_EH_set_hook_value[] = "__eh_set_hook_value";
589 /* The name of the callback function in end.o */
590 static char HP_ACC_EH_notify_callback[] = "__d_eh_notify_callback";
591 /* Name of function in end.o on which a break is set (called by above). */
592 static char HP_ACC_EH_break[] = "__d_eh_break";
593 /* Name of flag (in end.o) that enables catching throws. */
594 static char HP_ACC_EH_catch_throw[] = "__d_eh_catch_throw";
595 /* Name of flag (in end.o) that enables catching catching. */
596 static char HP_ACC_EH_catch_catch[] = "__d_eh_catch_catch";
597 /* The enum used by aCC. */
598 typedef enum
599 {
600 __EH_NOTIFY_THROW,
601 __EH_NOTIFY_CATCH
602 }
603 __eh_notification;
604
605 /* Is exception-handling support available with this executable? */
606 static int hp_cxx_exception_support = 0;
607 /* Has the initialize function been run? */
608 static int hp_cxx_exception_support_initialized = 0;
609 /* Address of __eh_notify_hook */
610 static CORE_ADDR eh_notify_hook_addr = 0;
611 /* Address of __d_eh_notify_callback */
612 static CORE_ADDR eh_notify_callback_addr = 0;
613 /* Address of __d_eh_break */
614 static CORE_ADDR eh_break_addr = 0;
615 /* Address of __d_eh_catch_catch */
616 static CORE_ADDR eh_catch_catch_addr = 0;
617 /* Address of __d_eh_catch_throw */
618 static CORE_ADDR eh_catch_throw_addr = 0;
619 /* Sal for __d_eh_break */
620 static struct symtab_and_line *break_callback_sal = 0;
621
622 /* Code in end.c expects __d_pid to be set in the inferior,
623 otherwise __d_eh_notify_callback doesn't bother to call
624 __d_eh_break! So we poke the pid into this symbol
625 ourselves.
626 0 => success
627 1 => failure */
628 static int
629 setup_d_pid_in_inferior (void)
630 {
631 CORE_ADDR anaddr;
632 struct minimal_symbol *msymbol;
633 char buf[4]; /* FIXME 32x64? */
634
635 /* Slam the pid of the process into __d_pid; failing is only a warning! */
636 msymbol = lookup_minimal_symbol ("__d_pid", NULL, symfile_objfile);
637 if (msymbol == NULL)
638 {
639 warning (_("Unable to find __d_pid symbol in object file.\n"
640 "Suggest linking executable with -g (links in /opt/langtools/lib/end.o)."));
641 return 1;
642 }
643
644 anaddr = SYMBOL_VALUE_ADDRESS (msymbol);
645 store_unsigned_integer (buf, 4, PIDGET (inferior_ptid)); /* FIXME 32x64? */
646 if (target_write_memory (anaddr, buf, 4)) /* FIXME 32x64? */
647 {
648 warning (_("Unable to write __d_pid.\n"
649 "Suggest linking executable with -g (links in /opt/langtools/lib/end.o)."));
650 return 1;
651 }
652 return 0;
653 }
654
655 /* elz: Used to lookup a symbol in the shared libraries.
656 This function calls shl_findsym, indirectly through a
657 call to __d_shl_get. __d_shl_get is in end.c, which is always
658 linked in by the hp compilers/linkers.
659 The call to shl_findsym cannot be made directly because it needs
660 to be active in target address space.
661 inputs: - minimal symbol pointer for the function we want to look up
662 - address in target space of the descriptor for the library
663 where we want to look the symbol up.
664 This address is retrieved using the
665 som_solib_get_solib_by_pc function (somsolib.c).
666 output: - real address in the library of the function.
667 note: the handle can be null, in which case shl_findsym will look for
668 the symbol in all the loaded shared libraries.
669 files to look at if you need reference on this stuff:
670 dld.c, dld_shl_findsym.c
671 end.c
672 man entry for shl_findsym */
673
674 static CORE_ADDR
675 find_stub_with_shl_get (struct minimal_symbol *function, CORE_ADDR handle)
676 {
677 struct symbol *get_sym, *symbol2;
678 struct minimal_symbol *buff_minsym, *msymbol;
679 struct type *ftype;
680 struct value **args;
681 struct value *funcval;
682 struct value *val;
683
684 int x, namelen, err_value, tmp = -1;
685 CORE_ADDR endo_buff_addr, value_return_addr, errno_return_addr;
686 CORE_ADDR stub_addr;
687
688
689 args = alloca (sizeof (struct value *) * 8); /* 6 for the arguments and one null one??? */
690 funcval = find_function_in_inferior ("__d_shl_get");
691 get_sym = lookup_symbol ("__d_shl_get", NULL, VAR_DOMAIN, NULL, NULL);
692 buff_minsym = lookup_minimal_symbol ("__buffer", NULL, NULL);
693 msymbol = lookup_minimal_symbol ("__shldp", NULL, NULL);
694 symbol2 = lookup_symbol ("__shldp", NULL, VAR_DOMAIN, NULL, NULL);
695 endo_buff_addr = SYMBOL_VALUE_ADDRESS (buff_minsym);
696 namelen = strlen (DEPRECATED_SYMBOL_NAME (function));
697 value_return_addr = endo_buff_addr + namelen;
698 ftype = check_typedef (SYMBOL_TYPE (get_sym));
699
700 /* do alignment */
701 if ((x = value_return_addr % 64) != 0)
702 value_return_addr = value_return_addr + 64 - x;
703
704 errno_return_addr = value_return_addr + 64;
705
706
707 /* set up stuff needed by __d_shl_get in buffer in end.o */
708
709 target_write_memory (endo_buff_addr, DEPRECATED_SYMBOL_NAME (function), namelen);
710
711 target_write_memory (value_return_addr, (char *) &tmp, 4);
712
713 target_write_memory (errno_return_addr, (char *) &tmp, 4);
714
715 target_write_memory (SYMBOL_VALUE_ADDRESS (msymbol),
716 (char *) &handle, 4);
717
718 /* now prepare the arguments for the call */
719
720 args[0] = value_from_longest (TYPE_FIELD_TYPE (ftype, 0), 12);
721 args[1] = value_from_pointer (TYPE_FIELD_TYPE (ftype, 1), SYMBOL_VALUE_ADDRESS (msymbol));
722 args[2] = value_from_pointer (TYPE_FIELD_TYPE (ftype, 2), endo_buff_addr);
723 args[3] = value_from_longest (TYPE_FIELD_TYPE (ftype, 3), TYPE_PROCEDURE);
724 args[4] = value_from_pointer (TYPE_FIELD_TYPE (ftype, 4), value_return_addr);
725 args[5] = value_from_pointer (TYPE_FIELD_TYPE (ftype, 5), errno_return_addr);
726
727 /* now call the function */
728
729 val = call_function_by_hand (funcval, 6, args);
730
731 /* now get the results */
732
733 target_read_memory (errno_return_addr, (char *) &err_value, sizeof (err_value));
734
735 target_read_memory (value_return_addr, (char *) &stub_addr, sizeof (stub_addr));
736 if (stub_addr <= 0)
737 error (_("call to __d_shl_get failed, error code is %d"), err_value);
738
739 return (stub_addr);
740 }
741
742 /* Cover routine for find_stub_with_shl_get to pass to catch_errors */
743 static int
744 cover_find_stub_with_shl_get (void *args_untyped)
745 {
746 args_for_find_stub *args = args_untyped;
747 args->return_val = find_stub_with_shl_get (args->msym, args->solib_handle);
748 return 0;
749 }
750
751 /* Initialize exception catchpoint support by looking for the
752 necessary hooks/callbacks in end.o, etc., and set the hook value
753 to point to the required debug function.
754
755 Return 0 => failure
756 1 => success */
757
758 static int
759 initialize_hp_cxx_exception_support (void)
760 {
761 struct symtabs_and_lines sals;
762 struct cleanup *old_chain;
763 struct cleanup *canonical_strings_chain = NULL;
764 int i;
765 char *addr_start;
766 char *addr_end = NULL;
767 char **canonical = (char **) NULL;
768 int thread = -1;
769 struct symbol *sym = NULL;
770 struct minimal_symbol *msym = NULL;
771 struct objfile *objfile;
772 asection *shlib_info;
773
774 /* Detect and disallow recursion. On HP-UX with aCC, infinite
775 recursion is a possibility because finding the hook for exception
776 callbacks involves making a call in the inferior, which means
777 re-inserting breakpoints which can re-invoke this code. */
778
779 static int recurse = 0;
780 if (recurse > 0)
781 {
782 hp_cxx_exception_support_initialized = 0;
783 deprecated_exception_support_initialized = 0;
784 return 0;
785 }
786
787 hp_cxx_exception_support = 0;
788
789 /* First check if we have seen any HP compiled objects; if not,
790 it is very unlikely that HP's idiosyncratic callback mechanism
791 for exception handling debug support will be available!
792 This will percolate back up to breakpoint.c, where our callers
793 will decide to try the g++ exception-handling support instead. */
794 if (!deprecated_hp_som_som_object_present)
795 return 0;
796
797 /* We have a SOM executable with SOM debug info; find the hooks. */
798
799 /* First look for the notify hook provided by aCC runtime libs */
800 /* If we find this symbol, we conclude that the executable must
801 have HP aCC exception support built in. If this symbol is not
802 found, even though we're a HP SOM-SOM file, we may have been
803 built with some other compiler (not aCC). This results percolates
804 back up to our callers in breakpoint.c which can decide to
805 try the g++ style of exception support instead.
806 If this symbol is found but the other symbols we require are
807 not found, there is something weird going on, and g++ support
808 should *not* be tried as an alternative.
809
810 ASSUMPTION: Only HP aCC code will have __eh_notify_hook defined.
811 ASSUMPTION: HP aCC and g++ modules cannot be linked together. */
812
813 /* libCsup has this hook; it'll usually be non-debuggable */
814 msym = lookup_minimal_symbol (HP_ACC_EH_notify_hook, NULL, NULL);
815 if (msym)
816 {
817 eh_notify_hook_addr = SYMBOL_VALUE_ADDRESS (msym);
818 hp_cxx_exception_support = 1;
819 }
820 else
821 {
822 warning (_("\
823 Unable to find exception callback hook (%s).\n\
824 Executable may not have been compiled debuggable with HP aCC.\n\
825 GDB will be unable to intercept exception events."),
826 HP_ACC_EH_notify_hook);
827 eh_notify_hook_addr = 0;
828 hp_cxx_exception_support = 0;
829 return 0;
830 }
831
832 /* Next look for the notify callback routine in end.o */
833 /* This is always available in the SOM symbol dictionary if end.o is
834 linked in. */
835 msym = lookup_minimal_symbol (HP_ACC_EH_notify_callback, NULL, NULL);
836 if (msym)
837 {
838 eh_notify_callback_addr = SYMBOL_VALUE_ADDRESS (msym);
839 hp_cxx_exception_support = 1;
840 }
841 else
842 {
843 warning (_("\
844 Unable to find exception callback routine (%s).\n\
845 Suggest linking executable with -g (links in /opt/langtools/lib/end.o).\n\
846 GDB will be unable to intercept exception events."),
847 HP_ACC_EH_notify_callback);
848 eh_notify_callback_addr = 0;
849 return 0;
850 }
851
852 if (!gdbarch_tdep (current_gdbarch)->is_elf)
853 {
854 /* Check whether the executable is dynamically linked or archive bound */
855 /* With an archive-bound executable we can use the raw addresses we find
856 for the callback function, etc. without modification. For an executable
857 with shared libraries, we have to do more work to find the plabel, which
858 can be the target of a call through $$dyncall from the aCC runtime
859 support library (libCsup) which is linked shared by default by aCC. */
860 /* This test below was copied from somsolib.c/somread.c. It may not be a very
861 reliable one to test that an executable is linked shared.
862 pai/1997-07-18 */
863 shlib_info = bfd_get_section_by_name (symfile_objfile->obfd, "$SHLIB_INFO$");
864 if (shlib_info && (bfd_section_size (symfile_objfile->obfd, shlib_info) != 0))
865 {
866 /* The minsym we have has the local code address, but that's not
867 the plabel that can be used by an inter-load-module call. */
868 /* Find solib handle for main image (which has end.o), and use
869 that and the min sym as arguments to __d_shl_get() (which
870 does the equivalent of shl_findsym()) to find the plabel. */
871
872 args_for_find_stub args;
873
874 args.solib_handle = gdbarch_tdep (current_gdbarch)->solib_get_solib_by_pc (eh_notify_callback_addr);
875 args.msym = msym;
876 args.return_val = 0;
877
878 recurse++;
879 catch_errors (cover_find_stub_with_shl_get, &args,
880 _("Error while finding exception callback hook:\n"),
881 RETURN_MASK_ALL);
882 eh_notify_callback_addr = args.return_val;
883 recurse--;
884
885 deprecated_exception_catchpoints_are_fragile = 1;
886
887 if (!eh_notify_callback_addr)
888 {
889 /* We can get here either if there is no plabel in the export list
890 for the main image, or if something strange happened (?) */
891 warning (_("\
892 Couldn't find a plabel (indirect function label) for the exception callback.\n\
893 GDB will not be able to intercept exception events."));
894 return 0;
895 }
896 }
897 else
898 deprecated_exception_catchpoints_are_fragile = 0;
899 }
900
901 /* Now, look for the breakpointable routine in end.o */
902 /* This should also be available in the SOM symbol dict. if end.o linked in */
903 msym = lookup_minimal_symbol (HP_ACC_EH_break, NULL, NULL);
904 if (msym)
905 {
906 eh_break_addr = SYMBOL_VALUE_ADDRESS (msym);
907 hp_cxx_exception_support = 1;
908 }
909 else
910 {
911 warning (_("\
912 Unable to find exception callback routine to set breakpoint (%s).\n\
913 Suggest linking executable with -g (link in /opt/langtools/lib/end.o).\n\
914 GDB will be unable to intercept exception events."),
915 HP_ACC_EH_break);
916 eh_break_addr = 0;
917 return 0;
918 }
919
920 /* Next look for the catch enable flag provided in end.o */
921 sym = lookup_symbol (HP_ACC_EH_catch_catch, (struct block *) NULL,
922 VAR_DOMAIN, 0, (struct symtab **) NULL);
923 if (sym) /* sometimes present in debug info */
924 {
925 eh_catch_catch_addr = SYMBOL_VALUE_ADDRESS (sym);
926 hp_cxx_exception_support = 1;
927 }
928 else
929 /* otherwise look in SOM symbol dict. */
930 {
931 msym = lookup_minimal_symbol (HP_ACC_EH_catch_catch, NULL, NULL);
932 if (msym)
933 {
934 eh_catch_catch_addr = SYMBOL_VALUE_ADDRESS (msym);
935 hp_cxx_exception_support = 1;
936 }
937 else
938 {
939 warning (_("\
940 Unable to enable interception of exception catches.\n\
941 Executable may not have been compiled debuggable with HP aCC.\n\
942 Suggest linking executable with -g (link in /opt/langtools/lib/end.o)."));
943 return 0;
944 }
945 }
946
947 /* Next look for the catch enable flag provided end.o */
948 sym = lookup_symbol (HP_ACC_EH_catch_catch, (struct block *) NULL,
949 VAR_DOMAIN, 0, (struct symtab **) NULL);
950 if (sym) /* sometimes present in debug info */
951 {
952 eh_catch_throw_addr = SYMBOL_VALUE_ADDRESS (sym);
953 hp_cxx_exception_support = 1;
954 }
955 else
956 /* otherwise look in SOM symbol dict. */
957 {
958 msym = lookup_minimal_symbol (HP_ACC_EH_catch_throw, NULL, NULL);
959 if (msym)
960 {
961 eh_catch_throw_addr = SYMBOL_VALUE_ADDRESS (msym);
962 hp_cxx_exception_support = 1;
963 }
964 else
965 {
966 warning (_("\
967 Unable to enable interception of exception throws.\n\
968 Executable may not have been compiled debuggable with HP aCC.\n\
969 Suggest linking executable with -g (link in /opt/langtools/lib/end.o)."));
970 return 0;
971 }
972 }
973
974 /* Set the flags */
975 hp_cxx_exception_support = 2; /* everything worked so far */
976 hp_cxx_exception_support_initialized = 1;
977 deprecated_exception_support_initialized = 1;
978
979 return 1;
980 }
981
982 /* Target operation for enabling or disabling interception of
983 exception events.
984 KIND is either EX_EVENT_THROW or EX_EVENT_CATCH
985 ENABLE is either 0 (disable) or 1 (enable).
986 Return value is NULL if no support found;
987 -1 if something went wrong,
988 or a pointer to a symtab/line struct if the breakpointable
989 address was found. */
990
991 struct symtab_and_line *
992 child_enable_exception_callback (enum exception_event_kind kind, int enable)
993 {
994 char buf[4];
995
996 if (!deprecated_exception_support_initialized
997 || !hp_cxx_exception_support_initialized)
998 if (!initialize_hp_cxx_exception_support ())
999 return NULL;
1000
1001 switch (hp_cxx_exception_support)
1002 {
1003 case 0:
1004 /* Assuming no HP support at all */
1005 return NULL;
1006 case 1:
1007 /* HP support should be present, but something went wrong */
1008 return (struct symtab_and_line *) -1; /* yuck! */
1009 /* there may be other cases in the future */
1010 }
1011
1012 /* Set the EH hook to point to the callback routine. */
1013 store_unsigned_integer (buf, 4, enable ? eh_notify_callback_addr : 0); /* FIXME 32x64 problem */
1014 /* pai: (temp) FIXME should there be a pack operation first? */
1015 if (target_write_memory (eh_notify_hook_addr, buf, 4)) /* FIXME 32x64 problem */
1016 {
1017 warning (_("\
1018 Could not write to target memory for exception event callback.\n\
1019 Interception of exception events may not work."));
1020 return (struct symtab_and_line *) -1;
1021 }
1022 if (enable)
1023 {
1024 /* Ensure that __d_pid is set up correctly -- end.c code checks this. :-( */
1025 if (PIDGET (inferior_ptid) > 0)
1026 {
1027 if (setup_d_pid_in_inferior ())
1028 return (struct symtab_and_line *) -1;
1029 }
1030 else
1031 {
1032 warning (_("Internal error: Invalid inferior pid? Cannot intercept exception events."));
1033 return (struct symtab_and_line *) -1;
1034 }
1035 }
1036
1037 switch (kind)
1038 {
1039 case EX_EVENT_THROW:
1040 store_unsigned_integer (buf, 4, enable ? 1 : 0);
1041 if (target_write_memory (eh_catch_throw_addr, buf, 4)) /* FIXME 32x64? */
1042 {
1043 warning (_("Couldn't enable exception throw interception."));
1044 return (struct symtab_and_line *) -1;
1045 }
1046 break;
1047 case EX_EVENT_CATCH:
1048 store_unsigned_integer (buf, 4, enable ? 1 : 0);
1049 if (target_write_memory (eh_catch_catch_addr, buf, 4)) /* FIXME 32x64? */
1050 {
1051 warning (_("Couldn't enable exception catch interception."));
1052 return (struct symtab_and_line *) -1;
1053 }
1054 break;
1055 default:
1056 error (_("Request to enable unknown or unsupported exception event."));
1057 }
1058
1059 /* Copy break address into new sal struct, malloc'ing if needed. */
1060 if (!break_callback_sal)
1061 break_callback_sal = XMALLOC (struct symtab_and_line);
1062 init_sal (break_callback_sal);
1063 break_callback_sal->symtab = NULL;
1064 break_callback_sal->pc = eh_break_addr;
1065 break_callback_sal->line = 0;
1066 break_callback_sal->end = eh_break_addr;
1067
1068 return break_callback_sal;
1069 }
1070
1071 /* Record some information about the current exception event */
1072 static struct exception_event_record current_ex_event;
1073
1074 /* Report current exception event. Returns a pointer to a record
1075 that describes the kind of the event, where it was thrown from,
1076 and where it will be caught. More information may be reported
1077 in the future */
1078 struct exception_event_record *
1079 child_get_current_exception_event (void)
1080 {
1081 CORE_ADDR event_kind;
1082 CORE_ADDR throw_addr;
1083 CORE_ADDR catch_addr;
1084 struct frame_info *fi, *curr_frame;
1085 int level = 1;
1086
1087 curr_frame = get_current_frame ();
1088 if (!curr_frame)
1089 return (struct exception_event_record *) NULL;
1090
1091 /* Go up one frame to __d_eh_notify_callback, because at the
1092 point when this code is executed, there's garbage in the
1093 arguments of __d_eh_break. */
1094 fi = find_relative_frame (curr_frame, &level);
1095 if (level != 0)
1096 return (struct exception_event_record *) NULL;
1097
1098 select_frame (fi);
1099
1100 /* Read in the arguments */
1101 /* __d_eh_notify_callback() is called with 3 arguments:
1102 1. event kind catch or throw
1103 2. the target address if known
1104 3. a flag -- not sure what this is. pai/1997-07-17 */
1105 event_kind = read_register (HPPA_ARG0_REGNUM);
1106 catch_addr = read_register (HPPA_ARG1_REGNUM);
1107
1108 /* Now go down to a user frame */
1109 /* For a throw, __d_eh_break is called by
1110 __d_eh_notify_callback which is called by
1111 __notify_throw which is called
1112 from user code.
1113 For a catch, __d_eh_break is called by
1114 __d_eh_notify_callback which is called by
1115 <stackwalking stuff> which is called by
1116 __throw__<stuff> or __rethrow_<stuff> which is called
1117 from user code. */
1118 /* FIXME: Don't use such magic numbers; search for the frames */
1119 level = (event_kind == EX_EVENT_THROW) ? 3 : 4;
1120 fi = find_relative_frame (curr_frame, &level);
1121 if (level != 0)
1122 return (struct exception_event_record *) NULL;
1123
1124 select_frame (fi);
1125 throw_addr = get_frame_pc (fi);
1126
1127 /* Go back to original (top) frame */
1128 select_frame (curr_frame);
1129
1130 current_ex_event.kind = (enum exception_event_kind) event_kind;
1131 current_ex_event.throw_sal = find_pc_line (throw_addr, 1);
1132 current_ex_event.catch_sal = find_pc_line (catch_addr, 1);
1133
1134 return &current_ex_event;
1135 }
1136
1137 /* Signal frames. */
1138 struct hppa_hpux_sigtramp_unwind_cache
1139 {
1140 CORE_ADDR base;
1141 struct trad_frame_saved_reg *saved_regs;
1142 };
1143
1144 static int hppa_hpux_tramp_reg[] = {
1145 HPPA_SAR_REGNUM,
1146 HPPA_PCOQ_HEAD_REGNUM,
1147 HPPA_PCSQ_HEAD_REGNUM,
1148 HPPA_PCOQ_TAIL_REGNUM,
1149 HPPA_PCSQ_TAIL_REGNUM,
1150 HPPA_EIEM_REGNUM,
1151 HPPA_IIR_REGNUM,
1152 HPPA_ISR_REGNUM,
1153 HPPA_IOR_REGNUM,
1154 HPPA_IPSW_REGNUM,
1155 -1,
1156 HPPA_SR4_REGNUM,
1157 HPPA_SR4_REGNUM + 1,
1158 HPPA_SR4_REGNUM + 2,
1159 HPPA_SR4_REGNUM + 3,
1160 HPPA_SR4_REGNUM + 4,
1161 HPPA_SR4_REGNUM + 5,
1162 HPPA_SR4_REGNUM + 6,
1163 HPPA_SR4_REGNUM + 7,
1164 HPPA_RCR_REGNUM,
1165 HPPA_PID0_REGNUM,
1166 HPPA_PID1_REGNUM,
1167 HPPA_CCR_REGNUM,
1168 HPPA_PID2_REGNUM,
1169 HPPA_PID3_REGNUM,
1170 HPPA_TR0_REGNUM,
1171 HPPA_TR0_REGNUM + 1,
1172 HPPA_TR0_REGNUM + 2,
1173 HPPA_CR27_REGNUM
1174 };
1175
1176 static struct hppa_hpux_sigtramp_unwind_cache *
1177 hppa_hpux_sigtramp_frame_unwind_cache (struct frame_info *next_frame,
1178 void **this_cache)
1179
1180 {
1181 struct gdbarch *gdbarch = get_frame_arch (next_frame);
1182 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1183 struct hppa_hpux_sigtramp_unwind_cache *info;
1184 unsigned int flag;
1185 CORE_ADDR sp, scptr, off;
1186 int i, incr, szoff;
1187
1188 if (*this_cache)
1189 return *this_cache;
1190
1191 info = FRAME_OBSTACK_ZALLOC (struct hppa_hpux_sigtramp_unwind_cache);
1192 *this_cache = info;
1193 info->saved_regs = trad_frame_alloc_saved_regs (next_frame);
1194
1195 sp = frame_unwind_register_unsigned (next_frame, HPPA_SP_REGNUM);
1196
1197 if (IS_32BIT_TARGET (gdbarch))
1198 scptr = sp - 1352;
1199 else
1200 scptr = sp - 1520;
1201
1202 off = scptr;
1203
1204 /* See /usr/include/machine/save_state.h for the structure of the save_state_t
1205 structure. */
1206
1207 flag = read_memory_unsigned_integer(scptr + HPPA_HPUX_SS_FLAGS_OFFSET, 4);
1208
1209 if (!(flag & HPPA_HPUX_SS_WIDEREGS))
1210 {
1211 /* Narrow registers. */
1212 off = scptr + HPPA_HPUX_SS_NARROW_OFFSET;
1213 incr = 4;
1214 szoff = 0;
1215 }
1216 else
1217 {
1218 /* Wide registers. */
1219 off = scptr + HPPA_HPUX_SS_WIDE_OFFSET + 8;
1220 incr = 8;
1221 szoff = (tdep->bytes_per_address == 4 ? 4 : 0);
1222 }
1223
1224 for (i = 1; i < 32; i++)
1225 {
1226 info->saved_regs[HPPA_R0_REGNUM + i].addr = off + szoff;
1227 off += incr;
1228 }
1229
1230 for (i = 0; i < ARRAY_SIZE (hppa_hpux_tramp_reg); i++)
1231 {
1232 if (hppa_hpux_tramp_reg[i] > 0)
1233 info->saved_regs[hppa_hpux_tramp_reg[i]].addr = off + szoff;
1234
1235 off += incr;
1236 }
1237
1238 /* TODO: fp regs */
1239
1240 info->base = frame_unwind_register_unsigned (next_frame, HPPA_SP_REGNUM);
1241
1242 return info;
1243 }
1244
1245 static void
1246 hppa_hpux_sigtramp_frame_this_id (struct frame_info *next_frame,
1247 void **this_prologue_cache,
1248 struct frame_id *this_id)
1249 {
1250 struct hppa_hpux_sigtramp_unwind_cache *info
1251 = hppa_hpux_sigtramp_frame_unwind_cache (next_frame, this_prologue_cache);
1252 *this_id = frame_id_build (info->base, frame_pc_unwind (next_frame));
1253 }
1254
1255 static void
1256 hppa_hpux_sigtramp_frame_prev_register (struct frame_info *next_frame,
1257 void **this_prologue_cache,
1258 int regnum, int *optimizedp,
1259 enum lval_type *lvalp,
1260 CORE_ADDR *addrp,
1261 int *realnump, gdb_byte *valuep)
1262 {
1263 struct hppa_hpux_sigtramp_unwind_cache *info
1264 = hppa_hpux_sigtramp_frame_unwind_cache (next_frame, this_prologue_cache);
1265 hppa_frame_prev_register_helper (next_frame, info->saved_regs, regnum,
1266 optimizedp, lvalp, addrp, realnump, valuep);
1267 }
1268
1269 static const struct frame_unwind hppa_hpux_sigtramp_frame_unwind = {
1270 SIGTRAMP_FRAME,
1271 hppa_hpux_sigtramp_frame_this_id,
1272 hppa_hpux_sigtramp_frame_prev_register
1273 };
1274
1275 static const struct frame_unwind *
1276 hppa_hpux_sigtramp_unwind_sniffer (struct frame_info *next_frame)
1277 {
1278 struct unwind_table_entry *u;
1279 CORE_ADDR pc = frame_pc_unwind (next_frame);
1280
1281 u = find_unwind_entry (pc);
1282
1283 /* If this is an export stub, try to get the unwind descriptor for
1284 the actual function itself. */
1285 if (u && u->stub_unwind.stub_type == EXPORT)
1286 {
1287 gdb_byte buf[HPPA_INSN_SIZE];
1288 unsigned long insn;
1289
1290 if (!safe_frame_unwind_memory (next_frame, u->region_start,
1291 buf, sizeof buf))
1292 return NULL;
1293
1294 insn = extract_unsigned_integer (buf, sizeof buf);
1295 if ((insn & 0xffe0e000) == 0xe8400000)
1296 u = find_unwind_entry(u->region_start + hppa_extract_17 (insn) + 8);
1297 }
1298
1299 if (u && u->HP_UX_interrupt_marker)
1300 return &hppa_hpux_sigtramp_frame_unwind;
1301
1302 return NULL;
1303 }
1304
1305 static CORE_ADDR
1306 hppa32_hpux_find_global_pointer (struct value *function)
1307 {
1308 CORE_ADDR faddr;
1309
1310 faddr = value_as_address (function);
1311
1312 /* Is this a plabel? If so, dereference it to get the gp value. */
1313 if (faddr & 2)
1314 {
1315 int status;
1316 char buf[4];
1317
1318 faddr &= ~3;
1319
1320 status = target_read_memory (faddr + 4, buf, sizeof (buf));
1321 if (status == 0)
1322 return extract_unsigned_integer (buf, sizeof (buf));
1323 }
1324
1325 return gdbarch_tdep (current_gdbarch)->solib_get_got_by_pc (faddr);
1326 }
1327
1328 static CORE_ADDR
1329 hppa64_hpux_find_global_pointer (struct value *function)
1330 {
1331 CORE_ADDR faddr;
1332 char buf[32];
1333
1334 faddr = value_as_address (function);
1335
1336 if (in_opd_section (faddr))
1337 {
1338 target_read_memory (faddr, buf, sizeof (buf));
1339 return extract_unsigned_integer (&buf[24], 8);
1340 }
1341 else
1342 {
1343 return gdbarch_tdep (current_gdbarch)->solib_get_got_by_pc (faddr);
1344 }
1345 }
1346
1347 static unsigned int ldsid_pattern[] = {
1348 0x000010a0, /* ldsid (rX),rY */
1349 0x00001820, /* mtsp rY,sr0 */
1350 0xe0000000 /* be,n (sr0,rX) */
1351 };
1352
1353 static CORE_ADDR
1354 hppa_hpux_search_pattern (CORE_ADDR start, CORE_ADDR end,
1355 unsigned int *patterns, int count)
1356 {
1357 int num_insns = (end - start + HPPA_INSN_SIZE) / HPPA_INSN_SIZE;
1358 unsigned int *insns;
1359 gdb_byte *buf;
1360 int offset, i;
1361
1362 buf = alloca (num_insns * HPPA_INSN_SIZE);
1363 insns = alloca (num_insns * sizeof (unsigned int));
1364
1365 read_memory (start, buf, num_insns * HPPA_INSN_SIZE);
1366 for (i = 0; i < num_insns; i++, buf += HPPA_INSN_SIZE)
1367 insns[i] = extract_unsigned_integer (buf, HPPA_INSN_SIZE);
1368
1369 for (offset = 0; offset <= num_insns - count; offset++)
1370 {
1371 for (i = 0; i < count; i++)
1372 {
1373 if ((insns[offset + i] & patterns[i]) != patterns[i])
1374 break;
1375 }
1376 if (i == count)
1377 break;
1378 }
1379
1380 if (offset <= num_insns - count)
1381 return start + offset * HPPA_INSN_SIZE;
1382 else
1383 return 0;
1384 }
1385
1386 static CORE_ADDR
1387 hppa32_hpux_search_dummy_call_sequence (struct gdbarch *gdbarch, CORE_ADDR pc,
1388 int *argreg)
1389 {
1390 struct objfile *obj;
1391 struct obj_section *sec;
1392 struct hppa_objfile_private *priv;
1393 struct frame_info *frame;
1394 struct unwind_table_entry *u;
1395 CORE_ADDR addr, rp;
1396 char buf[4];
1397 unsigned int insn;
1398
1399 sec = find_pc_section (pc);
1400 obj = sec->objfile;
1401 priv = objfile_data (obj, hppa_objfile_priv_data);
1402
1403 if (!priv)
1404 priv = hppa_init_objfile_priv_data (obj);
1405 if (!priv)
1406 error (_("Internal error creating objfile private data."));
1407
1408 /* Use the cached value if we have one. */
1409 if (priv->dummy_call_sequence_addr != 0)
1410 {
1411 *argreg = priv->dummy_call_sequence_reg;
1412 return priv->dummy_call_sequence_addr;
1413 }
1414
1415 /* First try a heuristic; if we are in a shared library call, our return
1416 pointer is likely to point at an export stub. */
1417 frame = get_current_frame ();
1418 rp = frame_unwind_register_unsigned (frame, 2);
1419 u = find_unwind_entry (rp);
1420 if (u && u->stub_unwind.stub_type == EXPORT)
1421 {
1422 addr = hppa_hpux_search_pattern (u->region_start, u->region_end,
1423 ldsid_pattern,
1424 ARRAY_SIZE (ldsid_pattern));
1425 if (addr)
1426 goto found_pattern;
1427 }
1428
1429 /* Next thing to try is to look for an export stub. */
1430 if (priv->unwind_info)
1431 {
1432 int i;
1433
1434 for (i = 0; i < priv->unwind_info->last; i++)
1435 {
1436 struct unwind_table_entry *u;
1437 u = &priv->unwind_info->table[i];
1438 if (u->stub_unwind.stub_type == EXPORT)
1439 {
1440 addr = hppa_hpux_search_pattern (u->region_start, u->region_end,
1441 ldsid_pattern,
1442 ARRAY_SIZE (ldsid_pattern));
1443 if (addr)
1444 {
1445 goto found_pattern;
1446 }
1447 }
1448 }
1449 }
1450
1451 /* Finally, if this is the main executable, try to locate a sequence
1452 from noshlibs */
1453 addr = hppa_symbol_address ("noshlibs");
1454 sec = find_pc_section (addr);
1455
1456 if (sec && sec->objfile == obj)
1457 {
1458 CORE_ADDR start, end;
1459
1460 find_pc_partial_function (addr, NULL, &start, &end);
1461 if (start != 0 && end != 0)
1462 {
1463 addr = hppa_hpux_search_pattern (start, end, ldsid_pattern,
1464 ARRAY_SIZE (ldsid_pattern));
1465 if (addr)
1466 goto found_pattern;
1467 }
1468 }
1469
1470 /* Can't find a suitable sequence. */
1471 return 0;
1472
1473 found_pattern:
1474 target_read_memory (addr, buf, sizeof (buf));
1475 insn = extract_unsigned_integer (buf, sizeof (buf));
1476 priv->dummy_call_sequence_addr = addr;
1477 priv->dummy_call_sequence_reg = (insn >> 21) & 0x1f;
1478
1479 *argreg = priv->dummy_call_sequence_reg;
1480 return priv->dummy_call_sequence_addr;
1481 }
1482
1483 static CORE_ADDR
1484 hppa64_hpux_search_dummy_call_sequence (struct gdbarch *gdbarch, CORE_ADDR pc,
1485 int *argreg)
1486 {
1487 struct objfile *obj;
1488 struct obj_section *sec;
1489 struct hppa_objfile_private *priv;
1490 CORE_ADDR addr;
1491 struct minimal_symbol *msym;
1492 int i;
1493
1494 sec = find_pc_section (pc);
1495 obj = sec->objfile;
1496 priv = objfile_data (obj, hppa_objfile_priv_data);
1497
1498 if (!priv)
1499 priv = hppa_init_objfile_priv_data (obj);
1500 if (!priv)
1501 error (_("Internal error creating objfile private data."));
1502
1503 /* Use the cached value if we have one. */
1504 if (priv->dummy_call_sequence_addr != 0)
1505 {
1506 *argreg = priv->dummy_call_sequence_reg;
1507 return priv->dummy_call_sequence_addr;
1508 }
1509
1510 /* FIXME: Without stub unwind information, locating a suitable sequence is
1511 fairly difficult. For now, we implement a very naive and inefficient
1512 scheme; try to read in blocks of code, and look for a "bve,n (rp)"
1513 instruction. These are likely to occur at the end of functions, so
1514 we only look at the last two instructions of each function. */
1515 for (i = 0, msym = obj->msymbols; i < obj->minimal_symbol_count; i++, msym++)
1516 {
1517 CORE_ADDR begin, end;
1518 char *name;
1519 gdb_byte buf[2 * HPPA_INSN_SIZE];
1520 int offset;
1521
1522 find_pc_partial_function (SYMBOL_VALUE_ADDRESS (msym), &name,
1523 &begin, &end);
1524
1525 if (name == NULL || begin == 0 || end == 0)
1526 continue;
1527
1528 if (target_read_memory (end - sizeof (buf), buf, sizeof (buf)) == 0)
1529 {
1530 for (offset = 0; offset < sizeof (buf); offset++)
1531 {
1532 unsigned int insn;
1533
1534 insn = extract_unsigned_integer (buf + offset, HPPA_INSN_SIZE);
1535 if (insn == 0xe840d002) /* bve,n (rp) */
1536 {
1537 addr = (end - sizeof (buf)) + offset;
1538 goto found_pattern;
1539 }
1540 }
1541 }
1542 }
1543
1544 /* Can't find a suitable sequence. */
1545 return 0;
1546
1547 found_pattern:
1548 priv->dummy_call_sequence_addr = addr;
1549 /* Right now we only look for a "bve,l (rp)" sequence, so the register is
1550 always HPPA_RP_REGNUM. */
1551 priv->dummy_call_sequence_reg = HPPA_RP_REGNUM;
1552
1553 *argreg = priv->dummy_call_sequence_reg;
1554 return priv->dummy_call_sequence_addr;
1555 }
1556
1557 static CORE_ADDR
1558 hppa_hpux_find_import_stub_for_addr (CORE_ADDR funcaddr)
1559 {
1560 struct objfile *objfile;
1561 struct minimal_symbol *funsym, *stubsym;
1562 CORE_ADDR stubaddr;
1563
1564 funsym = lookup_minimal_symbol_by_pc (funcaddr);
1565 stubaddr = 0;
1566
1567 ALL_OBJFILES (objfile)
1568 {
1569 stubsym = lookup_minimal_symbol_solib_trampoline
1570 (SYMBOL_LINKAGE_NAME (funsym), objfile);
1571
1572 if (stubsym)
1573 {
1574 struct unwind_table_entry *u;
1575
1576 u = find_unwind_entry (SYMBOL_VALUE (stubsym));
1577 if (u == NULL
1578 || (u->stub_unwind.stub_type != IMPORT
1579 && u->stub_unwind.stub_type != IMPORT_SHLIB))
1580 continue;
1581
1582 stubaddr = SYMBOL_VALUE (stubsym);
1583
1584 /* If we found an IMPORT stub, then we can stop searching;
1585 if we found an IMPORT_SHLIB, we want to continue the search
1586 in the hopes that we will find an IMPORT stub. */
1587 if (u->stub_unwind.stub_type == IMPORT)
1588 break;
1589 }
1590 }
1591
1592 return stubaddr;
1593 }
1594
1595 static int
1596 hppa_hpux_sr_for_addr (CORE_ADDR addr)
1597 {
1598 int sr;
1599 /* The space register to use is encoded in the top 2 bits of the address. */
1600 sr = addr >> (gdbarch_tdep (current_gdbarch)->bytes_per_address * 8 - 2);
1601 return sr + 4;
1602 }
1603
1604 static CORE_ADDR
1605 hppa_hpux_find_dummy_bpaddr (CORE_ADDR addr)
1606 {
1607 /* In order for us to restore the space register to its starting state,
1608 we need the dummy trampoline to return to the an instruction address in
1609 the same space as where we started the call. We used to place the
1610 breakpoint near the current pc, however, this breaks nested dummy calls
1611 as the nested call will hit the breakpoint address and terminate
1612 prematurely. Instead, we try to look for an address in the same space to
1613 put the breakpoint.
1614
1615 This is similar in spirit to putting the breakpoint at the "entry point"
1616 of an executable. */
1617
1618 struct obj_section *sec;
1619 struct unwind_table_entry *u;
1620 struct minimal_symbol *msym;
1621 CORE_ADDR func;
1622 int i;
1623
1624 sec = find_pc_section (addr);
1625 if (sec)
1626 {
1627 /* First try the lowest address in the section; we can use it as long
1628 as it is "regular" code (i.e. not a stub) */
1629 u = find_unwind_entry (sec->addr);
1630 if (!u || u->stub_unwind.stub_type == 0)
1631 return sec->addr;
1632
1633 /* Otherwise, we need to find a symbol for a regular function. We
1634 do this by walking the list of msymbols in the objfile. The symbol
1635 we find should not be the same as the function that was passed in. */
1636
1637 /* FIXME: this is broken, because we can find a function that will be
1638 called by the dummy call target function, which will still not
1639 work. */
1640
1641 find_pc_partial_function (addr, NULL, &func, NULL);
1642 for (i = 0, msym = sec->objfile->msymbols;
1643 i < sec->objfile->minimal_symbol_count;
1644 i++, msym++)
1645 {
1646 u = find_unwind_entry (SYMBOL_VALUE_ADDRESS (msym));
1647 if (func != SYMBOL_VALUE_ADDRESS (msym)
1648 && (!u || u->stub_unwind.stub_type == 0))
1649 return SYMBOL_VALUE_ADDRESS (msym);
1650 }
1651 }
1652
1653 warning (_("Cannot find suitable address to place dummy breakpoint; nested "
1654 "calls may fail."));
1655 return addr - 4;
1656 }
1657
1658 static CORE_ADDR
1659 hppa_hpux_push_dummy_code (struct gdbarch *gdbarch, CORE_ADDR sp,
1660 CORE_ADDR funcaddr, int using_gcc,
1661 struct value **args, int nargs,
1662 struct type *value_type,
1663 CORE_ADDR *real_pc, CORE_ADDR *bp_addr)
1664 {
1665 CORE_ADDR pc, stubaddr;
1666 int argreg = 0;
1667
1668 pc = read_pc ();
1669
1670 /* Note: we don't want to pass a function descriptor here; push_dummy_call
1671 fills in the PIC register for us. */
1672 funcaddr = gdbarch_convert_from_func_ptr_addr (gdbarch, funcaddr, NULL);
1673
1674 /* The simple case is where we call a function in the same space that we are
1675 currently in; in that case we don't really need to do anything. */
1676 if (hppa_hpux_sr_for_addr (pc) == hppa_hpux_sr_for_addr (funcaddr))
1677 {
1678 /* Intraspace call. */
1679 *bp_addr = hppa_hpux_find_dummy_bpaddr (pc);
1680 *real_pc = funcaddr;
1681 regcache_cooked_write_unsigned (current_regcache, HPPA_RP_REGNUM, *bp_addr);
1682
1683 return sp;
1684 }
1685
1686 /* In order to make an interspace call, we need to go through a stub.
1687 gcc supplies an appropriate stub called "__gcc_plt_call", however, if
1688 an application is compiled with HP compilers then this stub is not
1689 available. We used to fallback to "__d_plt_call", however that stub
1690 is not entirely useful for us because it doesn't do an interspace
1691 return back to the caller. Also, on hppa64-hpux, there is no
1692 __gcc_plt_call available. In order to keep the code uniform, we
1693 instead don't use either of these stubs, but instead write our own
1694 onto the stack.
1695
1696 A problem arises since the stack is located in a different space than
1697 code, so in order to branch to a stack stub, we will need to do an
1698 interspace branch. Previous versions of gdb did this by modifying code
1699 at the current pc and doing single-stepping to set the pcsq. Since this
1700 is highly undesirable, we use a different scheme:
1701
1702 All we really need to do the branch to the stub is a short instruction
1703 sequence like this:
1704
1705 PA1.1:
1706 ldsid (rX),r1
1707 mtsp r1,sr0
1708 be,n (sr0,rX)
1709
1710 PA2.0:
1711 bve,n (sr0,rX)
1712
1713 Instead of writing these sequences ourselves, we can find it in
1714 the instruction stream that belongs to the current space. While this
1715 seems difficult at first, we are actually guaranteed to find the sequences
1716 in several places:
1717
1718 For 32-bit code:
1719 - in export stubs for shared libraries
1720 - in the "noshlibs" routine in the main module
1721
1722 For 64-bit code:
1723 - at the end of each "regular" function
1724
1725 We cache the address of these sequences in the objfile's private data
1726 since these operations can potentially be quite expensive.
1727
1728 So, what we do is:
1729 - write a stack trampoline
1730 - look for a suitable instruction sequence in the current space
1731 - point the sequence at the trampoline
1732 - set the return address of the trampoline to the current space
1733 (see hppa_hpux_find_dummy_call_bpaddr)
1734 - set the continuing address of the "dummy code" as the sequence.
1735
1736 */
1737
1738 if (IS_32BIT_TARGET (gdbarch))
1739 {
1740 static unsigned int hppa32_tramp[] = {
1741 0x0fdf1291, /* stw r31,-8(,sp) */
1742 0x02c010a1, /* ldsid (,r22),r1 */
1743 0x00011820, /* mtsp r1,sr0 */
1744 0xe6c00000, /* be,l 0(sr0,r22),%sr0,%r31 */
1745 0x081f0242, /* copy r31,rp */
1746 0x0fd11082, /* ldw -8(,sp),rp */
1747 0x004010a1, /* ldsid (,rp),r1 */
1748 0x00011820, /* mtsp r1,sr0 */
1749 0xe0400000, /* be 0(sr0,rp) */
1750 0x08000240 /* nop */
1751 };
1752
1753 /* for hppa32, we must call the function through a stub so that on
1754 return it can return to the space of our trampoline. */
1755 stubaddr = hppa_hpux_find_import_stub_for_addr (funcaddr);
1756 if (stubaddr == 0)
1757 error (_("Cannot call external function not referenced by application "
1758 "(no import stub).\n"));
1759 regcache_cooked_write_unsigned (current_regcache, 22, stubaddr);
1760
1761 write_memory (sp, (char *)&hppa32_tramp, sizeof (hppa32_tramp));
1762
1763 *bp_addr = hppa_hpux_find_dummy_bpaddr (pc);
1764 regcache_cooked_write_unsigned (current_regcache, 31, *bp_addr);
1765
1766 *real_pc = hppa32_hpux_search_dummy_call_sequence (gdbarch, pc, &argreg);
1767 if (*real_pc == 0)
1768 error (_("Cannot make interspace call from here."));
1769
1770 regcache_cooked_write_unsigned (current_regcache, argreg, sp);
1771
1772 sp += sizeof (hppa32_tramp);
1773 }
1774 else
1775 {
1776 static unsigned int hppa64_tramp[] = {
1777 0xeac0f000, /* bve,l (r22),%r2 */
1778 0x0fdf12d1, /* std r31,-8(,sp) */
1779 0x0fd110c2, /* ldd -8(,sp),rp */
1780 0xe840d002, /* bve,n (rp) */
1781 0x08000240 /* nop */
1782 };
1783
1784 /* for hppa64, we don't need to call through a stub; all functions
1785 return via a bve. */
1786 regcache_cooked_write_unsigned (current_regcache, 22, funcaddr);
1787 write_memory (sp, (char *)&hppa64_tramp, sizeof (hppa64_tramp));
1788
1789 *bp_addr = pc - 4;
1790 regcache_cooked_write_unsigned (current_regcache, 31, *bp_addr);
1791
1792 *real_pc = hppa64_hpux_search_dummy_call_sequence (gdbarch, pc, &argreg);
1793 if (*real_pc == 0)
1794 error (_("Cannot make interspace call from here."));
1795
1796 regcache_cooked_write_unsigned (current_regcache, argreg, sp);
1797
1798 sp += sizeof (hppa64_tramp);
1799 }
1800
1801 sp = gdbarch_frame_align (gdbarch, sp);
1802
1803 return sp;
1804 }
1805
1806 \f
1807
1808 static void
1809 hppa_hpux_supply_ss_narrow (struct regcache *regcache,
1810 int regnum, const char *save_state)
1811 {
1812 const char *ss_narrow = save_state + HPPA_HPUX_SS_NARROW_OFFSET;
1813 int i, offset = 0;
1814
1815 for (i = HPPA_R1_REGNUM; i < HPPA_FP0_REGNUM; i++)
1816 {
1817 if (regnum == i || regnum == -1)
1818 regcache_raw_supply (regcache, i, ss_narrow + offset);
1819
1820 offset += 4;
1821 }
1822 }
1823
1824 static void
1825 hppa_hpux_supply_ss_fpblock (struct regcache *regcache,
1826 int regnum, const char *save_state)
1827 {
1828 const char *ss_fpblock = save_state + HPPA_HPUX_SS_FPBLOCK_OFFSET;
1829 int i, offset = 0;
1830
1831 /* FIXME: We view the floating-point state as 64 single-precision
1832 registers for 32-bit code, and 32 double-precision register for
1833 64-bit code. This distinction is artificial and should be
1834 eliminated. If that ever happens, we should remove the if-clause
1835 below. */
1836
1837 if (register_size (get_regcache_arch (regcache), HPPA_FP0_REGNUM) == 4)
1838 {
1839 for (i = HPPA_FP0_REGNUM; i < HPPA_FP0_REGNUM + 64; i++)
1840 {
1841 if (regnum == i || regnum == -1)
1842 regcache_raw_supply (regcache, i, ss_fpblock + offset);
1843
1844 offset += 4;
1845 }
1846 }
1847 else
1848 {
1849 for (i = HPPA_FP0_REGNUM; i < HPPA_FP0_REGNUM + 32; i++)
1850 {
1851 if (regnum == i || regnum == -1)
1852 regcache_raw_supply (regcache, i, ss_fpblock + offset);
1853
1854 offset += 8;
1855 }
1856 }
1857 }
1858
1859 static void
1860 hppa_hpux_supply_ss_wide (struct regcache *regcache,
1861 int regnum, const char *save_state)
1862 {
1863 const char *ss_wide = save_state + HPPA_HPUX_SS_WIDE_OFFSET;
1864 int i, offset = 8;
1865
1866 if (register_size (get_regcache_arch (regcache), HPPA_R1_REGNUM) == 4)
1867 offset += 4;
1868
1869 for (i = HPPA_R1_REGNUM; i < HPPA_FP0_REGNUM; i++)
1870 {
1871 if (regnum == i || regnum == -1)
1872 regcache_raw_supply (regcache, i, ss_wide + offset);
1873
1874 offset += 8;
1875 }
1876 }
1877
1878 static void
1879 hppa_hpux_supply_save_state (const struct regset *regset,
1880 struct regcache *regcache,
1881 int regnum, const void *regs, size_t len)
1882 {
1883 const char *proc_info = regs;
1884 const char *save_state = proc_info + 8;
1885 ULONGEST flags;
1886
1887 flags = extract_unsigned_integer (save_state + HPPA_HPUX_SS_FLAGS_OFFSET, 4);
1888 if (regnum == -1 || regnum == HPPA_FLAGS_REGNUM)
1889 {
1890 struct gdbarch *arch = get_regcache_arch (regcache);
1891 size_t size = register_size (arch, HPPA_FLAGS_REGNUM);
1892 char buf[8];
1893
1894 store_unsigned_integer (buf, size, flags);
1895 regcache_raw_supply (regcache, HPPA_FLAGS_REGNUM, buf);
1896 }
1897
1898 /* If the SS_WIDEREGS flag is set, we really do need the full
1899 `struct save_state'. */
1900 if (flags & HPPA_HPUX_SS_WIDEREGS && len < HPPA_HPUX_SAVE_STATE_SIZE)
1901 error (_("Register set contents too small"));
1902
1903 if (flags & HPPA_HPUX_SS_WIDEREGS)
1904 hppa_hpux_supply_ss_wide (regcache, regnum, save_state);
1905 else
1906 hppa_hpux_supply_ss_narrow (regcache, regnum, save_state);
1907
1908 hppa_hpux_supply_ss_fpblock (regcache, regnum, save_state);
1909 }
1910
1911 /* HP-UX register set. */
1912
1913 static struct regset hppa_hpux_regset =
1914 {
1915 NULL,
1916 hppa_hpux_supply_save_state
1917 };
1918
1919 static const struct regset *
1920 hppa_hpux_regset_from_core_section (struct gdbarch *gdbarch,
1921 const char *sect_name, size_t sect_size)
1922 {
1923 if (strcmp (sect_name, ".reg") == 0
1924 && sect_size >= HPPA_HPUX_PA89_SAVE_STATE_SIZE + 8)
1925 return &hppa_hpux_regset;
1926
1927 return NULL;
1928 }
1929 \f
1930
1931 /* Bit in the `ss_flag' member of `struct save_state' that indicates
1932 the state was saved from a system call. From
1933 <machine/save_state.h>. */
1934 #define HPPA_HPUX_SS_INSYSCALL 0x02
1935
1936 static CORE_ADDR
1937 hppa_hpux_read_pc (ptid_t ptid)
1938 {
1939 ULONGEST flags;
1940
1941 /* If we're currently in a system call return the contents of %r31. */
1942 flags = read_register_pid (HPPA_FLAGS_REGNUM, ptid);
1943 if (flags & HPPA_HPUX_SS_INSYSCALL)
1944 return read_register_pid (HPPA_R31_REGNUM, ptid) & ~0x3;
1945
1946 return hppa_read_pc (ptid);
1947 }
1948
1949 static void
1950 hppa_hpux_write_pc (CORE_ADDR pc, ptid_t ptid)
1951 {
1952 ULONGEST flags;
1953
1954 /* If we're currently in a system call also write PC into %r31. */
1955 flags = read_register_pid (HPPA_FLAGS_REGNUM, ptid);
1956 if (flags & HPPA_HPUX_SS_INSYSCALL)
1957 write_register_pid (HPPA_R31_REGNUM, pc | 0x3, ptid);
1958
1959 return hppa_write_pc (pc, ptid);
1960 }
1961
1962 static CORE_ADDR
1963 hppa_hpux_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
1964 {
1965 ULONGEST flags;
1966
1967 /* If we're currently in a system call return the contents of %r31. */
1968 flags = frame_unwind_register_unsigned (next_frame, HPPA_FLAGS_REGNUM);
1969 if (flags & HPPA_HPUX_SS_INSYSCALL)
1970 return frame_unwind_register_unsigned (next_frame, HPPA_R31_REGNUM) & ~0x3;
1971
1972 return hppa_unwind_pc (gdbarch, next_frame);
1973 }
1974 \f
1975
1976 static void
1977 hppa_hpux_inferior_created (struct target_ops *objfile, int from_tty)
1978 {
1979 /* Some HP-UX related globals to clear when a new "main"
1980 symbol file is loaded. HP-specific. */
1981 deprecated_hp_som_som_object_present = 0;
1982 hp_cxx_exception_support_initialized = 0;
1983 }
1984
1985 /* Given the current value of the pc, check to see if it is inside a stub, and
1986 if so, change the value of the pc to point to the caller of the stub.
1987 NEXT_FRAME is the next frame in the current list of frames.
1988 BASE contains to stack frame base of the current frame.
1989 SAVE_REGS is the register file stored in the frame cache. */
1990 static void
1991 hppa_hpux_unwind_adjust_stub (struct frame_info *next_frame, CORE_ADDR base,
1992 struct trad_frame_saved_reg *saved_regs)
1993 {
1994 int optimized, realreg;
1995 enum lval_type lval;
1996 CORE_ADDR addr;
1997 char buffer[sizeof(ULONGEST)];
1998 ULONGEST val;
1999 CORE_ADDR stubpc;
2000 struct unwind_table_entry *u;
2001
2002 trad_frame_get_prev_register (next_frame, saved_regs,
2003 HPPA_PCOQ_HEAD_REGNUM,
2004 &optimized, &lval, &addr, &realreg, buffer);
2005 val = extract_unsigned_integer (buffer,
2006 register_size (get_frame_arch (next_frame),
2007 HPPA_PCOQ_HEAD_REGNUM));
2008
2009 u = find_unwind_entry (val);
2010 if (u && u->stub_unwind.stub_type == EXPORT)
2011 {
2012 stubpc = read_memory_integer (base - 24, TARGET_PTR_BIT / 8);
2013 trad_frame_set_value (saved_regs, HPPA_PCOQ_HEAD_REGNUM, stubpc);
2014 }
2015 else if (hppa_symbol_address ("__gcc_plt_call")
2016 == get_pc_function_start (val))
2017 {
2018 stubpc = read_memory_integer (base - 8, TARGET_PTR_BIT / 8);
2019 trad_frame_set_value (saved_regs, HPPA_PCOQ_HEAD_REGNUM, stubpc);
2020 }
2021 }
2022
2023 static void
2024 hppa_hpux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
2025 {
2026 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2027
2028 if (IS_32BIT_TARGET (gdbarch))
2029 tdep->in_solib_call_trampoline = hppa32_hpux_in_solib_call_trampoline;
2030 else
2031 tdep->in_solib_call_trampoline = hppa64_hpux_in_solib_call_trampoline;
2032
2033 tdep->unwind_adjust_stub = hppa_hpux_unwind_adjust_stub;
2034
2035 set_gdbarch_in_solib_return_trampoline
2036 (gdbarch, hppa_hpux_in_solib_return_trampoline);
2037 set_gdbarch_skip_trampoline_code (gdbarch, hppa_hpux_skip_trampoline_code);
2038
2039 set_gdbarch_push_dummy_code (gdbarch, hppa_hpux_push_dummy_code);
2040 set_gdbarch_call_dummy_location (gdbarch, ON_STACK);
2041
2042 set_gdbarch_read_pc (gdbarch, hppa_hpux_read_pc);
2043 set_gdbarch_write_pc (gdbarch, hppa_hpux_write_pc);
2044 set_gdbarch_unwind_pc (gdbarch, hppa_hpux_unwind_pc);
2045 set_gdbarch_skip_permanent_breakpoint
2046 (gdbarch, hppa_skip_permanent_breakpoint);
2047
2048 set_gdbarch_regset_from_core_section
2049 (gdbarch, hppa_hpux_regset_from_core_section);
2050
2051 frame_unwind_append_sniffer (gdbarch, hppa_hpux_sigtramp_unwind_sniffer);
2052
2053 observer_attach_inferior_created (hppa_hpux_inferior_created);
2054 }
2055
2056 static void
2057 hppa_hpux_som_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
2058 {
2059 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2060
2061 tdep->is_elf = 0;
2062
2063 tdep->find_global_pointer = hppa32_hpux_find_global_pointer;
2064
2065 hppa_hpux_init_abi (info, gdbarch);
2066 som_solib_select (tdep);
2067 }
2068
2069 static void
2070 hppa_hpux_elf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
2071 {
2072 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2073
2074 tdep->is_elf = 1;
2075 tdep->find_global_pointer = hppa64_hpux_find_global_pointer;
2076
2077 hppa_hpux_init_abi (info, gdbarch);
2078 pa64_solib_select (tdep);
2079 }
2080
2081 static enum gdb_osabi
2082 hppa_hpux_core_osabi_sniffer (bfd *abfd)
2083 {
2084 if (strcmp (bfd_get_target (abfd), "hpux-core") == 0)
2085 return GDB_OSABI_HPUX_SOM;
2086 else if (strcmp (bfd_get_target (abfd), "elf64-hppa") == 0)
2087 {
2088 asection *section;
2089
2090 section = bfd_get_section_by_name (abfd, ".kernel");
2091 if (section)
2092 {
2093 bfd_size_type size;
2094 char *contents;
2095
2096 size = bfd_section_size (abfd, section);
2097 contents = alloca (size);
2098 if (bfd_get_section_contents (abfd, section, contents,
2099 (file_ptr) 0, size)
2100 && strcmp (contents, "HP-UX") == 0)
2101 return GDB_OSABI_HPUX_ELF;
2102 }
2103 }
2104
2105 return GDB_OSABI_UNKNOWN;
2106 }
2107
2108 void
2109 _initialize_hppa_hpux_tdep (void)
2110 {
2111 /* BFD doesn't set a flavour for HP-UX style core files. It doesn't
2112 set the architecture either. */
2113 gdbarch_register_osabi_sniffer (bfd_arch_unknown,
2114 bfd_target_unknown_flavour,
2115 hppa_hpux_core_osabi_sniffer);
2116 gdbarch_register_osabi_sniffer (bfd_arch_hppa,
2117 bfd_target_elf_flavour,
2118 hppa_hpux_core_osabi_sniffer);
2119
2120 gdbarch_register_osabi (bfd_arch_hppa, 0, GDB_OSABI_HPUX_SOM,
2121 hppa_hpux_som_init_abi);
2122 gdbarch_register_osabi (bfd_arch_hppa, bfd_mach_hppa20w, GDB_OSABI_HPUX_ELF,
2123 hppa_hpux_elf_init_abi);
2124 }
This page took 0.073878 seconds and 5 git commands to generate.