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