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