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