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