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 | ||
77d18ded RC |
70 | static int |
71 | in_opd_section (CORE_ADDR pc) | |
72 | { | |
73 | struct obj_section *s; | |
74 | int retval = 0; | |
75 | ||
76 | s = find_pc_section (pc); | |
77 | ||
78 | retval = (s != NULL | |
79 | && s->the_bfd_section->name != NULL | |
80 | && strcmp (s->the_bfd_section->name, ".opd") == 0); | |
81 | return (retval); | |
82 | } | |
83 | ||
abc485a1 RC |
84 | /* Return one if PC is in the call path of a trampoline, else return zero. |
85 | ||
86 | Note we return one for *any* call trampoline (long-call, arg-reloc), not | |
87 | just shared library trampolines (import, export). */ | |
88 | ||
89 | static int | |
90 | hppa32_hpux_in_solib_call_trampoline (CORE_ADDR pc, char *name) | |
91 | { | |
92 | struct minimal_symbol *minsym; | |
93 | struct unwind_table_entry *u; | |
abc485a1 RC |
94 | |
95 | /* First see if PC is in one of the two C-library trampolines. */ | |
3388d7ff RC |
96 | if (pc == hppa_symbol_address("$$dyncall") |
97 | || pc == hppa_symbol_address("_sr4export")) | |
abc485a1 RC |
98 | return 1; |
99 | ||
100 | minsym = lookup_minimal_symbol_by_pc (pc); | |
101 | if (minsym && strcmp (DEPRECATED_SYMBOL_NAME (minsym), ".stub") == 0) | |
102 | return 1; | |
103 | ||
104 | /* Get the unwind descriptor corresponding to PC, return zero | |
105 | if no unwind was found. */ | |
106 | u = find_unwind_entry (pc); | |
107 | if (!u) | |
108 | return 0; | |
109 | ||
110 | /* If this isn't a linker stub, then return now. */ | |
111 | if (u->stub_unwind.stub_type == 0) | |
112 | return 0; | |
113 | ||
114 | /* By definition a long-branch stub is a call stub. */ | |
115 | if (u->stub_unwind.stub_type == LONG_BRANCH) | |
116 | return 1; | |
117 | ||
118 | /* The call and return path execute the same instructions within | |
119 | an IMPORT stub! So an IMPORT stub is both a call and return | |
120 | trampoline. */ | |
121 | if (u->stub_unwind.stub_type == IMPORT) | |
122 | return 1; | |
123 | ||
124 | /* Parameter relocation stubs always have a call path and may have a | |
125 | return path. */ | |
126 | if (u->stub_unwind.stub_type == PARAMETER_RELOCATION | |
127 | || u->stub_unwind.stub_type == EXPORT) | |
128 | { | |
129 | CORE_ADDR addr; | |
130 | ||
131 | /* Search forward from the current PC until we hit a branch | |
132 | or the end of the stub. */ | |
133 | for (addr = pc; addr <= u->region_end; addr += 4) | |
134 | { | |
135 | unsigned long insn; | |
136 | ||
137 | insn = read_memory_integer (addr, 4); | |
138 | ||
139 | /* Does it look like a bl? If so then it's the call path, if | |
140 | we find a bv or be first, then we're on the return path. */ | |
141 | if ((insn & 0xfc00e000) == 0xe8000000) | |
142 | return 1; | |
143 | else if ((insn & 0xfc00e001) == 0xe800c000 | |
144 | || (insn & 0xfc000000) == 0xe0000000) | |
145 | return 0; | |
146 | } | |
147 | ||
148 | /* Should never happen. */ | |
8a3fe4f8 | 149 | warning (_("Unable to find branch in parameter relocation stub.")); |
abc485a1 RC |
150 | return 0; |
151 | } | |
152 | ||
153 | /* Unknown stub type. For now, just return zero. */ | |
154 | return 0; | |
155 | } | |
156 | ||
157 | static int | |
158 | hppa64_hpux_in_solib_call_trampoline (CORE_ADDR pc, char *name) | |
159 | { | |
160 | /* PA64 has a completely different stub/trampoline scheme. Is it | |
161 | better? Maybe. It's certainly harder to determine with any | |
162 | certainty that we are in a stub because we can not refer to the | |
163 | unwinders to help. | |
164 | ||
165 | The heuristic is simple. Try to lookup the current PC value in th | |
166 | minimal symbol table. If that fails, then assume we are not in a | |
167 | stub and return. | |
168 | ||
169 | Then see if the PC value falls within the section bounds for the | |
170 | section containing the minimal symbol we found in the first | |
171 | step. If it does, then assume we are not in a stub and return. | |
172 | ||
173 | Finally peek at the instructions to see if they look like a stub. */ | |
174 | struct minimal_symbol *minsym; | |
175 | asection *sec; | |
176 | CORE_ADDR addr; | |
177 | int insn, i; | |
178 | ||
179 | minsym = lookup_minimal_symbol_by_pc (pc); | |
180 | if (! minsym) | |
181 | return 0; | |
182 | ||
183 | sec = SYMBOL_BFD_SECTION (minsym); | |
184 | ||
185 | if (bfd_get_section_vma (sec->owner, sec) <= pc | |
186 | && pc < (bfd_get_section_vma (sec->owner, sec) | |
187 | + bfd_section_size (sec->owner, sec))) | |
188 | return 0; | |
189 | ||
190 | /* We might be in a stub. Peek at the instructions. Stubs are 3 | |
191 | instructions long. */ | |
192 | insn = read_memory_integer (pc, 4); | |
193 | ||
194 | /* Find out where we think we are within the stub. */ | |
195 | if ((insn & 0xffffc00e) == 0x53610000) | |
196 | addr = pc; | |
197 | else if ((insn & 0xffffffff) == 0xe820d000) | |
198 | addr = pc - 4; | |
199 | else if ((insn & 0xffffc00e) == 0x537b0000) | |
200 | addr = pc - 8; | |
201 | else | |
202 | return 0; | |
203 | ||
204 | /* Now verify each insn in the range looks like a stub instruction. */ | |
205 | insn = read_memory_integer (addr, 4); | |
206 | if ((insn & 0xffffc00e) != 0x53610000) | |
207 | return 0; | |
208 | ||
209 | /* Now verify each insn in the range looks like a stub instruction. */ | |
210 | insn = read_memory_integer (addr + 4, 4); | |
211 | if ((insn & 0xffffffff) != 0xe820d000) | |
212 | return 0; | |
213 | ||
214 | /* Now verify each insn in the range looks like a stub instruction. */ | |
215 | insn = read_memory_integer (addr + 8, 4); | |
216 | if ((insn & 0xffffc00e) != 0x537b0000) | |
217 | return 0; | |
218 | ||
219 | /* Looks like a stub. */ | |
220 | return 1; | |
221 | } | |
222 | ||
223 | /* Return one if PC is in the return path of a trampoline, else return zero. | |
224 | ||
225 | Note we return one for *any* call trampoline (long-call, arg-reloc), not | |
226 | just shared library trampolines (import, export). */ | |
227 | ||
228 | static int | |
229 | hppa_hpux_in_solib_return_trampoline (CORE_ADDR pc, char *name) | |
230 | { | |
231 | struct unwind_table_entry *u; | |
232 | ||
233 | /* Get the unwind descriptor corresponding to PC, return zero | |
234 | if no unwind was found. */ | |
235 | u = find_unwind_entry (pc); | |
236 | if (!u) | |
237 | return 0; | |
238 | ||
239 | /* If this isn't a linker stub or it's just a long branch stub, then | |
240 | return zero. */ | |
241 | if (u->stub_unwind.stub_type == 0 || u->stub_unwind.stub_type == LONG_BRANCH) | |
242 | return 0; | |
243 | ||
244 | /* The call and return path execute the same instructions within | |
245 | an IMPORT stub! So an IMPORT stub is both a call and return | |
246 | trampoline. */ | |
247 | if (u->stub_unwind.stub_type == IMPORT) | |
248 | return 1; | |
249 | ||
250 | /* Parameter relocation stubs always have a call path and may have a | |
251 | return path. */ | |
252 | if (u->stub_unwind.stub_type == PARAMETER_RELOCATION | |
253 | || u->stub_unwind.stub_type == EXPORT) | |
254 | { | |
255 | CORE_ADDR addr; | |
256 | ||
257 | /* Search forward from the current PC until we hit a branch | |
258 | or the end of the stub. */ | |
259 | for (addr = pc; addr <= u->region_end; addr += 4) | |
260 | { | |
261 | unsigned long insn; | |
262 | ||
263 | insn = read_memory_integer (addr, 4); | |
264 | ||
265 | /* Does it look like a bl? If so then it's the call path, if | |
266 | we find a bv or be first, then we're on the return path. */ | |
267 | if ((insn & 0xfc00e000) == 0xe8000000) | |
268 | return 0; | |
269 | else if ((insn & 0xfc00e001) == 0xe800c000 | |
270 | || (insn & 0xfc000000) == 0xe0000000) | |
271 | return 1; | |
272 | } | |
273 | ||
274 | /* Should never happen. */ | |
8a3fe4f8 | 275 | warning (_("Unable to find branch in parameter relocation stub.")); |
abc485a1 RC |
276 | return 0; |
277 | } | |
278 | ||
279 | /* Unknown stub type. For now, just return zero. */ | |
280 | return 0; | |
281 | ||
282 | } | |
283 | ||
284 | /* Figure out if PC is in a trampoline, and if so find out where | |
285 | the trampoline will jump to. If not in a trampoline, return zero. | |
286 | ||
287 | Simple code examination probably is not a good idea since the code | |
288 | sequences in trampolines can also appear in user code. | |
289 | ||
290 | We use unwinds and information from the minimal symbol table to | |
291 | determine when we're in a trampoline. This won't work for ELF | |
292 | (yet) since it doesn't create stub unwind entries. Whether or | |
293 | not ELF will create stub unwinds or normal unwinds for linker | |
294 | stubs is still being debated. | |
295 | ||
296 | This should handle simple calls through dyncall or sr4export, | |
297 | long calls, argument relocation stubs, and dyncall/sr4export | |
298 | calling an argument relocation stub. It even handles some stubs | |
299 | used in dynamic executables. */ | |
300 | ||
301 | static CORE_ADDR | |
302 | hppa_hpux_skip_trampoline_code (CORE_ADDR pc) | |
303 | { | |
304 | long orig_pc = pc; | |
305 | long prev_inst, curr_inst, loc; | |
abc485a1 RC |
306 | struct minimal_symbol *msym; |
307 | struct unwind_table_entry *u; | |
308 | ||
abc485a1 RC |
309 | /* Addresses passed to dyncall may *NOT* be the actual address |
310 | of the function. So we may have to do something special. */ | |
3388d7ff | 311 | if (pc == hppa_symbol_address("$$dyncall")) |
abc485a1 RC |
312 | { |
313 | pc = (CORE_ADDR) read_register (22); | |
314 | ||
315 | /* If bit 30 (counting from the left) is on, then pc is the address of | |
316 | the PLT entry for this function, not the address of the function | |
317 | itself. Bit 31 has meaning too, but only for MPE. */ | |
318 | if (pc & 0x2) | |
319 | pc = (CORE_ADDR) read_memory_integer (pc & ~0x3, TARGET_PTR_BIT / 8); | |
320 | } | |
3388d7ff | 321 | if (pc == hppa_symbol_address("$$dyncall_external")) |
abc485a1 RC |
322 | { |
323 | pc = (CORE_ADDR) read_register (22); | |
324 | pc = (CORE_ADDR) read_memory_integer (pc & ~0x3, TARGET_PTR_BIT / 8); | |
325 | } | |
3388d7ff | 326 | else if (pc == hppa_symbol_address("_sr4export")) |
abc485a1 RC |
327 | pc = (CORE_ADDR) (read_register (22)); |
328 | ||
329 | /* Get the unwind descriptor corresponding to PC, return zero | |
330 | if no unwind was found. */ | |
331 | u = find_unwind_entry (pc); | |
332 | if (!u) | |
333 | return 0; | |
334 | ||
335 | /* If this isn't a linker stub, then return now. */ | |
336 | /* elz: attention here! (FIXME) because of a compiler/linker | |
337 | error, some stubs which should have a non zero stub_unwind.stub_type | |
338 | have unfortunately a value of zero. So this function would return here | |
339 | as if we were not in a trampoline. To fix this, we go look at the partial | |
340 | symbol information, which reports this guy as a stub. | |
341 | (FIXME): Unfortunately, we are not that lucky: it turns out that the | |
342 | partial symbol information is also wrong sometimes. This is because | |
343 | when it is entered (somread.c::som_symtab_read()) it can happen that | |
344 | if the type of the symbol (from the som) is Entry, and the symbol is | |
345 | in a shared library, then it can also be a trampoline. This would | |
346 | be OK, except that I believe the way they decide if we are ina shared library | |
347 | does not work. SOOOO..., even if we have a regular function w/o trampolines | |
348 | its minimal symbol can be assigned type mst_solib_trampoline. | |
349 | Also, if we find that the symbol is a real stub, then we fix the unwind | |
350 | descriptor, and define the stub type to be EXPORT. | |
351 | Hopefully this is correct most of the times. */ | |
352 | if (u->stub_unwind.stub_type == 0) | |
353 | { | |
354 | ||
355 | /* elz: NOTE (FIXME!) once the problem with the unwind information is fixed | |
356 | we can delete all the code which appears between the lines */ | |
357 | /*--------------------------------------------------------------------------*/ | |
358 | msym = lookup_minimal_symbol_by_pc (pc); | |
359 | ||
360 | if (msym == NULL || MSYMBOL_TYPE (msym) != mst_solib_trampoline) | |
361 | return orig_pc == pc ? 0 : pc & ~0x3; | |
362 | ||
363 | else if (msym != NULL && MSYMBOL_TYPE (msym) == mst_solib_trampoline) | |
364 | { | |
365 | struct objfile *objfile; | |
366 | struct minimal_symbol *msymbol; | |
367 | int function_found = 0; | |
368 | ||
369 | /* go look if there is another minimal symbol with the same name as | |
370 | this one, but with type mst_text. This would happen if the msym | |
371 | is an actual trampoline, in which case there would be another | |
372 | symbol with the same name corresponding to the real function */ | |
373 | ||
374 | ALL_MSYMBOLS (objfile, msymbol) | |
375 | { | |
376 | if (MSYMBOL_TYPE (msymbol) == mst_text | |
377 | && DEPRECATED_STREQ (DEPRECATED_SYMBOL_NAME (msymbol), DEPRECATED_SYMBOL_NAME (msym))) | |
378 | { | |
379 | function_found = 1; | |
380 | break; | |
381 | } | |
382 | } | |
383 | ||
384 | if (function_found) | |
385 | /* the type of msym is correct (mst_solib_trampoline), but | |
386 | the unwind info is wrong, so set it to the correct value */ | |
387 | u->stub_unwind.stub_type = EXPORT; | |
388 | else | |
389 | /* the stub type info in the unwind is correct (this is not a | |
390 | trampoline), but the msym type information is wrong, it | |
391 | should be mst_text. So we need to fix the msym, and also | |
392 | get out of this function */ | |
393 | { | |
394 | MSYMBOL_TYPE (msym) = mst_text; | |
395 | return orig_pc == pc ? 0 : pc & ~0x3; | |
396 | } | |
397 | } | |
398 | ||
399 | /*--------------------------------------------------------------------------*/ | |
400 | } | |
401 | ||
402 | /* It's a stub. Search for a branch and figure out where it goes. | |
403 | Note we have to handle multi insn branch sequences like ldil;ble. | |
404 | Most (all?) other branches can be determined by examining the contents | |
405 | of certain registers and the stack. */ | |
406 | ||
407 | loc = pc; | |
408 | curr_inst = 0; | |
409 | prev_inst = 0; | |
410 | while (1) | |
411 | { | |
412 | /* Make sure we haven't walked outside the range of this stub. */ | |
413 | if (u != find_unwind_entry (loc)) | |
414 | { | |
8a3fe4f8 | 415 | warning (_("Unable to find branch in linker stub")); |
abc485a1 RC |
416 | return orig_pc == pc ? 0 : pc & ~0x3; |
417 | } | |
418 | ||
419 | prev_inst = curr_inst; | |
420 | curr_inst = read_memory_integer (loc, 4); | |
421 | ||
422 | /* Does it look like a branch external using %r1? Then it's the | |
423 | branch from the stub to the actual function. */ | |
424 | if ((curr_inst & 0xffe0e000) == 0xe0202000) | |
425 | { | |
426 | /* Yup. See if the previous instruction loaded | |
427 | a value into %r1. If so compute and return the jump address. */ | |
428 | if ((prev_inst & 0xffe00000) == 0x20200000) | |
429 | return (hppa_extract_21 (prev_inst) + hppa_extract_17 (curr_inst)) & ~0x3; | |
430 | else | |
431 | { | |
8a3fe4f8 | 432 | warning (_("Unable to find ldil X,%%r1 before ble Y(%%sr4,%%r1).")); |
abc485a1 RC |
433 | return orig_pc == pc ? 0 : pc & ~0x3; |
434 | } | |
435 | } | |
436 | ||
437 | /* Does it look like a be 0(sr0,%r21)? OR | |
438 | Does it look like a be, n 0(sr0,%r21)? OR | |
439 | Does it look like a bve (r21)? (this is on PA2.0) | |
440 | Does it look like a bve, n(r21)? (this is also on PA2.0) | |
441 | That's the branch from an | |
442 | import stub to an export stub. | |
443 | ||
444 | It is impossible to determine the target of the branch via | |
445 | simple examination of instructions and/or data (consider | |
446 | that the address in the plabel may be the address of the | |
447 | bind-on-reference routine in the dynamic loader). | |
448 | ||
449 | So we have try an alternative approach. | |
450 | ||
451 | Get the name of the symbol at our current location; it should | |
452 | be a stub symbol with the same name as the symbol in the | |
453 | shared library. | |
454 | ||
455 | Then lookup a minimal symbol with the same name; we should | |
456 | get the minimal symbol for the target routine in the shared | |
457 | library as those take precedence of import/export stubs. */ | |
458 | if ((curr_inst == 0xe2a00000) || | |
459 | (curr_inst == 0xe2a00002) || | |
460 | (curr_inst == 0xeaa0d000) || | |
461 | (curr_inst == 0xeaa0d002)) | |
462 | { | |
463 | struct minimal_symbol *stubsym, *libsym; | |
464 | ||
465 | stubsym = lookup_minimal_symbol_by_pc (loc); | |
466 | if (stubsym == NULL) | |
467 | { | |
8a3fe4f8 | 468 | warning (_("Unable to find symbol for 0x%lx"), loc); |
abc485a1 RC |
469 | return orig_pc == pc ? 0 : pc & ~0x3; |
470 | } | |
471 | ||
472 | libsym = lookup_minimal_symbol (DEPRECATED_SYMBOL_NAME (stubsym), NULL, NULL); | |
473 | if (libsym == NULL) | |
474 | { | |
8a3fe4f8 | 475 | warning (_("Unable to find library symbol for %s."), |
abc485a1 RC |
476 | DEPRECATED_SYMBOL_NAME (stubsym)); |
477 | return orig_pc == pc ? 0 : pc & ~0x3; | |
478 | } | |
479 | ||
480 | return SYMBOL_VALUE (libsym); | |
481 | } | |
482 | ||
483 | /* Does it look like bl X,%rp or bl X,%r0? Another way to do a | |
484 | branch from the stub to the actual function. */ | |
485 | /*elz */ | |
486 | else if ((curr_inst & 0xffe0e000) == 0xe8400000 | |
487 | || (curr_inst & 0xffe0e000) == 0xe8000000 | |
488 | || (curr_inst & 0xffe0e000) == 0xe800A000) | |
489 | return (loc + hppa_extract_17 (curr_inst) + 8) & ~0x3; | |
490 | ||
491 | /* Does it look like bv (rp)? Note this depends on the | |
492 | current stack pointer being the same as the stack | |
493 | pointer in the stub itself! This is a branch on from the | |
494 | stub back to the original caller. */ | |
495 | /*else if ((curr_inst & 0xffe0e000) == 0xe840c000) */ | |
496 | else if ((curr_inst & 0xffe0f000) == 0xe840c000) | |
497 | { | |
498 | /* Yup. See if the previous instruction loaded | |
499 | rp from sp - 8. */ | |
500 | if (prev_inst == 0x4bc23ff1) | |
501 | return (read_memory_integer | |
502 | (read_register (HPPA_SP_REGNUM) - 8, 4)) & ~0x3; | |
503 | else | |
504 | { | |
8a3fe4f8 | 505 | warning (_("Unable to find restore of %%rp before bv (%%rp).")); |
abc485a1 RC |
506 | return orig_pc == pc ? 0 : pc & ~0x3; |
507 | } | |
508 | } | |
509 | ||
510 | /* elz: added this case to capture the new instruction | |
511 | at the end of the return part of an export stub used by | |
512 | the PA2.0: BVE, n (rp) */ | |
513 | else if ((curr_inst & 0xffe0f000) == 0xe840d000) | |
514 | { | |
515 | return (read_memory_integer | |
516 | (read_register (HPPA_SP_REGNUM) - 24, TARGET_PTR_BIT / 8)) & ~0x3; | |
517 | } | |
518 | ||
519 | /* What about be,n 0(sr0,%rp)? It's just another way we return to | |
520 | the original caller from the stub. Used in dynamic executables. */ | |
521 | else if (curr_inst == 0xe0400002) | |
522 | { | |
523 | /* The value we jump to is sitting in sp - 24. But that's | |
524 | loaded several instructions before the be instruction. | |
525 | I guess we could check for the previous instruction being | |
526 | mtsp %r1,%sr0 if we want to do sanity checking. */ | |
527 | return (read_memory_integer | |
528 | (read_register (HPPA_SP_REGNUM) - 24, TARGET_PTR_BIT / 8)) & ~0x3; | |
529 | } | |
530 | ||
531 | /* Haven't found the branch yet, but we're still in the stub. | |
532 | Keep looking. */ | |
533 | loc += 4; | |
534 | } | |
535 | } | |
536 | ||
6d350bb5 UW |
537 | static void |
538 | hppa_skip_permanent_breakpoint (struct regcache *regcache) | |
5aac166f RC |
539 | { |
540 | /* To step over a breakpoint instruction on the PA takes some | |
541 | fiddling with the instruction address queue. | |
542 | ||
543 | When we stop at a breakpoint, the IA queue front (the instruction | |
544 | we're executing now) points at the breakpoint instruction, and | |
545 | the IA queue back (the next instruction to execute) points to | |
546 | whatever instruction we would execute after the breakpoint, if it | |
547 | were an ordinary instruction. This is the case even if the | |
548 | breakpoint is in the delay slot of a branch instruction. | |
549 | ||
550 | Clearly, to step past the breakpoint, we need to set the queue | |
551 | front to the back. But what do we put in the back? What | |
552 | instruction comes after that one? Because of the branch delay | |
553 | slot, the next insn is always at the back + 4. */ | |
5aac166f | 554 | |
6d350bb5 UW |
555 | ULONGEST pcoq_tail, pcsq_tail; |
556 | regcache_cooked_read_unsigned (regcache, HPPA_PCOQ_TAIL_REGNUM, &pcoq_tail); | |
557 | regcache_cooked_read_unsigned (regcache, HPPA_PCSQ_TAIL_REGNUM, &pcsq_tail); | |
558 | ||
559 | regcache_cooked_write_unsigned (regcache, HPPA_PCOQ_HEAD_REGNUM, pcoq_tail); | |
560 | regcache_cooked_write_unsigned (regcache, HPPA_PCSQ_HEAD_REGNUM, pcsq_tail); | |
561 | ||
562 | regcache_cooked_write_unsigned (regcache, HPPA_PCOQ_TAIL_REGNUM, pcoq_tail + 4); | |
5aac166f RC |
563 | /* We can leave the tail's space the same, since there's no jump. */ |
564 | } | |
abc485a1 | 565 | |
4c02c60c | 566 | |
43613416 RC |
567 | /* Signal frames. */ |
568 | struct hppa_hpux_sigtramp_unwind_cache | |
569 | { | |
570 | CORE_ADDR base; | |
571 | struct trad_frame_saved_reg *saved_regs; | |
572 | }; | |
573 | ||
574 | static int hppa_hpux_tramp_reg[] = { | |
575 | HPPA_SAR_REGNUM, | |
576 | HPPA_PCOQ_HEAD_REGNUM, | |
577 | HPPA_PCSQ_HEAD_REGNUM, | |
578 | HPPA_PCOQ_TAIL_REGNUM, | |
579 | HPPA_PCSQ_TAIL_REGNUM, | |
580 | HPPA_EIEM_REGNUM, | |
581 | HPPA_IIR_REGNUM, | |
582 | HPPA_ISR_REGNUM, | |
583 | HPPA_IOR_REGNUM, | |
584 | HPPA_IPSW_REGNUM, | |
585 | -1, | |
586 | HPPA_SR4_REGNUM, | |
587 | HPPA_SR4_REGNUM + 1, | |
588 | HPPA_SR4_REGNUM + 2, | |
589 | HPPA_SR4_REGNUM + 3, | |
590 | HPPA_SR4_REGNUM + 4, | |
591 | HPPA_SR4_REGNUM + 5, | |
592 | HPPA_SR4_REGNUM + 6, | |
593 | HPPA_SR4_REGNUM + 7, | |
594 | HPPA_RCR_REGNUM, | |
595 | HPPA_PID0_REGNUM, | |
596 | HPPA_PID1_REGNUM, | |
597 | HPPA_CCR_REGNUM, | |
598 | HPPA_PID2_REGNUM, | |
599 | HPPA_PID3_REGNUM, | |
600 | HPPA_TR0_REGNUM, | |
601 | HPPA_TR0_REGNUM + 1, | |
602 | HPPA_TR0_REGNUM + 2, | |
603 | HPPA_CR27_REGNUM | |
604 | }; | |
605 | ||
606 | static struct hppa_hpux_sigtramp_unwind_cache * | |
607 | hppa_hpux_sigtramp_frame_unwind_cache (struct frame_info *next_frame, | |
608 | void **this_cache) | |
609 | ||
610 | { | |
611 | struct gdbarch *gdbarch = get_frame_arch (next_frame); | |
612 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
613 | struct hppa_hpux_sigtramp_unwind_cache *info; | |
614 | unsigned int flag; | |
27b08a0c RC |
615 | CORE_ADDR sp, scptr, off; |
616 | int i, incr, szoff; | |
43613416 RC |
617 | |
618 | if (*this_cache) | |
619 | return *this_cache; | |
620 | ||
621 | info = FRAME_OBSTACK_ZALLOC (struct hppa_hpux_sigtramp_unwind_cache); | |
622 | *this_cache = info; | |
623 | info->saved_regs = trad_frame_alloc_saved_regs (next_frame); | |
624 | ||
625 | sp = frame_unwind_register_unsigned (next_frame, HPPA_SP_REGNUM); | |
626 | ||
27b08a0c RC |
627 | if (IS_32BIT_TARGET (gdbarch)) |
628 | scptr = sp - 1352; | |
629 | else | |
630 | scptr = sp - 1520; | |
631 | ||
43613416 RC |
632 | off = scptr; |
633 | ||
634 | /* See /usr/include/machine/save_state.h for the structure of the save_state_t | |
635 | structure. */ | |
636 | ||
27b08a0c RC |
637 | flag = read_memory_unsigned_integer(scptr + HPPA_HPUX_SS_FLAGS_OFFSET, 4); |
638 | ||
639 | if (!(flag & HPPA_HPUX_SS_WIDEREGS)) | |
43613416 RC |
640 | { |
641 | /* Narrow registers. */ | |
27b08a0c | 642 | off = scptr + HPPA_HPUX_SS_NARROW_OFFSET; |
43613416 RC |
643 | incr = 4; |
644 | szoff = 0; | |
645 | } | |
646 | else | |
647 | { | |
648 | /* Wide registers. */ | |
27b08a0c | 649 | off = scptr + HPPA_HPUX_SS_WIDE_OFFSET + 8; |
43613416 RC |
650 | incr = 8; |
651 | szoff = (tdep->bytes_per_address == 4 ? 4 : 0); | |
652 | } | |
653 | ||
654 | for (i = 1; i < 32; i++) | |
655 | { | |
656 | info->saved_regs[HPPA_R0_REGNUM + i].addr = off + szoff; | |
657 | off += incr; | |
658 | } | |
659 | ||
01926a69 | 660 | for (i = 0; i < ARRAY_SIZE (hppa_hpux_tramp_reg); i++) |
43613416 RC |
661 | { |
662 | if (hppa_hpux_tramp_reg[i] > 0) | |
663 | info->saved_regs[hppa_hpux_tramp_reg[i]].addr = off + szoff; | |
27b08a0c | 664 | |
43613416 RC |
665 | off += incr; |
666 | } | |
667 | ||
668 | /* TODO: fp regs */ | |
669 | ||
670 | info->base = frame_unwind_register_unsigned (next_frame, HPPA_SP_REGNUM); | |
671 | ||
672 | return info; | |
673 | } | |
674 | ||
675 | static void | |
676 | hppa_hpux_sigtramp_frame_this_id (struct frame_info *next_frame, | |
677 | void **this_prologue_cache, | |
678 | struct frame_id *this_id) | |
679 | { | |
680 | struct hppa_hpux_sigtramp_unwind_cache *info | |
681 | = hppa_hpux_sigtramp_frame_unwind_cache (next_frame, this_prologue_cache); | |
682 | *this_id = frame_id_build (info->base, frame_pc_unwind (next_frame)); | |
683 | } | |
684 | ||
685 | static void | |
686 | hppa_hpux_sigtramp_frame_prev_register (struct frame_info *next_frame, | |
a7aad9aa MK |
687 | void **this_prologue_cache, |
688 | int regnum, int *optimizedp, | |
689 | enum lval_type *lvalp, | |
690 | CORE_ADDR *addrp, | |
691 | int *realnump, gdb_byte *valuep) | |
43613416 RC |
692 | { |
693 | struct hppa_hpux_sigtramp_unwind_cache *info | |
694 | = hppa_hpux_sigtramp_frame_unwind_cache (next_frame, this_prologue_cache); | |
695 | hppa_frame_prev_register_helper (next_frame, info->saved_regs, regnum, | |
696 | optimizedp, lvalp, addrp, realnump, valuep); | |
697 | } | |
698 | ||
699 | static const struct frame_unwind hppa_hpux_sigtramp_frame_unwind = { | |
700 | SIGTRAMP_FRAME, | |
701 | hppa_hpux_sigtramp_frame_this_id, | |
702 | hppa_hpux_sigtramp_frame_prev_register | |
703 | }; | |
704 | ||
705 | static const struct frame_unwind * | |
706 | hppa_hpux_sigtramp_unwind_sniffer (struct frame_info *next_frame) | |
707 | { | |
765697c9 | 708 | struct unwind_table_entry *u; |
43613416 | 709 | CORE_ADDR pc = frame_pc_unwind (next_frame); |
43613416 | 710 | |
765697c9 | 711 | u = find_unwind_entry (pc); |
43613416 | 712 | |
a717134b MK |
713 | /* If this is an export stub, try to get the unwind descriptor for |
714 | the actual function itself. */ | |
715 | if (u && u->stub_unwind.stub_type == EXPORT) | |
716 | { | |
717 | gdb_byte buf[HPPA_INSN_SIZE]; | |
718 | unsigned long insn; | |
719 | ||
720 | if (!safe_frame_unwind_memory (next_frame, u->region_start, | |
721 | buf, sizeof buf)) | |
722 | return NULL; | |
723 | ||
724 | insn = extract_unsigned_integer (buf, sizeof buf); | |
725 | if ((insn & 0xffe0e000) == 0xe8400000) | |
726 | u = find_unwind_entry(u->region_start + hppa_extract_17 (insn) + 8); | |
727 | } | |
728 | ||
765697c9 | 729 | if (u && u->HP_UX_interrupt_marker) |
43613416 RC |
730 | return &hppa_hpux_sigtramp_frame_unwind; |
731 | ||
732 | return NULL; | |
733 | } | |
734 | ||
c268433a | 735 | static CORE_ADDR |
77d18ded | 736 | hppa32_hpux_find_global_pointer (struct value *function) |
c268433a RC |
737 | { |
738 | CORE_ADDR faddr; | |
739 | ||
740 | faddr = value_as_address (function); | |
741 | ||
742 | /* Is this a plabel? If so, dereference it to get the gp value. */ | |
743 | if (faddr & 2) | |
744 | { | |
745 | int status; | |
746 | char buf[4]; | |
747 | ||
748 | faddr &= ~3; | |
749 | ||
750 | status = target_read_memory (faddr + 4, buf, sizeof (buf)); | |
751 | if (status == 0) | |
752 | return extract_unsigned_integer (buf, sizeof (buf)); | |
753 | } | |
754 | ||
61aff869 | 755 | return gdbarch_tdep (current_gdbarch)->solib_get_got_by_pc (faddr); |
c268433a RC |
756 | } |
757 | ||
758 | static CORE_ADDR | |
77d18ded | 759 | hppa64_hpux_find_global_pointer (struct value *function) |
c268433a | 760 | { |
77d18ded RC |
761 | CORE_ADDR faddr; |
762 | char buf[32]; | |
763 | ||
764 | faddr = value_as_address (function); | |
765 | ||
766 | if (in_opd_section (faddr)) | |
767 | { | |
768 | target_read_memory (faddr, buf, sizeof (buf)); | |
769 | return extract_unsigned_integer (&buf[24], 8); | |
770 | } | |
771 | else | |
c268433a | 772 | { |
77d18ded RC |
773 | return gdbarch_tdep (current_gdbarch)->solib_get_got_by_pc (faddr); |
774 | } | |
775 | } | |
776 | ||
777 | static unsigned int ldsid_pattern[] = { | |
778 | 0x000010a0, /* ldsid (rX),rY */ | |
779 | 0x00001820, /* mtsp rY,sr0 */ | |
780 | 0xe0000000 /* be,n (sr0,rX) */ | |
781 | }; | |
782 | ||
783 | static CORE_ADDR | |
784 | hppa_hpux_search_pattern (CORE_ADDR start, CORE_ADDR end, | |
785 | unsigned int *patterns, int count) | |
786 | { | |
d275c051 MK |
787 | int num_insns = (end - start + HPPA_INSN_SIZE) / HPPA_INSN_SIZE; |
788 | unsigned int *insns; | |
789 | gdb_byte *buf; | |
77d18ded | 790 | int offset, i; |
77d18ded | 791 | |
d275c051 MK |
792 | buf = alloca (num_insns * HPPA_INSN_SIZE); |
793 | insns = alloca (num_insns * sizeof (unsigned int)); | |
c268433a | 794 | |
d275c051 MK |
795 | read_memory (start, buf, num_insns * HPPA_INSN_SIZE); |
796 | for (i = 0; i < num_insns; i++, buf += HPPA_INSN_SIZE) | |
797 | insns[i] = extract_unsigned_integer (buf, HPPA_INSN_SIZE); | |
c268433a | 798 | |
d275c051 | 799 | for (offset = 0; offset <= num_insns - count; offset++) |
77d18ded RC |
800 | { |
801 | for (i = 0; i < count; i++) | |
c268433a | 802 | { |
d275c051 | 803 | if ((insns[offset + i] & patterns[i]) != patterns[i]) |
77d18ded RC |
804 | break; |
805 | } | |
806 | if (i == count) | |
807 | break; | |
808 | } | |
d275c051 MK |
809 | |
810 | if (offset <= num_insns - count) | |
811 | return start + offset * HPPA_INSN_SIZE; | |
77d18ded RC |
812 | else |
813 | return 0; | |
814 | } | |
c268433a | 815 | |
77d18ded RC |
816 | static CORE_ADDR |
817 | hppa32_hpux_search_dummy_call_sequence (struct gdbarch *gdbarch, CORE_ADDR pc, | |
818 | int *argreg) | |
819 | { | |
820 | struct objfile *obj; | |
821 | struct obj_section *sec; | |
822 | struct hppa_objfile_private *priv; | |
823 | struct frame_info *frame; | |
824 | struct unwind_table_entry *u; | |
825 | CORE_ADDR addr, rp; | |
826 | char buf[4]; | |
827 | unsigned int insn; | |
828 | ||
829 | sec = find_pc_section (pc); | |
830 | obj = sec->objfile; | |
831 | priv = objfile_data (obj, hppa_objfile_priv_data); | |
832 | ||
833 | if (!priv) | |
834 | priv = hppa_init_objfile_priv_data (obj); | |
835 | if (!priv) | |
8a3fe4f8 | 836 | error (_("Internal error creating objfile private data.")); |
77d18ded RC |
837 | |
838 | /* Use the cached value if we have one. */ | |
839 | if (priv->dummy_call_sequence_addr != 0) | |
840 | { | |
841 | *argreg = priv->dummy_call_sequence_reg; | |
842 | return priv->dummy_call_sequence_addr; | |
843 | } | |
c268433a | 844 | |
77d18ded RC |
845 | /* First try a heuristic; if we are in a shared library call, our return |
846 | pointer is likely to point at an export stub. */ | |
847 | frame = get_current_frame (); | |
848 | rp = frame_unwind_register_unsigned (frame, 2); | |
849 | u = find_unwind_entry (rp); | |
850 | if (u && u->stub_unwind.stub_type == EXPORT) | |
851 | { | |
852 | addr = hppa_hpux_search_pattern (u->region_start, u->region_end, | |
853 | ldsid_pattern, | |
854 | ARRAY_SIZE (ldsid_pattern)); | |
855 | if (addr) | |
856 | goto found_pattern; | |
857 | } | |
c268433a | 858 | |
77d18ded RC |
859 | /* Next thing to try is to look for an export stub. */ |
860 | if (priv->unwind_info) | |
861 | { | |
862 | int i; | |
c268433a | 863 | |
77d18ded RC |
864 | for (i = 0; i < priv->unwind_info->last; i++) |
865 | { | |
866 | struct unwind_table_entry *u; | |
867 | u = &priv->unwind_info->table[i]; | |
868 | if (u->stub_unwind.stub_type == EXPORT) | |
869 | { | |
870 | addr = hppa_hpux_search_pattern (u->region_start, u->region_end, | |
871 | ldsid_pattern, | |
872 | ARRAY_SIZE (ldsid_pattern)); | |
873 | if (addr) | |
874 | { | |
875 | goto found_pattern; | |
876 | } | |
c268433a RC |
877 | } |
878 | } | |
77d18ded | 879 | } |
c268433a | 880 | |
77d18ded RC |
881 | /* Finally, if this is the main executable, try to locate a sequence |
882 | from noshlibs */ | |
883 | addr = hppa_symbol_address ("noshlibs"); | |
884 | sec = find_pc_section (addr); | |
885 | ||
886 | if (sec && sec->objfile == obj) | |
887 | { | |
888 | CORE_ADDR start, end; | |
889 | ||
890 | find_pc_partial_function (addr, NULL, &start, &end); | |
891 | if (start != 0 && end != 0) | |
c268433a | 892 | { |
77d18ded RC |
893 | addr = hppa_hpux_search_pattern (start, end, ldsid_pattern, |
894 | ARRAY_SIZE (ldsid_pattern)); | |
895 | if (addr) | |
896 | goto found_pattern; | |
c268433a | 897 | } |
77d18ded RC |
898 | } |
899 | ||
900 | /* Can't find a suitable sequence. */ | |
901 | return 0; | |
902 | ||
903 | found_pattern: | |
904 | target_read_memory (addr, buf, sizeof (buf)); | |
905 | insn = extract_unsigned_integer (buf, sizeof (buf)); | |
906 | priv->dummy_call_sequence_addr = addr; | |
907 | priv->dummy_call_sequence_reg = (insn >> 21) & 0x1f; | |
908 | ||
909 | *argreg = priv->dummy_call_sequence_reg; | |
910 | return priv->dummy_call_sequence_addr; | |
911 | } | |
912 | ||
913 | static CORE_ADDR | |
914 | hppa64_hpux_search_dummy_call_sequence (struct gdbarch *gdbarch, CORE_ADDR pc, | |
915 | int *argreg) | |
916 | { | |
917 | struct objfile *obj; | |
918 | struct obj_section *sec; | |
919 | struct hppa_objfile_private *priv; | |
920 | CORE_ADDR addr; | |
921 | struct minimal_symbol *msym; | |
922 | int i; | |
923 | ||
924 | sec = find_pc_section (pc); | |
925 | obj = sec->objfile; | |
926 | priv = objfile_data (obj, hppa_objfile_priv_data); | |
927 | ||
928 | if (!priv) | |
929 | priv = hppa_init_objfile_priv_data (obj); | |
930 | if (!priv) | |
8a3fe4f8 | 931 | error (_("Internal error creating objfile private data.")); |
77d18ded RC |
932 | |
933 | /* Use the cached value if we have one. */ | |
934 | if (priv->dummy_call_sequence_addr != 0) | |
935 | { | |
936 | *argreg = priv->dummy_call_sequence_reg; | |
937 | return priv->dummy_call_sequence_addr; | |
938 | } | |
939 | ||
940 | /* FIXME: Without stub unwind information, locating a suitable sequence is | |
941 | fairly difficult. For now, we implement a very naive and inefficient | |
942 | scheme; try to read in blocks of code, and look for a "bve,n (rp)" | |
943 | instruction. These are likely to occur at the end of functions, so | |
944 | we only look at the last two instructions of each function. */ | |
945 | for (i = 0, msym = obj->msymbols; i < obj->minimal_symbol_count; i++, msym++) | |
946 | { | |
947 | CORE_ADDR begin, end; | |
948 | char *name; | |
d275c051 | 949 | gdb_byte buf[2 * HPPA_INSN_SIZE]; |
77d18ded RC |
950 | int offset; |
951 | ||
952 | find_pc_partial_function (SYMBOL_VALUE_ADDRESS (msym), &name, | |
953 | &begin, &end); | |
954 | ||
81092a3e | 955 | if (name == NULL || begin == 0 || end == 0) |
77d18ded RC |
956 | continue; |
957 | ||
d275c051 | 958 | if (target_read_memory (end - sizeof (buf), buf, sizeof (buf)) == 0) |
c268433a | 959 | { |
d275c051 | 960 | for (offset = 0; offset < sizeof (buf); offset++) |
77d18ded RC |
961 | { |
962 | unsigned int insn; | |
963 | ||
d275c051 | 964 | insn = extract_unsigned_integer (buf + offset, HPPA_INSN_SIZE); |
77d18ded RC |
965 | if (insn == 0xe840d002) /* bve,n (rp) */ |
966 | { | |
d275c051 | 967 | addr = (end - sizeof (buf)) + offset; |
77d18ded RC |
968 | goto found_pattern; |
969 | } | |
970 | } | |
971 | } | |
972 | } | |
973 | ||
974 | /* Can't find a suitable sequence. */ | |
975 | return 0; | |
976 | ||
977 | found_pattern: | |
978 | priv->dummy_call_sequence_addr = addr; | |
979 | /* Right now we only look for a "bve,l (rp)" sequence, so the register is | |
980 | always HPPA_RP_REGNUM. */ | |
981 | priv->dummy_call_sequence_reg = HPPA_RP_REGNUM; | |
982 | ||
983 | *argreg = priv->dummy_call_sequence_reg; | |
984 | return priv->dummy_call_sequence_addr; | |
985 | } | |
986 | ||
987 | static CORE_ADDR | |
988 | hppa_hpux_find_import_stub_for_addr (CORE_ADDR funcaddr) | |
989 | { | |
990 | struct objfile *objfile; | |
991 | struct minimal_symbol *funsym, *stubsym; | |
992 | CORE_ADDR stubaddr; | |
993 | ||
994 | funsym = lookup_minimal_symbol_by_pc (funcaddr); | |
995 | stubaddr = 0; | |
996 | ||
997 | ALL_OBJFILES (objfile) | |
998 | { | |
999 | stubsym = lookup_minimal_symbol_solib_trampoline | |
1000 | (SYMBOL_LINKAGE_NAME (funsym), objfile); | |
1001 | ||
1002 | if (stubsym) | |
1003 | { | |
1004 | struct unwind_table_entry *u; | |
1005 | ||
1006 | u = find_unwind_entry (SYMBOL_VALUE (stubsym)); | |
1007 | if (u == NULL | |
1008 | || (u->stub_unwind.stub_type != IMPORT | |
1009 | && u->stub_unwind.stub_type != IMPORT_SHLIB)) | |
1010 | continue; | |
1011 | ||
1012 | stubaddr = SYMBOL_VALUE (stubsym); | |
1013 | ||
1014 | /* If we found an IMPORT stub, then we can stop searching; | |
1015 | if we found an IMPORT_SHLIB, we want to continue the search | |
1016 | in the hopes that we will find an IMPORT stub. */ | |
1017 | if (u->stub_unwind.stub_type == IMPORT) | |
1018 | break; | |
1019 | } | |
1020 | } | |
1021 | ||
1022 | return stubaddr; | |
1023 | } | |
1024 | ||
1025 | static int | |
1026 | hppa_hpux_sr_for_addr (CORE_ADDR addr) | |
1027 | { | |
1028 | int sr; | |
1029 | /* The space register to use is encoded in the top 2 bits of the address. */ | |
1030 | sr = addr >> (gdbarch_tdep (current_gdbarch)->bytes_per_address * 8 - 2); | |
1031 | return sr + 4; | |
1032 | } | |
1033 | ||
1034 | static CORE_ADDR | |
1035 | hppa_hpux_find_dummy_bpaddr (CORE_ADDR addr) | |
1036 | { | |
1037 | /* In order for us to restore the space register to its starting state, | |
1038 | we need the dummy trampoline to return to the an instruction address in | |
1039 | the same space as where we started the call. We used to place the | |
1040 | breakpoint near the current pc, however, this breaks nested dummy calls | |
1041 | as the nested call will hit the breakpoint address and terminate | |
1042 | prematurely. Instead, we try to look for an address in the same space to | |
1043 | put the breakpoint. | |
1044 | ||
1045 | This is similar in spirit to putting the breakpoint at the "entry point" | |
1046 | of an executable. */ | |
1047 | ||
1048 | struct obj_section *sec; | |
1049 | struct unwind_table_entry *u; | |
1050 | struct minimal_symbol *msym; | |
1051 | CORE_ADDR func; | |
1052 | int i; | |
1053 | ||
1054 | sec = find_pc_section (addr); | |
1055 | if (sec) | |
1056 | { | |
1057 | /* First try the lowest address in the section; we can use it as long | |
1058 | as it is "regular" code (i.e. not a stub) */ | |
1059 | u = find_unwind_entry (sec->addr); | |
1060 | if (!u || u->stub_unwind.stub_type == 0) | |
1061 | return sec->addr; | |
1062 | ||
1063 | /* Otherwise, we need to find a symbol for a regular function. We | |
1064 | do this by walking the list of msymbols in the objfile. The symbol | |
1065 | we find should not be the same as the function that was passed in. */ | |
1066 | ||
1067 | /* FIXME: this is broken, because we can find a function that will be | |
1068 | called by the dummy call target function, which will still not | |
1069 | work. */ | |
1070 | ||
1071 | find_pc_partial_function (addr, NULL, &func, NULL); | |
1072 | for (i = 0, msym = sec->objfile->msymbols; | |
1073 | i < sec->objfile->minimal_symbol_count; | |
1074 | i++, msym++) | |
1075 | { | |
1076 | u = find_unwind_entry (SYMBOL_VALUE_ADDRESS (msym)); | |
1077 | if (func != SYMBOL_VALUE_ADDRESS (msym) | |
1078 | && (!u || u->stub_unwind.stub_type == 0)) | |
1079 | return SYMBOL_VALUE_ADDRESS (msym); | |
c268433a | 1080 | } |
77d18ded | 1081 | } |
c268433a | 1082 | |
8a3fe4f8 AC |
1083 | warning (_("Cannot find suitable address to place dummy breakpoint; nested " |
1084 | "calls may fail.")); | |
77d18ded RC |
1085 | return addr - 4; |
1086 | } | |
1087 | ||
1088 | static CORE_ADDR | |
1089 | hppa_hpux_push_dummy_code (struct gdbarch *gdbarch, CORE_ADDR sp, | |
1090 | CORE_ADDR funcaddr, int using_gcc, | |
1091 | struct value **args, int nargs, | |
1092 | struct type *value_type, | |
1093 | CORE_ADDR *real_pc, CORE_ADDR *bp_addr) | |
1094 | { | |
1095 | CORE_ADDR pc, stubaddr; | |
9846e541 | 1096 | int argreg = 0; |
77d18ded RC |
1097 | |
1098 | pc = read_pc (); | |
1099 | ||
1100 | /* Note: we don't want to pass a function descriptor here; push_dummy_call | |
1101 | fills in the PIC register for us. */ | |
1102 | funcaddr = gdbarch_convert_from_func_ptr_addr (gdbarch, funcaddr, NULL); | |
1103 | ||
1104 | /* The simple case is where we call a function in the same space that we are | |
1105 | currently in; in that case we don't really need to do anything. */ | |
1106 | if (hppa_hpux_sr_for_addr (pc) == hppa_hpux_sr_for_addr (funcaddr)) | |
1107 | { | |
1108 | /* Intraspace call. */ | |
1109 | *bp_addr = hppa_hpux_find_dummy_bpaddr (pc); | |
1110 | *real_pc = funcaddr; | |
1111 | regcache_cooked_write_unsigned (current_regcache, HPPA_RP_REGNUM, *bp_addr); | |
1112 | ||
1113 | return sp; | |
1114 | } | |
1115 | ||
1116 | /* In order to make an interspace call, we need to go through a stub. | |
1117 | gcc supplies an appropriate stub called "__gcc_plt_call", however, if | |
1118 | an application is compiled with HP compilers then this stub is not | |
1119 | available. We used to fallback to "__d_plt_call", however that stub | |
1120 | is not entirely useful for us because it doesn't do an interspace | |
1121 | return back to the caller. Also, on hppa64-hpux, there is no | |
1122 | __gcc_plt_call available. In order to keep the code uniform, we | |
1123 | instead don't use either of these stubs, but instead write our own | |
1124 | onto the stack. | |
1125 | ||
1126 | A problem arises since the stack is located in a different space than | |
1127 | code, so in order to branch to a stack stub, we will need to do an | |
1128 | interspace branch. Previous versions of gdb did this by modifying code | |
1129 | at the current pc and doing single-stepping to set the pcsq. Since this | |
1130 | is highly undesirable, we use a different scheme: | |
1131 | ||
1132 | All we really need to do the branch to the stub is a short instruction | |
1133 | sequence like this: | |
1134 | ||
1135 | PA1.1: | |
1136 | ldsid (rX),r1 | |
1137 | mtsp r1,sr0 | |
1138 | be,n (sr0,rX) | |
1139 | ||
1140 | PA2.0: | |
1141 | bve,n (sr0,rX) | |
1142 | ||
1143 | Instead of writing these sequences ourselves, we can find it in | |
1144 | the instruction stream that belongs to the current space. While this | |
1145 | seems difficult at first, we are actually guaranteed to find the sequences | |
1146 | in several places: | |
1147 | ||
1148 | For 32-bit code: | |
1149 | - in export stubs for shared libraries | |
1150 | - in the "noshlibs" routine in the main module | |
1151 | ||
1152 | For 64-bit code: | |
1153 | - at the end of each "regular" function | |
1154 | ||
1155 | We cache the address of these sequences in the objfile's private data | |
1156 | since these operations can potentially be quite expensive. | |
1157 | ||
1158 | So, what we do is: | |
1159 | - write a stack trampoline | |
1160 | - look for a suitable instruction sequence in the current space | |
1161 | - point the sequence at the trampoline | |
1162 | - set the return address of the trampoline to the current space | |
1163 | (see hppa_hpux_find_dummy_call_bpaddr) | |
1164 | - set the continuing address of the "dummy code" as the sequence. | |
1165 | ||
1166 | */ | |
1167 | ||
1168 | if (IS_32BIT_TARGET (gdbarch)) | |
1169 | { | |
1170 | static unsigned int hppa32_tramp[] = { | |
1171 | 0x0fdf1291, /* stw r31,-8(,sp) */ | |
1172 | 0x02c010a1, /* ldsid (,r22),r1 */ | |
1173 | 0x00011820, /* mtsp r1,sr0 */ | |
1174 | 0xe6c00000, /* be,l 0(sr0,r22),%sr0,%r31 */ | |
1175 | 0x081f0242, /* copy r31,rp */ | |
1176 | 0x0fd11082, /* ldw -8(,sp),rp */ | |
1177 | 0x004010a1, /* ldsid (,rp),r1 */ | |
1178 | 0x00011820, /* mtsp r1,sr0 */ | |
1179 | 0xe0400000, /* be 0(sr0,rp) */ | |
1180 | 0x08000240 /* nop */ | |
1181 | }; | |
1182 | ||
1183 | /* for hppa32, we must call the function through a stub so that on | |
1184 | return it can return to the space of our trampoline. */ | |
1185 | stubaddr = hppa_hpux_find_import_stub_for_addr (funcaddr); | |
1186 | if (stubaddr == 0) | |
8a3fe4f8 AC |
1187 | error (_("Cannot call external function not referenced by application " |
1188 | "(no import stub).\n")); | |
77d18ded RC |
1189 | regcache_cooked_write_unsigned (current_regcache, 22, stubaddr); |
1190 | ||
1191 | write_memory (sp, (char *)&hppa32_tramp, sizeof (hppa32_tramp)); | |
1192 | ||
1193 | *bp_addr = hppa_hpux_find_dummy_bpaddr (pc); | |
c268433a RC |
1194 | regcache_cooked_write_unsigned (current_regcache, 31, *bp_addr); |
1195 | ||
77d18ded RC |
1196 | *real_pc = hppa32_hpux_search_dummy_call_sequence (gdbarch, pc, &argreg); |
1197 | if (*real_pc == 0) | |
8a3fe4f8 | 1198 | error (_("Cannot make interspace call from here.")); |
77d18ded RC |
1199 | |
1200 | regcache_cooked_write_unsigned (current_regcache, argreg, sp); | |
1201 | ||
1202 | sp += sizeof (hppa32_tramp); | |
c268433a RC |
1203 | } |
1204 | else | |
1205 | { | |
77d18ded RC |
1206 | static unsigned int hppa64_tramp[] = { |
1207 | 0xeac0f000, /* bve,l (r22),%r2 */ | |
1208 | 0x0fdf12d1, /* std r31,-8(,sp) */ | |
1209 | 0x0fd110c2, /* ldd -8(,sp),rp */ | |
1210 | 0xe840d002, /* bve,n (rp) */ | |
1211 | 0x08000240 /* nop */ | |
1212 | }; | |
1213 | ||
1214 | /* for hppa64, we don't need to call through a stub; all functions | |
1215 | return via a bve. */ | |
1216 | regcache_cooked_write_unsigned (current_regcache, 22, funcaddr); | |
1217 | write_memory (sp, (char *)&hppa64_tramp, sizeof (hppa64_tramp)); | |
1218 | ||
1219 | *bp_addr = pc - 4; | |
1220 | regcache_cooked_write_unsigned (current_regcache, 31, *bp_addr); | |
c268433a | 1221 | |
77d18ded RC |
1222 | *real_pc = hppa64_hpux_search_dummy_call_sequence (gdbarch, pc, &argreg); |
1223 | if (*real_pc == 0) | |
8a3fe4f8 | 1224 | error (_("Cannot make interspace call from here.")); |
c268433a | 1225 | |
77d18ded | 1226 | regcache_cooked_write_unsigned (current_regcache, argreg, sp); |
c268433a | 1227 | |
77d18ded | 1228 | sp += sizeof (hppa64_tramp); |
c268433a RC |
1229 | } |
1230 | ||
77d18ded | 1231 | sp = gdbarch_frame_align (gdbarch, sp); |
c268433a RC |
1232 | |
1233 | return sp; | |
1234 | } | |
77d18ded | 1235 | |
cc72850f MK |
1236 | \f |
1237 | ||
08d53055 MK |
1238 | static void |
1239 | hppa_hpux_supply_ss_narrow (struct regcache *regcache, | |
1240 | int regnum, const char *save_state) | |
1241 | { | |
1242 | const char *ss_narrow = save_state + HPPA_HPUX_SS_NARROW_OFFSET; | |
1243 | int i, offset = 0; | |
1244 | ||
1245 | for (i = HPPA_R1_REGNUM; i < HPPA_FP0_REGNUM; i++) | |
1246 | { | |
1247 | if (regnum == i || regnum == -1) | |
1248 | regcache_raw_supply (regcache, i, ss_narrow + offset); | |
1249 | ||
1250 | offset += 4; | |
1251 | } | |
1252 | } | |
1253 | ||
1254 | static void | |
1255 | hppa_hpux_supply_ss_fpblock (struct regcache *regcache, | |
1256 | int regnum, const char *save_state) | |
1257 | { | |
1258 | const char *ss_fpblock = save_state + HPPA_HPUX_SS_FPBLOCK_OFFSET; | |
1259 | int i, offset = 0; | |
1260 | ||
1261 | /* FIXME: We view the floating-point state as 64 single-precision | |
1262 | registers for 32-bit code, and 32 double-precision register for | |
1263 | 64-bit code. This distinction is artificial and should be | |
1264 | eliminated. If that ever happens, we should remove the if-clause | |
1265 | below. */ | |
1266 | ||
1267 | if (register_size (get_regcache_arch (regcache), HPPA_FP0_REGNUM) == 4) | |
1268 | { | |
1269 | for (i = HPPA_FP0_REGNUM; i < HPPA_FP0_REGNUM + 64; i++) | |
1270 | { | |
1271 | if (regnum == i || regnum == -1) | |
1272 | regcache_raw_supply (regcache, i, ss_fpblock + offset); | |
1273 | ||
1274 | offset += 4; | |
1275 | } | |
1276 | } | |
1277 | else | |
1278 | { | |
1279 | for (i = HPPA_FP0_REGNUM; i < HPPA_FP0_REGNUM + 32; i++) | |
1280 | { | |
1281 | if (regnum == i || regnum == -1) | |
1282 | regcache_raw_supply (regcache, i, ss_fpblock + offset); | |
1283 | ||
1284 | offset += 8; | |
1285 | } | |
1286 | } | |
1287 | } | |
1288 | ||
1289 | static void | |
1290 | hppa_hpux_supply_ss_wide (struct regcache *regcache, | |
1291 | int regnum, const char *save_state) | |
1292 | { | |
1293 | const char *ss_wide = save_state + HPPA_HPUX_SS_WIDE_OFFSET; | |
1294 | int i, offset = 8; | |
1295 | ||
1296 | if (register_size (get_regcache_arch (regcache), HPPA_R1_REGNUM) == 4) | |
1297 | offset += 4; | |
1298 | ||
1299 | for (i = HPPA_R1_REGNUM; i < HPPA_FP0_REGNUM; i++) | |
1300 | { | |
1301 | if (regnum == i || regnum == -1) | |
1302 | regcache_raw_supply (regcache, i, ss_wide + offset); | |
1303 | ||
1304 | offset += 8; | |
1305 | } | |
1306 | } | |
1307 | ||
1308 | static void | |
1309 | hppa_hpux_supply_save_state (const struct regset *regset, | |
1310 | struct regcache *regcache, | |
1311 | int regnum, const void *regs, size_t len) | |
1312 | { | |
1313 | const char *proc_info = regs; | |
1314 | const char *save_state = proc_info + 8; | |
1315 | ULONGEST flags; | |
1316 | ||
1317 | flags = extract_unsigned_integer (save_state + HPPA_HPUX_SS_FLAGS_OFFSET, 4); | |
1318 | if (regnum == -1 || regnum == HPPA_FLAGS_REGNUM) | |
1319 | { | |
1320 | struct gdbarch *arch = get_regcache_arch (regcache); | |
1321 | size_t size = register_size (arch, HPPA_FLAGS_REGNUM); | |
1322 | char buf[8]; | |
1323 | ||
1324 | store_unsigned_integer (buf, size, flags); | |
1325 | regcache_raw_supply (regcache, HPPA_FLAGS_REGNUM, buf); | |
1326 | } | |
1327 | ||
1328 | /* If the SS_WIDEREGS flag is set, we really do need the full | |
1329 | `struct save_state'. */ | |
1330 | if (flags & HPPA_HPUX_SS_WIDEREGS && len < HPPA_HPUX_SAVE_STATE_SIZE) | |
8a3fe4f8 | 1331 | error (_("Register set contents too small")); |
08d53055 MK |
1332 | |
1333 | if (flags & HPPA_HPUX_SS_WIDEREGS) | |
1334 | hppa_hpux_supply_ss_wide (regcache, regnum, save_state); | |
1335 | else | |
1336 | hppa_hpux_supply_ss_narrow (regcache, regnum, save_state); | |
1337 | ||
1338 | hppa_hpux_supply_ss_fpblock (regcache, regnum, save_state); | |
1339 | } | |
1340 | ||
1341 | /* HP-UX register set. */ | |
1342 | ||
1343 | static struct regset hppa_hpux_regset = | |
1344 | { | |
1345 | NULL, | |
1346 | hppa_hpux_supply_save_state | |
1347 | }; | |
1348 | ||
1349 | static const struct regset * | |
1350 | hppa_hpux_regset_from_core_section (struct gdbarch *gdbarch, | |
1351 | const char *sect_name, size_t sect_size) | |
1352 | { | |
1353 | if (strcmp (sect_name, ".reg") == 0 | |
1354 | && sect_size >= HPPA_HPUX_PA89_SAVE_STATE_SIZE + 8) | |
1355 | return &hppa_hpux_regset; | |
1356 | ||
1357 | return NULL; | |
1358 | } | |
1359 | \f | |
1360 | ||
cc72850f MK |
1361 | /* Bit in the `ss_flag' member of `struct save_state' that indicates |
1362 | the state was saved from a system call. From | |
1363 | <machine/save_state.h>. */ | |
1364 | #define HPPA_HPUX_SS_INSYSCALL 0x02 | |
1365 | ||
1366 | static CORE_ADDR | |
1367 | hppa_hpux_read_pc (ptid_t ptid) | |
1368 | { | |
1369 | ULONGEST flags; | |
1370 | ||
1371 | /* If we're currently in a system call return the contents of %r31. */ | |
1372 | flags = read_register_pid (HPPA_FLAGS_REGNUM, ptid); | |
1373 | if (flags & HPPA_HPUX_SS_INSYSCALL) | |
1374 | return read_register_pid (HPPA_R31_REGNUM, ptid) & ~0x3; | |
1375 | ||
1376 | return hppa_read_pc (ptid); | |
1377 | } | |
1378 | ||
1379 | static void | |
1380 | hppa_hpux_write_pc (CORE_ADDR pc, ptid_t ptid) | |
1381 | { | |
1382 | ULONGEST flags; | |
1383 | ||
1384 | /* If we're currently in a system call also write PC into %r31. */ | |
1385 | flags = read_register_pid (HPPA_FLAGS_REGNUM, ptid); | |
1386 | if (flags & HPPA_HPUX_SS_INSYSCALL) | |
1387 | write_register_pid (HPPA_R31_REGNUM, pc | 0x3, ptid); | |
1388 | ||
1389 | return hppa_write_pc (pc, ptid); | |
1390 | } | |
1391 | ||
1392 | static CORE_ADDR | |
1393 | hppa_hpux_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame) | |
1394 | { | |
1395 | ULONGEST flags; | |
1396 | ||
1397 | /* If we're currently in a system call return the contents of %r31. */ | |
1398 | flags = frame_unwind_register_unsigned (next_frame, HPPA_FLAGS_REGNUM); | |
1399 | if (flags & HPPA_HPUX_SS_INSYSCALL) | |
1400 | return frame_unwind_register_unsigned (next_frame, HPPA_R31_REGNUM) & ~0x3; | |
1401 | ||
1402 | return hppa_unwind_pc (gdbarch, next_frame); | |
1403 | } | |
1404 | \f | |
c268433a | 1405 | |
f77a2124 RC |
1406 | /* Given the current value of the pc, check to see if it is inside a stub, and |
1407 | if so, change the value of the pc to point to the caller of the stub. | |
1408 | NEXT_FRAME is the next frame in the current list of frames. | |
1409 | BASE contains to stack frame base of the current frame. | |
1410 | SAVE_REGS is the register file stored in the frame cache. */ | |
1411 | static void | |
1412 | hppa_hpux_unwind_adjust_stub (struct frame_info *next_frame, CORE_ADDR base, | |
1413 | struct trad_frame_saved_reg *saved_regs) | |
1414 | { | |
1415 | int optimized, realreg; | |
1416 | enum lval_type lval; | |
1417 | CORE_ADDR addr; | |
1418 | char buffer[sizeof(ULONGEST)]; | |
1419 | ULONGEST val; | |
1420 | CORE_ADDR stubpc; | |
1421 | struct unwind_table_entry *u; | |
1422 | ||
1423 | trad_frame_get_prev_register (next_frame, saved_regs, | |
1424 | HPPA_PCOQ_HEAD_REGNUM, | |
1425 | &optimized, &lval, &addr, &realreg, buffer); | |
1426 | val = extract_unsigned_integer (buffer, | |
1427 | register_size (get_frame_arch (next_frame), | |
1428 | HPPA_PCOQ_HEAD_REGNUM)); | |
1429 | ||
1430 | u = find_unwind_entry (val); | |
1431 | if (u && u->stub_unwind.stub_type == EXPORT) | |
1432 | { | |
1433 | stubpc = read_memory_integer (base - 24, TARGET_PTR_BIT / 8); | |
1434 | trad_frame_set_value (saved_regs, HPPA_PCOQ_HEAD_REGNUM, stubpc); | |
1435 | } | |
1436 | else if (hppa_symbol_address ("__gcc_plt_call") | |
1437 | == get_pc_function_start (val)) | |
1438 | { | |
1439 | stubpc = read_memory_integer (base - 8, TARGET_PTR_BIT / 8); | |
1440 | trad_frame_set_value (saved_regs, HPPA_PCOQ_HEAD_REGNUM, stubpc); | |
1441 | } | |
1442 | } | |
1443 | ||
7d773d96 JB |
1444 | static void |
1445 | hppa_hpux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) | |
1446 | { | |
abc485a1 RC |
1447 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
1448 | ||
77d18ded | 1449 | if (IS_32BIT_TARGET (gdbarch)) |
84674fe1 | 1450 | tdep->in_solib_call_trampoline = hppa32_hpux_in_solib_call_trampoline; |
abc485a1 | 1451 | else |
84674fe1 | 1452 | tdep->in_solib_call_trampoline = hppa64_hpux_in_solib_call_trampoline; |
abc485a1 | 1453 | |
f77a2124 RC |
1454 | tdep->unwind_adjust_stub = hppa_hpux_unwind_adjust_stub; |
1455 | ||
3cd36e7c MK |
1456 | set_gdbarch_in_solib_return_trampoline |
1457 | (gdbarch, hppa_hpux_in_solib_return_trampoline); | |
abc485a1 | 1458 | set_gdbarch_skip_trampoline_code (gdbarch, hppa_hpux_skip_trampoline_code); |
43613416 | 1459 | |
c268433a RC |
1460 | set_gdbarch_push_dummy_code (gdbarch, hppa_hpux_push_dummy_code); |
1461 | set_gdbarch_call_dummy_location (gdbarch, ON_STACK); | |
1462 | ||
cc72850f MK |
1463 | set_gdbarch_read_pc (gdbarch, hppa_hpux_read_pc); |
1464 | set_gdbarch_write_pc (gdbarch, hppa_hpux_write_pc); | |
1465 | set_gdbarch_unwind_pc (gdbarch, hppa_hpux_unwind_pc); | |
6d350bb5 UW |
1466 | set_gdbarch_skip_permanent_breakpoint |
1467 | (gdbarch, hppa_skip_permanent_breakpoint); | |
cc72850f | 1468 | |
08d53055 MK |
1469 | set_gdbarch_regset_from_core_section |
1470 | (gdbarch, hppa_hpux_regset_from_core_section); | |
1471 | ||
43613416 | 1472 | frame_unwind_append_sniffer (gdbarch, hppa_hpux_sigtramp_unwind_sniffer); |
7d773d96 | 1473 | } |
60e1ff27 | 1474 | |
273f8429 JB |
1475 | static void |
1476 | hppa_hpux_som_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) | |
1477 | { | |
fdd72f95 RC |
1478 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
1479 | ||
1480 | tdep->is_elf = 0; | |
c268433a | 1481 | |
77d18ded RC |
1482 | tdep->find_global_pointer = hppa32_hpux_find_global_pointer; |
1483 | ||
7d773d96 | 1484 | hppa_hpux_init_abi (info, gdbarch); |
acf86d54 | 1485 | som_solib_select (tdep); |
273f8429 JB |
1486 | } |
1487 | ||
1488 | static void | |
1489 | hppa_hpux_elf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) | |
1490 | { | |
fdd72f95 RC |
1491 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
1492 | ||
1493 | tdep->is_elf = 1; | |
77d18ded RC |
1494 | tdep->find_global_pointer = hppa64_hpux_find_global_pointer; |
1495 | ||
7d773d96 | 1496 | hppa_hpux_init_abi (info, gdbarch); |
acf86d54 | 1497 | pa64_solib_select (tdep); |
273f8429 JB |
1498 | } |
1499 | ||
08d53055 MK |
1500 | static enum gdb_osabi |
1501 | hppa_hpux_core_osabi_sniffer (bfd *abfd) | |
1502 | { | |
1503 | if (strcmp (bfd_get_target (abfd), "hpux-core") == 0) | |
1504 | return GDB_OSABI_HPUX_SOM; | |
6b79fde8 RC |
1505 | else if (strcmp (bfd_get_target (abfd), "elf64-hppa") == 0) |
1506 | { | |
1507 | asection *section; | |
1508 | ||
1509 | section = bfd_get_section_by_name (abfd, ".kernel"); | |
1510 | if (section) | |
1511 | { | |
1512 | bfd_size_type size; | |
1513 | char *contents; | |
1514 | ||
1515 | size = bfd_section_size (abfd, section); | |
1516 | contents = alloca (size); | |
1517 | if (bfd_get_section_contents (abfd, section, contents, | |
1518 | (file_ptr) 0, size) | |
1519 | && strcmp (contents, "HP-UX") == 0) | |
1520 | return GDB_OSABI_HPUX_ELF; | |
1521 | } | |
1522 | } | |
08d53055 MK |
1523 | |
1524 | return GDB_OSABI_UNKNOWN; | |
1525 | } | |
1526 | ||
273f8429 JB |
1527 | void |
1528 | _initialize_hppa_hpux_tdep (void) | |
1529 | { | |
08d53055 MK |
1530 | /* BFD doesn't set a flavour for HP-UX style core files. It doesn't |
1531 | set the architecture either. */ | |
1532 | gdbarch_register_osabi_sniffer (bfd_arch_unknown, | |
1533 | bfd_target_unknown_flavour, | |
1534 | hppa_hpux_core_osabi_sniffer); | |
6b79fde8 RC |
1535 | gdbarch_register_osabi_sniffer (bfd_arch_hppa, |
1536 | bfd_target_elf_flavour, | |
1537 | hppa_hpux_core_osabi_sniffer); | |
08d53055 | 1538 | |
05816f70 | 1539 | gdbarch_register_osabi (bfd_arch_hppa, 0, GDB_OSABI_HPUX_SOM, |
273f8429 | 1540 | hppa_hpux_som_init_abi); |
51db5742 | 1541 | gdbarch_register_osabi (bfd_arch_hppa, bfd_mach_hppa20w, GDB_OSABI_HPUX_ELF, |
273f8429 JB |
1542 | hppa_hpux_elf_init_abi); |
1543 | } |