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