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