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