]>
Commit | Line | Data |
---|---|---|
c906108c SS |
1 | /* Target-dependent code for the HP PA architecture, for GDB. |
2 | Copyright 1986, 87, 89, 90, 91, 92, 93, 94, 95, 96, 1999 | |
3 | Free Software Foundation, Inc. | |
4 | ||
5 | Contributed by the Center for Software Science at the | |
6 | University of Utah ([email protected]). | |
7 | ||
c5aa993b | 8 | This file is part of GDB. |
c906108c | 9 | |
c5aa993b JM |
10 | This program is free software; you can redistribute it and/or modify |
11 | it under the terms of the GNU General Public License as published by | |
12 | the Free Software Foundation; either version 2 of the License, or | |
13 | (at your option) any later version. | |
c906108c | 14 | |
c5aa993b JM |
15 | This program is distributed in the hope that it will be useful, |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | GNU General Public License for more details. | |
c906108c | 19 | |
c5aa993b JM |
20 | You should have received a copy of the GNU General Public License |
21 | along with this program; if not, write to the Free Software | |
22 | Foundation, Inc., 59 Temple Place - Suite 330, | |
23 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
24 | |
25 | #include "defs.h" | |
26 | #include "frame.h" | |
27 | #include "bfd.h" | |
28 | #include "inferior.h" | |
29 | #include "value.h" | |
30 | ||
31 | /* For argument passing to the inferior */ | |
32 | #include "symtab.h" | |
33 | ||
34 | #ifdef USG | |
35 | #include <sys/types.h> | |
36 | #endif | |
37 | ||
38 | #include <dl.h> | |
39 | #include <sys/param.h> | |
40 | #include <signal.h> | |
41 | ||
42 | #include <sys/ptrace.h> | |
43 | #include <machine/save_state.h> | |
44 | ||
45 | #ifdef COFF_ENCAPSULATE | |
46 | #include "a.out.encap.h" | |
47 | #else | |
48 | #endif | |
49 | ||
c5aa993b | 50 | /*#include <sys/user.h> After a.out.h */ |
c906108c SS |
51 | #include <sys/file.h> |
52 | #include "gdb_stat.h" | |
53 | #include "wait.h" | |
54 | ||
55 | #include "gdbcore.h" | |
56 | #include "gdbcmd.h" | |
57 | #include "target.h" | |
58 | #include "symfile.h" | |
59 | #include "objfiles.h" | |
60 | ||
61 | /* To support asking "What CPU is this?" */ | |
62 | #include <unistd.h> | |
63 | ||
64 | /* To support detection of the pseudo-initial frame | |
65 | that threads have. */ | |
66 | #define THREAD_INITIAL_FRAME_SYMBOL "__pthread_exit" | |
67 | #define THREAD_INITIAL_FRAME_SYM_LEN sizeof(THREAD_INITIAL_FRAME_SYMBOL) | |
c5aa993b | 68 | |
c906108c SS |
69 | static int extract_5_load PARAMS ((unsigned int)); |
70 | ||
71 | static unsigned extract_5R_store PARAMS ((unsigned int)); | |
72 | ||
73 | static unsigned extract_5r_store PARAMS ((unsigned int)); | |
74 | ||
75 | static void find_dummy_frame_regs PARAMS ((struct frame_info *, | |
76 | struct frame_saved_regs *)); | |
77 | ||
78 | static int find_proc_framesize PARAMS ((CORE_ADDR)); | |
79 | ||
80 | static int find_return_regnum PARAMS ((CORE_ADDR)); | |
81 | ||
82 | struct unwind_table_entry *find_unwind_entry PARAMS ((CORE_ADDR)); | |
83 | ||
84 | static int extract_17 PARAMS ((unsigned int)); | |
85 | ||
86 | static unsigned deposit_21 PARAMS ((unsigned int, unsigned int)); | |
87 | ||
88 | static int extract_21 PARAMS ((unsigned)); | |
89 | ||
90 | static unsigned deposit_14 PARAMS ((int, unsigned int)); | |
91 | ||
92 | static int extract_14 PARAMS ((unsigned)); | |
93 | ||
94 | static void unwind_command PARAMS ((char *, int)); | |
95 | ||
96 | static int low_sign_extend PARAMS ((unsigned int, unsigned int)); | |
97 | ||
98 | static int sign_extend PARAMS ((unsigned int, unsigned int)); | |
99 | ||
100 | static int restore_pc_queue PARAMS ((struct frame_saved_regs *)); | |
101 | ||
102 | static int hppa_alignof PARAMS ((struct type *)); | |
103 | ||
104 | /* To support multi-threading and stepping. */ | |
105 | int hppa_prepare_to_proceed PARAMS (()); | |
106 | ||
107 | static int prologue_inst_adjust_sp PARAMS ((unsigned long)); | |
108 | ||
109 | static int is_branch PARAMS ((unsigned long)); | |
110 | ||
111 | static int inst_saves_gr PARAMS ((unsigned long)); | |
112 | ||
113 | static int inst_saves_fr PARAMS ((unsigned long)); | |
114 | ||
115 | static int pc_in_interrupt_handler PARAMS ((CORE_ADDR)); | |
116 | ||
117 | static int pc_in_linker_stub PARAMS ((CORE_ADDR)); | |
118 | ||
119 | static int compare_unwind_entries PARAMS ((const void *, const void *)); | |
120 | ||
121 | static void read_unwind_info PARAMS ((struct objfile *)); | |
122 | ||
123 | static void internalize_unwinds PARAMS ((struct objfile *, | |
124 | struct unwind_table_entry *, | |
125 | asection *, unsigned int, | |
126 | unsigned int, CORE_ADDR)); | |
127 | static void pa_print_registers PARAMS ((char *, int, int)); | |
128 | static void pa_strcat_registers PARAMS ((char *, int, int, GDB_FILE *)); | |
129 | static void pa_register_look_aside PARAMS ((char *, int, long *)); | |
130 | static void pa_print_fp_reg PARAMS ((int)); | |
131 | static void pa_strcat_fp_reg PARAMS ((int, GDB_FILE *, enum precision_type)); | |
132 | ||
c5aa993b JM |
133 | typedef struct |
134 | { | |
135 | struct minimal_symbol *msym; | |
136 | CORE_ADDR solib_handle; | |
a0b3c4fd | 137 | CORE_ADDR return_val; |
c5aa993b JM |
138 | } |
139 | args_for_find_stub; | |
c906108c | 140 | |
a0b3c4fd | 141 | static int cover_find_stub_with_shl_get (PTR); |
c906108c | 142 | |
c5aa993b | 143 | static int is_pa_2 = 0; /* False */ |
c906108c | 144 | |
c5aa993b | 145 | /* This is declared in symtab.c; set to 1 in hp-symtab-read.c */ |
c906108c SS |
146 | extern int hp_som_som_object_present; |
147 | ||
148 | /* In breakpoint.c */ | |
149 | extern int exception_catchpoints_are_fragile; | |
150 | ||
151 | /* This is defined in valops.c. */ | |
152 | extern value_ptr | |
c5aa993b | 153 | find_function_in_inferior PARAMS ((char *)); |
c906108c SS |
154 | |
155 | /* Should call_function allocate stack space for a struct return? */ | |
156 | int | |
157 | hppa_use_struct_convention (gcc_p, type) | |
158 | int gcc_p; | |
159 | struct type *type; | |
160 | { | |
161 | return (TYPE_LENGTH (type) > 8); | |
162 | } | |
c906108c | 163 | \f |
c5aa993b | 164 | |
c906108c SS |
165 | /* Routines to extract various sized constants out of hppa |
166 | instructions. */ | |
167 | ||
168 | /* This assumes that no garbage lies outside of the lower bits of | |
169 | value. */ | |
170 | ||
171 | static int | |
172 | sign_extend (val, bits) | |
173 | unsigned val, bits; | |
174 | { | |
c5aa993b | 175 | return (int) (val >> (bits - 1) ? (-1 << bits) | val : val); |
c906108c SS |
176 | } |
177 | ||
178 | /* For many immediate values the sign bit is the low bit! */ | |
179 | ||
180 | static int | |
181 | low_sign_extend (val, bits) | |
182 | unsigned val, bits; | |
183 | { | |
c5aa993b | 184 | return (int) ((val & 0x1 ? (-1 << (bits - 1)) : 0) | val >> 1); |
c906108c SS |
185 | } |
186 | ||
187 | /* extract the immediate field from a ld{bhw}s instruction */ | |
188 | ||
c906108c SS |
189 | static int |
190 | extract_5_load (word) | |
191 | unsigned word; | |
192 | { | |
193 | return low_sign_extend (word >> 16 & MASK_5, 5); | |
194 | } | |
195 | ||
c906108c SS |
196 | /* extract the immediate field from a break instruction */ |
197 | ||
198 | static unsigned | |
199 | extract_5r_store (word) | |
200 | unsigned word; | |
201 | { | |
202 | return (word & MASK_5); | |
203 | } | |
204 | ||
205 | /* extract the immediate field from a {sr}sm instruction */ | |
206 | ||
207 | static unsigned | |
208 | extract_5R_store (word) | |
209 | unsigned word; | |
210 | { | |
211 | return (word >> 16 & MASK_5); | |
212 | } | |
213 | ||
c906108c SS |
214 | /* extract a 14 bit immediate field */ |
215 | ||
216 | static int | |
217 | extract_14 (word) | |
218 | unsigned word; | |
219 | { | |
220 | return low_sign_extend (word & MASK_14, 14); | |
221 | } | |
222 | ||
223 | /* deposit a 14 bit constant in a word */ | |
224 | ||
225 | static unsigned | |
226 | deposit_14 (opnd, word) | |
227 | int opnd; | |
228 | unsigned word; | |
229 | { | |
230 | unsigned sign = (opnd < 0 ? 1 : 0); | |
231 | ||
c5aa993b | 232 | return word | ((unsigned) opnd << 1 & MASK_14) | sign; |
c906108c SS |
233 | } |
234 | ||
235 | /* extract a 21 bit constant */ | |
236 | ||
237 | static int | |
238 | extract_21 (word) | |
239 | unsigned word; | |
240 | { | |
241 | int val; | |
242 | ||
243 | word &= MASK_21; | |
244 | word <<= 11; | |
245 | val = GET_FIELD (word, 20, 20); | |
246 | val <<= 11; | |
247 | val |= GET_FIELD (word, 9, 19); | |
248 | val <<= 2; | |
249 | val |= GET_FIELD (word, 5, 6); | |
250 | val <<= 5; | |
251 | val |= GET_FIELD (word, 0, 4); | |
252 | val <<= 2; | |
253 | val |= GET_FIELD (word, 7, 8); | |
254 | return sign_extend (val, 21) << 11; | |
255 | } | |
256 | ||
257 | /* deposit a 21 bit constant in a word. Although 21 bit constants are | |
258 | usually the top 21 bits of a 32 bit constant, we assume that only | |
259 | the low 21 bits of opnd are relevant */ | |
260 | ||
261 | static unsigned | |
262 | deposit_21 (opnd, word) | |
263 | unsigned opnd, word; | |
264 | { | |
265 | unsigned val = 0; | |
266 | ||
267 | val |= GET_FIELD (opnd, 11 + 14, 11 + 18); | |
268 | val <<= 2; | |
269 | val |= GET_FIELD (opnd, 11 + 12, 11 + 13); | |
270 | val <<= 2; | |
271 | val |= GET_FIELD (opnd, 11 + 19, 11 + 20); | |
272 | val <<= 11; | |
273 | val |= GET_FIELD (opnd, 11 + 1, 11 + 11); | |
274 | val <<= 1; | |
275 | val |= GET_FIELD (opnd, 11 + 0, 11 + 0); | |
276 | return word | val; | |
277 | } | |
278 | ||
c906108c SS |
279 | /* extract a 17 bit constant from branch instructions, returning the |
280 | 19 bit signed value. */ | |
281 | ||
282 | static int | |
283 | extract_17 (word) | |
284 | unsigned word; | |
285 | { | |
286 | return sign_extend (GET_FIELD (word, 19, 28) | | |
287 | GET_FIELD (word, 29, 29) << 10 | | |
288 | GET_FIELD (word, 11, 15) << 11 | | |
289 | (word & 0x1) << 16, 17) << 2; | |
290 | } | |
291 | \f | |
292 | ||
293 | /* Compare the start address for two unwind entries returning 1 if | |
294 | the first address is larger than the second, -1 if the second is | |
295 | larger than the first, and zero if they are equal. */ | |
296 | ||
297 | static int | |
298 | compare_unwind_entries (arg1, arg2) | |
299 | const void *arg1; | |
300 | const void *arg2; | |
301 | { | |
302 | const struct unwind_table_entry *a = arg1; | |
303 | const struct unwind_table_entry *b = arg2; | |
304 | ||
305 | if (a->region_start > b->region_start) | |
306 | return 1; | |
307 | else if (a->region_start < b->region_start) | |
308 | return -1; | |
309 | else | |
310 | return 0; | |
311 | } | |
312 | ||
313 | static void | |
314 | internalize_unwinds (objfile, table, section, entries, size, text_offset) | |
315 | struct objfile *objfile; | |
316 | struct unwind_table_entry *table; | |
317 | asection *section; | |
318 | unsigned int entries, size; | |
319 | CORE_ADDR text_offset; | |
320 | { | |
321 | /* We will read the unwind entries into temporary memory, then | |
322 | fill in the actual unwind table. */ | |
323 | if (size > 0) | |
324 | { | |
325 | unsigned long tmp; | |
326 | unsigned i; | |
327 | char *buf = alloca (size); | |
328 | ||
329 | bfd_get_section_contents (objfile->obfd, section, buf, 0, size); | |
330 | ||
331 | /* Now internalize the information being careful to handle host/target | |
c5aa993b | 332 | endian issues. */ |
c906108c SS |
333 | for (i = 0; i < entries; i++) |
334 | { | |
335 | table[i].region_start = bfd_get_32 (objfile->obfd, | |
c5aa993b | 336 | (bfd_byte *) buf); |
c906108c SS |
337 | table[i].region_start += text_offset; |
338 | buf += 4; | |
c5aa993b | 339 | table[i].region_end = bfd_get_32 (objfile->obfd, (bfd_byte *) buf); |
c906108c SS |
340 | table[i].region_end += text_offset; |
341 | buf += 4; | |
c5aa993b | 342 | tmp = bfd_get_32 (objfile->obfd, (bfd_byte *) buf); |
c906108c SS |
343 | buf += 4; |
344 | table[i].Cannot_unwind = (tmp >> 31) & 0x1; | |
345 | table[i].Millicode = (tmp >> 30) & 0x1; | |
346 | table[i].Millicode_save_sr0 = (tmp >> 29) & 0x1; | |
347 | table[i].Region_description = (tmp >> 27) & 0x3; | |
348 | table[i].reserved1 = (tmp >> 26) & 0x1; | |
349 | table[i].Entry_SR = (tmp >> 25) & 0x1; | |
350 | table[i].Entry_FR = (tmp >> 21) & 0xf; | |
351 | table[i].Entry_GR = (tmp >> 16) & 0x1f; | |
352 | table[i].Args_stored = (tmp >> 15) & 0x1; | |
353 | table[i].Variable_Frame = (tmp >> 14) & 0x1; | |
354 | table[i].Separate_Package_Body = (tmp >> 13) & 0x1; | |
355 | table[i].Frame_Extension_Millicode = (tmp >> 12) & 0x1; | |
356 | table[i].Stack_Overflow_Check = (tmp >> 11) & 0x1; | |
357 | table[i].Two_Instruction_SP_Increment = (tmp >> 10) & 0x1; | |
358 | table[i].Ada_Region = (tmp >> 9) & 0x1; | |
359 | table[i].cxx_info = (tmp >> 8) & 0x1; | |
360 | table[i].cxx_try_catch = (tmp >> 7) & 0x1; | |
361 | table[i].sched_entry_seq = (tmp >> 6) & 0x1; | |
362 | table[i].reserved2 = (tmp >> 5) & 0x1; | |
363 | table[i].Save_SP = (tmp >> 4) & 0x1; | |
364 | table[i].Save_RP = (tmp >> 3) & 0x1; | |
365 | table[i].Save_MRP_in_frame = (tmp >> 2) & 0x1; | |
366 | table[i].extn_ptr_defined = (tmp >> 1) & 0x1; | |
367 | table[i].Cleanup_defined = tmp & 0x1; | |
c5aa993b | 368 | tmp = bfd_get_32 (objfile->obfd, (bfd_byte *) buf); |
c906108c SS |
369 | buf += 4; |
370 | table[i].MPE_XL_interrupt_marker = (tmp >> 31) & 0x1; | |
371 | table[i].HP_UX_interrupt_marker = (tmp >> 30) & 0x1; | |
372 | table[i].Large_frame = (tmp >> 29) & 0x1; | |
373 | table[i].Pseudo_SP_Set = (tmp >> 28) & 0x1; | |
374 | table[i].reserved4 = (tmp >> 27) & 0x1; | |
375 | table[i].Total_frame_size = tmp & 0x7ffffff; | |
376 | ||
c5aa993b | 377 | /* Stub unwinds are handled elsewhere. */ |
c906108c SS |
378 | table[i].stub_unwind.stub_type = 0; |
379 | table[i].stub_unwind.padding = 0; | |
380 | } | |
381 | } | |
382 | } | |
383 | ||
384 | /* Read in the backtrace information stored in the `$UNWIND_START$' section of | |
385 | the object file. This info is used mainly by find_unwind_entry() to find | |
386 | out the stack frame size and frame pointer used by procedures. We put | |
387 | everything on the psymbol obstack in the objfile so that it automatically | |
388 | gets freed when the objfile is destroyed. */ | |
389 | ||
390 | static void | |
391 | read_unwind_info (objfile) | |
392 | struct objfile *objfile; | |
393 | { | |
394 | asection *unwind_sec, *elf_unwind_sec, *stub_unwind_sec; | |
395 | unsigned unwind_size, elf_unwind_size, stub_unwind_size, total_size; | |
396 | unsigned index, unwind_entries, elf_unwind_entries; | |
397 | unsigned stub_entries, total_entries; | |
398 | CORE_ADDR text_offset; | |
399 | struct obj_unwind_info *ui; | |
400 | obj_private_data_t *obj_private; | |
401 | ||
402 | text_offset = ANOFFSET (objfile->section_offsets, 0); | |
c5aa993b JM |
403 | ui = (struct obj_unwind_info *) obstack_alloc (&objfile->psymbol_obstack, |
404 | sizeof (struct obj_unwind_info)); | |
c906108c SS |
405 | |
406 | ui->table = NULL; | |
407 | ui->cache = NULL; | |
408 | ui->last = -1; | |
409 | ||
410 | /* Get hooks to all unwind sections. Note there is no linker-stub unwind | |
411 | section in ELF at the moment. */ | |
412 | unwind_sec = bfd_get_section_by_name (objfile->obfd, "$UNWIND_START$"); | |
413 | elf_unwind_sec = bfd_get_section_by_name (objfile->obfd, ".PARISC.unwind"); | |
414 | stub_unwind_sec = bfd_get_section_by_name (objfile->obfd, "$UNWIND_END$"); | |
415 | ||
416 | /* Get sizes and unwind counts for all sections. */ | |
417 | if (unwind_sec) | |
418 | { | |
419 | unwind_size = bfd_section_size (objfile->obfd, unwind_sec); | |
420 | unwind_entries = unwind_size / UNWIND_ENTRY_SIZE; | |
421 | } | |
422 | else | |
423 | { | |
424 | unwind_size = 0; | |
425 | unwind_entries = 0; | |
426 | } | |
427 | ||
428 | if (elf_unwind_sec) | |
429 | { | |
c5aa993b JM |
430 | elf_unwind_size = bfd_section_size (objfile->obfd, elf_unwind_sec); /* purecov: deadcode */ |
431 | elf_unwind_entries = elf_unwind_size / UNWIND_ENTRY_SIZE; /* purecov: deadcode */ | |
c906108c SS |
432 | } |
433 | else | |
434 | { | |
435 | elf_unwind_size = 0; | |
436 | elf_unwind_entries = 0; | |
437 | } | |
438 | ||
439 | if (stub_unwind_sec) | |
440 | { | |
441 | stub_unwind_size = bfd_section_size (objfile->obfd, stub_unwind_sec); | |
442 | stub_entries = stub_unwind_size / STUB_UNWIND_ENTRY_SIZE; | |
443 | } | |
444 | else | |
445 | { | |
446 | stub_unwind_size = 0; | |
447 | stub_entries = 0; | |
448 | } | |
449 | ||
450 | /* Compute total number of unwind entries and their total size. */ | |
451 | total_entries = unwind_entries + elf_unwind_entries + stub_entries; | |
452 | total_size = total_entries * sizeof (struct unwind_table_entry); | |
453 | ||
454 | /* Allocate memory for the unwind table. */ | |
455 | ui->table = (struct unwind_table_entry *) | |
456 | obstack_alloc (&objfile->psymbol_obstack, total_size); | |
c5aa993b | 457 | ui->last = total_entries - 1; |
c906108c SS |
458 | |
459 | /* Internalize the standard unwind entries. */ | |
460 | index = 0; | |
461 | internalize_unwinds (objfile, &ui->table[index], unwind_sec, | |
462 | unwind_entries, unwind_size, text_offset); | |
463 | index += unwind_entries; | |
464 | internalize_unwinds (objfile, &ui->table[index], elf_unwind_sec, | |
465 | elf_unwind_entries, elf_unwind_size, text_offset); | |
466 | index += elf_unwind_entries; | |
467 | ||
468 | /* Now internalize the stub unwind entries. */ | |
469 | if (stub_unwind_size > 0) | |
470 | { | |
471 | unsigned int i; | |
472 | char *buf = alloca (stub_unwind_size); | |
473 | ||
474 | /* Read in the stub unwind entries. */ | |
475 | bfd_get_section_contents (objfile->obfd, stub_unwind_sec, buf, | |
476 | 0, stub_unwind_size); | |
477 | ||
478 | /* Now convert them into regular unwind entries. */ | |
479 | for (i = 0; i < stub_entries; i++, index++) | |
480 | { | |
481 | /* Clear out the next unwind entry. */ | |
482 | memset (&ui->table[index], 0, sizeof (struct unwind_table_entry)); | |
483 | ||
484 | /* Convert offset & size into region_start and region_end. | |
485 | Stuff away the stub type into "reserved" fields. */ | |
486 | ui->table[index].region_start = bfd_get_32 (objfile->obfd, | |
487 | (bfd_byte *) buf); | |
488 | ui->table[index].region_start += text_offset; | |
489 | buf += 4; | |
490 | ui->table[index].stub_unwind.stub_type = bfd_get_8 (objfile->obfd, | |
c5aa993b | 491 | (bfd_byte *) buf); |
c906108c SS |
492 | buf += 2; |
493 | ui->table[index].region_end | |
c5aa993b JM |
494 | = ui->table[index].region_start + 4 * |
495 | (bfd_get_16 (objfile->obfd, (bfd_byte *) buf) - 1); | |
c906108c SS |
496 | buf += 2; |
497 | } | |
498 | ||
499 | } | |
500 | ||
501 | /* Unwind table needs to be kept sorted. */ | |
502 | qsort (ui->table, total_entries, sizeof (struct unwind_table_entry), | |
503 | compare_unwind_entries); | |
504 | ||
505 | /* Keep a pointer to the unwind information. */ | |
c5aa993b | 506 | if (objfile->obj_private == NULL) |
c906108c SS |
507 | { |
508 | obj_private = (obj_private_data_t *) | |
c5aa993b JM |
509 | obstack_alloc (&objfile->psymbol_obstack, |
510 | sizeof (obj_private_data_t)); | |
c906108c | 511 | obj_private->unwind_info = NULL; |
c5aa993b JM |
512 | obj_private->so_info = NULL; |
513 | ||
c906108c SS |
514 | objfile->obj_private = (PTR) obj_private; |
515 | } | |
c5aa993b | 516 | obj_private = (obj_private_data_t *) objfile->obj_private; |
c906108c SS |
517 | obj_private->unwind_info = ui; |
518 | } | |
519 | ||
520 | /* Lookup the unwind (stack backtrace) info for the given PC. We search all | |
521 | of the objfiles seeking the unwind table entry for this PC. Each objfile | |
522 | contains a sorted list of struct unwind_table_entry. Since we do a binary | |
523 | search of the unwind tables, we depend upon them to be sorted. */ | |
524 | ||
525 | struct unwind_table_entry * | |
c5aa993b | 526 | find_unwind_entry (pc) |
c906108c SS |
527 | CORE_ADDR pc; |
528 | { | |
529 | int first, middle, last; | |
530 | struct objfile *objfile; | |
531 | ||
532 | /* A function at address 0? Not in HP-UX! */ | |
533 | if (pc == (CORE_ADDR) 0) | |
534 | return NULL; | |
535 | ||
536 | ALL_OBJFILES (objfile) | |
c5aa993b JM |
537 | { |
538 | struct obj_unwind_info *ui; | |
539 | ui = NULL; | |
540 | if (objfile->obj_private) | |
541 | ui = ((obj_private_data_t *) (objfile->obj_private))->unwind_info; | |
c906108c | 542 | |
c5aa993b JM |
543 | if (!ui) |
544 | { | |
545 | read_unwind_info (objfile); | |
546 | if (objfile->obj_private == NULL) | |
547 | error ("Internal error reading unwind information."); /* purecov: deadcode */ | |
548 | ui = ((obj_private_data_t *) (objfile->obj_private))->unwind_info; | |
549 | } | |
c906108c | 550 | |
c5aa993b | 551 | /* First, check the cache */ |
c906108c | 552 | |
c5aa993b JM |
553 | if (ui->cache |
554 | && pc >= ui->cache->region_start | |
555 | && pc <= ui->cache->region_end) | |
556 | return ui->cache; | |
c906108c | 557 | |
c5aa993b | 558 | /* Not in the cache, do a binary search */ |
c906108c | 559 | |
c5aa993b JM |
560 | first = 0; |
561 | last = ui->last; | |
c906108c | 562 | |
c5aa993b JM |
563 | while (first <= last) |
564 | { | |
565 | middle = (first + last) / 2; | |
566 | if (pc >= ui->table[middle].region_start | |
567 | && pc <= ui->table[middle].region_end) | |
568 | { | |
569 | ui->cache = &ui->table[middle]; | |
570 | return &ui->table[middle]; | |
571 | } | |
c906108c | 572 | |
c5aa993b JM |
573 | if (pc < ui->table[middle].region_start) |
574 | last = middle - 1; | |
575 | else | |
576 | first = middle + 1; | |
577 | } | |
578 | } /* ALL_OBJFILES() */ | |
c906108c SS |
579 | return NULL; |
580 | } | |
581 | ||
582 | /* Return the adjustment necessary to make for addresses on the stack | |
583 | as presented by hpread.c. | |
584 | ||
585 | This is necessary because of the stack direction on the PA and the | |
586 | bizarre way in which someone (?) decided they wanted to handle | |
587 | frame pointerless code in GDB. */ | |
588 | int | |
589 | hpread_adjust_stack_address (func_addr) | |
590 | CORE_ADDR func_addr; | |
591 | { | |
592 | struct unwind_table_entry *u; | |
593 | ||
594 | u = find_unwind_entry (func_addr); | |
595 | if (!u) | |
596 | return 0; | |
597 | else | |
598 | return u->Total_frame_size << 3; | |
599 | } | |
600 | ||
601 | /* Called to determine if PC is in an interrupt handler of some | |
602 | kind. */ | |
603 | ||
604 | static int | |
605 | pc_in_interrupt_handler (pc) | |
606 | CORE_ADDR pc; | |
607 | { | |
608 | struct unwind_table_entry *u; | |
609 | struct minimal_symbol *msym_us; | |
610 | ||
611 | u = find_unwind_entry (pc); | |
612 | if (!u) | |
613 | return 0; | |
614 | ||
615 | /* Oh joys. HPUX sets the interrupt bit for _sigreturn even though | |
616 | its frame isn't a pure interrupt frame. Deal with this. */ | |
617 | msym_us = lookup_minimal_symbol_by_pc (pc); | |
618 | ||
619 | return u->HP_UX_interrupt_marker && !IN_SIGTRAMP (pc, SYMBOL_NAME (msym_us)); | |
620 | } | |
621 | ||
622 | /* Called when no unwind descriptor was found for PC. Returns 1 if it | |
623 | appears that PC is in a linker stub. */ | |
624 | ||
625 | static int | |
626 | pc_in_linker_stub (pc) | |
627 | CORE_ADDR pc; | |
628 | { | |
629 | int found_magic_instruction = 0; | |
630 | int i; | |
631 | char buf[4]; | |
632 | ||
633 | /* If unable to read memory, assume pc is not in a linker stub. */ | |
634 | if (target_read_memory (pc, buf, 4) != 0) | |
635 | return 0; | |
636 | ||
637 | /* We are looking for something like | |
638 | ||
639 | ; $$dyncall jams RP into this special spot in the frame (RP') | |
640 | ; before calling the "call stub" | |
641 | ldw -18(sp),rp | |
642 | ||
643 | ldsid (rp),r1 ; Get space associated with RP into r1 | |
644 | mtsp r1,sp ; Move it into space register 0 | |
645 | be,n 0(sr0),rp) ; back to your regularly scheduled program */ | |
646 | ||
647 | /* Maximum known linker stub size is 4 instructions. Search forward | |
648 | from the given PC, then backward. */ | |
649 | for (i = 0; i < 4; i++) | |
650 | { | |
651 | /* If we hit something with an unwind, stop searching this direction. */ | |
652 | ||
653 | if (find_unwind_entry (pc + i * 4) != 0) | |
654 | break; | |
655 | ||
656 | /* Check for ldsid (rp),r1 which is the magic instruction for a | |
c5aa993b | 657 | return from a cross-space function call. */ |
c906108c SS |
658 | if (read_memory_integer (pc + i * 4, 4) == 0x004010a1) |
659 | { | |
660 | found_magic_instruction = 1; | |
661 | break; | |
662 | } | |
663 | /* Add code to handle long call/branch and argument relocation stubs | |
c5aa993b | 664 | here. */ |
c906108c SS |
665 | } |
666 | ||
667 | if (found_magic_instruction != 0) | |
668 | return 1; | |
669 | ||
670 | /* Now look backward. */ | |
671 | for (i = 0; i < 4; i++) | |
672 | { | |
673 | /* If we hit something with an unwind, stop searching this direction. */ | |
674 | ||
675 | if (find_unwind_entry (pc - i * 4) != 0) | |
676 | break; | |
677 | ||
678 | /* Check for ldsid (rp),r1 which is the magic instruction for a | |
c5aa993b | 679 | return from a cross-space function call. */ |
c906108c SS |
680 | if (read_memory_integer (pc - i * 4, 4) == 0x004010a1) |
681 | { | |
682 | found_magic_instruction = 1; | |
683 | break; | |
684 | } | |
685 | /* Add code to handle long call/branch and argument relocation stubs | |
c5aa993b | 686 | here. */ |
c906108c SS |
687 | } |
688 | return found_magic_instruction; | |
689 | } | |
690 | ||
691 | static int | |
c5aa993b | 692 | find_return_regnum (pc) |
c906108c SS |
693 | CORE_ADDR pc; |
694 | { | |
695 | struct unwind_table_entry *u; | |
696 | ||
697 | u = find_unwind_entry (pc); | |
698 | ||
699 | if (!u) | |
700 | return RP_REGNUM; | |
701 | ||
702 | if (u->Millicode) | |
703 | return 31; | |
704 | ||
705 | return RP_REGNUM; | |
706 | } | |
707 | ||
708 | /* Return size of frame, or -1 if we should use a frame pointer. */ | |
709 | static int | |
710 | find_proc_framesize (pc) | |
711 | CORE_ADDR pc; | |
712 | { | |
713 | struct unwind_table_entry *u; | |
714 | struct minimal_symbol *msym_us; | |
715 | ||
716 | /* This may indicate a bug in our callers... */ | |
c5aa993b | 717 | if (pc == (CORE_ADDR) 0) |
c906108c | 718 | return -1; |
c5aa993b | 719 | |
c906108c SS |
720 | u = find_unwind_entry (pc); |
721 | ||
722 | if (!u) | |
723 | { | |
724 | if (pc_in_linker_stub (pc)) | |
725 | /* Linker stubs have a zero size frame. */ | |
726 | return 0; | |
727 | else | |
728 | return -1; | |
729 | } | |
730 | ||
731 | msym_us = lookup_minimal_symbol_by_pc (pc); | |
732 | ||
733 | /* If Save_SP is set, and we're not in an interrupt or signal caller, | |
734 | then we have a frame pointer. Use it. */ | |
735 | if (u->Save_SP && !pc_in_interrupt_handler (pc) | |
736 | && !IN_SIGTRAMP (pc, SYMBOL_NAME (msym_us))) | |
737 | return -1; | |
738 | ||
739 | return u->Total_frame_size << 3; | |
740 | } | |
741 | ||
742 | /* Return offset from sp at which rp is saved, or 0 if not saved. */ | |
743 | static int rp_saved PARAMS ((CORE_ADDR)); | |
744 | ||
745 | static int | |
746 | rp_saved (pc) | |
747 | CORE_ADDR pc; | |
748 | { | |
749 | struct unwind_table_entry *u; | |
750 | ||
751 | /* A function at, and thus a return PC from, address 0? Not in HP-UX! */ | |
752 | if (pc == (CORE_ADDR) 0) | |
753 | return 0; | |
754 | ||
755 | u = find_unwind_entry (pc); | |
756 | ||
757 | if (!u) | |
758 | { | |
759 | if (pc_in_linker_stub (pc)) | |
760 | /* This is the so-called RP'. */ | |
761 | return -24; | |
762 | else | |
763 | return 0; | |
764 | } | |
765 | ||
766 | if (u->Save_RP) | |
767 | return -20; | |
768 | else if (u->stub_unwind.stub_type != 0) | |
769 | { | |
770 | switch (u->stub_unwind.stub_type) | |
771 | { | |
772 | case EXPORT: | |
773 | case IMPORT: | |
774 | return -24; | |
775 | case PARAMETER_RELOCATION: | |
776 | return -8; | |
777 | default: | |
778 | return 0; | |
779 | } | |
780 | } | |
781 | else | |
782 | return 0; | |
783 | } | |
784 | \f | |
785 | int | |
786 | frameless_function_invocation (frame) | |
787 | struct frame_info *frame; | |
788 | { | |
789 | struct unwind_table_entry *u; | |
790 | ||
791 | u = find_unwind_entry (frame->pc); | |
792 | ||
793 | if (u == 0) | |
794 | return 0; | |
795 | ||
796 | return (u->Total_frame_size == 0 && u->stub_unwind.stub_type == 0); | |
797 | } | |
798 | ||
799 | CORE_ADDR | |
800 | saved_pc_after_call (frame) | |
801 | struct frame_info *frame; | |
802 | { | |
803 | int ret_regnum; | |
804 | CORE_ADDR pc; | |
805 | struct unwind_table_entry *u; | |
806 | ||
807 | ret_regnum = find_return_regnum (get_frame_pc (frame)); | |
808 | pc = read_register (ret_regnum) & ~0x3; | |
c5aa993b | 809 | |
c906108c SS |
810 | /* If PC is in a linker stub, then we need to dig the address |
811 | the stub will return to out of the stack. */ | |
812 | u = find_unwind_entry (pc); | |
813 | if (u && u->stub_unwind.stub_type != 0) | |
814 | return FRAME_SAVED_PC (frame); | |
815 | else | |
816 | return pc; | |
817 | } | |
818 | \f | |
819 | CORE_ADDR | |
820 | hppa_frame_saved_pc (frame) | |
821 | struct frame_info *frame; | |
822 | { | |
823 | CORE_ADDR pc = get_frame_pc (frame); | |
824 | struct unwind_table_entry *u; | |
825 | CORE_ADDR old_pc; | |
c5aa993b JM |
826 | int spun_around_loop = 0; |
827 | int rp_offset = 0; | |
c906108c SS |
828 | |
829 | /* BSD, HPUX & OSF1 all lay out the hardware state in the same manner | |
830 | at the base of the frame in an interrupt handler. Registers within | |
831 | are saved in the exact same order as GDB numbers registers. How | |
832 | convienent. */ | |
833 | if (pc_in_interrupt_handler (pc)) | |
834 | return read_memory_integer (frame->frame + PC_REGNUM * 4, 4) & ~0x3; | |
835 | ||
836 | #ifdef FRAME_SAVED_PC_IN_SIGTRAMP | |
837 | /* Deal with signal handler caller frames too. */ | |
838 | if (frame->signal_handler_caller) | |
839 | { | |
840 | CORE_ADDR rp; | |
841 | FRAME_SAVED_PC_IN_SIGTRAMP (frame, &rp); | |
842 | return rp & ~0x3; | |
843 | } | |
844 | #endif | |
845 | ||
846 | if (frameless_function_invocation (frame)) | |
847 | { | |
848 | int ret_regnum; | |
849 | ||
850 | ret_regnum = find_return_regnum (pc); | |
851 | ||
852 | /* If the next frame is an interrupt frame or a signal | |
c5aa993b JM |
853 | handler caller, then we need to look in the saved |
854 | register area to get the return pointer (the values | |
855 | in the registers may not correspond to anything useful). */ | |
856 | if (frame->next | |
c906108c SS |
857 | && (frame->next->signal_handler_caller |
858 | || pc_in_interrupt_handler (frame->next->pc))) | |
859 | { | |
860 | struct frame_saved_regs saved_regs; | |
861 | ||
862 | get_frame_saved_regs (frame->next, &saved_regs); | |
863 | if (read_memory_integer (saved_regs.regs[FLAGS_REGNUM], 4) & 0x2) | |
864 | { | |
865 | pc = read_memory_integer (saved_regs.regs[31], 4) & ~0x3; | |
866 | ||
867 | /* Syscalls are really two frames. The syscall stub itself | |
c5aa993b JM |
868 | with a return pointer in %rp and the kernel call with |
869 | a return pointer in %r31. We return the %rp variant | |
870 | if %r31 is the same as frame->pc. */ | |
c906108c SS |
871 | if (pc == frame->pc) |
872 | pc = read_memory_integer (saved_regs.regs[RP_REGNUM], 4) & ~0x3; | |
873 | } | |
874 | else | |
875 | pc = read_memory_integer (saved_regs.regs[RP_REGNUM], 4) & ~0x3; | |
876 | } | |
877 | else | |
878 | pc = read_register (ret_regnum) & ~0x3; | |
879 | } | |
880 | else | |
881 | { | |
882 | spun_around_loop = 0; | |
c5aa993b | 883 | old_pc = pc; |
c906108c | 884 | |
c5aa993b | 885 | restart: |
c906108c SS |
886 | rp_offset = rp_saved (pc); |
887 | ||
888 | /* Similar to code in frameless function case. If the next | |
c5aa993b JM |
889 | frame is a signal or interrupt handler, then dig the right |
890 | information out of the saved register info. */ | |
c906108c SS |
891 | if (rp_offset == 0 |
892 | && frame->next | |
893 | && (frame->next->signal_handler_caller | |
894 | || pc_in_interrupt_handler (frame->next->pc))) | |
895 | { | |
896 | struct frame_saved_regs saved_regs; | |
897 | ||
898 | get_frame_saved_regs (frame->next, &saved_regs); | |
899 | if (read_memory_integer (saved_regs.regs[FLAGS_REGNUM], 4) & 0x2) | |
900 | { | |
901 | pc = read_memory_integer (saved_regs.regs[31], 4) & ~0x3; | |
902 | ||
903 | /* Syscalls are really two frames. The syscall stub itself | |
c5aa993b JM |
904 | with a return pointer in %rp and the kernel call with |
905 | a return pointer in %r31. We return the %rp variant | |
906 | if %r31 is the same as frame->pc. */ | |
c906108c SS |
907 | if (pc == frame->pc) |
908 | pc = read_memory_integer (saved_regs.regs[RP_REGNUM], 4) & ~0x3; | |
909 | } | |
910 | else | |
911 | pc = read_memory_integer (saved_regs.regs[RP_REGNUM], 4) & ~0x3; | |
912 | } | |
913 | else if (rp_offset == 0) | |
c5aa993b JM |
914 | { |
915 | old_pc = pc; | |
916 | pc = read_register (RP_REGNUM) & ~0x3; | |
917 | } | |
c906108c | 918 | else |
c5aa993b JM |
919 | { |
920 | old_pc = pc; | |
921 | pc = read_memory_integer (frame->frame + rp_offset, 4) & ~0x3; | |
922 | } | |
c906108c SS |
923 | } |
924 | ||
925 | /* If PC is inside a linker stub, then dig out the address the stub | |
926 | will return to. | |
927 | ||
928 | Don't do this for long branch stubs. Why? For some unknown reason | |
929 | _start is marked as a long branch stub in hpux10. */ | |
930 | u = find_unwind_entry (pc); | |
931 | if (u && u->stub_unwind.stub_type != 0 | |
932 | && u->stub_unwind.stub_type != LONG_BRANCH) | |
933 | { | |
934 | unsigned int insn; | |
935 | ||
936 | /* If this is a dynamic executable, and we're in a signal handler, | |
c5aa993b JM |
937 | then the call chain will eventually point us into the stub for |
938 | _sigreturn. Unlike most cases, we'll be pointed to the branch | |
939 | to the real sigreturn rather than the code after the real branch!. | |
c906108c | 940 | |
c5aa993b JM |
941 | Else, try to dig the address the stub will return to in the normal |
942 | fashion. */ | |
c906108c SS |
943 | insn = read_memory_integer (pc, 4); |
944 | if ((insn & 0xfc00e000) == 0xe8000000) | |
945 | return (pc + extract_17 (insn) + 8) & ~0x3; | |
946 | else | |
947 | { | |
c5aa993b JM |
948 | if (old_pc == pc) |
949 | spun_around_loop++; | |
950 | ||
951 | if (spun_around_loop > 1) | |
952 | { | |
953 | /* We're just about to go around the loop again with | |
954 | no more hope of success. Die. */ | |
955 | error ("Unable to find return pc for this frame"); | |
956 | } | |
957 | else | |
958 | goto restart; | |
c906108c SS |
959 | } |
960 | } | |
961 | ||
962 | return pc; | |
963 | } | |
964 | \f | |
965 | /* We need to correct the PC and the FP for the outermost frame when we are | |
966 | in a system call. */ | |
967 | ||
968 | void | |
969 | init_extra_frame_info (fromleaf, frame) | |
970 | int fromleaf; | |
971 | struct frame_info *frame; | |
972 | { | |
973 | int flags; | |
974 | int framesize; | |
975 | ||
976 | if (frame->next && !fromleaf) | |
977 | return; | |
978 | ||
979 | /* If the next frame represents a frameless function invocation | |
980 | then we have to do some adjustments that are normally done by | |
981 | FRAME_CHAIN. (FRAME_CHAIN is not called in this case.) */ | |
982 | if (fromleaf) | |
983 | { | |
984 | /* Find the framesize of *this* frame without peeking at the PC | |
c5aa993b | 985 | in the current frame structure (it isn't set yet). */ |
c906108c SS |
986 | framesize = find_proc_framesize (FRAME_SAVED_PC (get_next_frame (frame))); |
987 | ||
988 | /* Now adjust our base frame accordingly. If we have a frame pointer | |
c5aa993b JM |
989 | use it, else subtract the size of this frame from the current |
990 | frame. (we always want frame->frame to point at the lowest address | |
991 | in the frame). */ | |
c906108c SS |
992 | if (framesize == -1) |
993 | frame->frame = TARGET_READ_FP (); | |
994 | else | |
995 | frame->frame -= framesize; | |
996 | return; | |
997 | } | |
998 | ||
999 | flags = read_register (FLAGS_REGNUM); | |
c5aa993b | 1000 | if (flags & 2) /* In system call? */ |
c906108c SS |
1001 | frame->pc = read_register (31) & ~0x3; |
1002 | ||
1003 | /* The outermost frame is always derived from PC-framesize | |
1004 | ||
1005 | One might think frameless innermost frames should have | |
1006 | a frame->frame that is the same as the parent's frame->frame. | |
1007 | That is wrong; frame->frame in that case should be the *high* | |
1008 | address of the parent's frame. It's complicated as hell to | |
1009 | explain, but the parent *always* creates some stack space for | |
1010 | the child. So the child actually does have a frame of some | |
1011 | sorts, and its base is the high address in its parent's frame. */ | |
c5aa993b | 1012 | framesize = find_proc_framesize (frame->pc); |
c906108c SS |
1013 | if (framesize == -1) |
1014 | frame->frame = TARGET_READ_FP (); | |
1015 | else | |
1016 | frame->frame = read_register (SP_REGNUM) - framesize; | |
1017 | } | |
1018 | \f | |
1019 | /* Given a GDB frame, determine the address of the calling function's frame. | |
1020 | This will be used to create a new GDB frame struct, and then | |
1021 | INIT_EXTRA_FRAME_INFO and INIT_FRAME_PC will be called for the new frame. | |
1022 | ||
1023 | This may involve searching through prologues for several functions | |
1024 | at boundaries where GCC calls HP C code, or where code which has | |
1025 | a frame pointer calls code without a frame pointer. */ | |
1026 | ||
1027 | CORE_ADDR | |
1028 | frame_chain (frame) | |
1029 | struct frame_info *frame; | |
1030 | { | |
1031 | int my_framesize, caller_framesize; | |
1032 | struct unwind_table_entry *u; | |
1033 | CORE_ADDR frame_base; | |
1034 | struct frame_info *tmp_frame; | |
1035 | ||
c5aa993b | 1036 | CORE_ADDR caller_pc; |
c906108c SS |
1037 | |
1038 | struct minimal_symbol *min_frame_symbol; | |
c5aa993b JM |
1039 | struct symbol *frame_symbol; |
1040 | char *frame_symbol_name; | |
c906108c SS |
1041 | |
1042 | /* If this is a threaded application, and we see the | |
1043 | routine "__pthread_exit", treat it as the stack root | |
1044 | for this thread. */ | |
c5aa993b JM |
1045 | min_frame_symbol = lookup_minimal_symbol_by_pc (frame->pc); |
1046 | frame_symbol = find_pc_function (frame->pc); | |
c906108c | 1047 | |
c5aa993b | 1048 | if ((min_frame_symbol != 0) /* && (frame_symbol == 0) */ ) |
c906108c | 1049 | { |
c5aa993b JM |
1050 | /* The test above for "no user function name" would defend |
1051 | against the slim likelihood that a user might define a | |
1052 | routine named "__pthread_exit" and then try to debug it. | |
1053 | ||
1054 | If it weren't commented out, and you tried to debug the | |
1055 | pthread library itself, you'd get errors. | |
1056 | ||
1057 | So for today, we don't make that check. */ | |
1058 | frame_symbol_name = SYMBOL_NAME (min_frame_symbol); | |
1059 | if (frame_symbol_name != 0) | |
1060 | { | |
1061 | if (0 == strncmp (frame_symbol_name, | |
1062 | THREAD_INITIAL_FRAME_SYMBOL, | |
1063 | THREAD_INITIAL_FRAME_SYM_LEN)) | |
1064 | { | |
1065 | /* Pretend we've reached the bottom of the stack. */ | |
1066 | return (CORE_ADDR) 0; | |
1067 | } | |
1068 | } | |
1069 | } /* End of hacky code for threads. */ | |
1070 | ||
c906108c SS |
1071 | /* Handle HPUX, BSD, and OSF1 style interrupt frames first. These |
1072 | are easy; at *sp we have a full save state strucutre which we can | |
1073 | pull the old stack pointer from. Also see frame_saved_pc for | |
1074 | code to dig a saved PC out of the save state structure. */ | |
1075 | if (pc_in_interrupt_handler (frame->pc)) | |
1076 | frame_base = read_memory_integer (frame->frame + SP_REGNUM * 4, 4); | |
1077 | #ifdef FRAME_BASE_BEFORE_SIGTRAMP | |
1078 | else if (frame->signal_handler_caller) | |
1079 | { | |
1080 | FRAME_BASE_BEFORE_SIGTRAMP (frame, &frame_base); | |
1081 | } | |
1082 | #endif | |
1083 | else | |
1084 | frame_base = frame->frame; | |
1085 | ||
1086 | /* Get frame sizes for the current frame and the frame of the | |
1087 | caller. */ | |
1088 | my_framesize = find_proc_framesize (frame->pc); | |
c5aa993b | 1089 | caller_pc = FRAME_SAVED_PC (frame); |
c906108c SS |
1090 | |
1091 | /* If we can't determine the caller's PC, then it's not likely we can | |
1092 | really determine anything meaningful about its frame. We'll consider | |
1093 | this to be stack bottom. */ | |
1094 | if (caller_pc == (CORE_ADDR) 0) | |
1095 | return (CORE_ADDR) 0; | |
1096 | ||
c5aa993b | 1097 | caller_framesize = find_proc_framesize (FRAME_SAVED_PC (frame)); |
c906108c SS |
1098 | |
1099 | /* If caller does not have a frame pointer, then its frame | |
1100 | can be found at current_frame - caller_framesize. */ | |
1101 | if (caller_framesize != -1) | |
1102 | { | |
1103 | return frame_base - caller_framesize; | |
1104 | } | |
1105 | /* Both caller and callee have frame pointers and are GCC compiled | |
1106 | (SAVE_SP bit in unwind descriptor is on for both functions. | |
1107 | The previous frame pointer is found at the top of the current frame. */ | |
1108 | if (caller_framesize == -1 && my_framesize == -1) | |
1109 | { | |
1110 | return read_memory_integer (frame_base, 4); | |
1111 | } | |
1112 | /* Caller has a frame pointer, but callee does not. This is a little | |
1113 | more difficult as GCC and HP C lay out locals and callee register save | |
1114 | areas very differently. | |
1115 | ||
1116 | The previous frame pointer could be in a register, or in one of | |
1117 | several areas on the stack. | |
1118 | ||
1119 | Walk from the current frame to the innermost frame examining | |
1120 | unwind descriptors to determine if %r3 ever gets saved into the | |
1121 | stack. If so return whatever value got saved into the stack. | |
1122 | If it was never saved in the stack, then the value in %r3 is still | |
1123 | valid, so use it. | |
1124 | ||
1125 | We use information from unwind descriptors to determine if %r3 | |
1126 | is saved into the stack (Entry_GR field has this information). */ | |
1127 | ||
1128 | tmp_frame = frame; | |
1129 | while (tmp_frame) | |
1130 | { | |
1131 | u = find_unwind_entry (tmp_frame->pc); | |
1132 | ||
1133 | if (!u) | |
1134 | { | |
1135 | /* We could find this information by examining prologues. I don't | |
1136 | think anyone has actually written any tools (not even "strip") | |
1137 | which leave them out of an executable, so maybe this is a moot | |
1138 | point. */ | |
c5aa993b JM |
1139 | /* ??rehrauer: Actually, it's quite possible to stepi your way into |
1140 | code that doesn't have unwind entries. For example, stepping into | |
1141 | the dynamic linker will give you a PC that has none. Thus, I've | |
1142 | disabled this warning. */ | |
c906108c SS |
1143 | #if 0 |
1144 | warning ("Unable to find unwind for PC 0x%x -- Help!", tmp_frame->pc); | |
1145 | #endif | |
1146 | return (CORE_ADDR) 0; | |
1147 | } | |
1148 | ||
1149 | /* Entry_GR specifies the number of callee-saved general registers | |
c5aa993b | 1150 | saved in the stack. It starts at %r3, so %r3 would be 1. */ |
c906108c SS |
1151 | if (u->Entry_GR >= 1 || u->Save_SP |
1152 | || tmp_frame->signal_handler_caller | |
1153 | || pc_in_interrupt_handler (tmp_frame->pc)) | |
1154 | break; | |
1155 | else | |
1156 | tmp_frame = tmp_frame->next; | |
1157 | } | |
1158 | ||
1159 | if (tmp_frame) | |
1160 | { | |
1161 | /* We may have walked down the chain into a function with a frame | |
c5aa993b | 1162 | pointer. */ |
c906108c SS |
1163 | if (u->Save_SP |
1164 | && !tmp_frame->signal_handler_caller | |
1165 | && !pc_in_interrupt_handler (tmp_frame->pc)) | |
1166 | { | |
1167 | return read_memory_integer (tmp_frame->frame, 4); | |
1168 | } | |
1169 | /* %r3 was saved somewhere in the stack. Dig it out. */ | |
c5aa993b | 1170 | else |
c906108c SS |
1171 | { |
1172 | struct frame_saved_regs saved_regs; | |
1173 | ||
1174 | /* Sick. | |
1175 | ||
1176 | For optimization purposes many kernels don't have the | |
1177 | callee saved registers into the save_state structure upon | |
1178 | entry into the kernel for a syscall; the optimization | |
1179 | is usually turned off if the process is being traced so | |
1180 | that the debugger can get full register state for the | |
1181 | process. | |
c5aa993b | 1182 | |
c906108c SS |
1183 | This scheme works well except for two cases: |
1184 | ||
c5aa993b JM |
1185 | * Attaching to a process when the process is in the |
1186 | kernel performing a system call (debugger can't get | |
1187 | full register state for the inferior process since | |
1188 | the process wasn't being traced when it entered the | |
1189 | system call). | |
c906108c | 1190 | |
c5aa993b JM |
1191 | * Register state is not complete if the system call |
1192 | causes the process to core dump. | |
c906108c SS |
1193 | |
1194 | ||
1195 | The following heinous code is an attempt to deal with | |
1196 | the lack of register state in a core dump. It will | |
1197 | fail miserably if the function which performs the | |
1198 | system call has a variable sized stack frame. */ | |
1199 | ||
1200 | get_frame_saved_regs (tmp_frame, &saved_regs); | |
1201 | ||
1202 | /* Abominable hack. */ | |
1203 | if (current_target.to_has_execution == 0 | |
1204 | && ((saved_regs.regs[FLAGS_REGNUM] | |
c5aa993b | 1205 | && (read_memory_integer (saved_regs.regs[FLAGS_REGNUM], 4) |
c906108c SS |
1206 | & 0x2)) |
1207 | || (saved_regs.regs[FLAGS_REGNUM] == 0 | |
1208 | && read_register (FLAGS_REGNUM) & 0x2))) | |
1209 | { | |
1210 | u = find_unwind_entry (FRAME_SAVED_PC (frame)); | |
1211 | if (!u) | |
1212 | { | |
1213 | return read_memory_integer (saved_regs.regs[FP_REGNUM], 4); | |
1214 | } | |
1215 | else | |
1216 | { | |
1217 | return frame_base - (u->Total_frame_size << 3); | |
1218 | } | |
1219 | } | |
c5aa993b | 1220 | |
c906108c SS |
1221 | return read_memory_integer (saved_regs.regs[FP_REGNUM], 4); |
1222 | } | |
1223 | } | |
1224 | else | |
1225 | { | |
1226 | struct frame_saved_regs saved_regs; | |
1227 | ||
1228 | /* Get the innermost frame. */ | |
1229 | tmp_frame = frame; | |
1230 | while (tmp_frame->next != NULL) | |
1231 | tmp_frame = tmp_frame->next; | |
1232 | ||
1233 | get_frame_saved_regs (tmp_frame, &saved_regs); | |
1234 | /* Abominable hack. See above. */ | |
1235 | if (current_target.to_has_execution == 0 | |
1236 | && ((saved_regs.regs[FLAGS_REGNUM] | |
1237 | && (read_memory_integer (saved_regs.regs[FLAGS_REGNUM], 4) | |
1238 | & 0x2)) | |
1239 | || (saved_regs.regs[FLAGS_REGNUM] == 0 | |
c5aa993b | 1240 | && read_register (FLAGS_REGNUM) & 0x2))) |
c906108c SS |
1241 | { |
1242 | u = find_unwind_entry (FRAME_SAVED_PC (frame)); | |
1243 | if (!u) | |
1244 | { | |
1245 | return read_memory_integer (saved_regs.regs[FP_REGNUM], 4); | |
1246 | } | |
c5aa993b JM |
1247 | else |
1248 | { | |
1249 | return frame_base - (u->Total_frame_size << 3); | |
1250 | } | |
c906108c | 1251 | } |
c5aa993b | 1252 | |
c906108c | 1253 | /* The value in %r3 was never saved into the stack (thus %r3 still |
c5aa993b | 1254 | holds the value of the previous frame pointer). */ |
c906108c SS |
1255 | return TARGET_READ_FP (); |
1256 | } | |
1257 | } | |
c906108c | 1258 | \f |
c5aa993b | 1259 | |
c906108c SS |
1260 | /* To see if a frame chain is valid, see if the caller looks like it |
1261 | was compiled with gcc. */ | |
1262 | ||
1263 | int | |
1264 | hppa_frame_chain_valid (chain, thisframe) | |
1265 | CORE_ADDR chain; | |
1266 | struct frame_info *thisframe; | |
1267 | { | |
1268 | struct minimal_symbol *msym_us; | |
1269 | struct minimal_symbol *msym_start; | |
1270 | struct unwind_table_entry *u, *next_u = NULL; | |
1271 | struct frame_info *next; | |
1272 | ||
1273 | if (!chain) | |
1274 | return 0; | |
1275 | ||
1276 | u = find_unwind_entry (thisframe->pc); | |
1277 | ||
1278 | if (u == NULL) | |
1279 | return 1; | |
1280 | ||
1281 | /* We can't just check that the same of msym_us is "_start", because | |
1282 | someone idiotically decided that they were going to make a Ltext_end | |
1283 | symbol with the same address. This Ltext_end symbol is totally | |
1284 | indistinguishable (as nearly as I can tell) from the symbol for a function | |
1285 | which is (legitimately, since it is in the user's namespace) | |
1286 | named Ltext_end, so we can't just ignore it. */ | |
1287 | msym_us = lookup_minimal_symbol_by_pc (FRAME_SAVED_PC (thisframe)); | |
1288 | msym_start = lookup_minimal_symbol ("_start", NULL, NULL); | |
1289 | if (msym_us | |
1290 | && msym_start | |
1291 | && SYMBOL_VALUE_ADDRESS (msym_us) == SYMBOL_VALUE_ADDRESS (msym_start)) | |
1292 | return 0; | |
1293 | ||
1294 | /* Grrrr. Some new idiot decided that they don't want _start for the | |
1295 | PRO configurations; $START$ calls main directly.... Deal with it. */ | |
1296 | msym_start = lookup_minimal_symbol ("$START$", NULL, NULL); | |
1297 | if (msym_us | |
1298 | && msym_start | |
1299 | && SYMBOL_VALUE_ADDRESS (msym_us) == SYMBOL_VALUE_ADDRESS (msym_start)) | |
1300 | return 0; | |
1301 | ||
1302 | next = get_next_frame (thisframe); | |
1303 | if (next) | |
1304 | next_u = find_unwind_entry (next->pc); | |
1305 | ||
1306 | /* If this frame does not save SP, has no stack, isn't a stub, | |
1307 | and doesn't "call" an interrupt routine or signal handler caller, | |
1308 | then its not valid. */ | |
1309 | if (u->Save_SP || u->Total_frame_size || u->stub_unwind.stub_type != 0 | |
1310 | || (thisframe->next && thisframe->next->signal_handler_caller) | |
1311 | || (next_u && next_u->HP_UX_interrupt_marker)) | |
1312 | return 1; | |
1313 | ||
1314 | if (pc_in_linker_stub (thisframe->pc)) | |
1315 | return 1; | |
1316 | ||
1317 | return 0; | |
1318 | } | |
1319 | ||
1320 | /* | |
1321 | These functions deal with saving and restoring register state | |
1322 | around a function call in the inferior. They keep the stack | |
1323 | double-word aligned; eventually, on an hp700, the stack will have | |
1324 | to be aligned to a 64-byte boundary. */ | |
1325 | ||
1326 | void | |
1327 | push_dummy_frame (inf_status) | |
1328 | struct inferior_status *inf_status; | |
1329 | { | |
1330 | CORE_ADDR sp, pc, pcspace; | |
1331 | register int regnum; | |
1332 | int int_buffer; | |
1333 | double freg_buffer; | |
1334 | ||
1335 | /* Oh, what a hack. If we're trying to perform an inferior call | |
1336 | while the inferior is asleep, we have to make sure to clear | |
1337 | the "in system call" bit in the flag register (the call will | |
1338 | start after the syscall returns, so we're no longer in the system | |
1339 | call!) This state is kept in "inf_status", change it there. | |
1340 | ||
1341 | We also need a number of horrid hacks to deal with lossage in the | |
1342 | PC queue registers (apparently they're not valid when the in syscall | |
1343 | bit is set). */ | |
1344 | pc = target_read_pc (inferior_pid); | |
1345 | int_buffer = read_register (FLAGS_REGNUM); | |
1346 | if (int_buffer & 0x2) | |
1347 | { | |
1348 | unsigned int sid; | |
1349 | int_buffer &= ~0x2; | |
7a292a7a SS |
1350 | write_inferior_status_register (inf_status, 0, int_buffer); |
1351 | write_inferior_status_register (inf_status, PCOQ_HEAD_REGNUM, pc + 0); | |
1352 | write_inferior_status_register (inf_status, PCOQ_TAIL_REGNUM, pc + 4); | |
c906108c SS |
1353 | sid = (pc >> 30) & 0x3; |
1354 | if (sid == 0) | |
1355 | pcspace = read_register (SR4_REGNUM); | |
1356 | else | |
1357 | pcspace = read_register (SR4_REGNUM + 4 + sid); | |
7a292a7a SS |
1358 | write_inferior_status_register (inf_status, PCSQ_HEAD_REGNUM, pcspace); |
1359 | write_inferior_status_register (inf_status, PCSQ_TAIL_REGNUM, pcspace); | |
c906108c SS |
1360 | } |
1361 | else | |
1362 | pcspace = read_register (PCSQ_HEAD_REGNUM); | |
1363 | ||
1364 | /* Space for "arguments"; the RP goes in here. */ | |
1365 | sp = read_register (SP_REGNUM) + 48; | |
1366 | int_buffer = read_register (RP_REGNUM) | 0x3; | |
c5aa993b | 1367 | write_memory (sp - 20, (char *) &int_buffer, 4); |
c906108c SS |
1368 | |
1369 | int_buffer = TARGET_READ_FP (); | |
c5aa993b | 1370 | write_memory (sp, (char *) &int_buffer, 4); |
c906108c SS |
1371 | |
1372 | write_register (FP_REGNUM, sp); | |
1373 | ||
1374 | sp += 8; | |
1375 | ||
1376 | for (regnum = 1; regnum < 32; regnum++) | |
1377 | if (regnum != RP_REGNUM && regnum != FP_REGNUM) | |
1378 | sp = push_word (sp, read_register (regnum)); | |
1379 | ||
1380 | sp += 4; | |
1381 | ||
1382 | for (regnum = FP0_REGNUM; regnum < NUM_REGS; regnum++) | |
1383 | { | |
c5aa993b JM |
1384 | read_register_bytes (REGISTER_BYTE (regnum), (char *) &freg_buffer, 8); |
1385 | sp = push_bytes (sp, (char *) &freg_buffer, 8); | |
c906108c SS |
1386 | } |
1387 | sp = push_word (sp, read_register (IPSW_REGNUM)); | |
1388 | sp = push_word (sp, read_register (SAR_REGNUM)); | |
1389 | sp = push_word (sp, pc); | |
1390 | sp = push_word (sp, pcspace); | |
1391 | sp = push_word (sp, pc + 4); | |
1392 | sp = push_word (sp, pcspace); | |
1393 | write_register (SP_REGNUM, sp); | |
1394 | } | |
1395 | ||
1396 | static void | |
1397 | find_dummy_frame_regs (frame, frame_saved_regs) | |
1398 | struct frame_info *frame; | |
1399 | struct frame_saved_regs *frame_saved_regs; | |
1400 | { | |
1401 | CORE_ADDR fp = frame->frame; | |
1402 | int i; | |
1403 | ||
1404 | frame_saved_regs->regs[RP_REGNUM] = (fp - 20) & ~0x3; | |
1405 | frame_saved_regs->regs[FP_REGNUM] = fp; | |
1406 | frame_saved_regs->regs[1] = fp + 8; | |
1407 | ||
1408 | for (fp += 12, i = 3; i < 32; i++) | |
1409 | { | |
1410 | if (i != FP_REGNUM) | |
1411 | { | |
1412 | frame_saved_regs->regs[i] = fp; | |
1413 | fp += 4; | |
1414 | } | |
1415 | } | |
1416 | ||
1417 | fp += 4; | |
1418 | for (i = FP0_REGNUM; i < NUM_REGS; i++, fp += 8) | |
1419 | frame_saved_regs->regs[i] = fp; | |
1420 | ||
1421 | frame_saved_regs->regs[IPSW_REGNUM] = fp; | |
1422 | frame_saved_regs->regs[SAR_REGNUM] = fp + 4; | |
1423 | frame_saved_regs->regs[PCOQ_HEAD_REGNUM] = fp + 8; | |
1424 | frame_saved_regs->regs[PCSQ_HEAD_REGNUM] = fp + 12; | |
1425 | frame_saved_regs->regs[PCOQ_TAIL_REGNUM] = fp + 16; | |
1426 | frame_saved_regs->regs[PCSQ_TAIL_REGNUM] = fp + 20; | |
1427 | } | |
1428 | ||
1429 | void | |
1430 | hppa_pop_frame () | |
1431 | { | |
1432 | register struct frame_info *frame = get_current_frame (); | |
1433 | register CORE_ADDR fp, npc, target_pc; | |
1434 | register int regnum; | |
1435 | struct frame_saved_regs fsr; | |
1436 | double freg_buffer; | |
1437 | ||
1438 | fp = FRAME_FP (frame); | |
1439 | get_frame_saved_regs (frame, &fsr); | |
1440 | ||
1441 | #ifndef NO_PC_SPACE_QUEUE_RESTORE | |
c5aa993b | 1442 | if (fsr.regs[IPSW_REGNUM]) /* Restoring a call dummy frame */ |
c906108c SS |
1443 | restore_pc_queue (&fsr); |
1444 | #endif | |
1445 | ||
1446 | for (regnum = 31; regnum > 0; regnum--) | |
1447 | if (fsr.regs[regnum]) | |
1448 | write_register (regnum, read_memory_integer (fsr.regs[regnum], 4)); | |
1449 | ||
c5aa993b | 1450 | for (regnum = NUM_REGS - 1; regnum >= FP0_REGNUM; regnum--) |
c906108c SS |
1451 | if (fsr.regs[regnum]) |
1452 | { | |
c5aa993b JM |
1453 | read_memory (fsr.regs[regnum], (char *) &freg_buffer, 8); |
1454 | write_register_bytes (REGISTER_BYTE (regnum), (char *) &freg_buffer, 8); | |
c906108c SS |
1455 | } |
1456 | ||
1457 | if (fsr.regs[IPSW_REGNUM]) | |
1458 | write_register (IPSW_REGNUM, | |
c5aa993b | 1459 | read_memory_integer (fsr.regs[IPSW_REGNUM], 4)); |
c906108c SS |
1460 | |
1461 | if (fsr.regs[SAR_REGNUM]) | |
1462 | write_register (SAR_REGNUM, | |
c5aa993b | 1463 | read_memory_integer (fsr.regs[SAR_REGNUM], 4)); |
c906108c SS |
1464 | |
1465 | /* If the PC was explicitly saved, then just restore it. */ | |
1466 | if (fsr.regs[PCOQ_TAIL_REGNUM]) | |
1467 | { | |
1468 | npc = read_memory_integer (fsr.regs[PCOQ_TAIL_REGNUM], 4); | |
1469 | write_register (PCOQ_TAIL_REGNUM, npc); | |
1470 | } | |
1471 | /* Else use the value in %rp to set the new PC. */ | |
c5aa993b | 1472 | else |
c906108c SS |
1473 | { |
1474 | npc = read_register (RP_REGNUM); | |
1475 | write_pc (npc); | |
1476 | } | |
1477 | ||
1478 | write_register (FP_REGNUM, read_memory_integer (fp, 4)); | |
1479 | ||
c5aa993b | 1480 | if (fsr.regs[IPSW_REGNUM]) /* call dummy */ |
c906108c SS |
1481 | write_register (SP_REGNUM, fp - 48); |
1482 | else | |
1483 | write_register (SP_REGNUM, fp); | |
1484 | ||
1485 | /* The PC we just restored may be inside a return trampoline. If so | |
1486 | we want to restart the inferior and run it through the trampoline. | |
1487 | ||
1488 | Do this by setting a momentary breakpoint at the location the | |
1489 | trampoline returns to. | |
1490 | ||
1491 | Don't skip through the trampoline if we're popping a dummy frame. */ | |
1492 | target_pc = SKIP_TRAMPOLINE_CODE (npc & ~0x3) & ~0x3; | |
1493 | if (target_pc && !fsr.regs[IPSW_REGNUM]) | |
1494 | { | |
1495 | struct symtab_and_line sal; | |
1496 | struct breakpoint *breakpoint; | |
1497 | struct cleanup *old_chain; | |
1498 | ||
1499 | /* Set up our breakpoint. Set it to be silent as the MI code | |
c5aa993b | 1500 | for "return_command" will print the frame we returned to. */ |
c906108c SS |
1501 | sal = find_pc_line (target_pc, 0); |
1502 | sal.pc = target_pc; | |
1503 | breakpoint = set_momentary_breakpoint (sal, NULL, bp_finish); | |
1504 | breakpoint->silent = 1; | |
1505 | ||
1506 | /* So we can clean things up. */ | |
1507 | old_chain = make_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint); | |
1508 | ||
1509 | /* Start up the inferior. */ | |
1510 | clear_proceed_status (); | |
1511 | proceed_to_finish = 1; | |
c5aa993b | 1512 | proceed ((CORE_ADDR) - 1, TARGET_SIGNAL_DEFAULT, 0); |
c906108c SS |
1513 | |
1514 | /* Perform our cleanups. */ | |
1515 | do_cleanups (old_chain); | |
1516 | } | |
1517 | flush_cached_frames (); | |
1518 | } | |
1519 | ||
1520 | /* After returning to a dummy on the stack, restore the instruction | |
1521 | queue space registers. */ | |
1522 | ||
1523 | static int | |
1524 | restore_pc_queue (fsr) | |
1525 | struct frame_saved_regs *fsr; | |
1526 | { | |
1527 | CORE_ADDR pc = read_pc (); | |
1528 | CORE_ADDR new_pc = read_memory_integer (fsr->regs[PCOQ_HEAD_REGNUM], 4); | |
1529 | struct target_waitstatus w; | |
1530 | int insn_count; | |
1531 | ||
1532 | /* Advance past break instruction in the call dummy. */ | |
1533 | write_register (PCOQ_HEAD_REGNUM, pc + 4); | |
1534 | write_register (PCOQ_TAIL_REGNUM, pc + 8); | |
1535 | ||
1536 | /* HPUX doesn't let us set the space registers or the space | |
1537 | registers of the PC queue through ptrace. Boo, hiss. | |
1538 | Conveniently, the call dummy has this sequence of instructions | |
1539 | after the break: | |
c5aa993b JM |
1540 | mtsp r21, sr0 |
1541 | ble,n 0(sr0, r22) | |
1542 | ||
c906108c SS |
1543 | So, load up the registers and single step until we are in the |
1544 | right place. */ | |
1545 | ||
1546 | write_register (21, read_memory_integer (fsr->regs[PCSQ_HEAD_REGNUM], 4)); | |
1547 | write_register (22, new_pc); | |
1548 | ||
1549 | for (insn_count = 0; insn_count < 3; insn_count++) | |
1550 | { | |
1551 | /* FIXME: What if the inferior gets a signal right now? Want to | |
c5aa993b JM |
1552 | merge this into wait_for_inferior (as a special kind of |
1553 | watchpoint? By setting a breakpoint at the end? Is there | |
1554 | any other choice? Is there *any* way to do this stuff with | |
1555 | ptrace() or some equivalent?). */ | |
c906108c SS |
1556 | resume (1, 0); |
1557 | target_wait (inferior_pid, &w); | |
1558 | ||
1559 | if (w.kind == TARGET_WAITKIND_SIGNALLED) | |
c5aa993b JM |
1560 | { |
1561 | stop_signal = w.value.sig; | |
1562 | terminal_ours_for_output (); | |
1563 | printf_unfiltered ("\nProgram terminated with signal %s, %s.\n", | |
c906108c SS |
1564 | target_signal_to_name (stop_signal), |
1565 | target_signal_to_string (stop_signal)); | |
c5aa993b JM |
1566 | gdb_flush (gdb_stdout); |
1567 | return 0; | |
1568 | } | |
c906108c SS |
1569 | } |
1570 | target_terminal_ours (); | |
1571 | target_fetch_registers (-1); | |
1572 | return 1; | |
1573 | } | |
1574 | ||
1575 | #if 0 | |
1576 | CORE_ADDR | |
1577 | hppa_push_arguments (nargs, args, sp, struct_return, struct_addr) | |
1578 | int nargs; | |
1579 | value_ptr *args; | |
1580 | CORE_ADDR sp; | |
1581 | int struct_return; | |
1582 | CORE_ADDR struct_addr; | |
1583 | { | |
1584 | /* array of arguments' offsets */ | |
c5aa993b | 1585 | int *offset = (int *) alloca (nargs * sizeof (int)); |
c906108c SS |
1586 | int cum = 0; |
1587 | int i, alignment; | |
c5aa993b | 1588 | |
c906108c SS |
1589 | for (i = 0; i < nargs; i++) |
1590 | { | |
1591 | int x = 0; | |
1592 | /* cum is the sum of the lengths in bytes of | |
c5aa993b | 1593 | the arguments seen so far */ |
c906108c SS |
1594 | cum += TYPE_LENGTH (VALUE_TYPE (args[i])); |
1595 | ||
c5aa993b JM |
1596 | /* value must go at proper alignment. Assume alignment is a |
1597 | power of two. */ | |
c906108c SS |
1598 | alignment = hppa_alignof (VALUE_TYPE (args[i])); |
1599 | ||
1600 | if (cum % alignment) | |
1601 | cum = (cum + alignment) & -alignment; | |
1602 | offset[i] = -cum; | |
1603 | ||
1604 | } | |
1605 | sp += max ((cum + 7) & -8, 16); | |
1606 | ||
1607 | for (i = 0; i < nargs; i++) | |
1608 | write_memory (sp + offset[i], VALUE_CONTENTS (args[i]), | |
1609 | TYPE_LENGTH (VALUE_TYPE (args[i]))); | |
1610 | ||
1611 | if (struct_return) | |
1612 | write_register (28, struct_addr); | |
1613 | return sp + 32; | |
1614 | } | |
1615 | #endif | |
1616 | ||
1617 | /* elz: I am rewriting this function, because the one above is a very | |
1618 | obscure piece of code. | |
1619 | This function pushes the arguments on the stack. The stack grows up | |
1620 | on the PA. | |
1621 | Each argument goes in one (or more) word (4 bytes) on the stack. | |
1622 | The first four words for the args must be allocated, even if they | |
1623 | are not used. | |
1624 | The 'topmost' arg is arg0, the 'bottom-most' is arg3. (if you think of | |
1625 | them as 1 word long). | |
1626 | Below these there can be any number of arguments, as needed by the function. | |
1627 | If an arg is bigger than one word, it will be written on the stack | |
1628 | occupying as many words as needed. Args that are bigger than 64bits | |
1629 | are not copied on the stack, a pointer is passed instead. | |
1630 | ||
1631 | On top of the arg0 word there are other 8 words (32bytes) which are used | |
1632 | for other purposes */ | |
1633 | ||
1634 | CORE_ADDR | |
1635 | hppa_push_arguments (nargs, args, sp, struct_return, struct_addr) | |
1636 | int nargs; | |
1637 | value_ptr *args; | |
1638 | CORE_ADDR sp; | |
1639 | int struct_return; | |
1640 | CORE_ADDR struct_addr; | |
1641 | { | |
1642 | /* array of arguments' offsets */ | |
c5aa993b | 1643 | int *offset = (int *) alloca (nargs * sizeof (int)); |
c906108c | 1644 | /* array of arguments' lengths: real lengths in bytes, not aligned to word size */ |
c5aa993b | 1645 | int *lengths = (int *) alloca (nargs * sizeof (int)); |
c906108c | 1646 | |
c5aa993b JM |
1647 | int bytes_reserved; /* this is the number of bytes on the stack occupied by an |
1648 | argument. This will be always a multiple of 4 */ | |
c906108c | 1649 | |
c5aa993b JM |
1650 | int cum_bytes_reserved = 0; /* this is the total number of bytes reserved by the args |
1651 | seen so far. It is a multiple of 4 always */ | |
1652 | int cum_bytes_aligned = 0; /* same as above, but aligned on 8 bytes */ | |
1653 | int i; | |
c906108c SS |
1654 | |
1655 | /* When an arg does not occupy a whole word, for instance in bitfields: | |
1656 | if the arg is x bits (0<x<32), it must be written | |
1657 | starting from the (x-1)-th position down until the 0-th position. | |
c5aa993b | 1658 | It is enough to align it to the word. */ |
c906108c SS |
1659 | /* if an arg occupies 8 bytes, it must be aligned on the 64-bits |
1660 | high order word in odd arg word. */ | |
1661 | /* if an arg is larger than 64 bits, we need to pass a pointer to it, and | |
1662 | copy the actual value on the stack, so that the callee can play with it. | |
1663 | This is taken care of in valops.c in the call_function_by_hand function. | |
1664 | The argument that is received in this function here has already be converted | |
1665 | to a pointer to whatever is needed, so that it just can be pushed | |
1666 | as a word argument */ | |
c5aa993b | 1667 | |
c906108c SS |
1668 | for (i = 0; i < nargs; i++) |
1669 | { | |
1670 | ||
1671 | lengths[i] = TYPE_LENGTH (VALUE_TYPE (args[i])); | |
1672 | ||
1673 | if (lengths[i] % 4) | |
c5aa993b JM |
1674 | bytes_reserved = (lengths[i] / 4) * 4 + 4; |
1675 | else | |
1676 | bytes_reserved = lengths[i]; | |
c906108c SS |
1677 | |
1678 | offset[i] = cum_bytes_reserved + lengths[i]; | |
1679 | ||
c5aa993b JM |
1680 | if ((bytes_reserved == 8) && (offset[i] % 8)) /* if 64-bit arg is not 64 bit aligned */ |
1681 | { | |
1682 | int new_offset = 0; | |
1683 | /* bytes_reserved is already aligned to the word, so we put it at one word | |
1684 | more down the stack. This will leave one empty word on the | |
1685 | stack, and one unused register. This is OK, see the calling | |
1686 | convention doc */ | |
1687 | /* the offset may have to be moved to the corresponding position | |
1688 | one word down the stack, to maintain | |
1689 | alignment. */ | |
1690 | new_offset = (offset[i] / 8) * 8 + 8; | |
1691 | if ((new_offset - offset[i]) >= 4) | |
1692 | { | |
1693 | bytes_reserved += 4; | |
1694 | offset[i] += 4; | |
1695 | } | |
1696 | } | |
c906108c SS |
1697 | |
1698 | cum_bytes_reserved += bytes_reserved; | |
1699 | ||
1700 | } | |
1701 | ||
1702 | /* now move up the sp to reserve at least 4 words required for the args, | |
1703 | or more than this if needed */ | |
1704 | /* wee also need to keep the sp aligned to 8 bytes */ | |
1705 | cum_bytes_aligned = STACK_ALIGN (cum_bytes_reserved); | |
1706 | sp += max (cum_bytes_aligned, 16); | |
1707 | ||
1708 | /* now write each of the args at the proper offset down the stack */ | |
1709 | for (i = 0; i < nargs; i++) | |
1710 | write_memory (sp - offset[i], VALUE_CONTENTS (args[i]), lengths[i]); | |
c906108c | 1711 | |
c5aa993b JM |
1712 | |
1713 | /* if a structure has to be returned, set up register 28 to hold its address */ | |
c906108c SS |
1714 | if (struct_return) |
1715 | write_register (28, struct_addr); | |
1716 | ||
c5aa993b | 1717 | /* the stack will have other 8 words on top of the args */ |
c906108c SS |
1718 | return sp + 32; |
1719 | } | |
1720 | ||
1721 | ||
1722 | /* elz: this function returns a value which is built looking at the given address. | |
1723 | It is called from call_function_by_hand, in case we need to return a | |
1724 | value which is larger than 64 bits, and it is stored in the stack rather than | |
1725 | in the registers r28 and r29 or fr4. | |
1726 | This function does the same stuff as value_being_returned in values.c, but | |
1727 | gets the value from the stack rather than from the buffer where all the | |
1728 | registers were saved when the function called completed. */ | |
1729 | value_ptr | |
c5aa993b | 1730 | hppa_value_returned_from_stack (valtype, addr) |
c906108c SS |
1731 | register struct type *valtype; |
1732 | CORE_ADDR addr; | |
1733 | { | |
1734 | register value_ptr val; | |
1735 | ||
1736 | val = allocate_value (valtype); | |
1737 | CHECK_TYPEDEF (valtype); | |
c5aa993b | 1738 | target_read_memory (addr, VALUE_CONTENTS_RAW (val), TYPE_LENGTH (valtype)); |
c906108c SS |
1739 | |
1740 | return val; | |
1741 | } | |
1742 | ||
1743 | ||
1744 | ||
1745 | /* elz: Used to lookup a symbol in the shared libraries. | |
c5aa993b JM |
1746 | This function calls shl_findsym, indirectly through a |
1747 | call to __d_shl_get. __d_shl_get is in end.c, which is always | |
1748 | linked in by the hp compilers/linkers. | |
1749 | The call to shl_findsym cannot be made directly because it needs | |
1750 | to be active in target address space. | |
1751 | inputs: - minimal symbol pointer for the function we want to look up | |
1752 | - address in target space of the descriptor for the library | |
1753 | where we want to look the symbol up. | |
1754 | This address is retrieved using the | |
1755 | som_solib_get_solib_by_pc function (somsolib.c). | |
1756 | output: - real address in the library of the function. | |
1757 | note: the handle can be null, in which case shl_findsym will look for | |
1758 | the symbol in all the loaded shared libraries. | |
1759 | files to look at if you need reference on this stuff: | |
1760 | dld.c, dld_shl_findsym.c | |
1761 | end.c | |
1762 | man entry for shl_findsym */ | |
c906108c SS |
1763 | |
1764 | CORE_ADDR | |
c5aa993b JM |
1765 | find_stub_with_shl_get (function, handle) |
1766 | struct minimal_symbol *function; | |
1767 | CORE_ADDR handle; | |
c906108c | 1768 | { |
c5aa993b JM |
1769 | struct symbol *get_sym, *symbol2; |
1770 | struct minimal_symbol *buff_minsym, *msymbol; | |
1771 | struct type *ftype; | |
1772 | value_ptr *args; | |
1773 | value_ptr funcval, val; | |
1774 | ||
1775 | int x, namelen, err_value, tmp = -1; | |
1776 | CORE_ADDR endo_buff_addr, value_return_addr, errno_return_addr; | |
1777 | CORE_ADDR stub_addr; | |
1778 | ||
1779 | ||
1780 | args = (value_ptr *) alloca (sizeof (value_ptr) * 8); /* 6 for the arguments and one null one??? */ | |
1781 | funcval = find_function_in_inferior ("__d_shl_get"); | |
1782 | get_sym = lookup_symbol ("__d_shl_get", NULL, VAR_NAMESPACE, NULL, NULL); | |
1783 | buff_minsym = lookup_minimal_symbol ("__buffer", NULL, NULL); | |
1784 | msymbol = lookup_minimal_symbol ("__shldp", NULL, NULL); | |
1785 | symbol2 = lookup_symbol ("__shldp", NULL, VAR_NAMESPACE, NULL, NULL); | |
1786 | endo_buff_addr = SYMBOL_VALUE_ADDRESS (buff_minsym); | |
1787 | namelen = strlen (SYMBOL_NAME (function)); | |
1788 | value_return_addr = endo_buff_addr + namelen; | |
1789 | ftype = check_typedef (SYMBOL_TYPE (get_sym)); | |
1790 | ||
1791 | /* do alignment */ | |
1792 | if ((x = value_return_addr % 64) != 0) | |
1793 | value_return_addr = value_return_addr + 64 - x; | |
1794 | ||
1795 | errno_return_addr = value_return_addr + 64; | |
1796 | ||
1797 | ||
1798 | /* set up stuff needed by __d_shl_get in buffer in end.o */ | |
1799 | ||
1800 | target_write_memory (endo_buff_addr, SYMBOL_NAME (function), namelen); | |
1801 | ||
1802 | target_write_memory (value_return_addr, (char *) &tmp, 4); | |
1803 | ||
1804 | target_write_memory (errno_return_addr, (char *) &tmp, 4); | |
1805 | ||
1806 | target_write_memory (SYMBOL_VALUE_ADDRESS (msymbol), | |
1807 | (char *) &handle, 4); | |
1808 | ||
1809 | /* now prepare the arguments for the call */ | |
1810 | ||
1811 | args[0] = value_from_longest (TYPE_FIELD_TYPE (ftype, 0), 12); | |
1812 | args[1] = value_from_longest (TYPE_FIELD_TYPE (ftype, 1), SYMBOL_VALUE_ADDRESS (msymbol)); | |
1813 | args[2] = value_from_longest (TYPE_FIELD_TYPE (ftype, 2), endo_buff_addr); | |
1814 | args[3] = value_from_longest (TYPE_FIELD_TYPE (ftype, 3), TYPE_PROCEDURE); | |
1815 | args[4] = value_from_longest (TYPE_FIELD_TYPE (ftype, 4), value_return_addr); | |
1816 | args[5] = value_from_longest (TYPE_FIELD_TYPE (ftype, 5), errno_return_addr); | |
1817 | ||
1818 | /* now call the function */ | |
1819 | ||
1820 | val = call_function_by_hand (funcval, 6, args); | |
1821 | ||
1822 | /* now get the results */ | |
1823 | ||
1824 | target_read_memory (errno_return_addr, (char *) &err_value, sizeof (err_value)); | |
1825 | ||
1826 | target_read_memory (value_return_addr, (char *) &stub_addr, sizeof (stub_addr)); | |
1827 | if (stub_addr <= 0) | |
1828 | error ("call to __d_shl_get failed, error code is %d", err_value); /* purecov: deadcode */ | |
1829 | ||
1830 | return (stub_addr); | |
c906108c SS |
1831 | } |
1832 | ||
c5aa993b | 1833 | /* Cover routine for find_stub_with_shl_get to pass to catch_errors */ |
a0b3c4fd JM |
1834 | static int |
1835 | cover_find_stub_with_shl_get (PTR args_untyped) | |
c906108c | 1836 | { |
a0b3c4fd JM |
1837 | args_for_find_stub *args = args_untyped; |
1838 | args->return_val = find_stub_with_shl_get (args->msym, args->solib_handle); | |
1839 | return 0; | |
c906108c SS |
1840 | } |
1841 | ||
c906108c SS |
1842 | /* Insert the specified number of args and function address |
1843 | into a call sequence of the above form stored at DUMMYNAME. | |
1844 | ||
1845 | On the hppa we need to call the stack dummy through $$dyncall. | |
1846 | Therefore our version of FIX_CALL_DUMMY takes an extra argument, | |
1847 | real_pc, which is the location where gdb should start up the | |
cce74817 JM |
1848 | inferior to do the function call. |
1849 | ||
1850 | This has to work across several versions of hpux, bsd, osf1. It has to | |
1851 | work regardless of what compiler was used to build the inferior program. | |
1852 | It should work regardless of whether or not end.o is available. It has | |
1853 | to work even if gdb can not call into the dynamic loader in the inferior | |
1854 | to query it for symbol names and addresses. | |
1855 | ||
1856 | Yes, all those cases should work. Luckily code exists to handle most | |
1857 | of them. The complexity is in selecting exactly what scheme should | |
1858 | be used to perform the inferior call. | |
1859 | ||
1860 | At the current time this routine is known not to handle cases where | |
1861 | the program was linked with HP's compiler without including end.o. | |
1862 | ||
1863 | Please contact Jeff Law ([email protected]) before changing this code. */ | |
c906108c SS |
1864 | |
1865 | CORE_ADDR | |
1866 | hppa_fix_call_dummy (dummy, pc, fun, nargs, args, type, gcc_p) | |
1867 | char *dummy; | |
1868 | CORE_ADDR pc; | |
1869 | CORE_ADDR fun; | |
1870 | int nargs; | |
1871 | value_ptr *args; | |
1872 | struct type *type; | |
1873 | int gcc_p; | |
1874 | { | |
1875 | CORE_ADDR dyncall_addr; | |
1876 | struct minimal_symbol *msymbol; | |
1877 | struct minimal_symbol *trampoline; | |
1878 | int flags = read_register (FLAGS_REGNUM); | |
cce74817 JM |
1879 | struct unwind_table_entry *u = NULL; |
1880 | CORE_ADDR new_stub = 0; | |
1881 | CORE_ADDR solib_handle = 0; | |
1882 | ||
1883 | /* Nonzero if we will use GCC's PLT call routine. This routine must be | |
c5aa993b | 1884 | passed an import stub, not a PLABEL. It is also necessary to set %r19 |
cce74817 | 1885 | (the PIC register) before performing the call. |
c906108c | 1886 | |
cce74817 JM |
1887 | If zero, then we are using __d_plt_call (HP's PLT call routine) or we |
1888 | are calling the target directly. When using __d_plt_call we want to | |
1889 | use a PLABEL instead of an import stub. */ | |
1890 | int using_gcc_plt_call = 1; | |
1891 | ||
1892 | /* Prefer __gcc_plt_call over the HP supplied routine because | |
c5aa993b | 1893 | __gcc_plt_call works for any number of arguments. */ |
c906108c | 1894 | trampoline = NULL; |
cce74817 JM |
1895 | if (lookup_minimal_symbol ("__gcc_plt_call", NULL, NULL) == NULL) |
1896 | using_gcc_plt_call = 0; | |
1897 | ||
c906108c SS |
1898 | msymbol = lookup_minimal_symbol ("$$dyncall", NULL, NULL); |
1899 | if (msymbol == NULL) | |
cce74817 | 1900 | error ("Can't find an address for $$dyncall trampoline"); |
c906108c SS |
1901 | |
1902 | dyncall_addr = SYMBOL_VALUE_ADDRESS (msymbol); | |
1903 | ||
1904 | /* FUN could be a procedure label, in which case we have to get | |
cce74817 JM |
1905 | its real address and the value of its GOT/DP if we plan to |
1906 | call the routine via gcc_plt_call. */ | |
1907 | if ((fun & 0x2) && using_gcc_plt_call) | |
c906108c SS |
1908 | { |
1909 | /* Get the GOT/DP value for the target function. It's | |
c5aa993b JM |
1910 | at *(fun+4). Note the call dummy is *NOT* allowed to |
1911 | trash %r19 before calling the target function. */ | |
c906108c SS |
1912 | write_register (19, read_memory_integer ((fun & ~0x3) + 4, 4)); |
1913 | ||
1914 | /* Now get the real address for the function we are calling, it's | |
c5aa993b | 1915 | at *fun. */ |
c906108c SS |
1916 | fun = (CORE_ADDR) read_memory_integer (fun & ~0x3, 4); |
1917 | } | |
1918 | else | |
1919 | { | |
1920 | ||
1921 | #ifndef GDB_TARGET_IS_PA_ELF | |
cce74817 | 1922 | /* FUN could be an export stub, the real address of a function, or |
c5aa993b JM |
1923 | a PLABEL. When using gcc's PLT call routine we must call an import |
1924 | stub rather than the export stub or real function for lazy binding | |
1925 | to work correctly | |
cce74817 | 1926 | |
c5aa993b JM |
1927 | /* If we are using the gcc PLT call routine, then we need to |
1928 | get the import stub for the target function. */ | |
cce74817 | 1929 | if (using_gcc_plt_call && som_solib_get_got_by_pc (fun)) |
c906108c SS |
1930 | { |
1931 | struct objfile *objfile; | |
1932 | struct minimal_symbol *funsymbol, *stub_symbol; | |
1933 | CORE_ADDR newfun = 0; | |
1934 | ||
1935 | funsymbol = lookup_minimal_symbol_by_pc (fun); | |
1936 | if (!funsymbol) | |
1937 | error ("Unable to find minimal symbol for target fucntion.\n"); | |
1938 | ||
1939 | /* Search all the object files for an import symbol with the | |
1940 | right name. */ | |
1941 | ALL_OBJFILES (objfile) | |
c5aa993b JM |
1942 | { |
1943 | stub_symbol | |
1944 | = lookup_minimal_symbol_solib_trampoline | |
1945 | (SYMBOL_NAME (funsymbol), NULL, objfile); | |
1946 | ||
1947 | if (!stub_symbol) | |
1948 | stub_symbol = lookup_minimal_symbol (SYMBOL_NAME (funsymbol), | |
1949 | NULL, objfile); | |
1950 | ||
1951 | /* Found a symbol with the right name. */ | |
1952 | if (stub_symbol) | |
1953 | { | |
1954 | struct unwind_table_entry *u; | |
1955 | /* It must be a shared library trampoline. */ | |
1956 | if (MSYMBOL_TYPE (stub_symbol) != mst_solib_trampoline) | |
1957 | continue; | |
1958 | ||
1959 | /* It must also be an import stub. */ | |
1960 | u = find_unwind_entry (SYMBOL_VALUE (stub_symbol)); | |
1961 | if (!u | |
1962 | || (u->stub_unwind.stub_type != IMPORT) | |
1963 | && u->stub_unwind.stub_type != IMPORT_SHLIB) | |
1964 | continue; | |
1965 | ||
1966 | /* OK. Looks like the correct import stub. */ | |
1967 | newfun = SYMBOL_VALUE (stub_symbol); | |
1968 | fun = newfun; | |
1969 | } | |
1970 | } | |
cce74817 JM |
1971 | |
1972 | /* Ouch. We did not find an import stub. Make an attempt to | |
1973 | do the right thing instead of just croaking. Most of the | |
1974 | time this will actually work. */ | |
c906108c SS |
1975 | if (newfun == 0) |
1976 | write_register (19, som_solib_get_got_by_pc (fun)); | |
cce74817 JM |
1977 | |
1978 | u = find_unwind_entry (fun); | |
c5aa993b | 1979 | if (u |
cce74817 JM |
1980 | && (u->stub_unwind.stub_type == IMPORT |
1981 | || u->stub_unwind.stub_type == IMPORT_SHLIB)) | |
1982 | trampoline = lookup_minimal_symbol ("__gcc_plt_call", NULL, NULL); | |
1983 | ||
1984 | /* If we found the import stub in the shared library, then we have | |
1985 | to set %r19 before we call the stub. */ | |
1986 | if (u && u->stub_unwind.stub_type == IMPORT_SHLIB) | |
1987 | write_register (19, som_solib_get_got_by_pc (fun)); | |
c906108c | 1988 | } |
c906108c SS |
1989 | #endif |
1990 | } | |
1991 | ||
cce74817 JM |
1992 | /* If we are calling into another load module then have sr4export call the |
1993 | magic __d_plt_call routine which is linked in from end.o. | |
c906108c | 1994 | |
cce74817 JM |
1995 | You can't use _sr4export to make the call as the value in sp-24 will get |
1996 | fried and you end up returning to the wrong location. You can't call the | |
1997 | target as the code to bind the PLT entry to a function can't return to a | |
1998 | stack address. | |
1999 | ||
2000 | Also, query the dynamic linker in the inferior to provide a suitable | |
2001 | PLABEL for the target function. */ | |
c5aa993b | 2002 | if (!using_gcc_plt_call) |
c906108c SS |
2003 | { |
2004 | CORE_ADDR new_fun; | |
2005 | ||
cce74817 | 2006 | /* Get a handle for the shared library containing FUN. Given the |
c5aa993b | 2007 | handle we can query the shared library for a PLABEL. */ |
cce74817 | 2008 | solib_handle = som_solib_get_solib_by_pc (fun); |
c906108c | 2009 | |
cce74817 | 2010 | if (solib_handle) |
c906108c | 2011 | { |
cce74817 | 2012 | struct minimal_symbol *fmsymbol = lookup_minimal_symbol_by_pc (fun); |
c906108c | 2013 | |
cce74817 JM |
2014 | trampoline = lookup_minimal_symbol ("__d_plt_call", NULL, NULL); |
2015 | ||
2016 | if (trampoline == NULL) | |
2017 | { | |
2018 | error ("Can't find an address for __d_plt_call or __gcc_plt_call trampoline\nSuggest linking executable with -g or compiling with gcc."); | |
2019 | } | |
2020 | ||
2021 | /* This is where sr4export will jump to. */ | |
2022 | new_fun = SYMBOL_VALUE_ADDRESS (trampoline); | |
2023 | ||
2024 | /* If the function is in a shared library, then call __d_shl_get to | |
2025 | get a PLABEL for the target function. */ | |
2026 | new_stub = find_stub_with_shl_get (fmsymbol, solib_handle); | |
2027 | ||
c5aa993b | 2028 | if (new_stub == 0) |
cce74817 | 2029 | error ("Can't find an import stub for %s", SYMBOL_NAME (fmsymbol)); |
c906108c SS |
2030 | |
2031 | /* We have to store the address of the stub in __shlib_funcptr. */ | |
cce74817 | 2032 | msymbol = lookup_minimal_symbol ("__shlib_funcptr", NULL, |
c5aa993b | 2033 | (struct objfile *) NULL); |
c906108c | 2034 | |
cce74817 JM |
2035 | if (msymbol == NULL) |
2036 | error ("Can't find an address for __shlib_funcptr"); | |
2037 | target_write_memory (SYMBOL_VALUE_ADDRESS (msymbol), | |
c5aa993b | 2038 | (char *) &new_stub, 4); |
c906108c SS |
2039 | |
2040 | /* We want sr4export to call __d_plt_call, so we claim it is | |
2041 | the final target. Clear trampoline. */ | |
cce74817 JM |
2042 | fun = new_fun; |
2043 | trampoline = NULL; | |
c906108c SS |
2044 | } |
2045 | } | |
2046 | ||
adf40b2e | 2047 | #ifndef GDB_TARGET_IS_HPPA_20W |
c906108c SS |
2048 | /* Store upper 21 bits of function address into ldil. fun will either be |
2049 | the final target (most cases) or __d_plt_call when calling into a shared | |
2050 | library and __gcc_plt_call is not available. */ | |
2051 | store_unsigned_integer | |
2052 | (&dummy[FUNC_LDIL_OFFSET], | |
2053 | INSTRUCTION_SIZE, | |
2054 | deposit_21 (fun >> 11, | |
2055 | extract_unsigned_integer (&dummy[FUNC_LDIL_OFFSET], | |
2056 | INSTRUCTION_SIZE))); | |
2057 | ||
2058 | /* Store lower 11 bits of function address into ldo */ | |
2059 | store_unsigned_integer | |
2060 | (&dummy[FUNC_LDO_OFFSET], | |
2061 | INSTRUCTION_SIZE, | |
2062 | deposit_14 (fun & MASK_11, | |
2063 | extract_unsigned_integer (&dummy[FUNC_LDO_OFFSET], | |
2064 | INSTRUCTION_SIZE))); | |
adf40b2e | 2065 | #endif /* GDB_TARGET_IS_HPPA_20W */ |
c906108c SS |
2066 | #ifdef SR4EXPORT_LDIL_OFFSET |
2067 | ||
2068 | { | |
2069 | CORE_ADDR trampoline_addr; | |
2070 | ||
2071 | /* We may still need sr4export's address too. */ | |
2072 | ||
2073 | if (trampoline == NULL) | |
2074 | { | |
2075 | msymbol = lookup_minimal_symbol ("_sr4export", NULL, NULL); | |
2076 | if (msymbol == NULL) | |
cce74817 | 2077 | error ("Can't find an address for _sr4export trampoline"); |
c906108c SS |
2078 | |
2079 | trampoline_addr = SYMBOL_VALUE_ADDRESS (msymbol); | |
2080 | } | |
2081 | else | |
2082 | trampoline_addr = SYMBOL_VALUE_ADDRESS (trampoline); | |
2083 | ||
2084 | ||
2085 | /* Store upper 21 bits of trampoline's address into ldil */ | |
2086 | store_unsigned_integer | |
2087 | (&dummy[SR4EXPORT_LDIL_OFFSET], | |
2088 | INSTRUCTION_SIZE, | |
2089 | deposit_21 (trampoline_addr >> 11, | |
2090 | extract_unsigned_integer (&dummy[SR4EXPORT_LDIL_OFFSET], | |
2091 | INSTRUCTION_SIZE))); | |
2092 | ||
2093 | /* Store lower 11 bits of trampoline's address into ldo */ | |
2094 | store_unsigned_integer | |
2095 | (&dummy[SR4EXPORT_LDO_OFFSET], | |
2096 | INSTRUCTION_SIZE, | |
2097 | deposit_14 (trampoline_addr & MASK_11, | |
2098 | extract_unsigned_integer (&dummy[SR4EXPORT_LDO_OFFSET], | |
2099 | INSTRUCTION_SIZE))); | |
2100 | } | |
2101 | #endif | |
2102 | ||
2103 | write_register (22, pc); | |
2104 | ||
2105 | /* If we are in a syscall, then we should call the stack dummy | |
2106 | directly. $$dyncall is not needed as the kernel sets up the | |
2107 | space id registers properly based on the value in %r31. In | |
2108 | fact calling $$dyncall will not work because the value in %r22 | |
2109 | will be clobbered on the syscall exit path. | |
2110 | ||
2111 | Similarly if the current PC is in a shared library. Note however, | |
2112 | this scheme won't work if the shared library isn't mapped into | |
2113 | the same space as the stack. */ | |
2114 | if (flags & 2) | |
2115 | return pc; | |
2116 | #ifndef GDB_TARGET_IS_PA_ELF | |
2117 | else if (som_solib_get_got_by_pc (target_read_pc (inferior_pid))) | |
2118 | return pc; | |
2119 | #endif | |
2120 | else | |
2121 | return dyncall_addr; | |
c906108c SS |
2122 | } |
2123 | ||
2124 | ||
2125 | ||
2126 | ||
2127 | /* If the pid is in a syscall, then the FP register is not readable. | |
2128 | We'll return zero in that case, rather than attempting to read it | |
2129 | and cause a warning. */ | |
2130 | CORE_ADDR | |
2131 | target_read_fp (pid) | |
c5aa993b | 2132 | int pid; |
c906108c SS |
2133 | { |
2134 | int flags = read_register (FLAGS_REGNUM); | |
2135 | ||
c5aa993b JM |
2136 | if (flags & 2) |
2137 | { | |
2138 | return (CORE_ADDR) 0; | |
2139 | } | |
c906108c SS |
2140 | |
2141 | /* This is the only site that may directly read_register () the FP | |
2142 | register. All others must use TARGET_READ_FP (). */ | |
2143 | return read_register (FP_REGNUM); | |
2144 | } | |
2145 | ||
2146 | ||
2147 | /* Get the PC from %r31 if currently in a syscall. Also mask out privilege | |
2148 | bits. */ | |
2149 | ||
2150 | CORE_ADDR | |
2151 | target_read_pc (pid) | |
2152 | int pid; | |
2153 | { | |
2154 | int flags = read_register_pid (FLAGS_REGNUM, pid); | |
2155 | ||
2156 | /* The following test does not belong here. It is OS-specific, and belongs | |
2157 | in native code. */ | |
2158 | /* Test SS_INSYSCALL */ | |
2159 | if (flags & 2) | |
2160 | return read_register_pid (31, pid) & ~0x3; | |
2161 | ||
2162 | return read_register_pid (PC_REGNUM, pid) & ~0x3; | |
2163 | } | |
2164 | ||
2165 | /* Write out the PC. If currently in a syscall, then also write the new | |
2166 | PC value into %r31. */ | |
2167 | ||
2168 | void | |
2169 | target_write_pc (v, pid) | |
2170 | CORE_ADDR v; | |
2171 | int pid; | |
2172 | { | |
2173 | int flags = read_register_pid (FLAGS_REGNUM, pid); | |
2174 | ||
2175 | /* The following test does not belong here. It is OS-specific, and belongs | |
2176 | in native code. */ | |
2177 | /* If in a syscall, then set %r31. Also make sure to get the | |
2178 | privilege bits set correctly. */ | |
2179 | /* Test SS_INSYSCALL */ | |
2180 | if (flags & 2) | |
2181 | write_register_pid (31, v | 0x3, pid); | |
2182 | ||
2183 | write_register_pid (PC_REGNUM, v, pid); | |
2184 | write_register_pid (NPC_REGNUM, v + 4, pid); | |
2185 | } | |
2186 | ||
2187 | /* return the alignment of a type in bytes. Structures have the maximum | |
2188 | alignment required by their fields. */ | |
2189 | ||
2190 | static int | |
2191 | hppa_alignof (type) | |
2192 | struct type *type; | |
2193 | { | |
2194 | int max_align, align, i; | |
2195 | CHECK_TYPEDEF (type); | |
2196 | switch (TYPE_CODE (type)) | |
2197 | { | |
2198 | case TYPE_CODE_PTR: | |
2199 | case TYPE_CODE_INT: | |
2200 | case TYPE_CODE_FLT: | |
2201 | return TYPE_LENGTH (type); | |
2202 | case TYPE_CODE_ARRAY: | |
2203 | return hppa_alignof (TYPE_FIELD_TYPE (type, 0)); | |
2204 | case TYPE_CODE_STRUCT: | |
2205 | case TYPE_CODE_UNION: | |
2206 | max_align = 1; | |
2207 | for (i = 0; i < TYPE_NFIELDS (type); i++) | |
2208 | { | |
2209 | /* Bit fields have no real alignment. */ | |
2210 | /* if (!TYPE_FIELD_BITPOS (type, i)) */ | |
c5aa993b | 2211 | if (!TYPE_FIELD_BITSIZE (type, i)) /* elz: this should be bitsize */ |
c906108c SS |
2212 | { |
2213 | align = hppa_alignof (TYPE_FIELD_TYPE (type, i)); | |
2214 | max_align = max (max_align, align); | |
2215 | } | |
2216 | } | |
2217 | return max_align; | |
2218 | default: | |
2219 | return 4; | |
2220 | } | |
2221 | } | |
2222 | ||
2223 | /* Print the register regnum, or all registers if regnum is -1 */ | |
2224 | ||
2225 | void | |
2226 | pa_do_registers_info (regnum, fpregs) | |
2227 | int regnum; | |
2228 | int fpregs; | |
2229 | { | |
c5aa993b | 2230 | char raw_regs[REGISTER_BYTES]; |
c906108c SS |
2231 | int i; |
2232 | ||
2233 | /* Make a copy of gdb's save area (may cause actual | |
2234 | reads from the target). */ | |
2235 | for (i = 0; i < NUM_REGS; i++) | |
2236 | read_relative_register_raw_bytes (i, raw_regs + REGISTER_BYTE (i)); | |
2237 | ||
2238 | if (regnum == -1) | |
2239 | pa_print_registers (raw_regs, regnum, fpregs); | |
c5aa993b JM |
2240 | else if (regnum < FP4_REGNUM) |
2241 | { | |
2242 | long reg_val[2]; | |
2243 | ||
2244 | /* Why is the value not passed through "extract_signed_integer" | |
2245 | as in "pa_print_registers" below? */ | |
2246 | pa_register_look_aside (raw_regs, regnum, ®_val[0]); | |
2247 | ||
2248 | if (!is_pa_2) | |
2249 | { | |
2250 | printf_unfiltered ("%s %x\n", REGISTER_NAME (regnum), reg_val[1]); | |
2251 | } | |
c906108c | 2252 | else |
c5aa993b JM |
2253 | { |
2254 | /* Fancy % formats to prevent leading zeros. */ | |
2255 | if (reg_val[0] == 0) | |
2256 | printf_unfiltered ("%s %x\n", REGISTER_NAME (regnum), reg_val[1]); | |
2257 | else | |
2258 | printf_unfiltered ("%s %x%8.8x\n", REGISTER_NAME (regnum), | |
2259 | reg_val[0], reg_val[1]); | |
2260 | } | |
c906108c | 2261 | } |
c906108c | 2262 | else |
c5aa993b JM |
2263 | /* Note that real floating point values only start at |
2264 | FP4_REGNUM. FP0 and up are just status and error | |
2265 | registers, which have integral (bit) values. */ | |
c906108c SS |
2266 | pa_print_fp_reg (regnum); |
2267 | } | |
2268 | ||
2269 | /********** new function ********************/ | |
2270 | void | |
2271 | pa_do_strcat_registers_info (regnum, fpregs, stream, precision) | |
2272 | int regnum; | |
2273 | int fpregs; | |
2274 | GDB_FILE *stream; | |
2275 | enum precision_type precision; | |
2276 | { | |
c5aa993b | 2277 | char raw_regs[REGISTER_BYTES]; |
c906108c SS |
2278 | int i; |
2279 | ||
2280 | /* Make a copy of gdb's save area (may cause actual | |
c5aa993b | 2281 | reads from the target). */ |
c906108c SS |
2282 | for (i = 0; i < NUM_REGS; i++) |
2283 | read_relative_register_raw_bytes (i, raw_regs + REGISTER_BYTE (i)); | |
2284 | ||
2285 | if (regnum == -1) | |
2286 | pa_strcat_registers (raw_regs, regnum, fpregs, stream); | |
2287 | ||
c5aa993b JM |
2288 | else if (regnum < FP4_REGNUM) |
2289 | { | |
2290 | long reg_val[2]; | |
2291 | ||
2292 | /* Why is the value not passed through "extract_signed_integer" | |
2293 | as in "pa_print_registers" below? */ | |
2294 | pa_register_look_aside (raw_regs, regnum, ®_val[0]); | |
c906108c | 2295 | |
c5aa993b JM |
2296 | if (!is_pa_2) |
2297 | { | |
2298 | fprintf_unfiltered (stream, "%s %x", REGISTER_NAME (regnum), reg_val[1]); | |
2299 | } | |
c906108c | 2300 | else |
c5aa993b JM |
2301 | { |
2302 | /* Fancy % formats to prevent leading zeros. */ | |
2303 | if (reg_val[0] == 0) | |
2304 | fprintf_unfiltered (stream, "%s %x", REGISTER_NAME (regnum), | |
2305 | reg_val[1]); | |
2306 | else | |
2307 | fprintf_unfiltered (stream, "%s %x%8.8x", REGISTER_NAME (regnum), | |
2308 | reg_val[0], reg_val[1]); | |
2309 | } | |
c906108c | 2310 | } |
c906108c | 2311 | else |
c5aa993b JM |
2312 | /* Note that real floating point values only start at |
2313 | FP4_REGNUM. FP0 and up are just status and error | |
2314 | registers, which have integral (bit) values. */ | |
c906108c SS |
2315 | pa_strcat_fp_reg (regnum, stream, precision); |
2316 | } | |
2317 | ||
2318 | /* If this is a PA2.0 machine, fetch the real 64-bit register | |
2319 | value. Otherwise use the info from gdb's saved register area. | |
2320 | ||
2321 | Note that reg_val is really expected to be an array of longs, | |
2322 | with two elements. */ | |
2323 | static void | |
c5aa993b | 2324 | pa_register_look_aside (raw_regs, regnum, raw_val) |
c906108c | 2325 | char *raw_regs; |
c5aa993b | 2326 | int regnum; |
c906108c SS |
2327 | long *raw_val; |
2328 | { | |
c5aa993b | 2329 | static int know_which = 0; /* False */ |
c906108c | 2330 | |
c5aa993b | 2331 | int regaddr; |
c906108c SS |
2332 | unsigned int offset; |
2333 | register int i; | |
c5aa993b JM |
2334 | int start; |
2335 | ||
2336 | ||
c906108c SS |
2337 | char buf[MAX_REGISTER_RAW_SIZE]; |
2338 | long long reg_val; | |
2339 | ||
c5aa993b JM |
2340 | if (!know_which) |
2341 | { | |
2342 | if (CPU_PA_RISC2_0 == sysconf (_SC_CPU_VERSION)) | |
2343 | { | |
2344 | is_pa_2 = (1 == 1); | |
2345 | } | |
2346 | ||
2347 | know_which = 1; /* True */ | |
2348 | } | |
c906108c SS |
2349 | |
2350 | raw_val[0] = 0; | |
2351 | raw_val[1] = 0; | |
2352 | ||
c5aa993b JM |
2353 | if (!is_pa_2) |
2354 | { | |
2355 | raw_val[1] = *(long *) (raw_regs + REGISTER_BYTE (regnum)); | |
c906108c | 2356 | return; |
c5aa993b | 2357 | } |
c906108c SS |
2358 | |
2359 | /* Code below copied from hppah-nat.c, with fixes for wide | |
2360 | registers, using different area of save_state, etc. */ | |
2361 | if (regnum == FLAGS_REGNUM || regnum >= FP0_REGNUM || | |
c5aa993b JM |
2362 | !HAVE_STRUCT_SAVE_STATE_T || !HAVE_STRUCT_MEMBER_SS_WIDE) |
2363 | { | |
c906108c | 2364 | /* Use narrow regs area of save_state and default macro. */ |
c5aa993b JM |
2365 | offset = U_REGS_OFFSET; |
2366 | regaddr = register_addr (regnum, offset); | |
2367 | start = 1; | |
2368 | } | |
2369 | else | |
2370 | { | |
c906108c SS |
2371 | /* Use wide regs area, and calculate registers as 8 bytes wide. |
2372 | ||
2373 | We'd like to do this, but current version of "C" doesn't | |
2374 | permit "offsetof": | |
2375 | ||
c5aa993b | 2376 | offset = offsetof(save_state_t, ss_wide); |
c906108c SS |
2377 | |
2378 | Note that to avoid "C" doing typed pointer arithmetic, we | |
2379 | have to cast away the type in our offset calculation: | |
2380 | otherwise we get an offset of 1! */ | |
2381 | ||
7a292a7a | 2382 | /* NB: save_state_t is not available before HPUX 9. |
c5aa993b | 2383 | The ss_wide field is not available previous to HPUX 10.20, |
7a292a7a SS |
2384 | so to avoid compile-time warnings, we only compile this for |
2385 | PA 2.0 processors. This control path should only be followed | |
2386 | if we're debugging a PA 2.0 processor, so this should not cause | |
2387 | problems. */ | |
2388 | ||
c906108c SS |
2389 | /* #if the following code out so that this file can still be |
2390 | compiled on older HPUX boxes (< 10.20) which don't have | |
2391 | this structure/structure member. */ | |
2392 | #if HAVE_STRUCT_SAVE_STATE_T == 1 && HAVE_STRUCT_MEMBER_SS_WIDE == 1 | |
2393 | save_state_t temp; | |
2394 | ||
2395 | offset = ((int) &temp.ss_wide) - ((int) &temp); | |
2396 | regaddr = offset + regnum * 8; | |
c5aa993b | 2397 | start = 0; |
c906108c | 2398 | #endif |
c5aa993b JM |
2399 | } |
2400 | ||
2401 | for (i = start; i < 2; i++) | |
c906108c SS |
2402 | { |
2403 | errno = 0; | |
2404 | raw_val[i] = call_ptrace (PT_RUREGS, inferior_pid, | |
c5aa993b | 2405 | (PTRACE_ARG3_TYPE) regaddr, 0); |
c906108c SS |
2406 | if (errno != 0) |
2407 | { | |
2408 | /* Warning, not error, in case we are attached; sometimes the | |
2409 | kernel doesn't let us at the registers. */ | |
2410 | char *err = safe_strerror (errno); | |
2411 | char *msg = alloca (strlen (err) + 128); | |
2412 | sprintf (msg, "reading register %s: %s", REGISTER_NAME (regnum), err); | |
2413 | warning (msg); | |
2414 | goto error_exit; | |
2415 | } | |
2416 | ||
2417 | regaddr += sizeof (long); | |
2418 | } | |
c5aa993b | 2419 | |
c906108c | 2420 | if (regnum == PCOQ_HEAD_REGNUM || regnum == PCOQ_TAIL_REGNUM) |
c5aa993b | 2421 | raw_val[1] &= ~0x3; /* I think we're masking out space bits */ |
c906108c SS |
2422 | |
2423 | error_exit: | |
2424 | ; | |
2425 | } | |
2426 | ||
2427 | /* "Info all-reg" command */ | |
c5aa993b | 2428 | |
c906108c SS |
2429 | static void |
2430 | pa_print_registers (raw_regs, regnum, fpregs) | |
2431 | char *raw_regs; | |
2432 | int regnum; | |
2433 | int fpregs; | |
2434 | { | |
c5aa993b | 2435 | int i, j; |
adf40b2e JM |
2436 | /* Alas, we are compiled so that "long long" is 32 bits */ |
2437 | long raw_val[2]; | |
c906108c | 2438 | long long_val; |
a0b3c4fd | 2439 | int rows = 48, columns = 2; |
c906108c | 2440 | |
adf40b2e | 2441 | for (i = 0; i < rows; i++) |
c906108c | 2442 | { |
adf40b2e | 2443 | for (j = 0; j < columns; j++) |
c906108c | 2444 | { |
adf40b2e JM |
2445 | /* We display registers in column-major order. */ |
2446 | int regnum = i + j * rows; | |
2447 | ||
c5aa993b JM |
2448 | /* Q: Why is the value passed through "extract_signed_integer", |
2449 | while above, in "pa_do_registers_info" it isn't? | |
2450 | A: ? */ | |
adf40b2e | 2451 | pa_register_look_aside (raw_regs, regnum, &raw_val[0]); |
c5aa993b JM |
2452 | |
2453 | /* Even fancier % formats to prevent leading zeros | |
2454 | and still maintain the output in columns. */ | |
2455 | if (!is_pa_2) | |
2456 | { | |
2457 | /* Being big-endian, on this machine the low bits | |
2458 | (the ones we want to look at) are in the second longword. */ | |
2459 | long_val = extract_signed_integer (&raw_val[1], 4); | |
a0b3c4fd | 2460 | printf_filtered ("%10.10s: %8x ", |
adf40b2e | 2461 | REGISTER_NAME (regnum), long_val); |
c5aa993b JM |
2462 | } |
2463 | else | |
2464 | { | |
2465 | /* raw_val = extract_signed_integer(&raw_val, 8); */ | |
2466 | if (raw_val[0] == 0) | |
a0b3c4fd | 2467 | printf_filtered ("%10.10s: %8x ", |
adf40b2e | 2468 | REGISTER_NAME (regnum), raw_val[1]); |
c5aa993b | 2469 | else |
a0b3c4fd JM |
2470 | printf_filtered ("%10.10s: %8x%8.8x ", |
2471 | REGISTER_NAME (regnum), | |
c5aa993b JM |
2472 | raw_val[0], raw_val[1]); |
2473 | } | |
c906108c SS |
2474 | } |
2475 | printf_unfiltered ("\n"); | |
2476 | } | |
c5aa993b | 2477 | |
c906108c | 2478 | if (fpregs) |
c5aa993b | 2479 | for (i = FP4_REGNUM; i < NUM_REGS; i++) /* FP4_REGNUM == 72 */ |
c906108c SS |
2480 | pa_print_fp_reg (i); |
2481 | } | |
2482 | ||
c5aa993b | 2483 | /************* new function ******************/ |
c906108c SS |
2484 | static void |
2485 | pa_strcat_registers (raw_regs, regnum, fpregs, stream) | |
2486 | char *raw_regs; | |
2487 | int regnum; | |
2488 | int fpregs; | |
2489 | GDB_FILE *stream; | |
2490 | { | |
c5aa993b JM |
2491 | int i, j; |
2492 | long raw_val[2]; /* Alas, we are compiled so that "long long" is 32 bits */ | |
c906108c SS |
2493 | long long_val; |
2494 | enum precision_type precision; | |
2495 | ||
2496 | precision = unspecified_precision; | |
2497 | ||
2498 | for (i = 0; i < 18; i++) | |
2499 | { | |
2500 | for (j = 0; j < 4; j++) | |
2501 | { | |
c5aa993b JM |
2502 | /* Q: Why is the value passed through "extract_signed_integer", |
2503 | while above, in "pa_do_registers_info" it isn't? | |
2504 | A: ? */ | |
2505 | pa_register_look_aside (raw_regs, i + (j * 18), &raw_val[0]); | |
2506 | ||
2507 | /* Even fancier % formats to prevent leading zeros | |
2508 | and still maintain the output in columns. */ | |
2509 | if (!is_pa_2) | |
2510 | { | |
2511 | /* Being big-endian, on this machine the low bits | |
2512 | (the ones we want to look at) are in the second longword. */ | |
2513 | long_val = extract_signed_integer (&raw_val[1], 4); | |
2514 | fprintf_filtered (stream, "%8.8s: %8x ", REGISTER_NAME (i + (j * 18)), long_val); | |
2515 | } | |
2516 | else | |
2517 | { | |
2518 | /* raw_val = extract_signed_integer(&raw_val, 8); */ | |
2519 | if (raw_val[0] == 0) | |
2520 | fprintf_filtered (stream, "%8.8s: %8x ", REGISTER_NAME (i + (j * 18)), | |
2521 | raw_val[1]); | |
2522 | else | |
2523 | fprintf_filtered (stream, "%8.8s: %8x%8.8x ", REGISTER_NAME (i + (j * 18)), | |
2524 | raw_val[0], raw_val[1]); | |
2525 | } | |
c906108c SS |
2526 | } |
2527 | fprintf_unfiltered (stream, "\n"); | |
2528 | } | |
c5aa993b | 2529 | |
c906108c | 2530 | if (fpregs) |
c5aa993b | 2531 | for (i = FP4_REGNUM; i < NUM_REGS; i++) /* FP4_REGNUM == 72 */ |
c906108c SS |
2532 | pa_strcat_fp_reg (i, stream, precision); |
2533 | } | |
2534 | ||
2535 | static void | |
2536 | pa_print_fp_reg (i) | |
2537 | int i; | |
2538 | { | |
2539 | char raw_buffer[MAX_REGISTER_RAW_SIZE]; | |
2540 | char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE]; | |
2541 | ||
2542 | /* Get 32bits of data. */ | |
2543 | read_relative_register_raw_bytes (i, raw_buffer); | |
2544 | ||
2545 | /* Put it in the buffer. No conversions are ever necessary. */ | |
2546 | memcpy (virtual_buffer, raw_buffer, REGISTER_RAW_SIZE (i)); | |
2547 | ||
2548 | fputs_filtered (REGISTER_NAME (i), gdb_stdout); | |
2549 | print_spaces_filtered (8 - strlen (REGISTER_NAME (i)), gdb_stdout); | |
2550 | fputs_filtered ("(single precision) ", gdb_stdout); | |
2551 | ||
2552 | val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0, 0, gdb_stdout, 0, | |
2553 | 1, 0, Val_pretty_default); | |
2554 | printf_filtered ("\n"); | |
2555 | ||
2556 | /* If "i" is even, then this register can also be a double-precision | |
2557 | FP register. Dump it out as such. */ | |
2558 | if ((i % 2) == 0) | |
2559 | { | |
2560 | /* Get the data in raw format for the 2nd half. */ | |
2561 | read_relative_register_raw_bytes (i + 1, raw_buffer); | |
2562 | ||
2563 | /* Copy it into the appropriate part of the virtual buffer. */ | |
2564 | memcpy (virtual_buffer + REGISTER_RAW_SIZE (i), raw_buffer, | |
2565 | REGISTER_RAW_SIZE (i)); | |
2566 | ||
2567 | /* Dump it as a double. */ | |
2568 | fputs_filtered (REGISTER_NAME (i), gdb_stdout); | |
2569 | print_spaces_filtered (8 - strlen (REGISTER_NAME (i)), gdb_stdout); | |
2570 | fputs_filtered ("(double precision) ", gdb_stdout); | |
2571 | ||
2572 | val_print (builtin_type_double, virtual_buffer, 0, 0, gdb_stdout, 0, | |
2573 | 1, 0, Val_pretty_default); | |
2574 | printf_filtered ("\n"); | |
2575 | } | |
2576 | } | |
2577 | ||
2578 | /*************** new function ***********************/ | |
2579 | static void | |
2580 | pa_strcat_fp_reg (i, stream, precision) | |
2581 | int i; | |
2582 | GDB_FILE *stream; | |
2583 | enum precision_type precision; | |
2584 | { | |
2585 | char raw_buffer[MAX_REGISTER_RAW_SIZE]; | |
2586 | char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE]; | |
2587 | ||
2588 | fputs_filtered (REGISTER_NAME (i), stream); | |
2589 | print_spaces_filtered (8 - strlen (REGISTER_NAME (i)), stream); | |
2590 | ||
2591 | /* Get 32bits of data. */ | |
2592 | read_relative_register_raw_bytes (i, raw_buffer); | |
2593 | ||
2594 | /* Put it in the buffer. No conversions are ever necessary. */ | |
2595 | memcpy (virtual_buffer, raw_buffer, REGISTER_RAW_SIZE (i)); | |
2596 | ||
2597 | if (precision == double_precision && (i % 2) == 0) | |
2598 | { | |
2599 | ||
c5aa993b JM |
2600 | char raw_buf[MAX_REGISTER_RAW_SIZE]; |
2601 | ||
2602 | /* Get the data in raw format for the 2nd half. */ | |
2603 | read_relative_register_raw_bytes (i + 1, raw_buf); | |
2604 | ||
2605 | /* Copy it into the appropriate part of the virtual buffer. */ | |
2606 | memcpy (virtual_buffer + REGISTER_RAW_SIZE (i), raw_buf, REGISTER_RAW_SIZE (i)); | |
c906108c | 2607 | |
c5aa993b JM |
2608 | val_print (builtin_type_double, virtual_buffer, 0, 0, stream, 0, |
2609 | 1, 0, Val_pretty_default); | |
c906108c SS |
2610 | |
2611 | } | |
c5aa993b JM |
2612 | else |
2613 | { | |
2614 | val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0, 0, stream, 0, | |
2615 | 1, 0, Val_pretty_default); | |
2616 | } | |
c906108c SS |
2617 | |
2618 | } | |
2619 | ||
2620 | /* Return one if PC is in the call path of a trampoline, else return zero. | |
2621 | ||
2622 | Note we return one for *any* call trampoline (long-call, arg-reloc), not | |
2623 | just shared library trampolines (import, export). */ | |
2624 | ||
2625 | int | |
2626 | in_solib_call_trampoline (pc, name) | |
2627 | CORE_ADDR pc; | |
2628 | char *name; | |
2629 | { | |
2630 | struct minimal_symbol *minsym; | |
2631 | struct unwind_table_entry *u; | |
2632 | static CORE_ADDR dyncall = 0; | |
2633 | static CORE_ADDR sr4export = 0; | |
2634 | ||
2635 | /* FIXME XXX - dyncall and sr4export must be initialized whenever we get a | |
2636 | new exec file */ | |
2637 | ||
2638 | /* First see if PC is in one of the two C-library trampolines. */ | |
2639 | if (!dyncall) | |
2640 | { | |
2641 | minsym = lookup_minimal_symbol ("$$dyncall", NULL, NULL); | |
2642 | if (minsym) | |
2643 | dyncall = SYMBOL_VALUE_ADDRESS (minsym); | |
2644 | else | |
2645 | dyncall = -1; | |
2646 | } | |
2647 | ||
2648 | if (!sr4export) | |
2649 | { | |
2650 | minsym = lookup_minimal_symbol ("_sr4export", NULL, NULL); | |
2651 | if (minsym) | |
2652 | sr4export = SYMBOL_VALUE_ADDRESS (minsym); | |
2653 | else | |
2654 | sr4export = -1; | |
2655 | } | |
2656 | ||
2657 | if (pc == dyncall || pc == sr4export) | |
2658 | return 1; | |
2659 | ||
2660 | /* Get the unwind descriptor corresponding to PC, return zero | |
2661 | if no unwind was found. */ | |
2662 | u = find_unwind_entry (pc); | |
2663 | if (!u) | |
2664 | return 0; | |
2665 | ||
2666 | /* If this isn't a linker stub, then return now. */ | |
2667 | if (u->stub_unwind.stub_type == 0) | |
2668 | return 0; | |
2669 | ||
2670 | /* By definition a long-branch stub is a call stub. */ | |
2671 | if (u->stub_unwind.stub_type == LONG_BRANCH) | |
2672 | return 1; | |
2673 | ||
2674 | /* The call and return path execute the same instructions within | |
2675 | an IMPORT stub! So an IMPORT stub is both a call and return | |
2676 | trampoline. */ | |
2677 | if (u->stub_unwind.stub_type == IMPORT) | |
2678 | return 1; | |
2679 | ||
2680 | /* Parameter relocation stubs always have a call path and may have a | |
2681 | return path. */ | |
2682 | if (u->stub_unwind.stub_type == PARAMETER_RELOCATION | |
2683 | || u->stub_unwind.stub_type == EXPORT) | |
2684 | { | |
2685 | CORE_ADDR addr; | |
2686 | ||
2687 | /* Search forward from the current PC until we hit a branch | |
c5aa993b | 2688 | or the end of the stub. */ |
c906108c SS |
2689 | for (addr = pc; addr <= u->region_end; addr += 4) |
2690 | { | |
2691 | unsigned long insn; | |
2692 | ||
2693 | insn = read_memory_integer (addr, 4); | |
2694 | ||
2695 | /* Does it look like a bl? If so then it's the call path, if | |
2696 | we find a bv or be first, then we're on the return path. */ | |
2697 | if ((insn & 0xfc00e000) == 0xe8000000) | |
2698 | return 1; | |
2699 | else if ((insn & 0xfc00e001) == 0xe800c000 | |
2700 | || (insn & 0xfc000000) == 0xe0000000) | |
2701 | return 0; | |
2702 | } | |
2703 | ||
2704 | /* Should never happen. */ | |
c5aa993b JM |
2705 | warning ("Unable to find branch in parameter relocation stub.\n"); /* purecov: deadcode */ |
2706 | return 0; /* purecov: deadcode */ | |
c906108c SS |
2707 | } |
2708 | ||
2709 | /* Unknown stub type. For now, just return zero. */ | |
c5aa993b | 2710 | return 0; /* purecov: deadcode */ |
c906108c SS |
2711 | } |
2712 | ||
2713 | /* Return one if PC is in the return path of a trampoline, else return zero. | |
2714 | ||
2715 | Note we return one for *any* call trampoline (long-call, arg-reloc), not | |
2716 | just shared library trampolines (import, export). */ | |
2717 | ||
2718 | int | |
2719 | in_solib_return_trampoline (pc, name) | |
2720 | CORE_ADDR pc; | |
2721 | char *name; | |
2722 | { | |
2723 | struct unwind_table_entry *u; | |
2724 | ||
2725 | /* Get the unwind descriptor corresponding to PC, return zero | |
2726 | if no unwind was found. */ | |
2727 | u = find_unwind_entry (pc); | |
2728 | if (!u) | |
2729 | return 0; | |
2730 | ||
2731 | /* If this isn't a linker stub or it's just a long branch stub, then | |
2732 | return zero. */ | |
2733 | if (u->stub_unwind.stub_type == 0 || u->stub_unwind.stub_type == LONG_BRANCH) | |
2734 | return 0; | |
2735 | ||
2736 | /* The call and return path execute the same instructions within | |
2737 | an IMPORT stub! So an IMPORT stub is both a call and return | |
2738 | trampoline. */ | |
2739 | if (u->stub_unwind.stub_type == IMPORT) | |
2740 | return 1; | |
2741 | ||
2742 | /* Parameter relocation stubs always have a call path and may have a | |
2743 | return path. */ | |
2744 | if (u->stub_unwind.stub_type == PARAMETER_RELOCATION | |
2745 | || u->stub_unwind.stub_type == EXPORT) | |
2746 | { | |
2747 | CORE_ADDR addr; | |
2748 | ||
2749 | /* Search forward from the current PC until we hit a branch | |
c5aa993b | 2750 | or the end of the stub. */ |
c906108c SS |
2751 | for (addr = pc; addr <= u->region_end; addr += 4) |
2752 | { | |
2753 | unsigned long insn; | |
2754 | ||
2755 | insn = read_memory_integer (addr, 4); | |
2756 | ||
2757 | /* Does it look like a bl? If so then it's the call path, if | |
2758 | we find a bv or be first, then we're on the return path. */ | |
2759 | if ((insn & 0xfc00e000) == 0xe8000000) | |
2760 | return 0; | |
2761 | else if ((insn & 0xfc00e001) == 0xe800c000 | |
2762 | || (insn & 0xfc000000) == 0xe0000000) | |
2763 | return 1; | |
2764 | } | |
2765 | ||
2766 | /* Should never happen. */ | |
c5aa993b JM |
2767 | warning ("Unable to find branch in parameter relocation stub.\n"); /* purecov: deadcode */ |
2768 | return 0; /* purecov: deadcode */ | |
c906108c SS |
2769 | } |
2770 | ||
2771 | /* Unknown stub type. For now, just return zero. */ | |
c5aa993b | 2772 | return 0; /* purecov: deadcode */ |
c906108c SS |
2773 | |
2774 | } | |
2775 | ||
2776 | /* Figure out if PC is in a trampoline, and if so find out where | |
2777 | the trampoline will jump to. If not in a trampoline, return zero. | |
2778 | ||
2779 | Simple code examination probably is not a good idea since the code | |
2780 | sequences in trampolines can also appear in user code. | |
2781 | ||
2782 | We use unwinds and information from the minimal symbol table to | |
2783 | determine when we're in a trampoline. This won't work for ELF | |
2784 | (yet) since it doesn't create stub unwind entries. Whether or | |
2785 | not ELF will create stub unwinds or normal unwinds for linker | |
2786 | stubs is still being debated. | |
2787 | ||
2788 | This should handle simple calls through dyncall or sr4export, | |
2789 | long calls, argument relocation stubs, and dyncall/sr4export | |
2790 | calling an argument relocation stub. It even handles some stubs | |
2791 | used in dynamic executables. */ | |
2792 | ||
c5aa993b | 2793 | #if 0 |
c906108c SS |
2794 | CORE_ADDR |
2795 | skip_trampoline_code (pc, name) | |
2796 | CORE_ADDR pc; | |
2797 | char *name; | |
2798 | { | |
c5aa993b | 2799 | return find_solib_trampoline_target (pc); |
c906108c SS |
2800 | } |
2801 | ||
2802 | #endif | |
2803 | ||
2804 | CORE_ADDR | |
2805 | skip_trampoline_code (pc, name) | |
2806 | CORE_ADDR pc; | |
2807 | char *name; | |
2808 | { | |
2809 | long orig_pc = pc; | |
2810 | long prev_inst, curr_inst, loc; | |
2811 | static CORE_ADDR dyncall = 0; | |
2812 | static CORE_ADDR dyncall_external = 0; | |
2813 | static CORE_ADDR sr4export = 0; | |
2814 | struct minimal_symbol *msym; | |
2815 | struct unwind_table_entry *u; | |
2816 | ||
2817 | ||
2818 | /* FIXME XXX - dyncall and sr4export must be initialized whenever we get a | |
2819 | new exec file */ | |
2820 | ||
2821 | if (!dyncall) | |
2822 | { | |
2823 | msym = lookup_minimal_symbol ("$$dyncall", NULL, NULL); | |
2824 | if (msym) | |
2825 | dyncall = SYMBOL_VALUE_ADDRESS (msym); | |
2826 | else | |
2827 | dyncall = -1; | |
2828 | } | |
2829 | ||
2830 | if (!dyncall_external) | |
2831 | { | |
2832 | msym = lookup_minimal_symbol ("$$dyncall_external", NULL, NULL); | |
2833 | if (msym) | |
2834 | dyncall_external = SYMBOL_VALUE_ADDRESS (msym); | |
2835 | else | |
2836 | dyncall_external = -1; | |
2837 | } | |
2838 | ||
2839 | if (!sr4export) | |
2840 | { | |
2841 | msym = lookup_minimal_symbol ("_sr4export", NULL, NULL); | |
2842 | if (msym) | |
2843 | sr4export = SYMBOL_VALUE_ADDRESS (msym); | |
2844 | else | |
2845 | sr4export = -1; | |
2846 | } | |
2847 | ||
2848 | /* Addresses passed to dyncall may *NOT* be the actual address | |
2849 | of the function. So we may have to do something special. */ | |
2850 | if (pc == dyncall) | |
2851 | { | |
2852 | pc = (CORE_ADDR) read_register (22); | |
2853 | ||
2854 | /* If bit 30 (counting from the left) is on, then pc is the address of | |
c5aa993b JM |
2855 | the PLT entry for this function, not the address of the function |
2856 | itself. Bit 31 has meaning too, but only for MPE. */ | |
c906108c SS |
2857 | if (pc & 0x2) |
2858 | pc = (CORE_ADDR) read_memory_integer (pc & ~0x3, 4); | |
2859 | } | |
2860 | if (pc == dyncall_external) | |
2861 | { | |
2862 | pc = (CORE_ADDR) read_register (22); | |
2863 | pc = (CORE_ADDR) read_memory_integer (pc & ~0x3, 4); | |
2864 | } | |
2865 | else if (pc == sr4export) | |
2866 | pc = (CORE_ADDR) (read_register (22)); | |
2867 | ||
2868 | /* Get the unwind descriptor corresponding to PC, return zero | |
2869 | if no unwind was found. */ | |
2870 | u = find_unwind_entry (pc); | |
2871 | if (!u) | |
2872 | return 0; | |
2873 | ||
2874 | /* If this isn't a linker stub, then return now. */ | |
2875 | /* elz: attention here! (FIXME) because of a compiler/linker | |
2876 | error, some stubs which should have a non zero stub_unwind.stub_type | |
2877 | have unfortunately a value of zero. So this function would return here | |
2878 | as if we were not in a trampoline. To fix this, we go look at the partial | |
2879 | symbol information, which reports this guy as a stub. | |
2880 | (FIXME): Unfortunately, we are not that lucky: it turns out that the | |
2881 | partial symbol information is also wrong sometimes. This is because | |
2882 | when it is entered (somread.c::som_symtab_read()) it can happen that | |
2883 | if the type of the symbol (from the som) is Entry, and the symbol is | |
2884 | in a shared library, then it can also be a trampoline. This would | |
2885 | be OK, except that I believe the way they decide if we are ina shared library | |
2886 | does not work. SOOOO..., even if we have a regular function w/o trampolines | |
2887 | its minimal symbol can be assigned type mst_solib_trampoline. | |
2888 | Also, if we find that the symbol is a real stub, then we fix the unwind | |
2889 | descriptor, and define the stub type to be EXPORT. | |
c5aa993b | 2890 | Hopefully this is correct most of the times. */ |
c906108c | 2891 | if (u->stub_unwind.stub_type == 0) |
c5aa993b | 2892 | { |
c906108c SS |
2893 | |
2894 | /* elz: NOTE (FIXME!) once the problem with the unwind information is fixed | |
2895 | we can delete all the code which appears between the lines */ | |
2896 | /*--------------------------------------------------------------------------*/ | |
c5aa993b | 2897 | msym = lookup_minimal_symbol_by_pc (pc); |
c906108c | 2898 | |
c5aa993b JM |
2899 | if (msym == NULL || MSYMBOL_TYPE (msym) != mst_solib_trampoline) |
2900 | return orig_pc == pc ? 0 : pc & ~0x3; | |
2901 | ||
2902 | else if (msym != NULL && MSYMBOL_TYPE (msym) == mst_solib_trampoline) | |
2903 | { | |
2904 | struct objfile *objfile; | |
2905 | struct minimal_symbol *msymbol; | |
2906 | int function_found = 0; | |
2907 | ||
2908 | /* go look if there is another minimal symbol with the same name as | |
2909 | this one, but with type mst_text. This would happen if the msym | |
2910 | is an actual trampoline, in which case there would be another | |
2911 | symbol with the same name corresponding to the real function */ | |
2912 | ||
2913 | ALL_MSYMBOLS (objfile, msymbol) | |
2914 | { | |
2915 | if (MSYMBOL_TYPE (msymbol) == mst_text | |
2916 | && STREQ (SYMBOL_NAME (msymbol), SYMBOL_NAME (msym))) | |
2917 | { | |
2918 | function_found = 1; | |
2919 | break; | |
2920 | } | |
2921 | } | |
2922 | ||
2923 | if (function_found) | |
2924 | /* the type of msym is correct (mst_solib_trampoline), but | |
2925 | the unwind info is wrong, so set it to the correct value */ | |
2926 | u->stub_unwind.stub_type = EXPORT; | |
2927 | else | |
2928 | /* the stub type info in the unwind is correct (this is not a | |
2929 | trampoline), but the msym type information is wrong, it | |
2930 | should be mst_text. So we need to fix the msym, and also | |
2931 | get out of this function */ | |
2932 | { | |
2933 | MSYMBOL_TYPE (msym) = mst_text; | |
2934 | return orig_pc == pc ? 0 : pc & ~0x3; | |
2935 | } | |
2936 | } | |
c906108c | 2937 | |
c906108c | 2938 | /*--------------------------------------------------------------------------*/ |
c5aa993b | 2939 | } |
c906108c SS |
2940 | |
2941 | /* It's a stub. Search for a branch and figure out where it goes. | |
2942 | Note we have to handle multi insn branch sequences like ldil;ble. | |
2943 | Most (all?) other branches can be determined by examining the contents | |
2944 | of certain registers and the stack. */ | |
2945 | ||
2946 | loc = pc; | |
2947 | curr_inst = 0; | |
2948 | prev_inst = 0; | |
2949 | while (1) | |
2950 | { | |
2951 | /* Make sure we haven't walked outside the range of this stub. */ | |
2952 | if (u != find_unwind_entry (loc)) | |
2953 | { | |
2954 | warning ("Unable to find branch in linker stub"); | |
2955 | return orig_pc == pc ? 0 : pc & ~0x3; | |
2956 | } | |
2957 | ||
2958 | prev_inst = curr_inst; | |
2959 | curr_inst = read_memory_integer (loc, 4); | |
2960 | ||
2961 | /* Does it look like a branch external using %r1? Then it's the | |
c5aa993b | 2962 | branch from the stub to the actual function. */ |
c906108c SS |
2963 | if ((curr_inst & 0xffe0e000) == 0xe0202000) |
2964 | { | |
2965 | /* Yup. See if the previous instruction loaded | |
2966 | a value into %r1. If so compute and return the jump address. */ | |
2967 | if ((prev_inst & 0xffe00000) == 0x20200000) | |
2968 | return (extract_21 (prev_inst) + extract_17 (curr_inst)) & ~0x3; | |
2969 | else | |
2970 | { | |
2971 | warning ("Unable to find ldil X,%%r1 before ble Y(%%sr4,%%r1)."); | |
2972 | return orig_pc == pc ? 0 : pc & ~0x3; | |
2973 | } | |
2974 | } | |
2975 | ||
2976 | /* Does it look like a be 0(sr0,%r21)? OR | |
2977 | Does it look like a be, n 0(sr0,%r21)? OR | |
2978 | Does it look like a bve (r21)? (this is on PA2.0) | |
2979 | Does it look like a bve, n(r21)? (this is also on PA2.0) | |
2980 | That's the branch from an | |
c5aa993b | 2981 | import stub to an export stub. |
c906108c | 2982 | |
c5aa993b JM |
2983 | It is impossible to determine the target of the branch via |
2984 | simple examination of instructions and/or data (consider | |
2985 | that the address in the plabel may be the address of the | |
2986 | bind-on-reference routine in the dynamic loader). | |
c906108c | 2987 | |
c5aa993b | 2988 | So we have try an alternative approach. |
c906108c | 2989 | |
c5aa993b JM |
2990 | Get the name of the symbol at our current location; it should |
2991 | be a stub symbol with the same name as the symbol in the | |
2992 | shared library. | |
c906108c | 2993 | |
c5aa993b JM |
2994 | Then lookup a minimal symbol with the same name; we should |
2995 | get the minimal symbol for the target routine in the shared | |
2996 | library as those take precedence of import/export stubs. */ | |
c906108c | 2997 | if ((curr_inst == 0xe2a00000) || |
c5aa993b JM |
2998 | (curr_inst == 0xe2a00002) || |
2999 | (curr_inst == 0xeaa0d000) || | |
3000 | (curr_inst == 0xeaa0d002)) | |
c906108c SS |
3001 | { |
3002 | struct minimal_symbol *stubsym, *libsym; | |
3003 | ||
3004 | stubsym = lookup_minimal_symbol_by_pc (loc); | |
3005 | if (stubsym == NULL) | |
3006 | { | |
3007 | warning ("Unable to find symbol for 0x%x", loc); | |
3008 | return orig_pc == pc ? 0 : pc & ~0x3; | |
3009 | } | |
3010 | ||
3011 | libsym = lookup_minimal_symbol (SYMBOL_NAME (stubsym), NULL, NULL); | |
3012 | if (libsym == NULL) | |
3013 | { | |
3014 | warning ("Unable to find library symbol for %s\n", | |
3015 | SYMBOL_NAME (stubsym)); | |
3016 | return orig_pc == pc ? 0 : pc & ~0x3; | |
3017 | } | |
3018 | ||
3019 | return SYMBOL_VALUE (libsym); | |
3020 | } | |
3021 | ||
3022 | /* Does it look like bl X,%rp or bl X,%r0? Another way to do a | |
c5aa993b JM |
3023 | branch from the stub to the actual function. */ |
3024 | /*elz */ | |
c906108c SS |
3025 | else if ((curr_inst & 0xffe0e000) == 0xe8400000 |
3026 | || (curr_inst & 0xffe0e000) == 0xe8000000 | |
c5aa993b | 3027 | || (curr_inst & 0xffe0e000) == 0xe800A000) |
c906108c SS |
3028 | return (loc + extract_17 (curr_inst) + 8) & ~0x3; |
3029 | ||
3030 | /* Does it look like bv (rp)? Note this depends on the | |
c5aa993b JM |
3031 | current stack pointer being the same as the stack |
3032 | pointer in the stub itself! This is a branch on from the | |
3033 | stub back to the original caller. */ | |
3034 | /*else if ((curr_inst & 0xffe0e000) == 0xe840c000) */ | |
c906108c SS |
3035 | else if ((curr_inst & 0xffe0f000) == 0xe840c000) |
3036 | { | |
3037 | /* Yup. See if the previous instruction loaded | |
3038 | rp from sp - 8. */ | |
3039 | if (prev_inst == 0x4bc23ff1) | |
3040 | return (read_memory_integer | |
3041 | (read_register (SP_REGNUM) - 8, 4)) & ~0x3; | |
3042 | else | |
3043 | { | |
3044 | warning ("Unable to find restore of %%rp before bv (%%rp)."); | |
3045 | return orig_pc == pc ? 0 : pc & ~0x3; | |
3046 | } | |
3047 | } | |
3048 | ||
3049 | /* elz: added this case to capture the new instruction | |
3050 | at the end of the return part of an export stub used by | |
3051 | the PA2.0: BVE, n (rp) */ | |
3052 | else if ((curr_inst & 0xffe0f000) == 0xe840d000) | |
3053 | { | |
c5aa993b | 3054 | return (read_memory_integer |
c906108c SS |
3055 | (read_register (SP_REGNUM) - 24, 4)) & ~0x3; |
3056 | } | |
3057 | ||
3058 | /* What about be,n 0(sr0,%rp)? It's just another way we return to | |
c5aa993b | 3059 | the original caller from the stub. Used in dynamic executables. */ |
c906108c SS |
3060 | else if (curr_inst == 0xe0400002) |
3061 | { | |
3062 | /* The value we jump to is sitting in sp - 24. But that's | |
3063 | loaded several instructions before the be instruction. | |
3064 | I guess we could check for the previous instruction being | |
3065 | mtsp %r1,%sr0 if we want to do sanity checking. */ | |
c5aa993b | 3066 | return (read_memory_integer |
c906108c SS |
3067 | (read_register (SP_REGNUM) - 24, 4)) & ~0x3; |
3068 | } | |
3069 | ||
3070 | /* Haven't found the branch yet, but we're still in the stub. | |
c5aa993b | 3071 | Keep looking. */ |
c906108c SS |
3072 | loc += 4; |
3073 | } | |
3074 | } | |
3075 | ||
3076 | ||
3077 | /* For the given instruction (INST), return any adjustment it makes | |
3078 | to the stack pointer or zero for no adjustment. | |
3079 | ||
3080 | This only handles instructions commonly found in prologues. */ | |
3081 | ||
3082 | static int | |
3083 | prologue_inst_adjust_sp (inst) | |
3084 | unsigned long inst; | |
3085 | { | |
3086 | /* This must persist across calls. */ | |
3087 | static int save_high21; | |
3088 | ||
3089 | /* The most common way to perform a stack adjustment ldo X(sp),sp */ | |
3090 | if ((inst & 0xffffc000) == 0x37de0000) | |
3091 | return extract_14 (inst); | |
3092 | ||
3093 | /* stwm X,D(sp) */ | |
3094 | if ((inst & 0xffe00000) == 0x6fc00000) | |
3095 | return extract_14 (inst); | |
3096 | ||
3097 | /* addil high21,%r1; ldo low11,(%r1),%r30) | |
3098 | save high bits in save_high21 for later use. */ | |
3099 | if ((inst & 0xffe00000) == 0x28200000) | |
3100 | { | |
3101 | save_high21 = extract_21 (inst); | |
3102 | return 0; | |
3103 | } | |
3104 | ||
3105 | if ((inst & 0xffff0000) == 0x343e0000) | |
3106 | return save_high21 + extract_14 (inst); | |
3107 | ||
3108 | /* fstws as used by the HP compilers. */ | |
3109 | if ((inst & 0xffffffe0) == 0x2fd01220) | |
3110 | return extract_5_load (inst); | |
3111 | ||
3112 | /* No adjustment. */ | |
3113 | return 0; | |
3114 | } | |
3115 | ||
3116 | /* Return nonzero if INST is a branch of some kind, else return zero. */ | |
3117 | ||
3118 | static int | |
3119 | is_branch (inst) | |
3120 | unsigned long inst; | |
3121 | { | |
3122 | switch (inst >> 26) | |
3123 | { | |
3124 | case 0x20: | |
3125 | case 0x21: | |
3126 | case 0x22: | |
3127 | case 0x23: | |
7be570e7 | 3128 | case 0x27: |
c906108c SS |
3129 | case 0x28: |
3130 | case 0x29: | |
3131 | case 0x2a: | |
3132 | case 0x2b: | |
7be570e7 | 3133 | case 0x2f: |
c906108c SS |
3134 | case 0x30: |
3135 | case 0x31: | |
3136 | case 0x32: | |
3137 | case 0x33: | |
3138 | case 0x38: | |
3139 | case 0x39: | |
3140 | case 0x3a: | |
7be570e7 | 3141 | case 0x3b: |
c906108c SS |
3142 | return 1; |
3143 | ||
3144 | default: | |
3145 | return 0; | |
3146 | } | |
3147 | } | |
3148 | ||
3149 | /* Return the register number for a GR which is saved by INST or | |
3150 | zero it INST does not save a GR. */ | |
3151 | ||
3152 | static int | |
3153 | inst_saves_gr (inst) | |
3154 | unsigned long inst; | |
3155 | { | |
3156 | /* Does it look like a stw? */ | |
7be570e7 JM |
3157 | if ((inst >> 26) == 0x1a || (inst >> 26) == 0x1b |
3158 | || (inst >> 26) == 0x1f | |
3159 | || ((inst >> 26) == 0x1f | |
3160 | && ((inst >> 6) == 0xa))) | |
3161 | return extract_5R_store (inst); | |
3162 | ||
3163 | /* Does it look like a std? */ | |
3164 | if ((inst >> 26) == 0x1c | |
3165 | || ((inst >> 26) == 0x03 | |
3166 | && ((inst >> 6) & 0xf) == 0xb)) | |
c906108c SS |
3167 | return extract_5R_store (inst); |
3168 | ||
3169 | /* Does it look like a stwm? GCC & HPC may use this in prologues. */ | |
3170 | if ((inst >> 26) == 0x1b) | |
3171 | return extract_5R_store (inst); | |
3172 | ||
3173 | /* Does it look like sth or stb? HPC versions 9.0 and later use these | |
3174 | too. */ | |
7be570e7 JM |
3175 | if ((inst >> 26) == 0x19 || (inst >> 26) == 0x18 |
3176 | || ((inst >> 26) == 0x3 | |
3177 | && (((inst >> 6) & 0xf) == 0x8 | |
3178 | || (inst >> 6) & 0xf) == 0x9)) | |
c906108c | 3179 | return extract_5R_store (inst); |
c5aa993b | 3180 | |
c906108c SS |
3181 | return 0; |
3182 | } | |
3183 | ||
3184 | /* Return the register number for a FR which is saved by INST or | |
3185 | zero it INST does not save a FR. | |
3186 | ||
3187 | Note we only care about full 64bit register stores (that's the only | |
3188 | kind of stores the prologue will use). | |
3189 | ||
3190 | FIXME: What about argument stores with the HP compiler in ANSI mode? */ | |
3191 | ||
3192 | static int | |
3193 | inst_saves_fr (inst) | |
3194 | unsigned long inst; | |
3195 | { | |
7be570e7 | 3196 | /* is this an FSTD ? */ |
c906108c SS |
3197 | if ((inst & 0xfc00dfc0) == 0x2c001200) |
3198 | return extract_5r_store (inst); | |
7be570e7 JM |
3199 | if ((inst & 0xfc000002) == 0x70000002) |
3200 | return extract_5R_store (inst); | |
3201 | /* is this an FSTW ? */ | |
c906108c SS |
3202 | if ((inst & 0xfc00df80) == 0x24001200) |
3203 | return extract_5r_store (inst); | |
7be570e7 JM |
3204 | if ((inst & 0xfc000002) == 0x7c000000) |
3205 | return extract_5R_store (inst); | |
c906108c SS |
3206 | return 0; |
3207 | } | |
3208 | ||
3209 | /* Advance PC across any function entry prologue instructions | |
3210 | to reach some "real" code. | |
3211 | ||
3212 | Use information in the unwind table to determine what exactly should | |
3213 | be in the prologue. */ | |
3214 | ||
3215 | ||
3216 | CORE_ADDR | |
3217 | skip_prologue_hard_way (pc) | |
3218 | CORE_ADDR pc; | |
3219 | { | |
3220 | char buf[4]; | |
3221 | CORE_ADDR orig_pc = pc; | |
3222 | unsigned long inst, stack_remaining, save_gr, save_fr, save_rp, save_sp; | |
3223 | unsigned long args_stored, status, i, restart_gr, restart_fr; | |
3224 | struct unwind_table_entry *u; | |
3225 | ||
3226 | restart_gr = 0; | |
3227 | restart_fr = 0; | |
3228 | ||
3229 | restart: | |
3230 | u = find_unwind_entry (pc); | |
3231 | if (!u) | |
3232 | return pc; | |
3233 | ||
c5aa993b | 3234 | /* If we are not at the beginning of a function, then return now. */ |
c906108c SS |
3235 | if ((pc & ~0x3) != u->region_start) |
3236 | return pc; | |
3237 | ||
3238 | /* This is how much of a frame adjustment we need to account for. */ | |
3239 | stack_remaining = u->Total_frame_size << 3; | |
3240 | ||
3241 | /* Magic register saves we want to know about. */ | |
3242 | save_rp = u->Save_RP; | |
3243 | save_sp = u->Save_SP; | |
3244 | ||
3245 | /* An indication that args may be stored into the stack. Unfortunately | |
3246 | the HPUX compilers tend to set this in cases where no args were | |
3247 | stored too!. */ | |
3248 | args_stored = 1; | |
3249 | ||
3250 | /* Turn the Entry_GR field into a bitmask. */ | |
3251 | save_gr = 0; | |
3252 | for (i = 3; i < u->Entry_GR + 3; i++) | |
3253 | { | |
3254 | /* Frame pointer gets saved into a special location. */ | |
3255 | if (u->Save_SP && i == FP_REGNUM) | |
3256 | continue; | |
3257 | ||
3258 | save_gr |= (1 << i); | |
3259 | } | |
3260 | save_gr &= ~restart_gr; | |
3261 | ||
3262 | /* Turn the Entry_FR field into a bitmask too. */ | |
3263 | save_fr = 0; | |
3264 | for (i = 12; i < u->Entry_FR + 12; i++) | |
3265 | save_fr |= (1 << i); | |
3266 | save_fr &= ~restart_fr; | |
3267 | ||
3268 | /* Loop until we find everything of interest or hit a branch. | |
3269 | ||
3270 | For unoptimized GCC code and for any HP CC code this will never ever | |
3271 | examine any user instructions. | |
3272 | ||
3273 | For optimzied GCC code we're faced with problems. GCC will schedule | |
3274 | its prologue and make prologue instructions available for delay slot | |
3275 | filling. The end result is user code gets mixed in with the prologue | |
3276 | and a prologue instruction may be in the delay slot of the first branch | |
3277 | or call. | |
3278 | ||
3279 | Some unexpected things are expected with debugging optimized code, so | |
3280 | we allow this routine to walk past user instructions in optimized | |
3281 | GCC code. */ | |
3282 | while (save_gr || save_fr || save_rp || save_sp || stack_remaining > 0 | |
3283 | || args_stored) | |
3284 | { | |
3285 | unsigned int reg_num; | |
3286 | unsigned long old_stack_remaining, old_save_gr, old_save_fr; | |
3287 | unsigned long old_save_rp, old_save_sp, next_inst; | |
3288 | ||
3289 | /* Save copies of all the triggers so we can compare them later | |
c5aa993b | 3290 | (only for HPC). */ |
c906108c SS |
3291 | old_save_gr = save_gr; |
3292 | old_save_fr = save_fr; | |
3293 | old_save_rp = save_rp; | |
3294 | old_save_sp = save_sp; | |
3295 | old_stack_remaining = stack_remaining; | |
3296 | ||
3297 | status = target_read_memory (pc, buf, 4); | |
3298 | inst = extract_unsigned_integer (buf, 4); | |
c5aa993b | 3299 | |
c906108c SS |
3300 | /* Yow! */ |
3301 | if (status != 0) | |
3302 | return pc; | |
3303 | ||
3304 | /* Note the interesting effects of this instruction. */ | |
3305 | stack_remaining -= prologue_inst_adjust_sp (inst); | |
3306 | ||
7be570e7 JM |
3307 | /* There are limited ways to store the return pointer into the |
3308 | stack. */ | |
3309 | if (inst == 0x6bc23fd9 || inst == 0x0fc212c1) | |
c906108c SS |
3310 | save_rp = 0; |
3311 | ||
3312 | /* This is the only way we save SP into the stack. At this time | |
c5aa993b | 3313 | the HP compilers never bother to save SP into the stack. */ |
c906108c SS |
3314 | if ((inst & 0xffffc000) == 0x6fc10000) |
3315 | save_sp = 0; | |
3316 | ||
3317 | /* Account for general and floating-point register saves. */ | |
3318 | reg_num = inst_saves_gr (inst); | |
3319 | save_gr &= ~(1 << reg_num); | |
3320 | ||
3321 | /* Ugh. Also account for argument stores into the stack. | |
c5aa993b JM |
3322 | Unfortunately args_stored only tells us that some arguments |
3323 | where stored into the stack. Not how many or what kind! | |
c906108c | 3324 | |
c5aa993b JM |
3325 | This is a kludge as on the HP compiler sets this bit and it |
3326 | never does prologue scheduling. So once we see one, skip past | |
3327 | all of them. We have similar code for the fp arg stores below. | |
c906108c | 3328 | |
c5aa993b JM |
3329 | FIXME. Can still die if we have a mix of GR and FR argument |
3330 | stores! */ | |
c906108c SS |
3331 | if (reg_num >= 23 && reg_num <= 26) |
3332 | { | |
3333 | while (reg_num >= 23 && reg_num <= 26) | |
3334 | { | |
3335 | pc += 4; | |
3336 | status = target_read_memory (pc, buf, 4); | |
3337 | inst = extract_unsigned_integer (buf, 4); | |
3338 | if (status != 0) | |
3339 | return pc; | |
3340 | reg_num = inst_saves_gr (inst); | |
3341 | } | |
3342 | args_stored = 0; | |
3343 | continue; | |
3344 | } | |
3345 | ||
3346 | reg_num = inst_saves_fr (inst); | |
3347 | save_fr &= ~(1 << reg_num); | |
3348 | ||
3349 | status = target_read_memory (pc + 4, buf, 4); | |
3350 | next_inst = extract_unsigned_integer (buf, 4); | |
c5aa993b | 3351 | |
c906108c SS |
3352 | /* Yow! */ |
3353 | if (status != 0) | |
3354 | return pc; | |
3355 | ||
3356 | /* We've got to be read to handle the ldo before the fp register | |
c5aa993b | 3357 | save. */ |
c906108c SS |
3358 | if ((inst & 0xfc000000) == 0x34000000 |
3359 | && inst_saves_fr (next_inst) >= 4 | |
3360 | && inst_saves_fr (next_inst) <= 7) | |
3361 | { | |
3362 | /* So we drop into the code below in a reasonable state. */ | |
3363 | reg_num = inst_saves_fr (next_inst); | |
3364 | pc -= 4; | |
3365 | } | |
3366 | ||
3367 | /* Ugh. Also account for argument stores into the stack. | |
c5aa993b JM |
3368 | This is a kludge as on the HP compiler sets this bit and it |
3369 | never does prologue scheduling. So once we see one, skip past | |
3370 | all of them. */ | |
c906108c SS |
3371 | if (reg_num >= 4 && reg_num <= 7) |
3372 | { | |
3373 | while (reg_num >= 4 && reg_num <= 7) | |
3374 | { | |
3375 | pc += 8; | |
3376 | status = target_read_memory (pc, buf, 4); | |
3377 | inst = extract_unsigned_integer (buf, 4); | |
3378 | if (status != 0) | |
3379 | return pc; | |
3380 | if ((inst & 0xfc000000) != 0x34000000) | |
3381 | break; | |
3382 | status = target_read_memory (pc + 4, buf, 4); | |
3383 | next_inst = extract_unsigned_integer (buf, 4); | |
3384 | if (status != 0) | |
3385 | return pc; | |
3386 | reg_num = inst_saves_fr (next_inst); | |
3387 | } | |
3388 | args_stored = 0; | |
3389 | continue; | |
3390 | } | |
3391 | ||
3392 | /* Quit if we hit any kind of branch. This can happen if a prologue | |
c5aa993b | 3393 | instruction is in the delay slot of the first call/branch. */ |
c906108c SS |
3394 | if (is_branch (inst)) |
3395 | break; | |
3396 | ||
3397 | /* What a crock. The HP compilers set args_stored even if no | |
c5aa993b JM |
3398 | arguments were stored into the stack (boo hiss). This could |
3399 | cause this code to then skip a bunch of user insns (up to the | |
3400 | first branch). | |
3401 | ||
3402 | To combat this we try to identify when args_stored was bogusly | |
3403 | set and clear it. We only do this when args_stored is nonzero, | |
3404 | all other resources are accounted for, and nothing changed on | |
3405 | this pass. */ | |
c906108c | 3406 | if (args_stored |
c5aa993b | 3407 | && !(save_gr || save_fr || save_rp || save_sp || stack_remaining > 0) |
c906108c SS |
3408 | && old_save_gr == save_gr && old_save_fr == save_fr |
3409 | && old_save_rp == save_rp && old_save_sp == save_sp | |
3410 | && old_stack_remaining == stack_remaining) | |
3411 | break; | |
c5aa993b | 3412 | |
c906108c SS |
3413 | /* Bump the PC. */ |
3414 | pc += 4; | |
3415 | } | |
3416 | ||
3417 | /* We've got a tenative location for the end of the prologue. However | |
3418 | because of limitations in the unwind descriptor mechanism we may | |
3419 | have went too far into user code looking for the save of a register | |
3420 | that does not exist. So, if there registers we expected to be saved | |
3421 | but never were, mask them out and restart. | |
3422 | ||
3423 | This should only happen in optimized code, and should be very rare. */ | |
c5aa993b | 3424 | if (save_gr || (save_fr && !(restart_fr || restart_gr))) |
c906108c SS |
3425 | { |
3426 | pc = orig_pc; | |
3427 | restart_gr = save_gr; | |
3428 | restart_fr = save_fr; | |
3429 | goto restart; | |
3430 | } | |
3431 | ||
3432 | return pc; | |
3433 | } | |
3434 | ||
3435 | ||
7be570e7 JM |
3436 | /* Return the address of the PC after the last prologue instruction if |
3437 | we can determine it from the debug symbols. Else return zero. */ | |
c906108c SS |
3438 | |
3439 | static CORE_ADDR | |
3440 | after_prologue (pc) | |
3441 | CORE_ADDR pc; | |
3442 | { | |
3443 | struct symtab_and_line sal; | |
3444 | CORE_ADDR func_addr, func_end; | |
3445 | struct symbol *f; | |
3446 | ||
7be570e7 JM |
3447 | /* If we can not find the symbol in the partial symbol table, then |
3448 | there is no hope we can determine the function's start address | |
3449 | with this code. */ | |
c906108c | 3450 | if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end)) |
7be570e7 | 3451 | return 0; |
c906108c | 3452 | |
7be570e7 | 3453 | /* Get the line associated with FUNC_ADDR. */ |
c906108c SS |
3454 | sal = find_pc_line (func_addr, 0); |
3455 | ||
7be570e7 JM |
3456 | /* There are only two cases to consider. First, the end of the source line |
3457 | is within the function bounds. In that case we return the end of the | |
3458 | source line. Second is the end of the source line extends beyond the | |
3459 | bounds of the current function. We need to use the slow code to | |
3460 | examine instructions in that case. | |
c906108c | 3461 | |
7be570e7 JM |
3462 | Anything else is simply a bug elsewhere. Fixing it here is absolutely |
3463 | the wrong thing to do. In fact, it should be entirely possible for this | |
3464 | function to always return zero since the slow instruction scanning code | |
3465 | is supposed to *always* work. If it does not, then it is a bug. */ | |
3466 | if (sal.end < func_end) | |
3467 | return sal.end; | |
c5aa993b | 3468 | else |
7be570e7 | 3469 | return 0; |
c906108c SS |
3470 | } |
3471 | ||
3472 | /* To skip prologues, I use this predicate. Returns either PC itself | |
3473 | if the code at PC does not look like a function prologue; otherwise | |
3474 | returns an address that (if we're lucky) follows the prologue. If | |
3475 | LENIENT, then we must skip everything which is involved in setting | |
3476 | up the frame (it's OK to skip more, just so long as we don't skip | |
3477 | anything which might clobber the registers which are being saved. | |
3478 | Currently we must not skip more on the alpha, but we might the lenient | |
3479 | stuff some day. */ | |
3480 | ||
3481 | CORE_ADDR | |
b83266a0 | 3482 | hppa_skip_prologue (pc) |
c906108c SS |
3483 | CORE_ADDR pc; |
3484 | { | |
c5aa993b JM |
3485 | unsigned long inst; |
3486 | int offset; | |
3487 | CORE_ADDR post_prologue_pc; | |
3488 | char buf[4]; | |
c906108c | 3489 | |
c5aa993b JM |
3490 | /* See if we can determine the end of the prologue via the symbol table. |
3491 | If so, then return either PC, or the PC after the prologue, whichever | |
3492 | is greater. */ | |
c906108c | 3493 | |
c5aa993b | 3494 | post_prologue_pc = after_prologue (pc); |
c906108c | 3495 | |
7be570e7 JM |
3496 | /* If after_prologue returned a useful address, then use it. Else |
3497 | fall back on the instruction skipping code. | |
3498 | ||
3499 | Some folks have claimed this causes problems because the breakpoint | |
3500 | may be the first instruction of the prologue. If that happens, then | |
3501 | the instruction skipping code has a bug that needs to be fixed. */ | |
c5aa993b JM |
3502 | if (post_prologue_pc != 0) |
3503 | return max (pc, post_prologue_pc); | |
c5aa993b JM |
3504 | else |
3505 | return (skip_prologue_hard_way (pc)); | |
c906108c SS |
3506 | } |
3507 | ||
3508 | /* Put here the code to store, into a struct frame_saved_regs, | |
3509 | the addresses of the saved registers of frame described by FRAME_INFO. | |
3510 | This includes special registers such as pc and fp saved in special | |
3511 | ways in the stack frame. sp is even more special: | |
3512 | the address we return for it IS the sp for the next frame. */ | |
3513 | ||
3514 | void | |
3515 | hppa_frame_find_saved_regs (frame_info, frame_saved_regs) | |
3516 | struct frame_info *frame_info; | |
3517 | struct frame_saved_regs *frame_saved_regs; | |
3518 | { | |
3519 | CORE_ADDR pc; | |
3520 | struct unwind_table_entry *u; | |
3521 | unsigned long inst, stack_remaining, save_gr, save_fr, save_rp, save_sp; | |
3522 | int status, i, reg; | |
3523 | char buf[4]; | |
3524 | int fp_loc = -1; | |
3525 | ||
3526 | /* Zero out everything. */ | |
3527 | memset (frame_saved_regs, '\0', sizeof (struct frame_saved_regs)); | |
3528 | ||
3529 | /* Call dummy frames always look the same, so there's no need to | |
3530 | examine the dummy code to determine locations of saved registers; | |
3531 | instead, let find_dummy_frame_regs fill in the correct offsets | |
3532 | for the saved registers. */ | |
3533 | if ((frame_info->pc >= frame_info->frame | |
3534 | && frame_info->pc <= (frame_info->frame + CALL_DUMMY_LENGTH | |
c5aa993b JM |
3535 | + 32 * 4 + (NUM_REGS - FP0_REGNUM) * 8 |
3536 | + 6 * 4))) | |
c906108c SS |
3537 | find_dummy_frame_regs (frame_info, frame_saved_regs); |
3538 | ||
3539 | /* Interrupt handlers are special too. They lay out the register | |
3540 | state in the exact same order as the register numbers in GDB. */ | |
3541 | if (pc_in_interrupt_handler (frame_info->pc)) | |
3542 | { | |
3543 | for (i = 0; i < NUM_REGS; i++) | |
3544 | { | |
3545 | /* SP is a little special. */ | |
3546 | if (i == SP_REGNUM) | |
3547 | frame_saved_regs->regs[SP_REGNUM] | |
3548 | = read_memory_integer (frame_info->frame + SP_REGNUM * 4, 4); | |
3549 | else | |
3550 | frame_saved_regs->regs[i] = frame_info->frame + i * 4; | |
3551 | } | |
3552 | return; | |
3553 | } | |
3554 | ||
3555 | #ifdef FRAME_FIND_SAVED_REGS_IN_SIGTRAMP | |
3556 | /* Handle signal handler callers. */ | |
3557 | if (frame_info->signal_handler_caller) | |
3558 | { | |
3559 | FRAME_FIND_SAVED_REGS_IN_SIGTRAMP (frame_info, frame_saved_regs); | |
3560 | return; | |
3561 | } | |
3562 | #endif | |
3563 | ||
3564 | /* Get the starting address of the function referred to by the PC | |
3565 | saved in frame. */ | |
3566 | pc = get_pc_function_start (frame_info->pc); | |
3567 | ||
3568 | /* Yow! */ | |
3569 | u = find_unwind_entry (pc); | |
3570 | if (!u) | |
3571 | return; | |
3572 | ||
3573 | /* This is how much of a frame adjustment we need to account for. */ | |
3574 | stack_remaining = u->Total_frame_size << 3; | |
3575 | ||
3576 | /* Magic register saves we want to know about. */ | |
3577 | save_rp = u->Save_RP; | |
3578 | save_sp = u->Save_SP; | |
3579 | ||
3580 | /* Turn the Entry_GR field into a bitmask. */ | |
3581 | save_gr = 0; | |
3582 | for (i = 3; i < u->Entry_GR + 3; i++) | |
3583 | { | |
3584 | /* Frame pointer gets saved into a special location. */ | |
3585 | if (u->Save_SP && i == FP_REGNUM) | |
3586 | continue; | |
3587 | ||
3588 | save_gr |= (1 << i); | |
3589 | } | |
3590 | ||
3591 | /* Turn the Entry_FR field into a bitmask too. */ | |
3592 | save_fr = 0; | |
3593 | for (i = 12; i < u->Entry_FR + 12; i++) | |
3594 | save_fr |= (1 << i); | |
3595 | ||
3596 | /* The frame always represents the value of %sp at entry to the | |
3597 | current function (and is thus equivalent to the "saved" stack | |
3598 | pointer. */ | |
3599 | frame_saved_regs->regs[SP_REGNUM] = frame_info->frame; | |
3600 | ||
3601 | /* Loop until we find everything of interest or hit a branch. | |
3602 | ||
3603 | For unoptimized GCC code and for any HP CC code this will never ever | |
3604 | examine any user instructions. | |
3605 | ||
7be570e7 | 3606 | For optimized GCC code we're faced with problems. GCC will schedule |
c906108c SS |
3607 | its prologue and make prologue instructions available for delay slot |
3608 | filling. The end result is user code gets mixed in with the prologue | |
3609 | and a prologue instruction may be in the delay slot of the first branch | |
3610 | or call. | |
3611 | ||
3612 | Some unexpected things are expected with debugging optimized code, so | |
3613 | we allow this routine to walk past user instructions in optimized | |
3614 | GCC code. */ | |
3615 | while (save_gr || save_fr || save_rp || save_sp || stack_remaining > 0) | |
3616 | { | |
3617 | status = target_read_memory (pc, buf, 4); | |
3618 | inst = extract_unsigned_integer (buf, 4); | |
3619 | ||
3620 | /* Yow! */ | |
3621 | if (status != 0) | |
3622 | return; | |
3623 | ||
3624 | /* Note the interesting effects of this instruction. */ | |
3625 | stack_remaining -= prologue_inst_adjust_sp (inst); | |
3626 | ||
3627 | /* There is only one instruction used for saving RP into the stack. */ | |
3628 | if (inst == 0x6bc23fd9) | |
3629 | { | |
3630 | save_rp = 0; | |
3631 | frame_saved_regs->regs[RP_REGNUM] = frame_info->frame - 20; | |
3632 | } | |
3633 | ||
3634 | /* Just note that we found the save of SP into the stack. The | |
c5aa993b | 3635 | value for frame_saved_regs was computed above. */ |
c906108c SS |
3636 | if ((inst & 0xffffc000) == 0x6fc10000) |
3637 | save_sp = 0; | |
3638 | ||
3639 | /* Account for general and floating-point register saves. */ | |
3640 | reg = inst_saves_gr (inst); | |
3641 | if (reg >= 3 && reg <= 18 | |
3642 | && (!u->Save_SP || reg != FP_REGNUM)) | |
3643 | { | |
3644 | save_gr &= ~(1 << reg); | |
3645 | ||
3646 | /* stwm with a positive displacement is a *post modify*. */ | |
3647 | if ((inst >> 26) == 0x1b | |
3648 | && extract_14 (inst) >= 0) | |
3649 | frame_saved_regs->regs[reg] = frame_info->frame; | |
3650 | else | |
3651 | { | |
3652 | /* Handle code with and without frame pointers. */ | |
3653 | if (u->Save_SP) | |
3654 | frame_saved_regs->regs[reg] | |
3655 | = frame_info->frame + extract_14 (inst); | |
3656 | else | |
3657 | frame_saved_regs->regs[reg] | |
3658 | = frame_info->frame + (u->Total_frame_size << 3) | |
c5aa993b | 3659 | + extract_14 (inst); |
c906108c SS |
3660 | } |
3661 | } | |
3662 | ||
3663 | ||
3664 | /* GCC handles callee saved FP regs a little differently. | |
3665 | ||
c5aa993b JM |
3666 | It emits an instruction to put the value of the start of |
3667 | the FP store area into %r1. It then uses fstds,ma with | |
3668 | a basereg of %r1 for the stores. | |
c906108c | 3669 | |
c5aa993b JM |
3670 | HP CC emits them at the current stack pointer modifying |
3671 | the stack pointer as it stores each register. */ | |
c906108c SS |
3672 | |
3673 | /* ldo X(%r3),%r1 or ldo X(%r30),%r1. */ | |
3674 | if ((inst & 0xffffc000) == 0x34610000 | |
3675 | || (inst & 0xffffc000) == 0x37c10000) | |
3676 | fp_loc = extract_14 (inst); | |
c5aa993b | 3677 | |
c906108c SS |
3678 | reg = inst_saves_fr (inst); |
3679 | if (reg >= 12 && reg <= 21) | |
3680 | { | |
3681 | /* Note +4 braindamage below is necessary because the FP status | |
3682 | registers are internally 8 registers rather than the expected | |
3683 | 4 registers. */ | |
3684 | save_fr &= ~(1 << reg); | |
3685 | if (fp_loc == -1) | |
3686 | { | |
3687 | /* 1st HP CC FP register store. After this instruction | |
c5aa993b JM |
3688 | we've set enough state that the GCC and HPCC code are |
3689 | both handled in the same manner. */ | |
c906108c SS |
3690 | frame_saved_regs->regs[reg + FP4_REGNUM + 4] = frame_info->frame; |
3691 | fp_loc = 8; | |
3692 | } | |
3693 | else | |
3694 | { | |
3695 | frame_saved_regs->regs[reg + FP0_REGNUM + 4] | |
3696 | = frame_info->frame + fp_loc; | |
3697 | fp_loc += 8; | |
3698 | } | |
3699 | } | |
3700 | ||
3701 | /* Quit if we hit any kind of branch. This can happen if a prologue | |
c5aa993b | 3702 | instruction is in the delay slot of the first call/branch. */ |
c906108c SS |
3703 | if (is_branch (inst)) |
3704 | break; | |
3705 | ||
3706 | /* Bump the PC. */ | |
3707 | pc += 4; | |
3708 | } | |
3709 | } | |
3710 | ||
3711 | ||
3712 | /* Exception handling support for the HP-UX ANSI C++ compiler. | |
3713 | The compiler (aCC) provides a callback for exception events; | |
3714 | GDB can set a breakpoint on this callback and find out what | |
3715 | exception event has occurred. */ | |
3716 | ||
3717 | /* The name of the hook to be set to point to the callback function */ | |
c5aa993b JM |
3718 | static char HP_ACC_EH_notify_hook[] = "__eh_notify_hook"; |
3719 | /* The name of the function to be used to set the hook value */ | |
3720 | static char HP_ACC_EH_set_hook_value[] = "__eh_set_hook_value"; | |
3721 | /* The name of the callback function in end.o */ | |
c906108c | 3722 | static char HP_ACC_EH_notify_callback[] = "__d_eh_notify_callback"; |
c5aa993b JM |
3723 | /* Name of function in end.o on which a break is set (called by above) */ |
3724 | static char HP_ACC_EH_break[] = "__d_eh_break"; | |
3725 | /* Name of flag (in end.o) that enables catching throws */ | |
3726 | static char HP_ACC_EH_catch_throw[] = "__d_eh_catch_throw"; | |
3727 | /* Name of flag (in end.o) that enables catching catching */ | |
3728 | static char HP_ACC_EH_catch_catch[] = "__d_eh_catch_catch"; | |
3729 | /* The enum used by aCC */ | |
3730 | typedef enum | |
3731 | { | |
3732 | __EH_NOTIFY_THROW, | |
3733 | __EH_NOTIFY_CATCH | |
3734 | } | |
3735 | __eh_notification; | |
c906108c SS |
3736 | |
3737 | /* Is exception-handling support available with this executable? */ | |
3738 | static int hp_cxx_exception_support = 0; | |
3739 | /* Has the initialize function been run? */ | |
3740 | int hp_cxx_exception_support_initialized = 0; | |
3741 | /* Similar to above, but imported from breakpoint.c -- non-target-specific */ | |
3742 | extern int exception_support_initialized; | |
3743 | /* Address of __eh_notify_hook */ | |
a0b3c4fd | 3744 | static CORE_ADDR eh_notify_hook_addr = 0; |
c906108c | 3745 | /* Address of __d_eh_notify_callback */ |
a0b3c4fd | 3746 | static CORE_ADDR eh_notify_callback_addr = 0; |
c906108c | 3747 | /* Address of __d_eh_break */ |
a0b3c4fd | 3748 | static CORE_ADDR eh_break_addr = 0; |
c906108c | 3749 | /* Address of __d_eh_catch_catch */ |
a0b3c4fd | 3750 | static CORE_ADDR eh_catch_catch_addr = 0; |
c906108c | 3751 | /* Address of __d_eh_catch_throw */ |
a0b3c4fd | 3752 | static CORE_ADDR eh_catch_throw_addr = 0; |
c906108c | 3753 | /* Sal for __d_eh_break */ |
a0b3c4fd | 3754 | static struct symtab_and_line *break_callback_sal = 0; |
c906108c SS |
3755 | |
3756 | /* Code in end.c expects __d_pid to be set in the inferior, | |
3757 | otherwise __d_eh_notify_callback doesn't bother to call | |
3758 | __d_eh_break! So we poke the pid into this symbol | |
3759 | ourselves. | |
3760 | 0 => success | |
c5aa993b | 3761 | 1 => failure */ |
c906108c SS |
3762 | int |
3763 | setup_d_pid_in_inferior () | |
3764 | { | |
3765 | CORE_ADDR anaddr; | |
c5aa993b JM |
3766 | struct minimal_symbol *msymbol; |
3767 | char buf[4]; /* FIXME 32x64? */ | |
3768 | ||
c906108c SS |
3769 | /* Slam the pid of the process into __d_pid; failing is only a warning! */ |
3770 | msymbol = lookup_minimal_symbol ("__d_pid", NULL, symfile_objfile); | |
3771 | if (msymbol == NULL) | |
3772 | { | |
3773 | warning ("Unable to find __d_pid symbol in object file."); | |
3774 | warning ("Suggest linking executable with -g (links in /opt/langtools/lib/end.o)."); | |
3775 | return 1; | |
3776 | } | |
3777 | ||
3778 | anaddr = SYMBOL_VALUE_ADDRESS (msymbol); | |
c5aa993b JM |
3779 | store_unsigned_integer (buf, 4, inferior_pid); /* FIXME 32x64? */ |
3780 | if (target_write_memory (anaddr, buf, 4)) /* FIXME 32x64? */ | |
c906108c SS |
3781 | { |
3782 | warning ("Unable to write __d_pid"); | |
3783 | warning ("Suggest linking executable with -g (links in /opt/langtools/lib/end.o)."); | |
3784 | return 1; | |
3785 | } | |
3786 | return 0; | |
3787 | } | |
3788 | ||
3789 | /* Initialize exception catchpoint support by looking for the | |
3790 | necessary hooks/callbacks in end.o, etc., and set the hook value to | |
3791 | point to the required debug function | |
3792 | ||
3793 | Return 0 => failure | |
c5aa993b | 3794 | 1 => success */ |
c906108c SS |
3795 | |
3796 | static int | |
3797 | initialize_hp_cxx_exception_support () | |
3798 | { | |
3799 | struct symtabs_and_lines sals; | |
c5aa993b JM |
3800 | struct cleanup *old_chain; |
3801 | struct cleanup *canonical_strings_chain = NULL; | |
c906108c | 3802 | int i; |
c5aa993b JM |
3803 | char *addr_start; |
3804 | char *addr_end = NULL; | |
3805 | char **canonical = (char **) NULL; | |
c906108c | 3806 | int thread = -1; |
c5aa993b JM |
3807 | struct symbol *sym = NULL; |
3808 | struct minimal_symbol *msym = NULL; | |
3809 | struct objfile *objfile; | |
c906108c SS |
3810 | asection *shlib_info; |
3811 | ||
3812 | /* Detect and disallow recursion. On HP-UX with aCC, infinite | |
3813 | recursion is a possibility because finding the hook for exception | |
3814 | callbacks involves making a call in the inferior, which means | |
3815 | re-inserting breakpoints which can re-invoke this code */ | |
3816 | ||
c5aa993b JM |
3817 | static int recurse = 0; |
3818 | if (recurse > 0) | |
c906108c SS |
3819 | { |
3820 | hp_cxx_exception_support_initialized = 0; | |
3821 | exception_support_initialized = 0; | |
3822 | return 0; | |
3823 | } | |
3824 | ||
3825 | hp_cxx_exception_support = 0; | |
3826 | ||
3827 | /* First check if we have seen any HP compiled objects; if not, | |
3828 | it is very unlikely that HP's idiosyncratic callback mechanism | |
3829 | for exception handling debug support will be available! | |
3830 | This will percolate back up to breakpoint.c, where our callers | |
3831 | will decide to try the g++ exception-handling support instead. */ | |
3832 | if (!hp_som_som_object_present) | |
3833 | return 0; | |
c5aa993b | 3834 | |
c906108c SS |
3835 | /* We have a SOM executable with SOM debug info; find the hooks */ |
3836 | ||
3837 | /* First look for the notify hook provided by aCC runtime libs */ | |
3838 | /* If we find this symbol, we conclude that the executable must | |
3839 | have HP aCC exception support built in. If this symbol is not | |
3840 | found, even though we're a HP SOM-SOM file, we may have been | |
3841 | built with some other compiler (not aCC). This results percolates | |
3842 | back up to our callers in breakpoint.c which can decide to | |
3843 | try the g++ style of exception support instead. | |
3844 | If this symbol is found but the other symbols we require are | |
3845 | not found, there is something weird going on, and g++ support | |
3846 | should *not* be tried as an alternative. | |
c5aa993b | 3847 | |
c906108c SS |
3848 | ASSUMPTION: Only HP aCC code will have __eh_notify_hook defined. |
3849 | ASSUMPTION: HP aCC and g++ modules cannot be linked together. */ | |
c5aa993b | 3850 | |
c906108c SS |
3851 | /* libCsup has this hook; it'll usually be non-debuggable */ |
3852 | msym = lookup_minimal_symbol (HP_ACC_EH_notify_hook, NULL, NULL); | |
3853 | if (msym) | |
3854 | { | |
3855 | eh_notify_hook_addr = SYMBOL_VALUE_ADDRESS (msym); | |
3856 | hp_cxx_exception_support = 1; | |
c5aa993b | 3857 | } |
c906108c SS |
3858 | else |
3859 | { | |
3860 | warning ("Unable to find exception callback hook (%s).", HP_ACC_EH_notify_hook); | |
3861 | warning ("Executable may not have been compiled debuggable with HP aCC."); | |
3862 | warning ("GDB will be unable to intercept exception events."); | |
3863 | eh_notify_hook_addr = 0; | |
3864 | hp_cxx_exception_support = 0; | |
3865 | return 0; | |
3866 | } | |
3867 | ||
c906108c | 3868 | /* Next look for the notify callback routine in end.o */ |
c5aa993b | 3869 | /* This is always available in the SOM symbol dictionary if end.o is linked in */ |
c906108c SS |
3870 | msym = lookup_minimal_symbol (HP_ACC_EH_notify_callback, NULL, NULL); |
3871 | if (msym) | |
3872 | { | |
3873 | eh_notify_callback_addr = SYMBOL_VALUE_ADDRESS (msym); | |
3874 | hp_cxx_exception_support = 1; | |
c5aa993b JM |
3875 | } |
3876 | else | |
c906108c SS |
3877 | { |
3878 | warning ("Unable to find exception callback routine (%s).", HP_ACC_EH_notify_callback); | |
3879 | warning ("Suggest linking executable with -g (links in /opt/langtools/lib/end.o)."); | |
3880 | warning ("GDB will be unable to intercept exception events."); | |
3881 | eh_notify_callback_addr = 0; | |
3882 | return 0; | |
3883 | } | |
3884 | ||
3885 | /* Check whether the executable is dynamically linked or archive bound */ | |
3886 | /* With an archive-bound executable we can use the raw addresses we find | |
3887 | for the callback function, etc. without modification. For an executable | |
3888 | with shared libraries, we have to do more work to find the plabel, which | |
3889 | can be the target of a call through $$dyncall from the aCC runtime support | |
3890 | library (libCsup) which is linked shared by default by aCC. */ | |
3891 | /* This test below was copied from somsolib.c/somread.c. It may not be a very | |
c5aa993b | 3892 | reliable one to test that an executable is linked shared. pai/1997-07-18 */ |
c906108c SS |
3893 | shlib_info = bfd_get_section_by_name (symfile_objfile->obfd, "$SHLIB_INFO$"); |
3894 | if (shlib_info && (bfd_section_size (symfile_objfile->obfd, shlib_info) != 0)) | |
3895 | { | |
3896 | /* The minsym we have has the local code address, but that's not the | |
3897 | plabel that can be used by an inter-load-module call. */ | |
3898 | /* Find solib handle for main image (which has end.o), and use that | |
3899 | and the min sym as arguments to __d_shl_get() (which does the equivalent | |
c5aa993b | 3900 | of shl_findsym()) to find the plabel. */ |
c906108c SS |
3901 | |
3902 | args_for_find_stub args; | |
3903 | static char message[] = "Error while finding exception callback hook:\n"; | |
c5aa993b | 3904 | |
c906108c SS |
3905 | args.solib_handle = som_solib_get_solib_by_pc (eh_notify_callback_addr); |
3906 | args.msym = msym; | |
a0b3c4fd | 3907 | args.return_val = 0; |
c5aa993b | 3908 | |
c906108c | 3909 | recurse++; |
a0b3c4fd JM |
3910 | catch_errors (cover_find_stub_with_shl_get, (PTR) &args, message, |
3911 | RETURN_MASK_ALL); | |
3912 | eh_notify_callback_addr = args.return_val; | |
c906108c | 3913 | recurse--; |
c5aa993b | 3914 | |
c906108c | 3915 | exception_catchpoints_are_fragile = 1; |
c5aa993b | 3916 | |
c906108c | 3917 | if (!eh_notify_callback_addr) |
c5aa993b JM |
3918 | { |
3919 | /* We can get here either if there is no plabel in the export list | |
3920 | for the main image, or if something strange happened (??) */ | |
3921 | warning ("Couldn't find a plabel (indirect function label) for the exception callback."); | |
3922 | warning ("GDB will not be able to intercept exception events."); | |
3923 | return 0; | |
3924 | } | |
c906108c SS |
3925 | } |
3926 | else | |
3927 | exception_catchpoints_are_fragile = 0; | |
3928 | ||
c906108c | 3929 | /* Now, look for the breakpointable routine in end.o */ |
c5aa993b | 3930 | /* This should also be available in the SOM symbol dict. if end.o linked in */ |
c906108c SS |
3931 | msym = lookup_minimal_symbol (HP_ACC_EH_break, NULL, NULL); |
3932 | if (msym) | |
3933 | { | |
3934 | eh_break_addr = SYMBOL_VALUE_ADDRESS (msym); | |
3935 | hp_cxx_exception_support = 1; | |
c5aa993b | 3936 | } |
c906108c SS |
3937 | else |
3938 | { | |
3939 | warning ("Unable to find exception callback routine to set breakpoint (%s).", HP_ACC_EH_break); | |
3940 | warning ("Suggest linking executable with -g (link in /opt/langtools/lib/end.o)."); | |
3941 | warning ("GDB will be unable to intercept exception events."); | |
3942 | eh_break_addr = 0; | |
3943 | return 0; | |
3944 | } | |
3945 | ||
c906108c SS |
3946 | /* Next look for the catch enable flag provided in end.o */ |
3947 | sym = lookup_symbol (HP_ACC_EH_catch_catch, (struct block *) NULL, | |
c5aa993b JM |
3948 | VAR_NAMESPACE, 0, (struct symtab **) NULL); |
3949 | if (sym) /* sometimes present in debug info */ | |
c906108c SS |
3950 | { |
3951 | eh_catch_catch_addr = SYMBOL_VALUE_ADDRESS (sym); | |
3952 | hp_cxx_exception_support = 1; | |
3953 | } | |
c5aa993b JM |
3954 | else |
3955 | /* otherwise look in SOM symbol dict. */ | |
c906108c SS |
3956 | { |
3957 | msym = lookup_minimal_symbol (HP_ACC_EH_catch_catch, NULL, NULL); | |
3958 | if (msym) | |
c5aa993b JM |
3959 | { |
3960 | eh_catch_catch_addr = SYMBOL_VALUE_ADDRESS (msym); | |
3961 | hp_cxx_exception_support = 1; | |
3962 | } | |
c906108c | 3963 | else |
c5aa993b JM |
3964 | { |
3965 | warning ("Unable to enable interception of exception catches."); | |
3966 | warning ("Executable may not have been compiled debuggable with HP aCC."); | |
3967 | warning ("Suggest linking executable with -g (link in /opt/langtools/lib/end.o)."); | |
3968 | return 0; | |
3969 | } | |
c906108c SS |
3970 | } |
3971 | ||
c906108c SS |
3972 | /* Next look for the catch enable flag provided end.o */ |
3973 | sym = lookup_symbol (HP_ACC_EH_catch_catch, (struct block *) NULL, | |
c5aa993b JM |
3974 | VAR_NAMESPACE, 0, (struct symtab **) NULL); |
3975 | if (sym) /* sometimes present in debug info */ | |
c906108c SS |
3976 | { |
3977 | eh_catch_throw_addr = SYMBOL_VALUE_ADDRESS (sym); | |
3978 | hp_cxx_exception_support = 1; | |
3979 | } | |
c5aa993b JM |
3980 | else |
3981 | /* otherwise look in SOM symbol dict. */ | |
c906108c SS |
3982 | { |
3983 | msym = lookup_minimal_symbol (HP_ACC_EH_catch_throw, NULL, NULL); | |
3984 | if (msym) | |
c5aa993b JM |
3985 | { |
3986 | eh_catch_throw_addr = SYMBOL_VALUE_ADDRESS (msym); | |
3987 | hp_cxx_exception_support = 1; | |
3988 | } | |
c906108c | 3989 | else |
c5aa993b JM |
3990 | { |
3991 | warning ("Unable to enable interception of exception throws."); | |
3992 | warning ("Executable may not have been compiled debuggable with HP aCC."); | |
3993 | warning ("Suggest linking executable with -g (link in /opt/langtools/lib/end.o)."); | |
3994 | return 0; | |
3995 | } | |
c906108c SS |
3996 | } |
3997 | ||
c5aa993b JM |
3998 | /* Set the flags */ |
3999 | hp_cxx_exception_support = 2; /* everything worked so far */ | |
c906108c SS |
4000 | hp_cxx_exception_support_initialized = 1; |
4001 | exception_support_initialized = 1; | |
4002 | ||
4003 | return 1; | |
4004 | } | |
4005 | ||
4006 | /* Target operation for enabling or disabling interception of | |
4007 | exception events. | |
4008 | KIND is either EX_EVENT_THROW or EX_EVENT_CATCH | |
4009 | ENABLE is either 0 (disable) or 1 (enable). | |
4010 | Return value is NULL if no support found; | |
4011 | -1 if something went wrong, | |
4012 | or a pointer to a symtab/line struct if the breakpointable | |
c5aa993b | 4013 | address was found. */ |
c906108c | 4014 | |
c5aa993b | 4015 | struct symtab_and_line * |
c906108c | 4016 | child_enable_exception_callback (kind, enable) |
c5aa993b JM |
4017 | enum exception_event_kind kind; |
4018 | int enable; | |
c906108c SS |
4019 | { |
4020 | char buf[4]; | |
4021 | ||
4022 | if (!exception_support_initialized || !hp_cxx_exception_support_initialized) | |
4023 | if (!initialize_hp_cxx_exception_support ()) | |
4024 | return NULL; | |
4025 | ||
4026 | switch (hp_cxx_exception_support) | |
4027 | { | |
c5aa993b JM |
4028 | case 0: |
4029 | /* Assuming no HP support at all */ | |
4030 | return NULL; | |
4031 | case 1: | |
4032 | /* HP support should be present, but something went wrong */ | |
4033 | return (struct symtab_and_line *) -1; /* yuck! */ | |
4034 | /* there may be other cases in the future */ | |
c906108c | 4035 | } |
c5aa993b | 4036 | |
c906108c | 4037 | /* Set the EH hook to point to the callback routine */ |
c5aa993b | 4038 | store_unsigned_integer (buf, 4, enable ? eh_notify_callback_addr : 0); /* FIXME 32x64 problem */ |
c906108c | 4039 | /* pai: (temp) FIXME should there be a pack operation first? */ |
c5aa993b | 4040 | if (target_write_memory (eh_notify_hook_addr, buf, 4)) /* FIXME 32x64 problem */ |
c906108c SS |
4041 | { |
4042 | warning ("Could not write to target memory for exception event callback."); | |
4043 | warning ("Interception of exception events may not work."); | |
c5aa993b | 4044 | return (struct symtab_and_line *) -1; |
c906108c SS |
4045 | } |
4046 | if (enable) | |
4047 | { | |
c5aa993b | 4048 | /* Ensure that __d_pid is set up correctly -- end.c code checks this. :-( */ |
c906108c | 4049 | if (inferior_pid > 0) |
c5aa993b JM |
4050 | { |
4051 | if (setup_d_pid_in_inferior ()) | |
4052 | return (struct symtab_and_line *) -1; | |
4053 | } | |
c906108c | 4054 | else |
c5aa993b JM |
4055 | { |
4056 | warning ("Internal error: Invalid inferior pid? Cannot intercept exception events."); /* purecov: deadcode */ | |
4057 | return (struct symtab_and_line *) -1; /* purecov: deadcode */ | |
4058 | } | |
c906108c | 4059 | } |
c5aa993b | 4060 | |
c906108c SS |
4061 | switch (kind) |
4062 | { | |
c5aa993b JM |
4063 | case EX_EVENT_THROW: |
4064 | store_unsigned_integer (buf, 4, enable ? 1 : 0); | |
4065 | if (target_write_memory (eh_catch_throw_addr, buf, 4)) /* FIXME 32x64? */ | |
4066 | { | |
4067 | warning ("Couldn't enable exception throw interception."); | |
4068 | return (struct symtab_and_line *) -1; | |
4069 | } | |
4070 | break; | |
4071 | case EX_EVENT_CATCH: | |
4072 | store_unsigned_integer (buf, 4, enable ? 1 : 0); | |
4073 | if (target_write_memory (eh_catch_catch_addr, buf, 4)) /* FIXME 32x64? */ | |
4074 | { | |
4075 | warning ("Couldn't enable exception catch interception."); | |
4076 | return (struct symtab_and_line *) -1; | |
4077 | } | |
4078 | break; | |
4079 | default: /* purecov: deadcode */ | |
4080 | error ("Request to enable unknown or unsupported exception event."); /* purecov: deadcode */ | |
c906108c | 4081 | } |
c5aa993b | 4082 | |
c906108c SS |
4083 | /* Copy break address into new sal struct, malloc'ing if needed. */ |
4084 | if (!break_callback_sal) | |
4085 | { | |
4086 | break_callback_sal = (struct symtab_and_line *) xmalloc (sizeof (struct symtab_and_line)); | |
4087 | } | |
c5aa993b | 4088 | INIT_SAL (break_callback_sal); |
c906108c SS |
4089 | break_callback_sal->symtab = NULL; |
4090 | break_callback_sal->pc = eh_break_addr; | |
4091 | break_callback_sal->line = 0; | |
4092 | break_callback_sal->end = eh_break_addr; | |
c5aa993b | 4093 | |
c906108c SS |
4094 | return break_callback_sal; |
4095 | } | |
4096 | ||
c5aa993b | 4097 | /* Record some information about the current exception event */ |
c906108c | 4098 | static struct exception_event_record current_ex_event; |
c5aa993b JM |
4099 | /* Convenience struct */ |
4100 | static struct symtab_and_line null_symtab_and_line = | |
4101 | {NULL, 0, 0, 0}; | |
c906108c SS |
4102 | |
4103 | /* Report current exception event. Returns a pointer to a record | |
4104 | that describes the kind of the event, where it was thrown from, | |
4105 | and where it will be caught. More information may be reported | |
c5aa993b | 4106 | in the future */ |
c906108c SS |
4107 | struct exception_event_record * |
4108 | child_get_current_exception_event () | |
4109 | { | |
c5aa993b JM |
4110 | CORE_ADDR event_kind; |
4111 | CORE_ADDR throw_addr; | |
4112 | CORE_ADDR catch_addr; | |
c906108c SS |
4113 | struct frame_info *fi, *curr_frame; |
4114 | int level = 1; | |
4115 | ||
c5aa993b | 4116 | curr_frame = get_current_frame (); |
c906108c SS |
4117 | if (!curr_frame) |
4118 | return (struct exception_event_record *) NULL; | |
4119 | ||
4120 | /* Go up one frame to __d_eh_notify_callback, because at the | |
4121 | point when this code is executed, there's garbage in the | |
4122 | arguments of __d_eh_break. */ | |
4123 | fi = find_relative_frame (curr_frame, &level); | |
4124 | if (level != 0) | |
4125 | return (struct exception_event_record *) NULL; | |
4126 | ||
4127 | select_frame (fi, -1); | |
4128 | ||
4129 | /* Read in the arguments */ | |
4130 | /* __d_eh_notify_callback() is called with 3 arguments: | |
c5aa993b JM |
4131 | 1. event kind catch or throw |
4132 | 2. the target address if known | |
4133 | 3. a flag -- not sure what this is. pai/1997-07-17 */ | |
4134 | event_kind = read_register (ARG0_REGNUM); | |
c906108c SS |
4135 | catch_addr = read_register (ARG1_REGNUM); |
4136 | ||
4137 | /* Now go down to a user frame */ | |
4138 | /* For a throw, __d_eh_break is called by | |
c5aa993b JM |
4139 | __d_eh_notify_callback which is called by |
4140 | __notify_throw which is called | |
4141 | from user code. | |
c906108c | 4142 | For a catch, __d_eh_break is called by |
c5aa993b JM |
4143 | __d_eh_notify_callback which is called by |
4144 | <stackwalking stuff> which is called by | |
4145 | __throw__<stuff> or __rethrow_<stuff> which is called | |
4146 | from user code. */ | |
4147 | /* FIXME: Don't use such magic numbers; search for the frames */ | |
c906108c SS |
4148 | level = (event_kind == EX_EVENT_THROW) ? 3 : 4; |
4149 | fi = find_relative_frame (curr_frame, &level); | |
4150 | if (level != 0) | |
4151 | return (struct exception_event_record *) NULL; | |
4152 | ||
4153 | select_frame (fi, -1); | |
4154 | throw_addr = fi->pc; | |
4155 | ||
4156 | /* Go back to original (top) frame */ | |
4157 | select_frame (curr_frame, -1); | |
4158 | ||
4159 | current_ex_event.kind = (enum exception_event_kind) event_kind; | |
4160 | current_ex_event.throw_sal = find_pc_line (throw_addr, 1); | |
4161 | current_ex_event.catch_sal = find_pc_line (catch_addr, 1); | |
4162 | ||
4163 | return ¤t_ex_event; | |
4164 | } | |
4165 | ||
c906108c SS |
4166 | static void |
4167 | unwind_command (exp, from_tty) | |
4168 | char *exp; | |
4169 | int from_tty; | |
4170 | { | |
4171 | CORE_ADDR address; | |
4172 | struct unwind_table_entry *u; | |
4173 | ||
4174 | /* If we have an expression, evaluate it and use it as the address. */ | |
4175 | ||
4176 | if (exp != 0 && *exp != 0) | |
4177 | address = parse_and_eval_address (exp); | |
4178 | else | |
4179 | return; | |
4180 | ||
4181 | u = find_unwind_entry (address); | |
4182 | ||
4183 | if (!u) | |
4184 | { | |
4185 | printf_unfiltered ("Can't find unwind table entry for %s\n", exp); | |
4186 | return; | |
4187 | } | |
4188 | ||
4189 | printf_unfiltered ("unwind_table_entry (0x%x):\n", u); | |
4190 | ||
4191 | printf_unfiltered ("\tregion_start = "); | |
4192 | print_address (u->region_start, gdb_stdout); | |
4193 | ||
4194 | printf_unfiltered ("\n\tregion_end = "); | |
4195 | print_address (u->region_end, gdb_stdout); | |
4196 | ||
4197 | #ifdef __STDC__ | |
4198 | #define pif(FLD) if (u->FLD) printf_unfiltered (" "#FLD); | |
4199 | #else | |
4200 | #define pif(FLD) if (u->FLD) printf_unfiltered (" FLD"); | |
4201 | #endif | |
4202 | ||
4203 | printf_unfiltered ("\n\tflags ="); | |
4204 | pif (Cannot_unwind); | |
4205 | pif (Millicode); | |
4206 | pif (Millicode_save_sr0); | |
4207 | pif (Entry_SR); | |
4208 | pif (Args_stored); | |
4209 | pif (Variable_Frame); | |
4210 | pif (Separate_Package_Body); | |
4211 | pif (Frame_Extension_Millicode); | |
4212 | pif (Stack_Overflow_Check); | |
4213 | pif (Two_Instruction_SP_Increment); | |
4214 | pif (Ada_Region); | |
4215 | pif (Save_SP); | |
4216 | pif (Save_RP); | |
4217 | pif (Save_MRP_in_frame); | |
4218 | pif (extn_ptr_defined); | |
4219 | pif (Cleanup_defined); | |
4220 | pif (MPE_XL_interrupt_marker); | |
4221 | pif (HP_UX_interrupt_marker); | |
4222 | pif (Large_frame); | |
4223 | ||
4224 | putchar_unfiltered ('\n'); | |
4225 | ||
4226 | #ifdef __STDC__ | |
4227 | #define pin(FLD) printf_unfiltered ("\t"#FLD" = 0x%x\n", u->FLD); | |
4228 | #else | |
4229 | #define pin(FLD) printf_unfiltered ("\tFLD = 0x%x\n", u->FLD); | |
4230 | #endif | |
4231 | ||
4232 | pin (Region_description); | |
4233 | pin (Entry_FR); | |
4234 | pin (Entry_GR); | |
4235 | pin (Total_frame_size); | |
4236 | } | |
c906108c SS |
4237 | |
4238 | #ifdef PREPARE_TO_PROCEED | |
4239 | ||
4240 | /* If the user has switched threads, and there is a breakpoint | |
4241 | at the old thread's pc location, then switch to that thread | |
4242 | and return TRUE, else return FALSE and don't do a thread | |
4243 | switch (or rather, don't seem to have done a thread switch). | |
4244 | ||
4245 | Ptrace-based gdb will always return FALSE to the thread-switch | |
4246 | query, and thus also to PREPARE_TO_PROCEED. | |
4247 | ||
4248 | The important thing is whether there is a BPT instruction, | |
4249 | not how many user breakpoints there are. So we have to worry | |
4250 | about things like these: | |
4251 | ||
4252 | o Non-bp stop -- NO | |
4253 | ||
4254 | o User hits bp, no switch -- NO | |
4255 | ||
4256 | o User hits bp, switches threads -- YES | |
4257 | ||
4258 | o User hits bp, deletes bp, switches threads -- NO | |
4259 | ||
4260 | o User hits bp, deletes one of two or more bps | |
c5aa993b | 4261 | at that PC, user switches threads -- YES |
c906108c SS |
4262 | |
4263 | o Plus, since we're buffering events, the user may have hit a | |
c5aa993b JM |
4264 | breakpoint, deleted the breakpoint and then gotten another |
4265 | hit on that same breakpoint on another thread which | |
4266 | actually hit before the delete. (FIXME in breakpoint.c | |
4267 | so that "dead" breakpoints are ignored?) -- NO | |
c906108c SS |
4268 | |
4269 | For these reasons, we have to violate information hiding and | |
4270 | call "breakpoint_here_p". If core gdb thinks there is a bpt | |
4271 | here, that's what counts, as core gdb is the one which is | |
4272 | putting the BPT instruction in and taking it out. */ | |
4273 | int | |
c5aa993b | 4274 | hppa_prepare_to_proceed () |
c906108c SS |
4275 | { |
4276 | pid_t old_thread; | |
4277 | pid_t current_thread; | |
4278 | ||
c5aa993b | 4279 | old_thread = hppa_switched_threads (inferior_pid); |
c906108c SS |
4280 | if (old_thread != 0) |
4281 | { | |
4282 | /* Switched over from "old_thread". Try to do | |
4283 | as little work as possible, 'cause mostly | |
4284 | we're going to switch back. */ | |
4285 | CORE_ADDR new_pc; | |
c5aa993b | 4286 | CORE_ADDR old_pc = read_pc (); |
c906108c SS |
4287 | |
4288 | /* Yuk, shouldn't use global to specify current | |
4289 | thread. But that's how gdb does it. */ | |
4290 | current_thread = inferior_pid; | |
c5aa993b | 4291 | inferior_pid = old_thread; |
c906108c | 4292 | |
c5aa993b JM |
4293 | new_pc = read_pc (); |
4294 | if (new_pc != old_pc /* If at same pc, no need */ | |
c906108c | 4295 | && breakpoint_here_p (new_pc)) |
c5aa993b | 4296 | { |
c906108c | 4297 | /* User hasn't deleted the BP. |
c5aa993b | 4298 | Return TRUE, finishing switch to "old_thread". */ |
c906108c SS |
4299 | flush_cached_frames (); |
4300 | registers_changed (); | |
4301 | #if 0 | |
c5aa993b | 4302 | printf ("---> PREPARE_TO_PROCEED (was %d, now %d)!\n", |
c906108c SS |
4303 | current_thread, inferior_pid); |
4304 | #endif | |
c5aa993b | 4305 | |
c906108c | 4306 | return 1; |
c5aa993b | 4307 | } |
c906108c SS |
4308 | |
4309 | /* Otherwise switch back to the user-chosen thread. */ | |
4310 | inferior_pid = current_thread; | |
c5aa993b | 4311 | new_pc = read_pc (); /* Re-prime register cache */ |
c906108c SS |
4312 | } |
4313 | ||
4314 | return 0; | |
4315 | } | |
4316 | #endif /* PREPARE_TO_PROCEED */ | |
4317 | ||
4318 | void | |
4319 | _initialize_hppa_tdep () | |
4320 | { | |
4321 | tm_print_insn = print_insn_hppa; | |
4322 | ||
c906108c SS |
4323 | add_cmd ("unwind", class_maintenance, unwind_command, |
4324 | "Print unwind table entry at given address.", | |
4325 | &maintenanceprintlist); | |
c906108c | 4326 | } |