* hppa-tdep.c (hppa32_push_dummy_call): Set the Stack Pointer.
[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, 2003, 2004 Free Software
5 Foundation, Inc.
6
7 Contributed by the Center for Software Science at the
8 University of Utah (pa-gdb-bugs@cs.utah.edu).
9
10 This file is part of GDB.
11
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. */
26
27 #include "defs.h"
28 #include "frame.h"
29 #include "bfd.h"
30 #include "inferior.h"
31 #include "value.h"
32 #include "regcache.h"
33 #include "completer.h"
34 #include "language.h"
35 #include "osabi.h"
36 #include "gdb_assert.h"
37 #include "infttrace.h"
38 #include "arch-utils.h"
39 /* For argument passing to the inferior */
40 #include "symtab.h"
41 #include "infcall.h"
42 #include "dis-asm.h"
43 #include "trad-frame.h"
44 #include "frame-unwind.h"
45 #include "frame-base.h"
46
47 #ifdef USG
48 #include <sys/types.h>
49 #endif
50
51 #include <dl.h>
52 #include <sys/param.h>
53 #include <signal.h>
54
55 #include <sys/ptrace.h>
56 #include <machine/save_state.h>
57
58 #ifdef COFF_ENCAPSULATE
59 #include "a.out.encap.h"
60 #else
61 #endif
62
63 /*#include <sys/user.h> After a.out.h */
64 #include <sys/file.h>
65 #include "gdb_stat.h"
66 #include "gdb_wait.h"
67
68 #include "gdbcore.h"
69 #include "gdbcmd.h"
70 #include "target.h"
71 #include "symfile.h"
72 #include "objfiles.h"
73 #include "hppa-tdep.h"
74
75 /* Some local constants. */
76 static const int hppa32_num_regs = 128;
77 static const int hppa64_num_regs = 96;
78
79 /* Get at various relevent fields of an instruction word. */
80 #define MASK_5 0x1f
81 #define MASK_11 0x7ff
82 #define MASK_14 0x3fff
83 #define MASK_21 0x1fffff
84
85 /* Define offsets into the call dummy for the _sr4export address.
86 See comments related to CALL_DUMMY for more info. */
87 #define SR4EXPORT_LDIL_OFFSET (INSTRUCTION_SIZE * 12)
88 #define SR4EXPORT_LDO_OFFSET (INSTRUCTION_SIZE * 13)
89
90 /* To support detection of the pseudo-initial frame
91 that threads have. */
92 #define THREAD_INITIAL_FRAME_SYMBOL "__pthread_exit"
93 #define THREAD_INITIAL_FRAME_SYM_LEN sizeof(THREAD_INITIAL_FRAME_SYMBOL)
94
95 /* Sizes (in bytes) of the native unwind entries. */
96 #define UNWIND_ENTRY_SIZE 16
97 #define STUB_UNWIND_ENTRY_SIZE 8
98
99 static int get_field (unsigned word, int from, int to);
100
101 static int extract_5_load (unsigned int);
102
103 static unsigned extract_5R_store (unsigned int);
104
105 static unsigned extract_5r_store (unsigned int);
106
107 struct unwind_table_entry *find_unwind_entry (CORE_ADDR);
108
109 static int extract_17 (unsigned int);
110
111 static int extract_21 (unsigned);
112
113 static int extract_14 (unsigned);
114
115 static void unwind_command (char *, int);
116
117 static int low_sign_extend (unsigned int, unsigned int);
118
119 static int sign_extend (unsigned int, unsigned int);
120
121 static int hppa_alignof (struct type *);
122
123 static int prologue_inst_adjust_sp (unsigned long);
124
125 static int is_branch (unsigned long);
126
127 static int inst_saves_gr (unsigned long);
128
129 static int inst_saves_fr (unsigned long);
130
131 static int compare_unwind_entries (const void *, const void *);
132
133 static void read_unwind_info (struct objfile *);
134
135 static void internalize_unwinds (struct objfile *,
136 struct unwind_table_entry *,
137 asection *, unsigned int,
138 unsigned int, CORE_ADDR);
139 static void record_text_segment_lowaddr (bfd *, asection *, void *);
140 /* FIXME: brobecker 2002-11-07: We will likely be able to make the
141 following functions static, once we hppa is partially multiarched. */
142 int hppa_reg_struct_has_addr (int gcc_p, struct type *type);
143 CORE_ADDR hppa_skip_prologue (CORE_ADDR pc);
144 CORE_ADDR hppa_skip_trampoline_code (CORE_ADDR pc);
145 int hppa_in_solib_call_trampoline (CORE_ADDR pc, char *name);
146 int hppa_in_solib_return_trampoline (CORE_ADDR pc, char *name);
147 int hppa_inner_than (CORE_ADDR lhs, CORE_ADDR rhs);
148 int hppa_pc_requires_run_before_use (CORE_ADDR pc);
149 int hppa_instruction_nullified (void);
150 int hppa_cannot_store_register (int regnum);
151 CORE_ADDR hppa_smash_text_address (CORE_ADDR addr);
152 CORE_ADDR hppa_target_read_pc (ptid_t ptid);
153 void hppa_target_write_pc (CORE_ADDR v, ptid_t ptid);
154
155 typedef struct
156 {
157 struct minimal_symbol *msym;
158 CORE_ADDR solib_handle;
159 CORE_ADDR return_val;
160 }
161 args_for_find_stub;
162
163 static int cover_find_stub_with_shl_get (void *);
164
165 static int is_pa_2 = 0; /* False */
166
167 /* This is declared in symtab.c; set to 1 in hp-symtab-read.c */
168 extern int hp_som_som_object_present;
169
170 /* In breakpoint.c */
171 extern int exception_catchpoints_are_fragile;
172
173 /* Handle 32/64-bit struct return conventions. */
174
175 static enum return_value_convention
176 hppa32_return_value (struct gdbarch *gdbarch,
177 struct type *type, struct regcache *regcache,
178 void *readbuf, const void *writebuf)
179 {
180 if (TYPE_CODE (type) == TYPE_CODE_FLT)
181 {
182 if (readbuf != NULL)
183 regcache_cooked_read_part (regcache, FP4_REGNUM, 0,
184 TYPE_LENGTH (type), readbuf);
185 if (writebuf != NULL)
186 regcache_cooked_write_part (regcache, FP4_REGNUM, 0,
187 TYPE_LENGTH (type), writebuf);
188 return RETURN_VALUE_REGISTER_CONVENTION;
189 }
190 if (TYPE_LENGTH (type) <= 2 * 4)
191 {
192 /* The value always lives in the right hand end of the register
193 (or register pair)? */
194 int b;
195 int reg = 28;
196 int part = TYPE_LENGTH (type) % 4;
197 /* The left hand register contains only part of the value,
198 transfer that first so that the rest can be xfered as entire
199 4-byte registers. */
200 if (part > 0)
201 {
202 if (readbuf != NULL)
203 regcache_cooked_read_part (regcache, reg, 4 - part,
204 part, readbuf);
205 if (writebuf != NULL)
206 regcache_cooked_write_part (regcache, reg, 4 - part,
207 part, writebuf);
208 reg++;
209 }
210 /* Now transfer the remaining register values. */
211 for (b = part; b < TYPE_LENGTH (type); b += 4)
212 {
213 if (readbuf != NULL)
214 regcache_cooked_read (regcache, reg, (char *) readbuf + b);
215 if (writebuf != NULL)
216 regcache_cooked_write (regcache, reg, (const char *) writebuf + b);
217 reg++;
218 }
219 return RETURN_VALUE_REGISTER_CONVENTION;
220 }
221 else
222 return RETURN_VALUE_STRUCT_CONVENTION;
223 }
224
225 static enum return_value_convention
226 hppa64_return_value (struct gdbarch *gdbarch,
227 struct type *type, struct regcache *regcache,
228 void *readbuf, const void *writebuf)
229 {
230 /* RM: Floats are returned in FR4R, doubles in FR4. Integral values
231 are in r28, padded on the left. Aggregates less that 65 bits are
232 in r28, right padded. Aggregates upto 128 bits are in r28 and
233 r29, right padded. */
234 if (TYPE_CODE (type) == TYPE_CODE_FLT
235 && TYPE_LENGTH (type) <= 8)
236 {
237 /* Floats are right aligned? */
238 int offset = register_size (gdbarch, FP4_REGNUM) - TYPE_LENGTH (type);
239 if (readbuf != NULL)
240 regcache_cooked_read_part (regcache, FP4_REGNUM, offset,
241 TYPE_LENGTH (type), readbuf);
242 if (writebuf != NULL)
243 regcache_cooked_write_part (regcache, FP4_REGNUM, offset,
244 TYPE_LENGTH (type), writebuf);
245 return RETURN_VALUE_REGISTER_CONVENTION;
246 }
247 else if (TYPE_LENGTH (type) <= 8 && is_integral_type (type))
248 {
249 /* Integrals are right aligned. */
250 int offset = register_size (gdbarch, FP4_REGNUM) - TYPE_LENGTH (type);
251 if (readbuf != NULL)
252 regcache_cooked_read_part (regcache, 28, offset,
253 TYPE_LENGTH (type), readbuf);
254 if (writebuf != NULL)
255 regcache_cooked_write_part (regcache, 28, offset,
256 TYPE_LENGTH (type), writebuf);
257 return RETURN_VALUE_REGISTER_CONVENTION;
258 }
259 else if (TYPE_LENGTH (type) <= 2 * 8)
260 {
261 /* Composite values are left aligned. */
262 int b;
263 for (b = 0; b < TYPE_LENGTH (type); b += 8)
264 {
265 int part = min (8, TYPE_LENGTH (type) - b);
266 if (readbuf != NULL)
267 regcache_cooked_read_part (regcache, 28 + b / 8, 0, part,
268 (char *) readbuf + b);
269 if (writebuf != NULL)
270 regcache_cooked_write_part (regcache, 28 + b / 8, 0, part,
271 (const char *) writebuf + b);
272 }
273 return RETURN_VALUE_REGISTER_CONVENTION;
274 }
275 else
276 return RETURN_VALUE_STRUCT_CONVENTION;
277 }
278
279 /* Routines to extract various sized constants out of hppa
280 instructions. */
281
282 /* This assumes that no garbage lies outside of the lower bits of
283 value. */
284
285 static int
286 sign_extend (unsigned val, unsigned bits)
287 {
288 return (int) (val >> (bits - 1) ? (-1 << bits) | val : val);
289 }
290
291 /* For many immediate values the sign bit is the low bit! */
292
293 static int
294 low_sign_extend (unsigned val, unsigned bits)
295 {
296 return (int) ((val & 0x1 ? (-1 << (bits - 1)) : 0) | val >> 1);
297 }
298
299 /* Extract the bits at positions between FROM and TO, using HP's numbering
300 (MSB = 0). */
301
302 static int
303 get_field (unsigned word, int from, int to)
304 {
305 return ((word) >> (31 - (to)) & ((1 << ((to) - (from) + 1)) - 1));
306 }
307
308 /* extract the immediate field from a ld{bhw}s instruction */
309
310 static int
311 extract_5_load (unsigned word)
312 {
313 return low_sign_extend (word >> 16 & MASK_5, 5);
314 }
315
316 /* extract the immediate field from a break instruction */
317
318 static unsigned
319 extract_5r_store (unsigned word)
320 {
321 return (word & MASK_5);
322 }
323
324 /* extract the immediate field from a {sr}sm instruction */
325
326 static unsigned
327 extract_5R_store (unsigned word)
328 {
329 return (word >> 16 & MASK_5);
330 }
331
332 /* extract a 14 bit immediate field */
333
334 static int
335 extract_14 (unsigned word)
336 {
337 return low_sign_extend (word & MASK_14, 14);
338 }
339
340 /* extract a 21 bit constant */
341
342 static int
343 extract_21 (unsigned word)
344 {
345 int val;
346
347 word &= MASK_21;
348 word <<= 11;
349 val = get_field (word, 20, 20);
350 val <<= 11;
351 val |= get_field (word, 9, 19);
352 val <<= 2;
353 val |= get_field (word, 5, 6);
354 val <<= 5;
355 val |= get_field (word, 0, 4);
356 val <<= 2;
357 val |= get_field (word, 7, 8);
358 return sign_extend (val, 21) << 11;
359 }
360
361 /* extract a 17 bit constant from branch instructions, returning the
362 19 bit signed value. */
363
364 static int
365 extract_17 (unsigned word)
366 {
367 return sign_extend (get_field (word, 19, 28) |
368 get_field (word, 29, 29) << 10 |
369 get_field (word, 11, 15) << 11 |
370 (word & 0x1) << 16, 17) << 2;
371 }
372 \f
373
374 /* Compare the start address for two unwind entries returning 1 if
375 the first address is larger than the second, -1 if the second is
376 larger than the first, and zero if they are equal. */
377
378 static int
379 compare_unwind_entries (const void *arg1, const void *arg2)
380 {
381 const struct unwind_table_entry *a = arg1;
382 const struct unwind_table_entry *b = arg2;
383
384 if (a->region_start > b->region_start)
385 return 1;
386 else if (a->region_start < b->region_start)
387 return -1;
388 else
389 return 0;
390 }
391
392 static CORE_ADDR low_text_segment_address;
393
394 static void
395 record_text_segment_lowaddr (bfd *abfd, asection *section, void *ignored)
396 {
397 if (((section->flags & (SEC_ALLOC | SEC_LOAD | SEC_READONLY))
398 == (SEC_ALLOC | SEC_LOAD | SEC_READONLY))
399 && section->vma < low_text_segment_address)
400 low_text_segment_address = section->vma;
401 }
402
403 static void
404 internalize_unwinds (struct objfile *objfile, struct unwind_table_entry *table,
405 asection *section, unsigned int entries, unsigned int size,
406 CORE_ADDR text_offset)
407 {
408 /* We will read the unwind entries into temporary memory, then
409 fill in the actual unwind table. */
410 if (size > 0)
411 {
412 unsigned long tmp;
413 unsigned i;
414 char *buf = alloca (size);
415
416 low_text_segment_address = -1;
417
418 /* If addresses are 64 bits wide, then unwinds are supposed to
419 be segment relative offsets instead of absolute addresses.
420
421 Note that when loading a shared library (text_offset != 0) the
422 unwinds are already relative to the text_offset that will be
423 passed in. */
424 if (TARGET_PTR_BIT == 64 && text_offset == 0)
425 {
426 bfd_map_over_sections (objfile->obfd,
427 record_text_segment_lowaddr, NULL);
428
429 /* ?!? Mask off some low bits. Should this instead subtract
430 out the lowest section's filepos or something like that?
431 This looks very hokey to me. */
432 low_text_segment_address &= ~0xfff;
433 text_offset += low_text_segment_address;
434 }
435
436 bfd_get_section_contents (objfile->obfd, section, buf, 0, size);
437
438 /* Now internalize the information being careful to handle host/target
439 endian issues. */
440 for (i = 0; i < entries; i++)
441 {
442 table[i].region_start = bfd_get_32 (objfile->obfd,
443 (bfd_byte *) buf);
444 table[i].region_start += text_offset;
445 buf += 4;
446 table[i].region_end = bfd_get_32 (objfile->obfd, (bfd_byte *) buf);
447 table[i].region_end += text_offset;
448 buf += 4;
449 tmp = bfd_get_32 (objfile->obfd, (bfd_byte *) buf);
450 buf += 4;
451 table[i].Cannot_unwind = (tmp >> 31) & 0x1;
452 table[i].Millicode = (tmp >> 30) & 0x1;
453 table[i].Millicode_save_sr0 = (tmp >> 29) & 0x1;
454 table[i].Region_description = (tmp >> 27) & 0x3;
455 table[i].reserved1 = (tmp >> 26) & 0x1;
456 table[i].Entry_SR = (tmp >> 25) & 0x1;
457 table[i].Entry_FR = (tmp >> 21) & 0xf;
458 table[i].Entry_GR = (tmp >> 16) & 0x1f;
459 table[i].Args_stored = (tmp >> 15) & 0x1;
460 table[i].Variable_Frame = (tmp >> 14) & 0x1;
461 table[i].Separate_Package_Body = (tmp >> 13) & 0x1;
462 table[i].Frame_Extension_Millicode = (tmp >> 12) & 0x1;
463 table[i].Stack_Overflow_Check = (tmp >> 11) & 0x1;
464 table[i].Two_Instruction_SP_Increment = (tmp >> 10) & 0x1;
465 table[i].Ada_Region = (tmp >> 9) & 0x1;
466 table[i].cxx_info = (tmp >> 8) & 0x1;
467 table[i].cxx_try_catch = (tmp >> 7) & 0x1;
468 table[i].sched_entry_seq = (tmp >> 6) & 0x1;
469 table[i].reserved2 = (tmp >> 5) & 0x1;
470 table[i].Save_SP = (tmp >> 4) & 0x1;
471 table[i].Save_RP = (tmp >> 3) & 0x1;
472 table[i].Save_MRP_in_frame = (tmp >> 2) & 0x1;
473 table[i].extn_ptr_defined = (tmp >> 1) & 0x1;
474 table[i].Cleanup_defined = tmp & 0x1;
475 tmp = bfd_get_32 (objfile->obfd, (bfd_byte *) buf);
476 buf += 4;
477 table[i].MPE_XL_interrupt_marker = (tmp >> 31) & 0x1;
478 table[i].HP_UX_interrupt_marker = (tmp >> 30) & 0x1;
479 table[i].Large_frame = (tmp >> 29) & 0x1;
480 table[i].Pseudo_SP_Set = (tmp >> 28) & 0x1;
481 table[i].reserved4 = (tmp >> 27) & 0x1;
482 table[i].Total_frame_size = tmp & 0x7ffffff;
483
484 /* Stub unwinds are handled elsewhere. */
485 table[i].stub_unwind.stub_type = 0;
486 table[i].stub_unwind.padding = 0;
487 }
488 }
489 }
490
491 /* Read in the backtrace information stored in the `$UNWIND_START$' section of
492 the object file. This info is used mainly by find_unwind_entry() to find
493 out the stack frame size and frame pointer used by procedures. We put
494 everything on the psymbol obstack in the objfile so that it automatically
495 gets freed when the objfile is destroyed. */
496
497 static void
498 read_unwind_info (struct objfile *objfile)
499 {
500 asection *unwind_sec, *stub_unwind_sec;
501 unsigned unwind_size, stub_unwind_size, total_size;
502 unsigned index, unwind_entries;
503 unsigned stub_entries, total_entries;
504 CORE_ADDR text_offset;
505 struct obj_unwind_info *ui;
506 obj_private_data_t *obj_private;
507
508 text_offset = ANOFFSET (objfile->section_offsets, 0);
509 ui = (struct obj_unwind_info *) obstack_alloc (&objfile->objfile_obstack,
510 sizeof (struct obj_unwind_info));
511
512 ui->table = NULL;
513 ui->cache = NULL;
514 ui->last = -1;
515
516 /* For reasons unknown the HP PA64 tools generate multiple unwinder
517 sections in a single executable. So we just iterate over every
518 section in the BFD looking for unwinder sections intead of trying
519 to do a lookup with bfd_get_section_by_name.
520
521 First determine the total size of the unwind tables so that we
522 can allocate memory in a nice big hunk. */
523 total_entries = 0;
524 for (unwind_sec = objfile->obfd->sections;
525 unwind_sec;
526 unwind_sec = unwind_sec->next)
527 {
528 if (strcmp (unwind_sec->name, "$UNWIND_START$") == 0
529 || strcmp (unwind_sec->name, ".PARISC.unwind") == 0)
530 {
531 unwind_size = bfd_section_size (objfile->obfd, unwind_sec);
532 unwind_entries = unwind_size / UNWIND_ENTRY_SIZE;
533
534 total_entries += unwind_entries;
535 }
536 }
537
538 /* Now compute the size of the stub unwinds. Note the ELF tools do not
539 use stub unwinds at the curren time. */
540 stub_unwind_sec = bfd_get_section_by_name (objfile->obfd, "$UNWIND_END$");
541
542 if (stub_unwind_sec)
543 {
544 stub_unwind_size = bfd_section_size (objfile->obfd, stub_unwind_sec);
545 stub_entries = stub_unwind_size / STUB_UNWIND_ENTRY_SIZE;
546 }
547 else
548 {
549 stub_unwind_size = 0;
550 stub_entries = 0;
551 }
552
553 /* Compute total number of unwind entries and their total size. */
554 total_entries += stub_entries;
555 total_size = total_entries * sizeof (struct unwind_table_entry);
556
557 /* Allocate memory for the unwind table. */
558 ui->table = (struct unwind_table_entry *)
559 obstack_alloc (&objfile->objfile_obstack, total_size);
560 ui->last = total_entries - 1;
561
562 /* Now read in each unwind section and internalize the standard unwind
563 entries. */
564 index = 0;
565 for (unwind_sec = objfile->obfd->sections;
566 unwind_sec;
567 unwind_sec = unwind_sec->next)
568 {
569 if (strcmp (unwind_sec->name, "$UNWIND_START$") == 0
570 || strcmp (unwind_sec->name, ".PARISC.unwind") == 0)
571 {
572 unwind_size = bfd_section_size (objfile->obfd, unwind_sec);
573 unwind_entries = unwind_size / UNWIND_ENTRY_SIZE;
574
575 internalize_unwinds (objfile, &ui->table[index], unwind_sec,
576 unwind_entries, unwind_size, text_offset);
577 index += unwind_entries;
578 }
579 }
580
581 /* Now read in and internalize the stub unwind entries. */
582 if (stub_unwind_size > 0)
583 {
584 unsigned int i;
585 char *buf = alloca (stub_unwind_size);
586
587 /* Read in the stub unwind entries. */
588 bfd_get_section_contents (objfile->obfd, stub_unwind_sec, buf,
589 0, stub_unwind_size);
590
591 /* Now convert them into regular unwind entries. */
592 for (i = 0; i < stub_entries; i++, index++)
593 {
594 /* Clear out the next unwind entry. */
595 memset (&ui->table[index], 0, sizeof (struct unwind_table_entry));
596
597 /* Convert offset & size into region_start and region_end.
598 Stuff away the stub type into "reserved" fields. */
599 ui->table[index].region_start = bfd_get_32 (objfile->obfd,
600 (bfd_byte *) buf);
601 ui->table[index].region_start += text_offset;
602 buf += 4;
603 ui->table[index].stub_unwind.stub_type = bfd_get_8 (objfile->obfd,
604 (bfd_byte *) buf);
605 buf += 2;
606 ui->table[index].region_end
607 = ui->table[index].region_start + 4 *
608 (bfd_get_16 (objfile->obfd, (bfd_byte *) buf) - 1);
609 buf += 2;
610 }
611
612 }
613
614 /* Unwind table needs to be kept sorted. */
615 qsort (ui->table, total_entries, sizeof (struct unwind_table_entry),
616 compare_unwind_entries);
617
618 /* Keep a pointer to the unwind information. */
619 if (objfile->obj_private == NULL)
620 {
621 obj_private = (obj_private_data_t *)
622 obstack_alloc (&objfile->objfile_obstack,
623 sizeof (obj_private_data_t));
624 obj_private->unwind_info = NULL;
625 obj_private->so_info = NULL;
626 obj_private->dp = 0;
627
628 objfile->obj_private = obj_private;
629 }
630 obj_private = (obj_private_data_t *) objfile->obj_private;
631 obj_private->unwind_info = ui;
632 }
633
634 /* Lookup the unwind (stack backtrace) info for the given PC. We search all
635 of the objfiles seeking the unwind table entry for this PC. Each objfile
636 contains a sorted list of struct unwind_table_entry. Since we do a binary
637 search of the unwind tables, we depend upon them to be sorted. */
638
639 struct unwind_table_entry *
640 find_unwind_entry (CORE_ADDR pc)
641 {
642 int first, middle, last;
643 struct objfile *objfile;
644
645 /* A function at address 0? Not in HP-UX! */
646 if (pc == (CORE_ADDR) 0)
647 return NULL;
648
649 ALL_OBJFILES (objfile)
650 {
651 struct obj_unwind_info *ui;
652 ui = NULL;
653 if (objfile->obj_private)
654 ui = ((obj_private_data_t *) (objfile->obj_private))->unwind_info;
655
656 if (!ui)
657 {
658 read_unwind_info (objfile);
659 if (objfile->obj_private == NULL)
660 error ("Internal error reading unwind information.");
661 ui = ((obj_private_data_t *) (objfile->obj_private))->unwind_info;
662 }
663
664 /* First, check the cache */
665
666 if (ui->cache
667 && pc >= ui->cache->region_start
668 && pc <= ui->cache->region_end)
669 return ui->cache;
670
671 /* Not in the cache, do a binary search */
672
673 first = 0;
674 last = ui->last;
675
676 while (first <= last)
677 {
678 middle = (first + last) / 2;
679 if (pc >= ui->table[middle].region_start
680 && pc <= ui->table[middle].region_end)
681 {
682 ui->cache = &ui->table[middle];
683 return &ui->table[middle];
684 }
685
686 if (pc < ui->table[middle].region_start)
687 last = middle - 1;
688 else
689 first = middle + 1;
690 }
691 } /* ALL_OBJFILES() */
692 return NULL;
693 }
694
695 const unsigned char *
696 hppa_breakpoint_from_pc (CORE_ADDR *pc, int *len)
697 {
698 static const unsigned char breakpoint[] = {0x00, 0x01, 0x00, 0x04};
699 (*len) = sizeof (breakpoint);
700 return breakpoint;
701 }
702
703 /* Return the name of a register. */
704
705 const char *
706 hppa32_register_name (int i)
707 {
708 static char *names[] = {
709 "flags", "r1", "rp", "r3",
710 "r4", "r5", "r6", "r7",
711 "r8", "r9", "r10", "r11",
712 "r12", "r13", "r14", "r15",
713 "r16", "r17", "r18", "r19",
714 "r20", "r21", "r22", "r23",
715 "r24", "r25", "r26", "dp",
716 "ret0", "ret1", "sp", "r31",
717 "sar", "pcoqh", "pcsqh", "pcoqt",
718 "pcsqt", "eiem", "iir", "isr",
719 "ior", "ipsw", "goto", "sr4",
720 "sr0", "sr1", "sr2", "sr3",
721 "sr5", "sr6", "sr7", "cr0",
722 "cr8", "cr9", "ccr", "cr12",
723 "cr13", "cr24", "cr25", "cr26",
724 "mpsfu_high","mpsfu_low","mpsfu_ovflo","pad",
725 "fpsr", "fpe1", "fpe2", "fpe3",
726 "fpe4", "fpe5", "fpe6", "fpe7",
727 "fr4", "fr4R", "fr5", "fr5R",
728 "fr6", "fr6R", "fr7", "fr7R",
729 "fr8", "fr8R", "fr9", "fr9R",
730 "fr10", "fr10R", "fr11", "fr11R",
731 "fr12", "fr12R", "fr13", "fr13R",
732 "fr14", "fr14R", "fr15", "fr15R",
733 "fr16", "fr16R", "fr17", "fr17R",
734 "fr18", "fr18R", "fr19", "fr19R",
735 "fr20", "fr20R", "fr21", "fr21R",
736 "fr22", "fr22R", "fr23", "fr23R",
737 "fr24", "fr24R", "fr25", "fr25R",
738 "fr26", "fr26R", "fr27", "fr27R",
739 "fr28", "fr28R", "fr29", "fr29R",
740 "fr30", "fr30R", "fr31", "fr31R"
741 };
742 if (i < 0 || i >= (sizeof (names) / sizeof (*names)))
743 return NULL;
744 else
745 return names[i];
746 }
747
748 const char *
749 hppa64_register_name (int i)
750 {
751 static char *names[] = {
752 "flags", "r1", "rp", "r3",
753 "r4", "r5", "r6", "r7",
754 "r8", "r9", "r10", "r11",
755 "r12", "r13", "r14", "r15",
756 "r16", "r17", "r18", "r19",
757 "r20", "r21", "r22", "r23",
758 "r24", "r25", "r26", "dp",
759 "ret0", "ret1", "sp", "r31",
760 "sar", "pcoqh", "pcsqh", "pcoqt",
761 "pcsqt", "eiem", "iir", "isr",
762 "ior", "ipsw", "goto", "sr4",
763 "sr0", "sr1", "sr2", "sr3",
764 "sr5", "sr6", "sr7", "cr0",
765 "cr8", "cr9", "ccr", "cr12",
766 "cr13", "cr24", "cr25", "cr26",
767 "mpsfu_high","mpsfu_low","mpsfu_ovflo","pad",
768 "fpsr", "fpe1", "fpe2", "fpe3",
769 "fr4", "fr5", "fr6", "fr7",
770 "fr8", "fr9", "fr10", "fr11",
771 "fr12", "fr13", "fr14", "fr15",
772 "fr16", "fr17", "fr18", "fr19",
773 "fr20", "fr21", "fr22", "fr23",
774 "fr24", "fr25", "fr26", "fr27",
775 "fr28", "fr29", "fr30", "fr31"
776 };
777 if (i < 0 || i >= (sizeof (names) / sizeof (*names)))
778 return NULL;
779 else
780 return names[i];
781 }
782
783
784
785 /* Return the adjustment necessary to make for addresses on the stack
786 as presented by hpread.c.
787
788 This is necessary because of the stack direction on the PA and the
789 bizarre way in which someone (?) decided they wanted to handle
790 frame pointerless code in GDB. */
791 int
792 hpread_adjust_stack_address (CORE_ADDR func_addr)
793 {
794 struct unwind_table_entry *u;
795
796 u = find_unwind_entry (func_addr);
797 if (!u)
798 return 0;
799 else
800 return u->Total_frame_size << 3;
801 }
802
803 /* This function pushes a stack frame with arguments as part of the
804 inferior function calling mechanism.
805
806 This is the version of the function for the 32-bit PA machines, in
807 which later arguments appear at lower addresses. (The stack always
808 grows towards higher addresses.)
809
810 We simply allocate the appropriate amount of stack space and put
811 arguments into their proper slots. */
812
813 CORE_ADDR
814 hppa32_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr,
815 struct regcache *regcache, CORE_ADDR bp_addr,
816 int nargs, struct value **args, CORE_ADDR sp,
817 int struct_return, CORE_ADDR struct_addr)
818 {
819 /* NOTE: cagney/2004-02-27: This is a guess - its implemented by
820 reverse engineering testsuite failures. */
821
822 /* Stack base address at which any pass-by-reference parameters are
823 stored. */
824 CORE_ADDR struct_end = 0;
825 /* Stack base address at which the first parameter is stored. */
826 CORE_ADDR param_end = 0;
827
828 /* The inner most end of the stack after all the parameters have
829 been pushed. */
830 CORE_ADDR new_sp = 0;
831
832 /* Two passes. First pass computes the location of everything,
833 second pass writes the bytes out. */
834 int write_pass;
835 for (write_pass = 0; write_pass < 2; write_pass++)
836 {
837 CORE_ADDR struct_ptr = 0;
838 CORE_ADDR param_ptr = 0;
839 int reg = 27; /* NOTE: Registers go down. */
840 int i;
841 for (i = 0; i < nargs; i++)
842 {
843 struct value *arg = args[i];
844 struct type *type = check_typedef (VALUE_TYPE (arg));
845 /* The corresponding parameter that is pushed onto the
846 stack, and [possibly] passed in a register. */
847 char param_val[8];
848 int param_len;
849 memset (param_val, 0, sizeof param_val);
850 if (TYPE_LENGTH (type) > 8)
851 {
852 /* Large parameter, pass by reference. Store the value
853 in "struct" area and then pass its address. */
854 param_len = 4;
855 struct_ptr += align_up (TYPE_LENGTH (type), 8);
856 if (write_pass)
857 write_memory (struct_end - struct_ptr, VALUE_CONTENTS (arg),
858 TYPE_LENGTH (type));
859 store_unsigned_integer (param_val, 4, struct_end - struct_ptr);
860 }
861 else if (TYPE_CODE (type) == TYPE_CODE_INT
862 || TYPE_CODE (type) == TYPE_CODE_ENUM)
863 {
864 /* Integer value store, right aligned. "unpack_long"
865 takes care of any sign-extension problems. */
866 param_len = align_up (TYPE_LENGTH (type), 4);
867 store_unsigned_integer (param_val, param_len,
868 unpack_long (type,
869 VALUE_CONTENTS (arg)));
870 }
871 else
872 {
873 /* Small struct value, store right aligned? */
874 param_len = align_up (TYPE_LENGTH (type), 4);
875 memcpy (param_val + param_len - TYPE_LENGTH (type),
876 VALUE_CONTENTS (arg), TYPE_LENGTH (type));
877 }
878 param_ptr += param_len;
879 reg -= param_len / 4;
880 if (write_pass)
881 {
882 write_memory (param_end - param_ptr, param_val, param_len);
883 if (reg >= 23)
884 {
885 regcache_cooked_write (regcache, reg, param_val);
886 if (param_len > 4)
887 regcache_cooked_write (regcache, reg + 1, param_val + 4);
888 }
889 }
890 }
891
892 /* Update the various stack pointers. */
893 if (!write_pass)
894 {
895 struct_end = sp + struct_ptr;
896 /* PARAM_PTR already accounts for all the arguments passed
897 by the user. However, the ABI mandates minimum stack
898 space allocations for outgoing arguments. The ABI also
899 mandates minimum stack alignments which we must
900 preserve. */
901 param_end = struct_end + max (align_up (param_ptr, 8),
902 REG_PARM_STACK_SPACE);
903 }
904 }
905
906 /* If a structure has to be returned, set up register 28 to hold its
907 address */
908 if (struct_return)
909 write_register (28, struct_addr);
910
911 /* Set the return address. */
912 regcache_cooked_write_unsigned (regcache, RP_REGNUM, bp_addr);
913
914 /* Update the Stack Pointer. */
915 regcache_cooked_write_unsigned (regcache, SP_REGNUM, param_end + 32);
916
917 /* The stack will have 32 bytes of additional space for a frame marker. */
918 return param_end + 32;
919 }
920
921 /* This function pushes a stack frame with arguments as part of the
922 inferior function calling mechanism.
923
924 This is the version for the PA64, in which later arguments appear
925 at higher addresses. (The stack always grows towards higher
926 addresses.)
927
928 We simply allocate the appropriate amount of stack space and put
929 arguments into their proper slots.
930
931 This ABI also requires that the caller provide an argument pointer
932 to the callee, so we do that too. */
933
934 CORE_ADDR
935 hppa64_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr,
936 struct regcache *regcache, CORE_ADDR bp_addr,
937 int nargs, struct value **args, CORE_ADDR sp,
938 int struct_return, CORE_ADDR struct_addr)
939 {
940 /* NOTE: cagney/2004-02-27: This is a guess - its implemented by
941 reverse engineering testsuite failures. */
942
943 /* Stack base address at which any pass-by-reference parameters are
944 stored. */
945 CORE_ADDR struct_end = 0;
946 /* Stack base address at which the first parameter is stored. */
947 CORE_ADDR param_end = 0;
948
949 /* The inner most end of the stack after all the parameters have
950 been pushed. */
951 CORE_ADDR new_sp = 0;
952
953 /* Two passes. First pass computes the location of everything,
954 second pass writes the bytes out. */
955 int write_pass;
956 for (write_pass = 0; write_pass < 2; write_pass++)
957 {
958 CORE_ADDR struct_ptr = 0;
959 CORE_ADDR param_ptr = 0;
960 int i;
961 for (i = 0; i < nargs; i++)
962 {
963 struct value *arg = args[i];
964 struct type *type = check_typedef (VALUE_TYPE (arg));
965 if ((TYPE_CODE (type) == TYPE_CODE_INT
966 || TYPE_CODE (type) == TYPE_CODE_ENUM)
967 && TYPE_LENGTH (type) <= 8)
968 {
969 /* Integer value store, right aligned. "unpack_long"
970 takes care of any sign-extension problems. */
971 param_ptr += 8;
972 if (write_pass)
973 {
974 ULONGEST val = unpack_long (type, VALUE_CONTENTS (arg));
975 int reg = 27 - param_ptr / 8;
976 write_memory_unsigned_integer (param_end - param_ptr,
977 val, 8);
978 if (reg >= 19)
979 regcache_cooked_write_unsigned (regcache, reg, val);
980 }
981 }
982 else
983 {
984 /* Small struct value, store left aligned? */
985 int reg;
986 if (TYPE_LENGTH (type) > 8)
987 {
988 param_ptr = align_up (param_ptr, 16);
989 reg = 26 - param_ptr / 8;
990 param_ptr += align_up (TYPE_LENGTH (type), 16);
991 }
992 else
993 {
994 param_ptr = align_up (param_ptr, 8);
995 reg = 26 - param_ptr / 8;
996 param_ptr += align_up (TYPE_LENGTH (type), 8);
997 }
998 if (write_pass)
999 {
1000 int byte;
1001 write_memory (param_end - param_ptr, VALUE_CONTENTS (arg),
1002 TYPE_LENGTH (type));
1003 for (byte = 0; byte < TYPE_LENGTH (type); byte += 8)
1004 {
1005 if (reg >= 19)
1006 {
1007 int len = min (8, TYPE_LENGTH (type) - byte);
1008 regcache_cooked_write_part (regcache, reg, 0, len,
1009 VALUE_CONTENTS (arg) + byte);
1010 }
1011 reg--;
1012 }
1013 }
1014 }
1015 }
1016 /* Update the various stack pointers. */
1017 if (!write_pass)
1018 {
1019 struct_end = sp + struct_ptr;
1020 /* PARAM_PTR already accounts for all the arguments passed
1021 by the user. However, the ABI mandates minimum stack
1022 space allocations for outgoing arguments. The ABI also
1023 mandates minimum stack alignments which we must
1024 preserve. */
1025 param_end = struct_end + max (align_up (param_ptr, 16),
1026 REG_PARM_STACK_SPACE);
1027 }
1028 }
1029
1030 /* If a structure has to be returned, set up register 28 to hold its
1031 address */
1032 if (struct_return)
1033 write_register (28, struct_addr);
1034
1035 /* Set the return address. */
1036 regcache_cooked_write_unsigned (regcache, RP_REGNUM, bp_addr);
1037
1038 /* Update the Stack Pointer. */
1039 regcache_cooked_write_unsigned (regcache, SP_REGNUM, param_end + 64);
1040
1041 /* The stack will have 32 bytes of additional space for a frame marker. */
1042 return param_end + 64;
1043 }
1044
1045 static CORE_ADDR
1046 hppa32_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr)
1047 {
1048 /* HP frames are 64-byte (or cache line) aligned (yes that's _byte_
1049 and not _bit_)! */
1050 return align_up (addr, 64);
1051 }
1052
1053 /* Force all frames to 16-byte alignment. Better safe than sorry. */
1054
1055 static CORE_ADDR
1056 hppa64_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr)
1057 {
1058 /* Just always 16-byte align. */
1059 return align_up (addr, 16);
1060 }
1061
1062
1063 /* elz: Used to lookup a symbol in the shared libraries.
1064 This function calls shl_findsym, indirectly through a
1065 call to __d_shl_get. __d_shl_get is in end.c, which is always
1066 linked in by the hp compilers/linkers.
1067 The call to shl_findsym cannot be made directly because it needs
1068 to be active in target address space.
1069 inputs: - minimal symbol pointer for the function we want to look up
1070 - address in target space of the descriptor for the library
1071 where we want to look the symbol up.
1072 This address is retrieved using the
1073 som_solib_get_solib_by_pc function (somsolib.c).
1074 output: - real address in the library of the function.
1075 note: the handle can be null, in which case shl_findsym will look for
1076 the symbol in all the loaded shared libraries.
1077 files to look at if you need reference on this stuff:
1078 dld.c, dld_shl_findsym.c
1079 end.c
1080 man entry for shl_findsym */
1081
1082 CORE_ADDR
1083 find_stub_with_shl_get (struct minimal_symbol *function, CORE_ADDR handle)
1084 {
1085 struct symbol *get_sym, *symbol2;
1086 struct minimal_symbol *buff_minsym, *msymbol;
1087 struct type *ftype;
1088 struct value **args;
1089 struct value *funcval;
1090 struct value *val;
1091
1092 int x, namelen, err_value, tmp = -1;
1093 CORE_ADDR endo_buff_addr, value_return_addr, errno_return_addr;
1094 CORE_ADDR stub_addr;
1095
1096
1097 args = alloca (sizeof (struct value *) * 8); /* 6 for the arguments and one null one??? */
1098 funcval = find_function_in_inferior ("__d_shl_get");
1099 get_sym = lookup_symbol ("__d_shl_get", NULL, VAR_DOMAIN, NULL, NULL);
1100 buff_minsym = lookup_minimal_symbol ("__buffer", NULL, NULL);
1101 msymbol = lookup_minimal_symbol ("__shldp", NULL, NULL);
1102 symbol2 = lookup_symbol ("__shldp", NULL, VAR_DOMAIN, NULL, NULL);
1103 endo_buff_addr = SYMBOL_VALUE_ADDRESS (buff_minsym);
1104 namelen = strlen (DEPRECATED_SYMBOL_NAME (function));
1105 value_return_addr = endo_buff_addr + namelen;
1106 ftype = check_typedef (SYMBOL_TYPE (get_sym));
1107
1108 /* do alignment */
1109 if ((x = value_return_addr % 64) != 0)
1110 value_return_addr = value_return_addr + 64 - x;
1111
1112 errno_return_addr = value_return_addr + 64;
1113
1114
1115 /* set up stuff needed by __d_shl_get in buffer in end.o */
1116
1117 target_write_memory (endo_buff_addr, DEPRECATED_SYMBOL_NAME (function), namelen);
1118
1119 target_write_memory (value_return_addr, (char *) &tmp, 4);
1120
1121 target_write_memory (errno_return_addr, (char *) &tmp, 4);
1122
1123 target_write_memory (SYMBOL_VALUE_ADDRESS (msymbol),
1124 (char *) &handle, 4);
1125
1126 /* now prepare the arguments for the call */
1127
1128 args[0] = value_from_longest (TYPE_FIELD_TYPE (ftype, 0), 12);
1129 args[1] = value_from_pointer (TYPE_FIELD_TYPE (ftype, 1), SYMBOL_VALUE_ADDRESS (msymbol));
1130 args[2] = value_from_pointer (TYPE_FIELD_TYPE (ftype, 2), endo_buff_addr);
1131 args[3] = value_from_longest (TYPE_FIELD_TYPE (ftype, 3), TYPE_PROCEDURE);
1132 args[4] = value_from_pointer (TYPE_FIELD_TYPE (ftype, 4), value_return_addr);
1133 args[5] = value_from_pointer (TYPE_FIELD_TYPE (ftype, 5), errno_return_addr);
1134
1135 /* now call the function */
1136
1137 val = call_function_by_hand (funcval, 6, args);
1138
1139 /* now get the results */
1140
1141 target_read_memory (errno_return_addr, (char *) &err_value, sizeof (err_value));
1142
1143 target_read_memory (value_return_addr, (char *) &stub_addr, sizeof (stub_addr));
1144 if (stub_addr <= 0)
1145 error ("call to __d_shl_get failed, error code is %d", err_value);
1146
1147 return (stub_addr);
1148 }
1149
1150 /* Cover routine for find_stub_with_shl_get to pass to catch_errors */
1151 static int
1152 cover_find_stub_with_shl_get (void *args_untyped)
1153 {
1154 args_for_find_stub *args = args_untyped;
1155 args->return_val = find_stub_with_shl_get (args->msym, args->solib_handle);
1156 return 0;
1157 }
1158
1159 /* Get the PC from %r31 if currently in a syscall. Also mask out privilege
1160 bits. */
1161
1162 CORE_ADDR
1163 hppa_target_read_pc (ptid_t ptid)
1164 {
1165 int flags = read_register_pid (FLAGS_REGNUM, ptid);
1166
1167 /* The following test does not belong here. It is OS-specific, and belongs
1168 in native code. */
1169 /* Test SS_INSYSCALL */
1170 if (flags & 2)
1171 return read_register_pid (31, ptid) & ~0x3;
1172
1173 return read_register_pid (PCOQ_HEAD_REGNUM, ptid) & ~0x3;
1174 }
1175
1176 /* Write out the PC. If currently in a syscall, then also write the new
1177 PC value into %r31. */
1178
1179 void
1180 hppa_target_write_pc (CORE_ADDR v, ptid_t ptid)
1181 {
1182 int flags = read_register_pid (FLAGS_REGNUM, ptid);
1183
1184 /* The following test does not belong here. It is OS-specific, and belongs
1185 in native code. */
1186 /* If in a syscall, then set %r31. Also make sure to get the
1187 privilege bits set correctly. */
1188 /* Test SS_INSYSCALL */
1189 if (flags & 2)
1190 write_register_pid (31, v | 0x3, ptid);
1191
1192 write_register_pid (PCOQ_HEAD_REGNUM, v, ptid);
1193 write_register_pid (PCOQ_TAIL_REGNUM, v + 4, ptid);
1194 }
1195
1196 /* return the alignment of a type in bytes. Structures have the maximum
1197 alignment required by their fields. */
1198
1199 static int
1200 hppa_alignof (struct type *type)
1201 {
1202 int max_align, align, i;
1203 CHECK_TYPEDEF (type);
1204 switch (TYPE_CODE (type))
1205 {
1206 case TYPE_CODE_PTR:
1207 case TYPE_CODE_INT:
1208 case TYPE_CODE_FLT:
1209 return TYPE_LENGTH (type);
1210 case TYPE_CODE_ARRAY:
1211 return hppa_alignof (TYPE_FIELD_TYPE (type, 0));
1212 case TYPE_CODE_STRUCT:
1213 case TYPE_CODE_UNION:
1214 max_align = 1;
1215 for (i = 0; i < TYPE_NFIELDS (type); i++)
1216 {
1217 /* Bit fields have no real alignment. */
1218 /* if (!TYPE_FIELD_BITPOS (type, i)) */
1219 if (!TYPE_FIELD_BITSIZE (type, i)) /* elz: this should be bitsize */
1220 {
1221 align = hppa_alignof (TYPE_FIELD_TYPE (type, i));
1222 max_align = max (max_align, align);
1223 }
1224 }
1225 return max_align;
1226 default:
1227 return 4;
1228 }
1229 }
1230
1231 /* Return one if PC is in the call path of a trampoline, else return zero.
1232
1233 Note we return one for *any* call trampoline (long-call, arg-reloc), not
1234 just shared library trampolines (import, export). */
1235
1236 int
1237 hppa_in_solib_call_trampoline (CORE_ADDR pc, char *name)
1238 {
1239 struct minimal_symbol *minsym;
1240 struct unwind_table_entry *u;
1241 static CORE_ADDR dyncall = 0;
1242 static CORE_ADDR sr4export = 0;
1243
1244 #ifdef GDB_TARGET_IS_HPPA_20W
1245 /* PA64 has a completely different stub/trampoline scheme. Is it
1246 better? Maybe. It's certainly harder to determine with any
1247 certainty that we are in a stub because we can not refer to the
1248 unwinders to help.
1249
1250 The heuristic is simple. Try to lookup the current PC value in th
1251 minimal symbol table. If that fails, then assume we are not in a
1252 stub and return.
1253
1254 Then see if the PC value falls within the section bounds for the
1255 section containing the minimal symbol we found in the first
1256 step. If it does, then assume we are not in a stub and return.
1257
1258 Finally peek at the instructions to see if they look like a stub. */
1259 {
1260 struct minimal_symbol *minsym;
1261 asection *sec;
1262 CORE_ADDR addr;
1263 int insn, i;
1264
1265 minsym = lookup_minimal_symbol_by_pc (pc);
1266 if (! minsym)
1267 return 0;
1268
1269 sec = SYMBOL_BFD_SECTION (minsym);
1270
1271 if (bfd_get_section_vma (sec->owner, sec) <= pc
1272 && pc < (bfd_get_section_vma (sec->owner, sec)
1273 + bfd_section_size (sec->owner, sec)))
1274 return 0;
1275
1276 /* We might be in a stub. Peek at the instructions. Stubs are 3
1277 instructions long. */
1278 insn = read_memory_integer (pc, 4);
1279
1280 /* Find out where we think we are within the stub. */
1281 if ((insn & 0xffffc00e) == 0x53610000)
1282 addr = pc;
1283 else if ((insn & 0xffffffff) == 0xe820d000)
1284 addr = pc - 4;
1285 else if ((insn & 0xffffc00e) == 0x537b0000)
1286 addr = pc - 8;
1287 else
1288 return 0;
1289
1290 /* Now verify each insn in the range looks like a stub instruction. */
1291 insn = read_memory_integer (addr, 4);
1292 if ((insn & 0xffffc00e) != 0x53610000)
1293 return 0;
1294
1295 /* Now verify each insn in the range looks like a stub instruction. */
1296 insn = read_memory_integer (addr + 4, 4);
1297 if ((insn & 0xffffffff) != 0xe820d000)
1298 return 0;
1299
1300 /* Now verify each insn in the range looks like a stub instruction. */
1301 insn = read_memory_integer (addr + 8, 4);
1302 if ((insn & 0xffffc00e) != 0x537b0000)
1303 return 0;
1304
1305 /* Looks like a stub. */
1306 return 1;
1307 }
1308 #endif
1309
1310 /* FIXME XXX - dyncall and sr4export must be initialized whenever we get a
1311 new exec file */
1312
1313 /* First see if PC is in one of the two C-library trampolines. */
1314 if (!dyncall)
1315 {
1316 minsym = lookup_minimal_symbol ("$$dyncall", NULL, NULL);
1317 if (minsym)
1318 dyncall = SYMBOL_VALUE_ADDRESS (minsym);
1319 else
1320 dyncall = -1;
1321 }
1322
1323 if (!sr4export)
1324 {
1325 minsym = lookup_minimal_symbol ("_sr4export", NULL, NULL);
1326 if (minsym)
1327 sr4export = SYMBOL_VALUE_ADDRESS (minsym);
1328 else
1329 sr4export = -1;
1330 }
1331
1332 if (pc == dyncall || pc == sr4export)
1333 return 1;
1334
1335 minsym = lookup_minimal_symbol_by_pc (pc);
1336 if (minsym && strcmp (DEPRECATED_SYMBOL_NAME (minsym), ".stub") == 0)
1337 return 1;
1338
1339 /* Get the unwind descriptor corresponding to PC, return zero
1340 if no unwind was found. */
1341 u = find_unwind_entry (pc);
1342 if (!u)
1343 return 0;
1344
1345 /* If this isn't a linker stub, then return now. */
1346 if (u->stub_unwind.stub_type == 0)
1347 return 0;
1348
1349 /* By definition a long-branch stub is a call stub. */
1350 if (u->stub_unwind.stub_type == LONG_BRANCH)
1351 return 1;
1352
1353 /* The call and return path execute the same instructions within
1354 an IMPORT stub! So an IMPORT stub is both a call and return
1355 trampoline. */
1356 if (u->stub_unwind.stub_type == IMPORT)
1357 return 1;
1358
1359 /* Parameter relocation stubs always have a call path and may have a
1360 return path. */
1361 if (u->stub_unwind.stub_type == PARAMETER_RELOCATION
1362 || u->stub_unwind.stub_type == EXPORT)
1363 {
1364 CORE_ADDR addr;
1365
1366 /* Search forward from the current PC until we hit a branch
1367 or the end of the stub. */
1368 for (addr = pc; addr <= u->region_end; addr += 4)
1369 {
1370 unsigned long insn;
1371
1372 insn = read_memory_integer (addr, 4);
1373
1374 /* Does it look like a bl? If so then it's the call path, if
1375 we find a bv or be first, then we're on the return path. */
1376 if ((insn & 0xfc00e000) == 0xe8000000)
1377 return 1;
1378 else if ((insn & 0xfc00e001) == 0xe800c000
1379 || (insn & 0xfc000000) == 0xe0000000)
1380 return 0;
1381 }
1382
1383 /* Should never happen. */
1384 warning ("Unable to find branch in parameter relocation stub.\n");
1385 return 0;
1386 }
1387
1388 /* Unknown stub type. For now, just return zero. */
1389 return 0;
1390 }
1391
1392 /* Return one if PC is in the return path of a trampoline, else return zero.
1393
1394 Note we return one for *any* call trampoline (long-call, arg-reloc), not
1395 just shared library trampolines (import, export). */
1396
1397 int
1398 hppa_in_solib_return_trampoline (CORE_ADDR pc, char *name)
1399 {
1400 struct unwind_table_entry *u;
1401
1402 /* Get the unwind descriptor corresponding to PC, return zero
1403 if no unwind was found. */
1404 u = find_unwind_entry (pc);
1405 if (!u)
1406 return 0;
1407
1408 /* If this isn't a linker stub or it's just a long branch stub, then
1409 return zero. */
1410 if (u->stub_unwind.stub_type == 0 || u->stub_unwind.stub_type == LONG_BRANCH)
1411 return 0;
1412
1413 /* The call and return path execute the same instructions within
1414 an IMPORT stub! So an IMPORT stub is both a call and return
1415 trampoline. */
1416 if (u->stub_unwind.stub_type == IMPORT)
1417 return 1;
1418
1419 /* Parameter relocation stubs always have a call path and may have a
1420 return path. */
1421 if (u->stub_unwind.stub_type == PARAMETER_RELOCATION
1422 || u->stub_unwind.stub_type == EXPORT)
1423 {
1424 CORE_ADDR addr;
1425
1426 /* Search forward from the current PC until we hit a branch
1427 or the end of the stub. */
1428 for (addr = pc; addr <= u->region_end; addr += 4)
1429 {
1430 unsigned long insn;
1431
1432 insn = read_memory_integer (addr, 4);
1433
1434 /* Does it look like a bl? If so then it's the call path, if
1435 we find a bv or be first, then we're on the return path. */
1436 if ((insn & 0xfc00e000) == 0xe8000000)
1437 return 0;
1438 else if ((insn & 0xfc00e001) == 0xe800c000
1439 || (insn & 0xfc000000) == 0xe0000000)
1440 return 1;
1441 }
1442
1443 /* Should never happen. */
1444 warning ("Unable to find branch in parameter relocation stub.\n");
1445 return 0;
1446 }
1447
1448 /* Unknown stub type. For now, just return zero. */
1449 return 0;
1450
1451 }
1452
1453 /* Figure out if PC is in a trampoline, and if so find out where
1454 the trampoline will jump to. If not in a trampoline, return zero.
1455
1456 Simple code examination probably is not a good idea since the code
1457 sequences in trampolines can also appear in user code.
1458
1459 We use unwinds and information from the minimal symbol table to
1460 determine when we're in a trampoline. This won't work for ELF
1461 (yet) since it doesn't create stub unwind entries. Whether or
1462 not ELF will create stub unwinds or normal unwinds for linker
1463 stubs is still being debated.
1464
1465 This should handle simple calls through dyncall or sr4export,
1466 long calls, argument relocation stubs, and dyncall/sr4export
1467 calling an argument relocation stub. It even handles some stubs
1468 used in dynamic executables. */
1469
1470 CORE_ADDR
1471 hppa_skip_trampoline_code (CORE_ADDR pc)
1472 {
1473 long orig_pc = pc;
1474 long prev_inst, curr_inst, loc;
1475 static CORE_ADDR dyncall = 0;
1476 static CORE_ADDR dyncall_external = 0;
1477 static CORE_ADDR sr4export = 0;
1478 struct minimal_symbol *msym;
1479 struct unwind_table_entry *u;
1480
1481 /* FIXME XXX - dyncall and sr4export must be initialized whenever we get a
1482 new exec file */
1483
1484 if (!dyncall)
1485 {
1486 msym = lookup_minimal_symbol ("$$dyncall", NULL, NULL);
1487 if (msym)
1488 dyncall = SYMBOL_VALUE_ADDRESS (msym);
1489 else
1490 dyncall = -1;
1491 }
1492
1493 if (!dyncall_external)
1494 {
1495 msym = lookup_minimal_symbol ("$$dyncall_external", NULL, NULL);
1496 if (msym)
1497 dyncall_external = SYMBOL_VALUE_ADDRESS (msym);
1498 else
1499 dyncall_external = -1;
1500 }
1501
1502 if (!sr4export)
1503 {
1504 msym = lookup_minimal_symbol ("_sr4export", NULL, NULL);
1505 if (msym)
1506 sr4export = SYMBOL_VALUE_ADDRESS (msym);
1507 else
1508 sr4export = -1;
1509 }
1510
1511 /* Addresses passed to dyncall may *NOT* be the actual address
1512 of the function. So we may have to do something special. */
1513 if (pc == dyncall)
1514 {
1515 pc = (CORE_ADDR) read_register (22);
1516
1517 /* If bit 30 (counting from the left) is on, then pc is the address of
1518 the PLT entry for this function, not the address of the function
1519 itself. Bit 31 has meaning too, but only for MPE. */
1520 if (pc & 0x2)
1521 pc = (CORE_ADDR) read_memory_integer (pc & ~0x3, TARGET_PTR_BIT / 8);
1522 }
1523 if (pc == dyncall_external)
1524 {
1525 pc = (CORE_ADDR) read_register (22);
1526 pc = (CORE_ADDR) read_memory_integer (pc & ~0x3, TARGET_PTR_BIT / 8);
1527 }
1528 else if (pc == sr4export)
1529 pc = (CORE_ADDR) (read_register (22));
1530
1531 /* Get the unwind descriptor corresponding to PC, return zero
1532 if no unwind was found. */
1533 u = find_unwind_entry (pc);
1534 if (!u)
1535 return 0;
1536
1537 /* If this isn't a linker stub, then return now. */
1538 /* elz: attention here! (FIXME) because of a compiler/linker
1539 error, some stubs which should have a non zero stub_unwind.stub_type
1540 have unfortunately a value of zero. So this function would return here
1541 as if we were not in a trampoline. To fix this, we go look at the partial
1542 symbol information, which reports this guy as a stub.
1543 (FIXME): Unfortunately, we are not that lucky: it turns out that the
1544 partial symbol information is also wrong sometimes. This is because
1545 when it is entered (somread.c::som_symtab_read()) it can happen that
1546 if the type of the symbol (from the som) is Entry, and the symbol is
1547 in a shared library, then it can also be a trampoline. This would
1548 be OK, except that I believe the way they decide if we are ina shared library
1549 does not work. SOOOO..., even if we have a regular function w/o trampolines
1550 its minimal symbol can be assigned type mst_solib_trampoline.
1551 Also, if we find that the symbol is a real stub, then we fix the unwind
1552 descriptor, and define the stub type to be EXPORT.
1553 Hopefully this is correct most of the times. */
1554 if (u->stub_unwind.stub_type == 0)
1555 {
1556
1557 /* elz: NOTE (FIXME!) once the problem with the unwind information is fixed
1558 we can delete all the code which appears between the lines */
1559 /*--------------------------------------------------------------------------*/
1560 msym = lookup_minimal_symbol_by_pc (pc);
1561
1562 if (msym == NULL || MSYMBOL_TYPE (msym) != mst_solib_trampoline)
1563 return orig_pc == pc ? 0 : pc & ~0x3;
1564
1565 else if (msym != NULL && MSYMBOL_TYPE (msym) == mst_solib_trampoline)
1566 {
1567 struct objfile *objfile;
1568 struct minimal_symbol *msymbol;
1569 int function_found = 0;
1570
1571 /* go look if there is another minimal symbol with the same name as
1572 this one, but with type mst_text. This would happen if the msym
1573 is an actual trampoline, in which case there would be another
1574 symbol with the same name corresponding to the real function */
1575
1576 ALL_MSYMBOLS (objfile, msymbol)
1577 {
1578 if (MSYMBOL_TYPE (msymbol) == mst_text
1579 && DEPRECATED_STREQ (DEPRECATED_SYMBOL_NAME (msymbol), DEPRECATED_SYMBOL_NAME (msym)))
1580 {
1581 function_found = 1;
1582 break;
1583 }
1584 }
1585
1586 if (function_found)
1587 /* the type of msym is correct (mst_solib_trampoline), but
1588 the unwind info is wrong, so set it to the correct value */
1589 u->stub_unwind.stub_type = EXPORT;
1590 else
1591 /* the stub type info in the unwind is correct (this is not a
1592 trampoline), but the msym type information is wrong, it
1593 should be mst_text. So we need to fix the msym, and also
1594 get out of this function */
1595 {
1596 MSYMBOL_TYPE (msym) = mst_text;
1597 return orig_pc == pc ? 0 : pc & ~0x3;
1598 }
1599 }
1600
1601 /*--------------------------------------------------------------------------*/
1602 }
1603
1604 /* It's a stub. Search for a branch and figure out where it goes.
1605 Note we have to handle multi insn branch sequences like ldil;ble.
1606 Most (all?) other branches can be determined by examining the contents
1607 of certain registers and the stack. */
1608
1609 loc = pc;
1610 curr_inst = 0;
1611 prev_inst = 0;
1612 while (1)
1613 {
1614 /* Make sure we haven't walked outside the range of this stub. */
1615 if (u != find_unwind_entry (loc))
1616 {
1617 warning ("Unable to find branch in linker stub");
1618 return orig_pc == pc ? 0 : pc & ~0x3;
1619 }
1620
1621 prev_inst = curr_inst;
1622 curr_inst = read_memory_integer (loc, 4);
1623
1624 /* Does it look like a branch external using %r1? Then it's the
1625 branch from the stub to the actual function. */
1626 if ((curr_inst & 0xffe0e000) == 0xe0202000)
1627 {
1628 /* Yup. See if the previous instruction loaded
1629 a value into %r1. If so compute and return the jump address. */
1630 if ((prev_inst & 0xffe00000) == 0x20200000)
1631 return (extract_21 (prev_inst) + extract_17 (curr_inst)) & ~0x3;
1632 else
1633 {
1634 warning ("Unable to find ldil X,%%r1 before ble Y(%%sr4,%%r1).");
1635 return orig_pc == pc ? 0 : pc & ~0x3;
1636 }
1637 }
1638
1639 /* Does it look like a be 0(sr0,%r21)? OR
1640 Does it look like a be, n 0(sr0,%r21)? OR
1641 Does it look like a bve (r21)? (this is on PA2.0)
1642 Does it look like a bve, n(r21)? (this is also on PA2.0)
1643 That's the branch from an
1644 import stub to an export stub.
1645
1646 It is impossible to determine the target of the branch via
1647 simple examination of instructions and/or data (consider
1648 that the address in the plabel may be the address of the
1649 bind-on-reference routine in the dynamic loader).
1650
1651 So we have try an alternative approach.
1652
1653 Get the name of the symbol at our current location; it should
1654 be a stub symbol with the same name as the symbol in the
1655 shared library.
1656
1657 Then lookup a minimal symbol with the same name; we should
1658 get the minimal symbol for the target routine in the shared
1659 library as those take precedence of import/export stubs. */
1660 if ((curr_inst == 0xe2a00000) ||
1661 (curr_inst == 0xe2a00002) ||
1662 (curr_inst == 0xeaa0d000) ||
1663 (curr_inst == 0xeaa0d002))
1664 {
1665 struct minimal_symbol *stubsym, *libsym;
1666
1667 stubsym = lookup_minimal_symbol_by_pc (loc);
1668 if (stubsym == NULL)
1669 {
1670 warning ("Unable to find symbol for 0x%lx", loc);
1671 return orig_pc == pc ? 0 : pc & ~0x3;
1672 }
1673
1674 libsym = lookup_minimal_symbol (DEPRECATED_SYMBOL_NAME (stubsym), NULL, NULL);
1675 if (libsym == NULL)
1676 {
1677 warning ("Unable to find library symbol for %s\n",
1678 DEPRECATED_SYMBOL_NAME (stubsym));
1679 return orig_pc == pc ? 0 : pc & ~0x3;
1680 }
1681
1682 return SYMBOL_VALUE (libsym);
1683 }
1684
1685 /* Does it look like bl X,%rp or bl X,%r0? Another way to do a
1686 branch from the stub to the actual function. */
1687 /*elz */
1688 else if ((curr_inst & 0xffe0e000) == 0xe8400000
1689 || (curr_inst & 0xffe0e000) == 0xe8000000
1690 || (curr_inst & 0xffe0e000) == 0xe800A000)
1691 return (loc + extract_17 (curr_inst) + 8) & ~0x3;
1692
1693 /* Does it look like bv (rp)? Note this depends on the
1694 current stack pointer being the same as the stack
1695 pointer in the stub itself! This is a branch on from the
1696 stub back to the original caller. */
1697 /*else if ((curr_inst & 0xffe0e000) == 0xe840c000) */
1698 else if ((curr_inst & 0xffe0f000) == 0xe840c000)
1699 {
1700 /* Yup. See if the previous instruction loaded
1701 rp from sp - 8. */
1702 if (prev_inst == 0x4bc23ff1)
1703 return (read_memory_integer
1704 (read_register (HPPA_SP_REGNUM) - 8, 4)) & ~0x3;
1705 else
1706 {
1707 warning ("Unable to find restore of %%rp before bv (%%rp).");
1708 return orig_pc == pc ? 0 : pc & ~0x3;
1709 }
1710 }
1711
1712 /* elz: added this case to capture the new instruction
1713 at the end of the return part of an export stub used by
1714 the PA2.0: BVE, n (rp) */
1715 else if ((curr_inst & 0xffe0f000) == 0xe840d000)
1716 {
1717 return (read_memory_integer
1718 (read_register (HPPA_SP_REGNUM) - 24, TARGET_PTR_BIT / 8)) & ~0x3;
1719 }
1720
1721 /* What about be,n 0(sr0,%rp)? It's just another way we return to
1722 the original caller from the stub. Used in dynamic executables. */
1723 else if (curr_inst == 0xe0400002)
1724 {
1725 /* The value we jump to is sitting in sp - 24. But that's
1726 loaded several instructions before the be instruction.
1727 I guess we could check for the previous instruction being
1728 mtsp %r1,%sr0 if we want to do sanity checking. */
1729 return (read_memory_integer
1730 (read_register (HPPA_SP_REGNUM) - 24, TARGET_PTR_BIT / 8)) & ~0x3;
1731 }
1732
1733 /* Haven't found the branch yet, but we're still in the stub.
1734 Keep looking. */
1735 loc += 4;
1736 }
1737 }
1738
1739
1740 /* For the given instruction (INST), return any adjustment it makes
1741 to the stack pointer or zero for no adjustment.
1742
1743 This only handles instructions commonly found in prologues. */
1744
1745 static int
1746 prologue_inst_adjust_sp (unsigned long inst)
1747 {
1748 /* This must persist across calls. */
1749 static int save_high21;
1750
1751 /* The most common way to perform a stack adjustment ldo X(sp),sp */
1752 if ((inst & 0xffffc000) == 0x37de0000)
1753 return extract_14 (inst);
1754
1755 /* stwm X,D(sp) */
1756 if ((inst & 0xffe00000) == 0x6fc00000)
1757 return extract_14 (inst);
1758
1759 /* std,ma X,D(sp) */
1760 if ((inst & 0xffe00008) == 0x73c00008)
1761 return (inst & 0x1 ? -1 << 13 : 0) | (((inst >> 4) & 0x3ff) << 3);
1762
1763 /* addil high21,%r1; ldo low11,(%r1),%r30)
1764 save high bits in save_high21 for later use. */
1765 if ((inst & 0xffe00000) == 0x28200000)
1766 {
1767 save_high21 = extract_21 (inst);
1768 return 0;
1769 }
1770
1771 if ((inst & 0xffff0000) == 0x343e0000)
1772 return save_high21 + extract_14 (inst);
1773
1774 /* fstws as used by the HP compilers. */
1775 if ((inst & 0xffffffe0) == 0x2fd01220)
1776 return extract_5_load (inst);
1777
1778 /* No adjustment. */
1779 return 0;
1780 }
1781
1782 /* Return nonzero if INST is a branch of some kind, else return zero. */
1783
1784 static int
1785 is_branch (unsigned long inst)
1786 {
1787 switch (inst >> 26)
1788 {
1789 case 0x20:
1790 case 0x21:
1791 case 0x22:
1792 case 0x23:
1793 case 0x27:
1794 case 0x28:
1795 case 0x29:
1796 case 0x2a:
1797 case 0x2b:
1798 case 0x2f:
1799 case 0x30:
1800 case 0x31:
1801 case 0x32:
1802 case 0x33:
1803 case 0x38:
1804 case 0x39:
1805 case 0x3a:
1806 case 0x3b:
1807 return 1;
1808
1809 default:
1810 return 0;
1811 }
1812 }
1813
1814 /* Return the register number for a GR which is saved by INST or
1815 zero it INST does not save a GR. */
1816
1817 static int
1818 inst_saves_gr (unsigned long inst)
1819 {
1820 /* Does it look like a stw? */
1821 if ((inst >> 26) == 0x1a || (inst >> 26) == 0x1b
1822 || (inst >> 26) == 0x1f
1823 || ((inst >> 26) == 0x1f
1824 && ((inst >> 6) == 0xa)))
1825 return extract_5R_store (inst);
1826
1827 /* Does it look like a std? */
1828 if ((inst >> 26) == 0x1c
1829 || ((inst >> 26) == 0x03
1830 && ((inst >> 6) & 0xf) == 0xb))
1831 return extract_5R_store (inst);
1832
1833 /* Does it look like a stwm? GCC & HPC may use this in prologues. */
1834 if ((inst >> 26) == 0x1b)
1835 return extract_5R_store (inst);
1836
1837 /* Does it look like sth or stb? HPC versions 9.0 and later use these
1838 too. */
1839 if ((inst >> 26) == 0x19 || (inst >> 26) == 0x18
1840 || ((inst >> 26) == 0x3
1841 && (((inst >> 6) & 0xf) == 0x8
1842 || (inst >> 6) & 0xf) == 0x9))
1843 return extract_5R_store (inst);
1844
1845 return 0;
1846 }
1847
1848 /* Return the register number for a FR which is saved by INST or
1849 zero it INST does not save a FR.
1850
1851 Note we only care about full 64bit register stores (that's the only
1852 kind of stores the prologue will use).
1853
1854 FIXME: What about argument stores with the HP compiler in ANSI mode? */
1855
1856 static int
1857 inst_saves_fr (unsigned long inst)
1858 {
1859 /* is this an FSTD ? */
1860 if ((inst & 0xfc00dfc0) == 0x2c001200)
1861 return extract_5r_store (inst);
1862 if ((inst & 0xfc000002) == 0x70000002)
1863 return extract_5R_store (inst);
1864 /* is this an FSTW ? */
1865 if ((inst & 0xfc00df80) == 0x24001200)
1866 return extract_5r_store (inst);
1867 if ((inst & 0xfc000002) == 0x7c000000)
1868 return extract_5R_store (inst);
1869 return 0;
1870 }
1871
1872 /* Advance PC across any function entry prologue instructions
1873 to reach some "real" code.
1874
1875 Use information in the unwind table to determine what exactly should
1876 be in the prologue. */
1877
1878
1879 CORE_ADDR
1880 skip_prologue_hard_way (CORE_ADDR pc)
1881 {
1882 char buf[4];
1883 CORE_ADDR orig_pc = pc;
1884 unsigned long inst, stack_remaining, save_gr, save_fr, save_rp, save_sp;
1885 unsigned long args_stored, status, i, restart_gr, restart_fr;
1886 struct unwind_table_entry *u;
1887
1888 restart_gr = 0;
1889 restart_fr = 0;
1890
1891 restart:
1892 u = find_unwind_entry (pc);
1893 if (!u)
1894 return pc;
1895
1896 /* If we are not at the beginning of a function, then return now. */
1897 if ((pc & ~0x3) != u->region_start)
1898 return pc;
1899
1900 /* This is how much of a frame adjustment we need to account for. */
1901 stack_remaining = u->Total_frame_size << 3;
1902
1903 /* Magic register saves we want to know about. */
1904 save_rp = u->Save_RP;
1905 save_sp = u->Save_SP;
1906
1907 /* An indication that args may be stored into the stack. Unfortunately
1908 the HPUX compilers tend to set this in cases where no args were
1909 stored too!. */
1910 args_stored = 1;
1911
1912 /* Turn the Entry_GR field into a bitmask. */
1913 save_gr = 0;
1914 for (i = 3; i < u->Entry_GR + 3; i++)
1915 {
1916 /* Frame pointer gets saved into a special location. */
1917 if (u->Save_SP && i == HPPA_FP_REGNUM)
1918 continue;
1919
1920 save_gr |= (1 << i);
1921 }
1922 save_gr &= ~restart_gr;
1923
1924 /* Turn the Entry_FR field into a bitmask too. */
1925 save_fr = 0;
1926 for (i = 12; i < u->Entry_FR + 12; i++)
1927 save_fr |= (1 << i);
1928 save_fr &= ~restart_fr;
1929
1930 /* Loop until we find everything of interest or hit a branch.
1931
1932 For unoptimized GCC code and for any HP CC code this will never ever
1933 examine any user instructions.
1934
1935 For optimzied GCC code we're faced with problems. GCC will schedule
1936 its prologue and make prologue instructions available for delay slot
1937 filling. The end result is user code gets mixed in with the prologue
1938 and a prologue instruction may be in the delay slot of the first branch
1939 or call.
1940
1941 Some unexpected things are expected with debugging optimized code, so
1942 we allow this routine to walk past user instructions in optimized
1943 GCC code. */
1944 while (save_gr || save_fr || save_rp || save_sp || stack_remaining > 0
1945 || args_stored)
1946 {
1947 unsigned int reg_num;
1948 unsigned long old_stack_remaining, old_save_gr, old_save_fr;
1949 unsigned long old_save_rp, old_save_sp, next_inst;
1950
1951 /* Save copies of all the triggers so we can compare them later
1952 (only for HPC). */
1953 old_save_gr = save_gr;
1954 old_save_fr = save_fr;
1955 old_save_rp = save_rp;
1956 old_save_sp = save_sp;
1957 old_stack_remaining = stack_remaining;
1958
1959 status = target_read_memory (pc, buf, 4);
1960 inst = extract_unsigned_integer (buf, 4);
1961
1962 /* Yow! */
1963 if (status != 0)
1964 return pc;
1965
1966 /* Note the interesting effects of this instruction. */
1967 stack_remaining -= prologue_inst_adjust_sp (inst);
1968
1969 /* There are limited ways to store the return pointer into the
1970 stack. */
1971 if (inst == 0x6bc23fd9 || inst == 0x0fc212c1)
1972 save_rp = 0;
1973
1974 /* These are the only ways we save SP into the stack. At this time
1975 the HP compilers never bother to save SP into the stack. */
1976 if ((inst & 0xffffc000) == 0x6fc10000
1977 || (inst & 0xffffc00c) == 0x73c10008)
1978 save_sp = 0;
1979
1980 /* Are we loading some register with an offset from the argument
1981 pointer? */
1982 if ((inst & 0xffe00000) == 0x37a00000
1983 || (inst & 0xffffffe0) == 0x081d0240)
1984 {
1985 pc += 4;
1986 continue;
1987 }
1988
1989 /* Account for general and floating-point register saves. */
1990 reg_num = inst_saves_gr (inst);
1991 save_gr &= ~(1 << reg_num);
1992
1993 /* Ugh. Also account for argument stores into the stack.
1994 Unfortunately args_stored only tells us that some arguments
1995 where stored into the stack. Not how many or what kind!
1996
1997 This is a kludge as on the HP compiler sets this bit and it
1998 never does prologue scheduling. So once we see one, skip past
1999 all of them. We have similar code for the fp arg stores below.
2000
2001 FIXME. Can still die if we have a mix of GR and FR argument
2002 stores! */
2003 if (reg_num >= (TARGET_PTR_BIT == 64 ? 19 : 23) && reg_num <= 26)
2004 {
2005 while (reg_num >= (TARGET_PTR_BIT == 64 ? 19 : 23) && reg_num <= 26)
2006 {
2007 pc += 4;
2008 status = target_read_memory (pc, buf, 4);
2009 inst = extract_unsigned_integer (buf, 4);
2010 if (status != 0)
2011 return pc;
2012 reg_num = inst_saves_gr (inst);
2013 }
2014 args_stored = 0;
2015 continue;
2016 }
2017
2018 reg_num = inst_saves_fr (inst);
2019 save_fr &= ~(1 << reg_num);
2020
2021 status = target_read_memory (pc + 4, buf, 4);
2022 next_inst = extract_unsigned_integer (buf, 4);
2023
2024 /* Yow! */
2025 if (status != 0)
2026 return pc;
2027
2028 /* We've got to be read to handle the ldo before the fp register
2029 save. */
2030 if ((inst & 0xfc000000) == 0x34000000
2031 && inst_saves_fr (next_inst) >= 4
2032 && inst_saves_fr (next_inst) <= (TARGET_PTR_BIT == 64 ? 11 : 7))
2033 {
2034 /* So we drop into the code below in a reasonable state. */
2035 reg_num = inst_saves_fr (next_inst);
2036 pc -= 4;
2037 }
2038
2039 /* Ugh. Also account for argument stores into the stack.
2040 This is a kludge as on the HP compiler sets this bit and it
2041 never does prologue scheduling. So once we see one, skip past
2042 all of them. */
2043 if (reg_num >= 4 && reg_num <= (TARGET_PTR_BIT == 64 ? 11 : 7))
2044 {
2045 while (reg_num >= 4 && reg_num <= (TARGET_PTR_BIT == 64 ? 11 : 7))
2046 {
2047 pc += 8;
2048 status = target_read_memory (pc, buf, 4);
2049 inst = extract_unsigned_integer (buf, 4);
2050 if (status != 0)
2051 return pc;
2052 if ((inst & 0xfc000000) != 0x34000000)
2053 break;
2054 status = target_read_memory (pc + 4, buf, 4);
2055 next_inst = extract_unsigned_integer (buf, 4);
2056 if (status != 0)
2057 return pc;
2058 reg_num = inst_saves_fr (next_inst);
2059 }
2060 args_stored = 0;
2061 continue;
2062 }
2063
2064 /* Quit if we hit any kind of branch. This can happen if a prologue
2065 instruction is in the delay slot of the first call/branch. */
2066 if (is_branch (inst))
2067 break;
2068
2069 /* What a crock. The HP compilers set args_stored even if no
2070 arguments were stored into the stack (boo hiss). This could
2071 cause this code to then skip a bunch of user insns (up to the
2072 first branch).
2073
2074 To combat this we try to identify when args_stored was bogusly
2075 set and clear it. We only do this when args_stored is nonzero,
2076 all other resources are accounted for, and nothing changed on
2077 this pass. */
2078 if (args_stored
2079 && !(save_gr || save_fr || save_rp || save_sp || stack_remaining > 0)
2080 && old_save_gr == save_gr && old_save_fr == save_fr
2081 && old_save_rp == save_rp && old_save_sp == save_sp
2082 && old_stack_remaining == stack_remaining)
2083 break;
2084
2085 /* Bump the PC. */
2086 pc += 4;
2087 }
2088
2089 /* We've got a tenative location for the end of the prologue. However
2090 because of limitations in the unwind descriptor mechanism we may
2091 have went too far into user code looking for the save of a register
2092 that does not exist. So, if there registers we expected to be saved
2093 but never were, mask them out and restart.
2094
2095 This should only happen in optimized code, and should be very rare. */
2096 if (save_gr || (save_fr && !(restart_fr || restart_gr)))
2097 {
2098 pc = orig_pc;
2099 restart_gr = save_gr;
2100 restart_fr = save_fr;
2101 goto restart;
2102 }
2103
2104 return pc;
2105 }
2106
2107
2108 /* Return the address of the PC after the last prologue instruction if
2109 we can determine it from the debug symbols. Else return zero. */
2110
2111 static CORE_ADDR
2112 after_prologue (CORE_ADDR pc)
2113 {
2114 struct symtab_and_line sal;
2115 CORE_ADDR func_addr, func_end;
2116 struct symbol *f;
2117
2118 /* If we can not find the symbol in the partial symbol table, then
2119 there is no hope we can determine the function's start address
2120 with this code. */
2121 if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
2122 return 0;
2123
2124 /* Get the line associated with FUNC_ADDR. */
2125 sal = find_pc_line (func_addr, 0);
2126
2127 /* There are only two cases to consider. First, the end of the source line
2128 is within the function bounds. In that case we return the end of the
2129 source line. Second is the end of the source line extends beyond the
2130 bounds of the current function. We need to use the slow code to
2131 examine instructions in that case.
2132
2133 Anything else is simply a bug elsewhere. Fixing it here is absolutely
2134 the wrong thing to do. In fact, it should be entirely possible for this
2135 function to always return zero since the slow instruction scanning code
2136 is supposed to *always* work. If it does not, then it is a bug. */
2137 if (sal.end < func_end)
2138 return sal.end;
2139 else
2140 return 0;
2141 }
2142
2143 /* To skip prologues, I use this predicate. Returns either PC itself
2144 if the code at PC does not look like a function prologue; otherwise
2145 returns an address that (if we're lucky) follows the prologue. If
2146 LENIENT, then we must skip everything which is involved in setting
2147 up the frame (it's OK to skip more, just so long as we don't skip
2148 anything which might clobber the registers which are being saved.
2149 Currently we must not skip more on the alpha, but we might the lenient
2150 stuff some day. */
2151
2152 CORE_ADDR
2153 hppa_skip_prologue (CORE_ADDR pc)
2154 {
2155 unsigned long inst;
2156 int offset;
2157 CORE_ADDR post_prologue_pc;
2158 char buf[4];
2159
2160 /* See if we can determine the end of the prologue via the symbol table.
2161 If so, then return either PC, or the PC after the prologue, whichever
2162 is greater. */
2163
2164 post_prologue_pc = after_prologue (pc);
2165
2166 /* If after_prologue returned a useful address, then use it. Else
2167 fall back on the instruction skipping code.
2168
2169 Some folks have claimed this causes problems because the breakpoint
2170 may be the first instruction of the prologue. If that happens, then
2171 the instruction skipping code has a bug that needs to be fixed. */
2172 if (post_prologue_pc != 0)
2173 return max (pc, post_prologue_pc);
2174 else
2175 return (skip_prologue_hard_way (pc));
2176 }
2177
2178 struct hppa_frame_cache
2179 {
2180 CORE_ADDR base;
2181 struct trad_frame_saved_reg *saved_regs;
2182 };
2183
2184 static struct hppa_frame_cache *
2185 hppa_frame_cache (struct frame_info *next_frame, void **this_cache)
2186 {
2187 struct hppa_frame_cache *cache;
2188 long saved_gr_mask;
2189 long saved_fr_mask;
2190 CORE_ADDR this_sp;
2191 long frame_size;
2192 struct unwind_table_entry *u;
2193 int i;
2194
2195 if ((*this_cache) != NULL)
2196 return (*this_cache);
2197 cache = FRAME_OBSTACK_ZALLOC (struct hppa_frame_cache);
2198 (*this_cache) = cache;
2199 cache->saved_regs = trad_frame_alloc_saved_regs (next_frame);
2200
2201 /* Yow! */
2202 u = find_unwind_entry (frame_func_unwind (next_frame));
2203 if (!u)
2204 return (*this_cache);
2205
2206 /* Turn the Entry_GR field into a bitmask. */
2207 saved_gr_mask = 0;
2208 for (i = 3; i < u->Entry_GR + 3; i++)
2209 {
2210 /* Frame pointer gets saved into a special location. */
2211 if (u->Save_SP && i == HPPA_FP_REGNUM)
2212 continue;
2213
2214 saved_gr_mask |= (1 << i);
2215 }
2216
2217 /* Turn the Entry_FR field into a bitmask too. */
2218 saved_fr_mask = 0;
2219 for (i = 12; i < u->Entry_FR + 12; i++)
2220 saved_fr_mask |= (1 << i);
2221
2222 /* Loop until we find everything of interest or hit a branch.
2223
2224 For unoptimized GCC code and for any HP CC code this will never ever
2225 examine any user instructions.
2226
2227 For optimized GCC code we're faced with problems. GCC will schedule
2228 its prologue and make prologue instructions available for delay slot
2229 filling. The end result is user code gets mixed in with the prologue
2230 and a prologue instruction may be in the delay slot of the first branch
2231 or call.
2232
2233 Some unexpected things are expected with debugging optimized code, so
2234 we allow this routine to walk past user instructions in optimized
2235 GCC code. */
2236 {
2237 int final_iteration = 0;
2238 CORE_ADDR pc;
2239 CORE_ADDR end_pc = skip_prologue_using_sal (pc);
2240 int looking_for_sp = u->Save_SP;
2241 int looking_for_rp = u->Save_RP;
2242 int fp_loc = -1;
2243 if (end_pc == 0)
2244 end_pc = frame_pc_unwind (next_frame);
2245 frame_size = 0;
2246 for (pc = frame_func_unwind (next_frame);
2247 ((saved_gr_mask || saved_fr_mask
2248 || looking_for_sp || looking_for_rp
2249 || frame_size < (u->Total_frame_size << 3))
2250 && pc <= end_pc);
2251 pc += 4)
2252 {
2253 int reg;
2254 char buf4[4];
2255 long status = target_read_memory (pc, buf4, sizeof buf4);
2256 long inst = extract_unsigned_integer (buf4, sizeof buf4);
2257
2258 /* Note the interesting effects of this instruction. */
2259 frame_size += prologue_inst_adjust_sp (inst);
2260
2261 /* There are limited ways to store the return pointer into the
2262 stack. */
2263 if (inst == 0x6bc23fd9) /* stw rp,-0x14(sr0,sp) */
2264 {
2265 looking_for_rp = 0;
2266 cache->saved_regs[RP_REGNUM].addr = -20;
2267 }
2268 else if (inst == 0x0fc212c1) /* std rp,-0x10(sr0,sp) */
2269 {
2270 looking_for_rp = 0;
2271 cache->saved_regs[RP_REGNUM].addr = -16;
2272 }
2273
2274 /* Check to see if we saved SP into the stack. This also
2275 happens to indicate the location of the saved frame
2276 pointer. */
2277 if ((inst & 0xffffc000) == 0x6fc10000 /* stw,ma r1,N(sr0,sp) */
2278 || (inst & 0xffffc00c) == 0x73c10008) /* std,ma r1,N(sr0,sp) */
2279 {
2280 looking_for_sp = 0;
2281 cache->saved_regs[HPPA_FP_REGNUM].addr = 0;
2282 }
2283
2284 /* Account for general and floating-point register saves. */
2285 reg = inst_saves_gr (inst);
2286 if (reg >= 3 && reg <= 18
2287 && (!u->Save_SP || reg != HPPA_FP_REGNUM))
2288 {
2289 saved_gr_mask &= ~(1 << reg);
2290 if ((inst >> 26) == 0x1b && extract_14 (inst) >= 0)
2291 /* stwm with a positive displacement is a _post_
2292 _modify_. */
2293 cache->saved_regs[reg].addr = 0;
2294 else if ((inst & 0xfc00000c) == 0x70000008)
2295 /* A std has explicit post_modify forms. */
2296 cache->saved_regs[reg].addr = 0;
2297 else
2298 {
2299 CORE_ADDR offset;
2300
2301 if ((inst >> 26) == 0x1c)
2302 offset = (inst & 0x1 ? -1 << 13 : 0) | (((inst >> 4) & 0x3ff) << 3);
2303 else if ((inst >> 26) == 0x03)
2304 offset = low_sign_extend (inst & 0x1f, 5);
2305 else
2306 offset = extract_14 (inst);
2307
2308 /* Handle code with and without frame pointers. */
2309 if (u->Save_SP)
2310 cache->saved_regs[reg].addr = offset;
2311 else
2312 cache->saved_regs[reg].addr = (u->Total_frame_size << 3) + offset;
2313 }
2314 }
2315
2316 /* GCC handles callee saved FP regs a little differently.
2317
2318 It emits an instruction to put the value of the start of
2319 the FP store area into %r1. It then uses fstds,ma with a
2320 basereg of %r1 for the stores.
2321
2322 HP CC emits them at the current stack pointer modifying the
2323 stack pointer as it stores each register. */
2324
2325 /* ldo X(%r3),%r1 or ldo X(%r30),%r1. */
2326 if ((inst & 0xffffc000) == 0x34610000
2327 || (inst & 0xffffc000) == 0x37c10000)
2328 fp_loc = extract_14 (inst);
2329
2330 reg = inst_saves_fr (inst);
2331 if (reg >= 12 && reg <= 21)
2332 {
2333 /* Note +4 braindamage below is necessary because the FP
2334 status registers are internally 8 registers rather than
2335 the expected 4 registers. */
2336 saved_fr_mask &= ~(1 << reg);
2337 if (fp_loc == -1)
2338 {
2339 /* 1st HP CC FP register store. After this
2340 instruction we've set enough state that the GCC and
2341 HPCC code are both handled in the same manner. */
2342 cache->saved_regs[reg + FP4_REGNUM + 4].addr = 0;
2343 fp_loc = 8;
2344 }
2345 else
2346 {
2347 cache->saved_regs[reg + HPPA_FP0_REGNUM + 4].addr = fp_loc;
2348 fp_loc += 8;
2349 }
2350 }
2351
2352 /* Quit if we hit any kind of branch the previous iteration. */
2353 if (final_iteration)
2354 break;
2355 /* We want to look precisely one instruction beyond the branch
2356 if we have not found everything yet. */
2357 if (is_branch (inst))
2358 final_iteration = 1;
2359 }
2360 }
2361
2362 {
2363 /* The frame base always represents the value of %sp at entry to
2364 the current function (and is thus equivalent to the "saved"
2365 stack pointer. */
2366 CORE_ADDR this_sp = frame_unwind_register_unsigned (next_frame, HPPA_SP_REGNUM);
2367 /* FIXME: cagney/2004-02-22: This assumes that the frame has been
2368 created. If it hasn't everything will be out-of-wack. */
2369 if (u->Save_SP && trad_frame_addr_p (cache->saved_regs, HPPA_SP_REGNUM))
2370 /* Both we're expecting the SP to be saved and the SP has been
2371 saved. The entry SP value is saved at this frame's SP
2372 address. */
2373 cache->base = read_memory_integer (this_sp, TARGET_PTR_BIT / 8);
2374 else
2375 /* The prologue has been slowly allocating stack space. Adjust
2376 the SP back. */
2377 cache->base = this_sp - frame_size;
2378 trad_frame_set_value (cache->saved_regs, HPPA_SP_REGNUM, cache->base);
2379 }
2380
2381 /* The PC is found in the "return register", "Millicode" uses "r31"
2382 as the return register while normal code uses "rp". */
2383 if (u->Millicode)
2384 cache->saved_regs[PCOQ_HEAD_REGNUM] = cache->saved_regs[31];
2385 else
2386 cache->saved_regs[PCOQ_HEAD_REGNUM] = cache->saved_regs[RP_REGNUM];
2387
2388 {
2389 /* Convert all the offsets into addresses. */
2390 int reg;
2391 for (reg = 0; reg < NUM_REGS; reg++)
2392 {
2393 if (trad_frame_addr_p (cache->saved_regs, reg))
2394 cache->saved_regs[reg].addr += cache->base;
2395 }
2396 }
2397
2398 return (*this_cache);
2399 }
2400
2401 static void
2402 hppa_frame_this_id (struct frame_info *next_frame, void **this_cache,
2403 struct frame_id *this_id)
2404 {
2405 struct hppa_frame_cache *info = hppa_frame_cache (next_frame, this_cache);
2406 (*this_id) = frame_id_build (info->base, frame_func_unwind (next_frame));
2407 }
2408
2409 static void
2410 hppa_frame_prev_register (struct frame_info *next_frame,
2411 void **this_cache,
2412 int regnum, int *optimizedp,
2413 enum lval_type *lvalp, CORE_ADDR *addrp,
2414 int *realnump, void *valuep)
2415 {
2416 struct hppa_frame_cache *info = hppa_frame_cache (next_frame, this_cache);
2417 struct gdbarch *gdbarch = get_frame_arch (next_frame);
2418 if (regnum == PCOQ_TAIL_REGNUM)
2419 {
2420 /* The PCOQ TAIL, or NPC, needs to be computed from the unwound
2421 PC register. */
2422 *optimizedp = 0;
2423 *lvalp = not_lval;
2424 *addrp = 0;
2425 *realnump = 0;
2426 if (valuep)
2427 {
2428 int regsize = register_size (gdbarch, PCOQ_HEAD_REGNUM);
2429 CORE_ADDR pc;
2430 int optimized;
2431 enum lval_type lval;
2432 CORE_ADDR addr;
2433 int realnum;
2434 bfd_byte value[MAX_REGISTER_SIZE];
2435 trad_frame_prev_register (next_frame, info->saved_regs,
2436 PCOQ_HEAD_REGNUM, &optimized, &lval, &addr,
2437 &realnum, &value);
2438 pc = extract_unsigned_integer (&value, regsize);
2439 store_unsigned_integer (valuep, regsize, pc + 4);
2440 }
2441 }
2442 else
2443 {
2444 trad_frame_prev_register (next_frame, info->saved_regs, regnum,
2445 optimizedp, lvalp, addrp, realnump, valuep);
2446 }
2447 }
2448
2449 static const struct frame_unwind hppa_frame_unwind =
2450 {
2451 NORMAL_FRAME,
2452 hppa_frame_this_id,
2453 hppa_frame_prev_register
2454 };
2455
2456 static const struct frame_unwind *
2457 hppa_frame_unwind_sniffer (struct frame_info *next_frame)
2458 {
2459 return &hppa_frame_unwind;
2460 }
2461
2462 static CORE_ADDR
2463 hppa_frame_base_address (struct frame_info *next_frame,
2464 void **this_cache)
2465 {
2466 struct hppa_frame_cache *info = hppa_frame_cache (next_frame,
2467 this_cache);
2468 return info->base;
2469 }
2470
2471 static const struct frame_base hppa_frame_base = {
2472 &hppa_frame_unwind,
2473 hppa_frame_base_address,
2474 hppa_frame_base_address,
2475 hppa_frame_base_address
2476 };
2477
2478 static const struct frame_base *
2479 hppa_frame_base_sniffer (struct frame_info *next_frame)
2480 {
2481 return &hppa_frame_base;
2482 }
2483
2484 static struct frame_id
2485 hppa_unwind_dummy_id (struct gdbarch *gdbarch, struct frame_info *next_frame)
2486 {
2487 return frame_id_build (frame_unwind_register_unsigned (next_frame,
2488 HPPA_SP_REGNUM),
2489 frame_pc_unwind (next_frame));
2490 }
2491
2492 static CORE_ADDR
2493 hppa_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
2494 {
2495 return frame_unwind_register_signed (next_frame, PCOQ_HEAD_REGNUM) & ~3;
2496 }
2497
2498 /* Exception handling support for the HP-UX ANSI C++ compiler.
2499 The compiler (aCC) provides a callback for exception events;
2500 GDB can set a breakpoint on this callback and find out what
2501 exception event has occurred. */
2502
2503 /* The name of the hook to be set to point to the callback function */
2504 static char HP_ACC_EH_notify_hook[] = "__eh_notify_hook";
2505 /* The name of the function to be used to set the hook value */
2506 static char HP_ACC_EH_set_hook_value[] = "__eh_set_hook_value";
2507 /* The name of the callback function in end.o */
2508 static char HP_ACC_EH_notify_callback[] = "__d_eh_notify_callback";
2509 /* Name of function in end.o on which a break is set (called by above) */
2510 static char HP_ACC_EH_break[] = "__d_eh_break";
2511 /* Name of flag (in end.o) that enables catching throws */
2512 static char HP_ACC_EH_catch_throw[] = "__d_eh_catch_throw";
2513 /* Name of flag (in end.o) that enables catching catching */
2514 static char HP_ACC_EH_catch_catch[] = "__d_eh_catch_catch";
2515 /* The enum used by aCC */
2516 typedef enum
2517 {
2518 __EH_NOTIFY_THROW,
2519 __EH_NOTIFY_CATCH
2520 }
2521 __eh_notification;
2522
2523 /* Is exception-handling support available with this executable? */
2524 static int hp_cxx_exception_support = 0;
2525 /* Has the initialize function been run? */
2526 int hp_cxx_exception_support_initialized = 0;
2527 /* Similar to above, but imported from breakpoint.c -- non-target-specific */
2528 extern int exception_support_initialized;
2529 /* Address of __eh_notify_hook */
2530 static CORE_ADDR eh_notify_hook_addr = 0;
2531 /* Address of __d_eh_notify_callback */
2532 static CORE_ADDR eh_notify_callback_addr = 0;
2533 /* Address of __d_eh_break */
2534 static CORE_ADDR eh_break_addr = 0;
2535 /* Address of __d_eh_catch_catch */
2536 static CORE_ADDR eh_catch_catch_addr = 0;
2537 /* Address of __d_eh_catch_throw */
2538 static CORE_ADDR eh_catch_throw_addr = 0;
2539 /* Sal for __d_eh_break */
2540 static struct symtab_and_line *break_callback_sal = 0;
2541
2542 /* Code in end.c expects __d_pid to be set in the inferior,
2543 otherwise __d_eh_notify_callback doesn't bother to call
2544 __d_eh_break! So we poke the pid into this symbol
2545 ourselves.
2546 0 => success
2547 1 => failure */
2548 int
2549 setup_d_pid_in_inferior (void)
2550 {
2551 CORE_ADDR anaddr;
2552 struct minimal_symbol *msymbol;
2553 char buf[4]; /* FIXME 32x64? */
2554
2555 /* Slam the pid of the process into __d_pid; failing is only a warning! */
2556 msymbol = lookup_minimal_symbol ("__d_pid", NULL, symfile_objfile);
2557 if (msymbol == NULL)
2558 {
2559 warning ("Unable to find __d_pid symbol in object file.");
2560 warning ("Suggest linking executable with -g (links in /opt/langtools/lib/end.o).");
2561 return 1;
2562 }
2563
2564 anaddr = SYMBOL_VALUE_ADDRESS (msymbol);
2565 store_unsigned_integer (buf, 4, PIDGET (inferior_ptid)); /* FIXME 32x64? */
2566 if (target_write_memory (anaddr, buf, 4)) /* FIXME 32x64? */
2567 {
2568 warning ("Unable to write __d_pid");
2569 warning ("Suggest linking executable with -g (links in /opt/langtools/lib/end.o).");
2570 return 1;
2571 }
2572 return 0;
2573 }
2574
2575 /* Initialize exception catchpoint support by looking for the
2576 necessary hooks/callbacks in end.o, etc., and set the hook value to
2577 point to the required debug function
2578
2579 Return 0 => failure
2580 1 => success */
2581
2582 static int
2583 initialize_hp_cxx_exception_support (void)
2584 {
2585 struct symtabs_and_lines sals;
2586 struct cleanup *old_chain;
2587 struct cleanup *canonical_strings_chain = NULL;
2588 int i;
2589 char *addr_start;
2590 char *addr_end = NULL;
2591 char **canonical = (char **) NULL;
2592 int thread = -1;
2593 struct symbol *sym = NULL;
2594 struct minimal_symbol *msym = NULL;
2595 struct objfile *objfile;
2596 asection *shlib_info;
2597
2598 /* Detect and disallow recursion. On HP-UX with aCC, infinite
2599 recursion is a possibility because finding the hook for exception
2600 callbacks involves making a call in the inferior, which means
2601 re-inserting breakpoints which can re-invoke this code */
2602
2603 static int recurse = 0;
2604 if (recurse > 0)
2605 {
2606 hp_cxx_exception_support_initialized = 0;
2607 exception_support_initialized = 0;
2608 return 0;
2609 }
2610
2611 hp_cxx_exception_support = 0;
2612
2613 /* First check if we have seen any HP compiled objects; if not,
2614 it is very unlikely that HP's idiosyncratic callback mechanism
2615 for exception handling debug support will be available!
2616 This will percolate back up to breakpoint.c, where our callers
2617 will decide to try the g++ exception-handling support instead. */
2618 if (!hp_som_som_object_present)
2619 return 0;
2620
2621 /* We have a SOM executable with SOM debug info; find the hooks */
2622
2623 /* First look for the notify hook provided by aCC runtime libs */
2624 /* If we find this symbol, we conclude that the executable must
2625 have HP aCC exception support built in. If this symbol is not
2626 found, even though we're a HP SOM-SOM file, we may have been
2627 built with some other compiler (not aCC). This results percolates
2628 back up to our callers in breakpoint.c which can decide to
2629 try the g++ style of exception support instead.
2630 If this symbol is found but the other symbols we require are
2631 not found, there is something weird going on, and g++ support
2632 should *not* be tried as an alternative.
2633
2634 ASSUMPTION: Only HP aCC code will have __eh_notify_hook defined.
2635 ASSUMPTION: HP aCC and g++ modules cannot be linked together. */
2636
2637 /* libCsup has this hook; it'll usually be non-debuggable */
2638 msym = lookup_minimal_symbol (HP_ACC_EH_notify_hook, NULL, NULL);
2639 if (msym)
2640 {
2641 eh_notify_hook_addr = SYMBOL_VALUE_ADDRESS (msym);
2642 hp_cxx_exception_support = 1;
2643 }
2644 else
2645 {
2646 warning ("Unable to find exception callback hook (%s).", HP_ACC_EH_notify_hook);
2647 warning ("Executable may not have been compiled debuggable with HP aCC.");
2648 warning ("GDB will be unable to intercept exception events.");
2649 eh_notify_hook_addr = 0;
2650 hp_cxx_exception_support = 0;
2651 return 0;
2652 }
2653
2654 /* Next look for the notify callback routine in end.o */
2655 /* This is always available in the SOM symbol dictionary if end.o is linked in */
2656 msym = lookup_minimal_symbol (HP_ACC_EH_notify_callback, NULL, NULL);
2657 if (msym)
2658 {
2659 eh_notify_callback_addr = SYMBOL_VALUE_ADDRESS (msym);
2660 hp_cxx_exception_support = 1;
2661 }
2662 else
2663 {
2664 warning ("Unable to find exception callback routine (%s).", HP_ACC_EH_notify_callback);
2665 warning ("Suggest linking executable with -g (links in /opt/langtools/lib/end.o).");
2666 warning ("GDB will be unable to intercept exception events.");
2667 eh_notify_callback_addr = 0;
2668 return 0;
2669 }
2670
2671 #ifndef GDB_TARGET_IS_HPPA_20W
2672 /* Check whether the executable is dynamically linked or archive bound */
2673 /* With an archive-bound executable we can use the raw addresses we find
2674 for the callback function, etc. without modification. For an executable
2675 with shared libraries, we have to do more work to find the plabel, which
2676 can be the target of a call through $$dyncall from the aCC runtime support
2677 library (libCsup) which is linked shared by default by aCC. */
2678 /* This test below was copied from somsolib.c/somread.c. It may not be a very
2679 reliable one to test that an executable is linked shared. pai/1997-07-18 */
2680 shlib_info = bfd_get_section_by_name (symfile_objfile->obfd, "$SHLIB_INFO$");
2681 if (shlib_info && (bfd_section_size (symfile_objfile->obfd, shlib_info) != 0))
2682 {
2683 /* The minsym we have has the local code address, but that's not the
2684 plabel that can be used by an inter-load-module call. */
2685 /* Find solib handle for main image (which has end.o), and use that
2686 and the min sym as arguments to __d_shl_get() (which does the equivalent
2687 of shl_findsym()) to find the plabel. */
2688
2689 args_for_find_stub args;
2690 static char message[] = "Error while finding exception callback hook:\n";
2691
2692 args.solib_handle = som_solib_get_solib_by_pc (eh_notify_callback_addr);
2693 args.msym = msym;
2694 args.return_val = 0;
2695
2696 recurse++;
2697 catch_errors (cover_find_stub_with_shl_get, &args, message,
2698 RETURN_MASK_ALL);
2699 eh_notify_callback_addr = args.return_val;
2700 recurse--;
2701
2702 exception_catchpoints_are_fragile = 1;
2703
2704 if (!eh_notify_callback_addr)
2705 {
2706 /* We can get here either if there is no plabel in the export list
2707 for the main image, or if something strange happened (?) */
2708 warning ("Couldn't find a plabel (indirect function label) for the exception callback.");
2709 warning ("GDB will not be able to intercept exception events.");
2710 return 0;
2711 }
2712 }
2713 else
2714 exception_catchpoints_are_fragile = 0;
2715 #endif
2716
2717 /* Now, look for the breakpointable routine in end.o */
2718 /* This should also be available in the SOM symbol dict. if end.o linked in */
2719 msym = lookup_minimal_symbol (HP_ACC_EH_break, NULL, NULL);
2720 if (msym)
2721 {
2722 eh_break_addr = SYMBOL_VALUE_ADDRESS (msym);
2723 hp_cxx_exception_support = 1;
2724 }
2725 else
2726 {
2727 warning ("Unable to find exception callback routine to set breakpoint (%s).", HP_ACC_EH_break);
2728 warning ("Suggest linking executable with -g (link in /opt/langtools/lib/end.o).");
2729 warning ("GDB will be unable to intercept exception events.");
2730 eh_break_addr = 0;
2731 return 0;
2732 }
2733
2734 /* Next look for the catch enable flag provided in end.o */
2735 sym = lookup_symbol (HP_ACC_EH_catch_catch, (struct block *) NULL,
2736 VAR_DOMAIN, 0, (struct symtab **) NULL);
2737 if (sym) /* sometimes present in debug info */
2738 {
2739 eh_catch_catch_addr = SYMBOL_VALUE_ADDRESS (sym);
2740 hp_cxx_exception_support = 1;
2741 }
2742 else
2743 /* otherwise look in SOM symbol dict. */
2744 {
2745 msym = lookup_minimal_symbol (HP_ACC_EH_catch_catch, NULL, NULL);
2746 if (msym)
2747 {
2748 eh_catch_catch_addr = SYMBOL_VALUE_ADDRESS (msym);
2749 hp_cxx_exception_support = 1;
2750 }
2751 else
2752 {
2753 warning ("Unable to enable interception of exception catches.");
2754 warning ("Executable may not have been compiled debuggable with HP aCC.");
2755 warning ("Suggest linking executable with -g (link in /opt/langtools/lib/end.o).");
2756 return 0;
2757 }
2758 }
2759
2760 /* Next look for the catch enable flag provided end.o */
2761 sym = lookup_symbol (HP_ACC_EH_catch_catch, (struct block *) NULL,
2762 VAR_DOMAIN, 0, (struct symtab **) NULL);
2763 if (sym) /* sometimes present in debug info */
2764 {
2765 eh_catch_throw_addr = SYMBOL_VALUE_ADDRESS (sym);
2766 hp_cxx_exception_support = 1;
2767 }
2768 else
2769 /* otherwise look in SOM symbol dict. */
2770 {
2771 msym = lookup_minimal_symbol (HP_ACC_EH_catch_throw, NULL, NULL);
2772 if (msym)
2773 {
2774 eh_catch_throw_addr = SYMBOL_VALUE_ADDRESS (msym);
2775 hp_cxx_exception_support = 1;
2776 }
2777 else
2778 {
2779 warning ("Unable to enable interception of exception throws.");
2780 warning ("Executable may not have been compiled debuggable with HP aCC.");
2781 warning ("Suggest linking executable with -g (link in /opt/langtools/lib/end.o).");
2782 return 0;
2783 }
2784 }
2785
2786 /* Set the flags */
2787 hp_cxx_exception_support = 2; /* everything worked so far */
2788 hp_cxx_exception_support_initialized = 1;
2789 exception_support_initialized = 1;
2790
2791 return 1;
2792 }
2793
2794 /* Target operation for enabling or disabling interception of
2795 exception events.
2796 KIND is either EX_EVENT_THROW or EX_EVENT_CATCH
2797 ENABLE is either 0 (disable) or 1 (enable).
2798 Return value is NULL if no support found;
2799 -1 if something went wrong,
2800 or a pointer to a symtab/line struct if the breakpointable
2801 address was found. */
2802
2803 struct symtab_and_line *
2804 child_enable_exception_callback (enum exception_event_kind kind, int enable)
2805 {
2806 char buf[4];
2807
2808 if (!exception_support_initialized || !hp_cxx_exception_support_initialized)
2809 if (!initialize_hp_cxx_exception_support ())
2810 return NULL;
2811
2812 switch (hp_cxx_exception_support)
2813 {
2814 case 0:
2815 /* Assuming no HP support at all */
2816 return NULL;
2817 case 1:
2818 /* HP support should be present, but something went wrong */
2819 return (struct symtab_and_line *) -1; /* yuck! */
2820 /* there may be other cases in the future */
2821 }
2822
2823 /* Set the EH hook to point to the callback routine */
2824 store_unsigned_integer (buf, 4, enable ? eh_notify_callback_addr : 0); /* FIXME 32x64 problem */
2825 /* pai: (temp) FIXME should there be a pack operation first? */
2826 if (target_write_memory (eh_notify_hook_addr, buf, 4)) /* FIXME 32x64 problem */
2827 {
2828 warning ("Could not write to target memory for exception event callback.");
2829 warning ("Interception of exception events may not work.");
2830 return (struct symtab_and_line *) -1;
2831 }
2832 if (enable)
2833 {
2834 /* Ensure that __d_pid is set up correctly -- end.c code checks this. :-( */
2835 if (PIDGET (inferior_ptid) > 0)
2836 {
2837 if (setup_d_pid_in_inferior ())
2838 return (struct symtab_and_line *) -1;
2839 }
2840 else
2841 {
2842 warning ("Internal error: Invalid inferior pid? Cannot intercept exception events.");
2843 return (struct symtab_and_line *) -1;
2844 }
2845 }
2846
2847 switch (kind)
2848 {
2849 case EX_EVENT_THROW:
2850 store_unsigned_integer (buf, 4, enable ? 1 : 0);
2851 if (target_write_memory (eh_catch_throw_addr, buf, 4)) /* FIXME 32x64? */
2852 {
2853 warning ("Couldn't enable exception throw interception.");
2854 return (struct symtab_and_line *) -1;
2855 }
2856 break;
2857 case EX_EVENT_CATCH:
2858 store_unsigned_integer (buf, 4, enable ? 1 : 0);
2859 if (target_write_memory (eh_catch_catch_addr, buf, 4)) /* FIXME 32x64? */
2860 {
2861 warning ("Couldn't enable exception catch interception.");
2862 return (struct symtab_and_line *) -1;
2863 }
2864 break;
2865 default:
2866 error ("Request to enable unknown or unsupported exception event.");
2867 }
2868
2869 /* Copy break address into new sal struct, malloc'ing if needed. */
2870 if (!break_callback_sal)
2871 {
2872 break_callback_sal = (struct symtab_and_line *) xmalloc (sizeof (struct symtab_and_line));
2873 }
2874 init_sal (break_callback_sal);
2875 break_callback_sal->symtab = NULL;
2876 break_callback_sal->pc = eh_break_addr;
2877 break_callback_sal->line = 0;
2878 break_callback_sal->end = eh_break_addr;
2879
2880 return break_callback_sal;
2881 }
2882
2883 /* Record some information about the current exception event */
2884 static struct exception_event_record current_ex_event;
2885 /* Convenience struct */
2886 static struct symtab_and_line null_symtab_and_line =
2887 {NULL, 0, 0, 0};
2888
2889 /* Report current exception event. Returns a pointer to a record
2890 that describes the kind of the event, where it was thrown from,
2891 and where it will be caught. More information may be reported
2892 in the future */
2893 struct exception_event_record *
2894 child_get_current_exception_event (void)
2895 {
2896 CORE_ADDR event_kind;
2897 CORE_ADDR throw_addr;
2898 CORE_ADDR catch_addr;
2899 struct frame_info *fi, *curr_frame;
2900 int level = 1;
2901
2902 curr_frame = get_current_frame ();
2903 if (!curr_frame)
2904 return (struct exception_event_record *) NULL;
2905
2906 /* Go up one frame to __d_eh_notify_callback, because at the
2907 point when this code is executed, there's garbage in the
2908 arguments of __d_eh_break. */
2909 fi = find_relative_frame (curr_frame, &level);
2910 if (level != 0)
2911 return (struct exception_event_record *) NULL;
2912
2913 select_frame (fi);
2914
2915 /* Read in the arguments */
2916 /* __d_eh_notify_callback() is called with 3 arguments:
2917 1. event kind catch or throw
2918 2. the target address if known
2919 3. a flag -- not sure what this is. pai/1997-07-17 */
2920 event_kind = read_register (ARG0_REGNUM);
2921 catch_addr = read_register (ARG1_REGNUM);
2922
2923 /* Now go down to a user frame */
2924 /* For a throw, __d_eh_break is called by
2925 __d_eh_notify_callback which is called by
2926 __notify_throw which is called
2927 from user code.
2928 For a catch, __d_eh_break is called by
2929 __d_eh_notify_callback which is called by
2930 <stackwalking stuff> which is called by
2931 __throw__<stuff> or __rethrow_<stuff> which is called
2932 from user code. */
2933 /* FIXME: Don't use such magic numbers; search for the frames */
2934 level = (event_kind == EX_EVENT_THROW) ? 3 : 4;
2935 fi = find_relative_frame (curr_frame, &level);
2936 if (level != 0)
2937 return (struct exception_event_record *) NULL;
2938
2939 select_frame (fi);
2940 throw_addr = get_frame_pc (fi);
2941
2942 /* Go back to original (top) frame */
2943 select_frame (curr_frame);
2944
2945 current_ex_event.kind = (enum exception_event_kind) event_kind;
2946 current_ex_event.throw_sal = find_pc_line (throw_addr, 1);
2947 current_ex_event.catch_sal = find_pc_line (catch_addr, 1);
2948
2949 return &current_ex_event;
2950 }
2951
2952 /* Instead of this nasty cast, add a method pvoid() that prints out a
2953 host VOID data type (remember %p isn't portable). */
2954
2955 static CORE_ADDR
2956 hppa_pointer_to_address_hack (void *ptr)
2957 {
2958 gdb_assert (sizeof (ptr) == TYPE_LENGTH (builtin_type_void_data_ptr));
2959 return POINTER_TO_ADDRESS (builtin_type_void_data_ptr, &ptr);
2960 }
2961
2962 static void
2963 unwind_command (char *exp, int from_tty)
2964 {
2965 CORE_ADDR address;
2966 struct unwind_table_entry *u;
2967
2968 /* If we have an expression, evaluate it and use it as the address. */
2969
2970 if (exp != 0 && *exp != 0)
2971 address = parse_and_eval_address (exp);
2972 else
2973 return;
2974
2975 u = find_unwind_entry (address);
2976
2977 if (!u)
2978 {
2979 printf_unfiltered ("Can't find unwind table entry for %s\n", exp);
2980 return;
2981 }
2982
2983 printf_unfiltered ("unwind_table_entry (0x%s):\n",
2984 paddr_nz (hppa_pointer_to_address_hack (u)));
2985
2986 printf_unfiltered ("\tregion_start = ");
2987 print_address (u->region_start, gdb_stdout);
2988
2989 printf_unfiltered ("\n\tregion_end = ");
2990 print_address (u->region_end, gdb_stdout);
2991
2992 #define pif(FLD) if (u->FLD) printf_unfiltered (" "#FLD);
2993
2994 printf_unfiltered ("\n\tflags =");
2995 pif (Cannot_unwind);
2996 pif (Millicode);
2997 pif (Millicode_save_sr0);
2998 pif (Entry_SR);
2999 pif (Args_stored);
3000 pif (Variable_Frame);
3001 pif (Separate_Package_Body);
3002 pif (Frame_Extension_Millicode);
3003 pif (Stack_Overflow_Check);
3004 pif (Two_Instruction_SP_Increment);
3005 pif (Ada_Region);
3006 pif (Save_SP);
3007 pif (Save_RP);
3008 pif (Save_MRP_in_frame);
3009 pif (extn_ptr_defined);
3010 pif (Cleanup_defined);
3011 pif (MPE_XL_interrupt_marker);
3012 pif (HP_UX_interrupt_marker);
3013 pif (Large_frame);
3014
3015 putchar_unfiltered ('\n');
3016
3017 #define pin(FLD) printf_unfiltered ("\t"#FLD" = 0x%x\n", u->FLD);
3018
3019 pin (Region_description);
3020 pin (Entry_FR);
3021 pin (Entry_GR);
3022 pin (Total_frame_size);
3023 }
3024
3025 void
3026 hppa_skip_permanent_breakpoint (void)
3027 {
3028 /* To step over a breakpoint instruction on the PA takes some
3029 fiddling with the instruction address queue.
3030
3031 When we stop at a breakpoint, the IA queue front (the instruction
3032 we're executing now) points at the breakpoint instruction, and
3033 the IA queue back (the next instruction to execute) points to
3034 whatever instruction we would execute after the breakpoint, if it
3035 were an ordinary instruction. This is the case even if the
3036 breakpoint is in the delay slot of a branch instruction.
3037
3038 Clearly, to step past the breakpoint, we need to set the queue
3039 front to the back. But what do we put in the back? What
3040 instruction comes after that one? Because of the branch delay
3041 slot, the next insn is always at the back + 4. */
3042 write_register (PCOQ_HEAD_REGNUM, read_register (PCOQ_TAIL_REGNUM));
3043 write_register (PCSQ_HEAD_REGNUM, read_register (PCSQ_TAIL_REGNUM));
3044
3045 write_register (PCOQ_TAIL_REGNUM, read_register (PCOQ_TAIL_REGNUM) + 4);
3046 /* We can leave the tail's space the same, since there's no jump. */
3047 }
3048
3049 int
3050 hppa_reg_struct_has_addr (int gcc_p, struct type *type)
3051 {
3052 /* On the PA, any pass-by-value structure > 8 bytes is actually passed
3053 via a pointer regardless of its type or the compiler used. */
3054 return (TYPE_LENGTH (type) > 8);
3055 }
3056
3057 int
3058 hppa_inner_than (CORE_ADDR lhs, CORE_ADDR rhs)
3059 {
3060 /* Stack grows upward */
3061 return (lhs > rhs);
3062 }
3063
3064 int
3065 hppa_pc_requires_run_before_use (CORE_ADDR pc)
3066 {
3067 /* Sometimes we may pluck out a minimal symbol that has a negative address.
3068
3069 An example of this occurs when an a.out is linked against a foo.sl.
3070 The foo.sl defines a global bar(), and the a.out declares a signature
3071 for bar(). However, the a.out doesn't directly call bar(), but passes
3072 its address in another call.
3073
3074 If you have this scenario and attempt to "break bar" before running,
3075 gdb will find a minimal symbol for bar() in the a.out. But that
3076 symbol's address will be negative. What this appears to denote is
3077 an index backwards from the base of the procedure linkage table (PLT)
3078 into the data linkage table (DLT), the end of which is contiguous
3079 with the start of the PLT. This is clearly not a valid address for
3080 us to set a breakpoint on.
3081
3082 Note that one must be careful in how one checks for a negative address.
3083 0xc0000000 is a legitimate address of something in a shared text
3084 segment, for example. Since I don't know what the possible range
3085 is of these "really, truly negative" addresses that come from the
3086 minimal symbols, I'm resorting to the gross hack of checking the
3087 top byte of the address for all 1's. Sigh. */
3088
3089 return (!target_has_stack && (pc & 0xFF000000));
3090 }
3091
3092 int
3093 hppa_instruction_nullified (void)
3094 {
3095 /* brobecker 2002/11/07: Couldn't we use a ULONGEST here? It would
3096 avoid the type cast. I'm leaving it as is for now as I'm doing
3097 semi-mechanical multiarching-related changes. */
3098 const int ipsw = (int) read_register (IPSW_REGNUM);
3099 const int flags = (int) read_register (FLAGS_REGNUM);
3100
3101 return ((ipsw & 0x00200000) && !(flags & 0x2));
3102 }
3103
3104 /* Return the GDB type object for the "standard" data type of data
3105 in register N. */
3106
3107 static struct type *
3108 hppa32_register_type (struct gdbarch *gdbarch, int reg_nr)
3109 {
3110 if (reg_nr < FP4_REGNUM)
3111 return builtin_type_uint32;
3112 else
3113 return builtin_type_ieee_single_big;
3114 }
3115
3116 /* Return the GDB type object for the "standard" data type of data
3117 in register N. hppa64 version. */
3118
3119 static struct type *
3120 hppa64_register_type (struct gdbarch *gdbarch, int reg_nr)
3121 {
3122 if (reg_nr < FP4_REGNUM)
3123 return builtin_type_uint64;
3124 else
3125 return builtin_type_ieee_double_big;
3126 }
3127
3128 /* Return True if REGNUM is not a register available to the user
3129 through ptrace(). */
3130
3131 int
3132 hppa_cannot_store_register (int regnum)
3133 {
3134 return (regnum == 0
3135 || regnum == PCSQ_HEAD_REGNUM
3136 || (regnum >= PCSQ_TAIL_REGNUM && regnum < IPSW_REGNUM)
3137 || (regnum > IPSW_REGNUM && regnum < FP4_REGNUM));
3138
3139 }
3140
3141 CORE_ADDR
3142 hppa_smash_text_address (CORE_ADDR addr)
3143 {
3144 /* The low two bits of the PC on the PA contain the privilege level.
3145 Some genius implementing a (non-GCC) compiler apparently decided
3146 this means that "addresses" in a text section therefore include a
3147 privilege level, and thus symbol tables should contain these bits.
3148 This seems like a bonehead thing to do--anyway, it seems to work
3149 for our purposes to just ignore those bits. */
3150
3151 return (addr &= ~0x3);
3152 }
3153
3154 /* Get the ith function argument for the current function. */
3155 CORE_ADDR
3156 hppa_fetch_pointer_argument (struct frame_info *frame, int argi,
3157 struct type *type)
3158 {
3159 CORE_ADDR addr;
3160 get_frame_register (frame, R0_REGNUM + 26 - argi, &addr);
3161 return addr;
3162 }
3163
3164 /* Here is a table of C type sizes on hppa with various compiles
3165 and options. I measured this on PA 9000/800 with HP-UX 11.11
3166 and these compilers:
3167
3168 /usr/ccs/bin/cc HP92453-01 A.11.01.21
3169 /opt/ansic/bin/cc HP92453-01 B.11.11.28706.GP
3170 /opt/aCC/bin/aCC B3910B A.03.45
3171 gcc gcc 3.3.2 native hppa2.0w-hp-hpux11.11
3172
3173 cc : 1 2 4 4 8 : 4 8 -- : 4 4
3174 ansic +DA1.1 : 1 2 4 4 8 : 4 8 16 : 4 4
3175 ansic +DA2.0 : 1 2 4 4 8 : 4 8 16 : 4 4
3176 ansic +DA2.0W : 1 2 4 8 8 : 4 8 16 : 8 8
3177 acc +DA1.1 : 1 2 4 4 8 : 4 8 16 : 4 4
3178 acc +DA2.0 : 1 2 4 4 8 : 4 8 16 : 4 4
3179 acc +DA2.0W : 1 2 4 8 8 : 4 8 16 : 8 8
3180 gcc : 1 2 4 4 8 : 4 8 16 : 4 4
3181
3182 Each line is:
3183
3184 compiler and options
3185 char, short, int, long, long long
3186 float, double, long double
3187 char *, void (*)()
3188
3189 So all these compilers use either ILP32 or LP64 model.
3190 TODO: gcc has more options so it needs more investigation.
3191
3192 For floating point types, see:
3193
3194 http://docs.hp.com/hpux/pdf/B3906-90006.pdf
3195 HP-UX floating-point guide, hpux 11.00
3196
3197 -- chastain 2003-12-18 */
3198
3199 static struct gdbarch *
3200 hppa_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
3201 {
3202 struct gdbarch_tdep *tdep;
3203 struct gdbarch *gdbarch;
3204
3205 /* Try to determine the ABI of the object we are loading. */
3206 if (info.abfd != NULL && info.osabi == GDB_OSABI_UNKNOWN)
3207 {
3208 /* If it's a SOM file, assume it's HP/UX SOM. */
3209 if (bfd_get_flavour (info.abfd) == bfd_target_som_flavour)
3210 info.osabi = GDB_OSABI_HPUX_SOM;
3211 }
3212
3213 /* find a candidate among the list of pre-declared architectures. */
3214 arches = gdbarch_list_lookup_by_info (arches, &info);
3215 if (arches != NULL)
3216 return (arches->gdbarch);
3217
3218 /* If none found, then allocate and initialize one. */
3219 tdep = XMALLOC (struct gdbarch_tdep);
3220 gdbarch = gdbarch_alloc (&info, tdep);
3221
3222 /* Determine from the bfd_arch_info structure if we are dealing with
3223 a 32 or 64 bits architecture. If the bfd_arch_info is not available,
3224 then default to a 32bit machine. */
3225 if (info.bfd_arch_info != NULL)
3226 tdep->bytes_per_address =
3227 info.bfd_arch_info->bits_per_address / info.bfd_arch_info->bits_per_byte;
3228 else
3229 tdep->bytes_per_address = 4;
3230
3231 /* Some parts of the gdbarch vector depend on whether we are running
3232 on a 32 bits or 64 bits target. */
3233 switch (tdep->bytes_per_address)
3234 {
3235 case 4:
3236 set_gdbarch_num_regs (gdbarch, hppa32_num_regs);
3237 set_gdbarch_register_name (gdbarch, hppa32_register_name);
3238 set_gdbarch_register_type (gdbarch, hppa32_register_type);
3239 break;
3240 case 8:
3241 set_gdbarch_num_regs (gdbarch, hppa64_num_regs);
3242 set_gdbarch_register_name (gdbarch, hppa64_register_name);
3243 set_gdbarch_register_type (gdbarch, hppa64_register_type);
3244 break;
3245 default:
3246 internal_error (__FILE__, __LINE__, "Unsupported address size: %d",
3247 tdep->bytes_per_address);
3248 }
3249
3250 set_gdbarch_long_bit (gdbarch, tdep->bytes_per_address * TARGET_CHAR_BIT);
3251 set_gdbarch_ptr_bit (gdbarch, tdep->bytes_per_address * TARGET_CHAR_BIT);
3252
3253 /* The following gdbarch vector elements are the same in both ILP32
3254 and LP64, but might show differences some day. */
3255 set_gdbarch_long_long_bit (gdbarch, 64);
3256 set_gdbarch_long_double_bit (gdbarch, 128);
3257 set_gdbarch_long_double_format (gdbarch, &floatformat_ia64_quad_big);
3258
3259 /* The following gdbarch vector elements do not depend on the address
3260 size, or in any other gdbarch element previously set. */
3261 set_gdbarch_skip_prologue (gdbarch, hppa_skip_prologue);
3262 set_gdbarch_skip_trampoline_code (gdbarch, hppa_skip_trampoline_code);
3263 set_gdbarch_in_solib_call_trampoline (gdbarch, hppa_in_solib_call_trampoline);
3264 set_gdbarch_in_solib_return_trampoline (gdbarch,
3265 hppa_in_solib_return_trampoline);
3266 set_gdbarch_inner_than (gdbarch, hppa_inner_than);
3267 set_gdbarch_sp_regnum (gdbarch, HPPA_SP_REGNUM);
3268 set_gdbarch_fp0_regnum (gdbarch, HPPA_FP0_REGNUM);
3269 set_gdbarch_cannot_store_register (gdbarch, hppa_cannot_store_register);
3270 set_gdbarch_addr_bits_remove (gdbarch, hppa_smash_text_address);
3271 set_gdbarch_smash_text_address (gdbarch, hppa_smash_text_address);
3272 set_gdbarch_believe_pcc_promotion (gdbarch, 1);
3273 set_gdbarch_read_pc (gdbarch, hppa_target_read_pc);
3274 set_gdbarch_write_pc (gdbarch, hppa_target_write_pc);
3275
3276 /* Helper for function argument information. */
3277 set_gdbarch_fetch_pointer_argument (gdbarch, hppa_fetch_pointer_argument);
3278
3279 set_gdbarch_print_insn (gdbarch, print_insn_hppa);
3280
3281 /* When a hardware watchpoint triggers, we'll move the inferior past
3282 it by removing all eventpoints; stepping past the instruction
3283 that caused the trigger; reinserting eventpoints; and checking
3284 whether any watched location changed. */
3285 set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1);
3286
3287 /* Inferior function call methods. */
3288 switch (tdep->bytes_per_address)
3289 {
3290 case 4:
3291 set_gdbarch_push_dummy_call (gdbarch, hppa32_push_dummy_call);
3292 set_gdbarch_frame_align (gdbarch, hppa32_frame_align);
3293 break;
3294 case 8:
3295 set_gdbarch_push_dummy_call (gdbarch, hppa64_push_dummy_call);
3296 set_gdbarch_frame_align (gdbarch, hppa64_frame_align);
3297 break;
3298 default:
3299 internal_error (__FILE__, __LINE__, "bad switch");
3300 }
3301
3302 /* Struct return methods. */
3303 switch (tdep->bytes_per_address)
3304 {
3305 case 4:
3306 set_gdbarch_return_value (gdbarch, hppa32_return_value);
3307 break;
3308 case 8:
3309 set_gdbarch_return_value (gdbarch, hppa64_return_value);
3310 break;
3311 default:
3312 internal_error (__FILE__, __LINE__, "bad switch");
3313 }
3314
3315 /* Frame unwind methods. */
3316 set_gdbarch_unwind_dummy_id (gdbarch, hppa_unwind_dummy_id);
3317 set_gdbarch_unwind_pc (gdbarch, hppa_unwind_pc);
3318 frame_unwind_append_sniffer (gdbarch, hppa_frame_unwind_sniffer);
3319 frame_base_append_sniffer (gdbarch, hppa_frame_base_sniffer);
3320
3321 /* Hook in ABI-specific overrides, if they have been registered. */
3322 gdbarch_init_osabi (info, gdbarch);
3323
3324 return gdbarch;
3325 }
3326
3327 static void
3328 hppa_dump_tdep (struct gdbarch *current_gdbarch, struct ui_file *file)
3329 {
3330 /* Nothing to print for the moment. */
3331 }
3332
3333 void
3334 _initialize_hppa_tdep (void)
3335 {
3336 struct cmd_list_element *c;
3337 void break_at_finish_command (char *arg, int from_tty);
3338 void tbreak_at_finish_command (char *arg, int from_tty);
3339 void break_at_finish_at_depth_command (char *arg, int from_tty);
3340
3341 gdbarch_register (bfd_arch_hppa, hppa_gdbarch_init, hppa_dump_tdep);
3342
3343 add_cmd ("unwind", class_maintenance, unwind_command,
3344 "Print unwind table entry at given address.",
3345 &maintenanceprintlist);
3346
3347 deprecate_cmd (add_com ("xbreak", class_breakpoint,
3348 break_at_finish_command,
3349 concat ("Set breakpoint at procedure exit. \n\
3350 Argument may be function name, or \"*\" and an address.\n\
3351 If function is specified, break at end of code for that function.\n\
3352 If an address is specified, break at the end of the function that contains \n\
3353 that exact address.\n",
3354 "With no arg, uses current execution address of selected stack frame.\n\
3355 This is useful for breaking on return to a stack frame.\n\
3356 \n\
3357 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
3358 \n\
3359 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL)), NULL);
3360 deprecate_cmd (add_com_alias ("xb", "xbreak", class_breakpoint, 1), NULL);
3361 deprecate_cmd (add_com_alias ("xbr", "xbreak", class_breakpoint, 1), NULL);
3362 deprecate_cmd (add_com_alias ("xbre", "xbreak", class_breakpoint, 1), NULL);
3363 deprecate_cmd (add_com_alias ("xbrea", "xbreak", class_breakpoint, 1), NULL);
3364
3365 deprecate_cmd (c = add_com ("txbreak", class_breakpoint,
3366 tbreak_at_finish_command,
3367 "Set temporary breakpoint at procedure exit. Either there should\n\
3368 be no argument or the argument must be a depth.\n"), NULL);
3369 set_cmd_completer (c, location_completer);
3370
3371 if (xdb_commands)
3372 deprecate_cmd (add_com ("bx", class_breakpoint,
3373 break_at_finish_at_depth_command,
3374 "Set breakpoint at procedure exit. Either there should\n\
3375 be no argument or the argument must be a depth.\n"), NULL);
3376 }
3377
This page took 0.093346 seconds and 5 git commands to generate.