1 /* Target-dependent code for the HP PA architecture, for GDB.
2 Copyright 1986, 87, 89, 90, 91, 92, 93, 94, 95, 96, 1999
3 Free Software Foundation, Inc.
5 Contributed by the Center for Software Science at the
6 University of Utah (pa-gdb-bugs@cs.utah.edu).
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
30 /* For argument passing to the inferior */
34 #include <sys/types.h>
38 #include <sys/param.h>
41 #include <sys/ptrace.h>
42 #include <machine/save_state.h>
44 #ifdef COFF_ENCAPSULATE
45 #include "a.out.encap.h"
49 /*#include <sys/user.h> After a.out.h */
60 /* To support asking "What CPU is this?" */
63 /* To support detection of the pseudo-initial frame
65 #define THREAD_INITIAL_FRAME_SYMBOL "__pthread_exit"
66 #define THREAD_INITIAL_FRAME_SYM_LEN sizeof(THREAD_INITIAL_FRAME_SYMBOL)
68 static int extract_5_load PARAMS ((unsigned int));
70 static unsigned extract_5R_store PARAMS ((unsigned int));
72 static unsigned extract_5r_store PARAMS ((unsigned int));
74 static void find_dummy_frame_regs PARAMS ((struct frame_info *,
75 struct frame_saved_regs *));
77 static int find_proc_framesize PARAMS ((CORE_ADDR));
79 static int find_return_regnum PARAMS ((CORE_ADDR));
81 struct unwind_table_entry *find_unwind_entry PARAMS ((CORE_ADDR));
83 static int extract_17 PARAMS ((unsigned int));
85 static unsigned deposit_21 PARAMS ((unsigned int, unsigned int));
87 static int extract_21 PARAMS ((unsigned));
89 static unsigned deposit_14 PARAMS ((int, unsigned int));
91 static int extract_14 PARAMS ((unsigned));
93 static void unwind_command PARAMS ((char *, int));
95 static int low_sign_extend PARAMS ((unsigned int, unsigned int));
97 static int sign_extend PARAMS ((unsigned int, unsigned int));
99 static int restore_pc_queue PARAMS ((struct frame_saved_regs *));
101 static int hppa_alignof PARAMS ((struct type *));
103 /* To support multi-threading and stepping. */
104 int hppa_prepare_to_proceed PARAMS (());
106 static int prologue_inst_adjust_sp PARAMS ((unsigned long));
108 static int is_branch PARAMS ((unsigned long));
110 static int inst_saves_gr PARAMS ((unsigned long));
112 static int inst_saves_fr PARAMS ((unsigned long));
114 static int pc_in_interrupt_handler PARAMS ((CORE_ADDR));
116 static int pc_in_linker_stub PARAMS ((CORE_ADDR));
118 static int compare_unwind_entries PARAMS ((const void *, const void *));
120 static void read_unwind_info PARAMS ((struct objfile *));
122 static void internalize_unwinds PARAMS ((struct objfile *,
123 struct unwind_table_entry *,
124 asection *, unsigned int,
125 unsigned int, CORE_ADDR));
126 static void pa_print_registers PARAMS ((char *, int, int));
127 static void pa_strcat_registers PARAMS ((char *, int, int, GDB_FILE *));
128 static void pa_register_look_aside PARAMS ((char *, int, long *));
129 static void pa_print_fp_reg PARAMS ((int));
130 static void pa_strcat_fp_reg PARAMS ((int, GDB_FILE *, enum precision_type));
133 struct minimal_symbol * msym;
134 CORE_ADDR solib_handle;
135 } args_for_find_stub;
137 static CORE_ADDR cover_find_stub_with_shl_get PARAMS ((args_for_find_stub *));
139 static int is_pa_2 = 0; /* False */
141 /* This is declared in symtab.c; set to 1 in hp-symtab-read.c */
142 extern int hp_som_som_object_present;
144 /* In breakpoint.c */
145 extern int exception_catchpoints_are_fragile;
147 /* This is defined in valops.c. */
149 find_function_in_inferior PARAMS((char *));
151 /* Should call_function allocate stack space for a struct return? */
153 hppa_use_struct_convention (gcc_p, type)
157 return (TYPE_LENGTH (type) > 8);
161 /* Routines to extract various sized constants out of hppa
164 /* This assumes that no garbage lies outside of the lower bits of
168 sign_extend (val, bits)
171 return (int)(val >> (bits - 1) ? (-1 << bits) | val : val);
174 /* For many immediate values the sign bit is the low bit! */
177 low_sign_extend (val, bits)
180 return (int)((val & 0x1 ? (-1 << (bits - 1)) : 0) | val >> 1);
183 /* extract the immediate field from a ld{bhw}s instruction */
188 get_field (val, from, to)
189 unsigned val, from, to;
191 val = val >> 31 - to;
192 return val & ((1 << 32 - from) - 1);
196 set_field (val, from, to, new_val)
197 unsigned *val, from, to;
199 unsigned mask = ~((1 << (to - from + 1)) << (31 - from));
200 return *val = *val & mask | (new_val << (31 - from));
203 /* extract a 3-bit space register number from a be, ble, mtsp or mfsp */
209 return GET_FIELD (word, 18, 18) << 2 | GET_FIELD (word, 16, 17);
215 extract_5_load (word)
218 return low_sign_extend (word >> 16 & MASK_5, 5);
223 /* extract the immediate field from a st{bhw}s instruction */
226 extract_5_store (word)
229 return low_sign_extend (word & MASK_5, 5);
234 /* extract the immediate field from a break instruction */
237 extract_5r_store (word)
240 return (word & MASK_5);
243 /* extract the immediate field from a {sr}sm instruction */
246 extract_5R_store (word)
249 return (word >> 16 & MASK_5);
252 /* extract an 11 bit immediate field */
260 return low_sign_extend (word & MASK_11, 11);
265 /* extract a 14 bit immediate field */
271 return low_sign_extend (word & MASK_14, 14);
274 /* deposit a 14 bit constant in a word */
277 deposit_14 (opnd, word)
281 unsigned sign = (opnd < 0 ? 1 : 0);
283 return word | ((unsigned)opnd << 1 & MASK_14) | sign;
286 /* extract a 21 bit constant */
296 val = GET_FIELD (word, 20, 20);
298 val |= GET_FIELD (word, 9, 19);
300 val |= GET_FIELD (word, 5, 6);
302 val |= GET_FIELD (word, 0, 4);
304 val |= GET_FIELD (word, 7, 8);
305 return sign_extend (val, 21) << 11;
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 */
313 deposit_21 (opnd, word)
318 val |= GET_FIELD (opnd, 11 + 14, 11 + 18);
320 val |= GET_FIELD (opnd, 11 + 12, 11 + 13);
322 val |= GET_FIELD (opnd, 11 + 19, 11 + 20);
324 val |= GET_FIELD (opnd, 11 + 1, 11 + 11);
326 val |= GET_FIELD (opnd, 11 + 0, 11 + 0);
330 /* extract a 12 bit constant from branch instructions */
338 return sign_extend (GET_FIELD (word, 19, 28) |
339 GET_FIELD (word, 29, 29) << 10 |
340 (word & 0x1) << 11, 12) << 2;
343 /* Deposit a 17 bit constant in an instruction (like bl). */
346 deposit_17 (opnd, word)
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] */
359 /* extract a 17 bit constant from branch instructions, returning the
360 19 bit signed value. */
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;
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. */
378 compare_unwind_entries (arg1, arg2)
382 const struct unwind_table_entry *a = arg1;
383 const struct unwind_table_entry *b = arg2;
385 if (a->region_start > b->region_start)
387 else if (a->region_start < b->region_start)
394 internalize_unwinds (objfile, table, section, entries, size, text_offset)
395 struct objfile *objfile;
396 struct unwind_table_entry *table;
398 unsigned int entries, size;
399 CORE_ADDR text_offset;
401 /* We will read the unwind entries into temporary memory, then
402 fill in the actual unwind table. */
407 char *buf = alloca (size);
409 bfd_get_section_contents (objfile->obfd, section, buf, 0, size);
411 /* Now internalize the information being careful to handle host/target
413 for (i = 0; i < entries; i++)
415 table[i].region_start = bfd_get_32 (objfile->obfd,
417 table[i].region_start += text_offset;
419 table[i].region_end = bfd_get_32 (objfile->obfd, (bfd_byte *)buf);
420 table[i].region_end += text_offset;
422 tmp = bfd_get_32 (objfile->obfd, (bfd_byte *)buf);
424 table[i].Cannot_unwind = (tmp >> 31) & 0x1;
425 table[i].Millicode = (tmp >> 30) & 0x1;
426 table[i].Millicode_save_sr0 = (tmp >> 29) & 0x1;
427 table[i].Region_description = (tmp >> 27) & 0x3;
428 table[i].reserved1 = (tmp >> 26) & 0x1;
429 table[i].Entry_SR = (tmp >> 25) & 0x1;
430 table[i].Entry_FR = (tmp >> 21) & 0xf;
431 table[i].Entry_GR = (tmp >> 16) & 0x1f;
432 table[i].Args_stored = (tmp >> 15) & 0x1;
433 table[i].Variable_Frame = (tmp >> 14) & 0x1;
434 table[i].Separate_Package_Body = (tmp >> 13) & 0x1;
435 table[i].Frame_Extension_Millicode = (tmp >> 12) & 0x1;
436 table[i].Stack_Overflow_Check = (tmp >> 11) & 0x1;
437 table[i].Two_Instruction_SP_Increment = (tmp >> 10) & 0x1;
438 table[i].Ada_Region = (tmp >> 9) & 0x1;
439 table[i].cxx_info = (tmp >> 8) & 0x1;
440 table[i].cxx_try_catch = (tmp >> 7) & 0x1;
441 table[i].sched_entry_seq = (tmp >> 6) & 0x1;
442 table[i].reserved2 = (tmp >> 5) & 0x1;
443 table[i].Save_SP = (tmp >> 4) & 0x1;
444 table[i].Save_RP = (tmp >> 3) & 0x1;
445 table[i].Save_MRP_in_frame = (tmp >> 2) & 0x1;
446 table[i].extn_ptr_defined = (tmp >> 1) & 0x1;
447 table[i].Cleanup_defined = tmp & 0x1;
448 tmp = bfd_get_32 (objfile->obfd, (bfd_byte *)buf);
450 table[i].MPE_XL_interrupt_marker = (tmp >> 31) & 0x1;
451 table[i].HP_UX_interrupt_marker = (tmp >> 30) & 0x1;
452 table[i].Large_frame = (tmp >> 29) & 0x1;
453 table[i].Pseudo_SP_Set = (tmp >> 28) & 0x1;
454 table[i].reserved4 = (tmp >> 27) & 0x1;
455 table[i].Total_frame_size = tmp & 0x7ffffff;
457 /* Stub unwinds are handled elsewhere. */
458 table[i].stub_unwind.stub_type = 0;
459 table[i].stub_unwind.padding = 0;
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. */
471 read_unwind_info (objfile)
472 struct objfile *objfile;
474 asection *unwind_sec, *elf_unwind_sec, *stub_unwind_sec;
475 unsigned unwind_size, elf_unwind_size, stub_unwind_size, total_size;
476 unsigned index, unwind_entries, elf_unwind_entries;
477 unsigned stub_entries, total_entries;
478 CORE_ADDR text_offset;
479 struct obj_unwind_info *ui;
480 obj_private_data_t *obj_private;
482 text_offset = ANOFFSET (objfile->section_offsets, 0);
483 ui = (struct obj_unwind_info *)obstack_alloc (&objfile->psymbol_obstack,
484 sizeof (struct obj_unwind_info));
490 /* Get hooks to all unwind sections. Note there is no linker-stub unwind
491 section in ELF at the moment. */
492 unwind_sec = bfd_get_section_by_name (objfile->obfd, "$UNWIND_START$");
493 elf_unwind_sec = bfd_get_section_by_name (objfile->obfd, ".PARISC.unwind");
494 stub_unwind_sec = bfd_get_section_by_name (objfile->obfd, "$UNWIND_END$");
496 /* Get sizes and unwind counts for all sections. */
499 unwind_size = bfd_section_size (objfile->obfd, unwind_sec);
500 unwind_entries = unwind_size / UNWIND_ENTRY_SIZE;
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 */
516 elf_unwind_entries = 0;
521 stub_unwind_size = bfd_section_size (objfile->obfd, stub_unwind_sec);
522 stub_entries = stub_unwind_size / STUB_UNWIND_ENTRY_SIZE;
526 stub_unwind_size = 0;
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);
534 /* Allocate memory for the unwind table. */
535 ui->table = (struct unwind_table_entry *)
536 obstack_alloc (&objfile->psymbol_obstack, total_size);
537 ui->last = total_entries - 1;
539 /* Internalize the standard unwind entries. */
541 internalize_unwinds (objfile, &ui->table[index], unwind_sec,
542 unwind_entries, unwind_size, text_offset);
543 index += unwind_entries;
544 internalize_unwinds (objfile, &ui->table[index], elf_unwind_sec,
545 elf_unwind_entries, elf_unwind_size, text_offset);
546 index += elf_unwind_entries;
548 /* Now internalize the stub unwind entries. */
549 if (stub_unwind_size > 0)
552 char *buf = alloca (stub_unwind_size);
554 /* Read in the stub unwind entries. */
555 bfd_get_section_contents (objfile->obfd, stub_unwind_sec, buf,
556 0, stub_unwind_size);
558 /* Now convert them into regular unwind entries. */
559 for (i = 0; i < stub_entries; i++, index++)
561 /* Clear out the next unwind entry. */
562 memset (&ui->table[index], 0, sizeof (struct unwind_table_entry));
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,
568 ui->table[index].region_start += text_offset;
570 ui->table[index].stub_unwind.stub_type = bfd_get_8 (objfile->obfd,
573 ui->table[index].region_end
574 = ui->table[index].region_start + 4 *
575 (bfd_get_16 (objfile->obfd, (bfd_byte *) buf) - 1);
581 /* Unwind table needs to be kept sorted. */
582 qsort (ui->table, total_entries, sizeof (struct unwind_table_entry),
583 compare_unwind_entries);
585 /* Keep a pointer to the unwind information. */
586 if(objfile->obj_private == NULL)
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;
594 objfile->obj_private = (PTR) obj_private;
596 obj_private = (obj_private_data_t *)objfile->obj_private;
597 obj_private->unwind_info = ui;
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. */
605 struct unwind_table_entry *
606 find_unwind_entry(pc)
609 int first, middle, last;
610 struct objfile *objfile;
612 /* A function at address 0? Not in HP-UX! */
613 if (pc == (CORE_ADDR) 0)
616 ALL_OBJFILES (objfile)
618 struct obj_unwind_info *ui;
620 if (objfile->obj_private)
621 ui = ((obj_private_data_t *)(objfile->obj_private))->unwind_info;
625 read_unwind_info (objfile);
626 if (objfile->obj_private == NULL)
627 error ("Internal error reading unwind information."); /* purecov: deadcode */
628 ui = ((obj_private_data_t *)(objfile->obj_private))->unwind_info;
631 /* First, check the cache */
634 && pc >= ui->cache->region_start
635 && pc <= ui->cache->region_end)
638 /* Not in the cache, do a binary search */
643 while (first <= last)
645 middle = (first + last) / 2;
646 if (pc >= ui->table[middle].region_start
647 && pc <= ui->table[middle].region_end)
649 ui->cache = &ui->table[middle];
650 return &ui->table[middle];
653 if (pc < ui->table[middle].region_start)
658 } /* ALL_OBJFILES() */
662 /* Return the adjustment necessary to make for addresses on the stack
663 as presented by hpread.c.
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. */
669 hpread_adjust_stack_address (func_addr)
672 struct unwind_table_entry *u;
674 u = find_unwind_entry (func_addr);
678 return u->Total_frame_size << 3;
681 /* Called to determine if PC is in an interrupt handler of some
685 pc_in_interrupt_handler (pc)
688 struct unwind_table_entry *u;
689 struct minimal_symbol *msym_us;
691 u = find_unwind_entry (pc);
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);
699 return u->HP_UX_interrupt_marker && !IN_SIGTRAMP (pc, SYMBOL_NAME (msym_us));
702 /* Called when no unwind descriptor was found for PC. Returns 1 if it
703 appears that PC is in a linker stub. */
706 pc_in_linker_stub (pc)
709 int found_magic_instruction = 0;
713 /* If unable to read memory, assume pc is not in a linker stub. */
714 if (target_read_memory (pc, buf, 4) != 0)
717 /* We are looking for something like
719 ; $$dyncall jams RP into this special spot in the frame (RP')
720 ; before calling the "call stub"
723 ldsid (rp),r1 ; Get space associated with RP into r1
724 mtsp r1,sp ; Move it into space register 0
725 be,n 0(sr0),rp) ; back to your regularly scheduled program */
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++)
731 /* If we hit something with an unwind, stop searching this direction. */
733 if (find_unwind_entry (pc + i * 4) != 0)
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)
740 found_magic_instruction = 1;
743 /* Add code to handle long call/branch and argument relocation stubs
747 if (found_magic_instruction != 0)
750 /* Now look backward. */
751 for (i = 0; i < 4; i++)
753 /* If we hit something with an unwind, stop searching this direction. */
755 if (find_unwind_entry (pc - i * 4) != 0)
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)
762 found_magic_instruction = 1;
765 /* Add code to handle long call/branch and argument relocation stubs
768 return found_magic_instruction;
772 find_return_regnum(pc)
775 struct unwind_table_entry *u;
777 u = find_unwind_entry (pc);
788 /* Return size of frame, or -1 if we should use a frame pointer. */
790 find_proc_framesize (pc)
793 struct unwind_table_entry *u;
794 struct minimal_symbol *msym_us;
796 /* This may indicate a bug in our callers... */
797 if (pc == (CORE_ADDR)0)
800 u = find_unwind_entry (pc);
804 if (pc_in_linker_stub (pc))
805 /* Linker stubs have a zero size frame. */
811 msym_us = lookup_minimal_symbol_by_pc (pc);
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)))
819 return u->Total_frame_size << 3;
822 /* Return offset from sp at which rp is saved, or 0 if not saved. */
823 static int rp_saved PARAMS ((CORE_ADDR));
829 struct unwind_table_entry *u;
831 /* A function at, and thus a return PC from, address 0? Not in HP-UX! */
832 if (pc == (CORE_ADDR) 0)
835 u = find_unwind_entry (pc);
839 if (pc_in_linker_stub (pc))
840 /* This is the so-called RP'. */
848 else if (u->stub_unwind.stub_type != 0)
850 switch (u->stub_unwind.stub_type)
855 case PARAMETER_RELOCATION:
866 frameless_function_invocation (frame)
867 struct frame_info *frame;
869 struct unwind_table_entry *u;
871 u = find_unwind_entry (frame->pc);
876 return (u->Total_frame_size == 0 && u->stub_unwind.stub_type == 0);
880 saved_pc_after_call (frame)
881 struct frame_info *frame;
885 struct unwind_table_entry *u;
887 ret_regnum = find_return_regnum (get_frame_pc (frame));
888 pc = read_register (ret_regnum) & ~0x3;
890 /* If PC is in a linker stub, then we need to dig the address
891 the stub will return to out of the stack. */
892 u = find_unwind_entry (pc);
893 if (u && u->stub_unwind.stub_type != 0)
894 return FRAME_SAVED_PC (frame);
900 hppa_frame_saved_pc (frame)
901 struct frame_info *frame;
903 CORE_ADDR pc = get_frame_pc (frame);
904 struct unwind_table_entry *u;
906 int spun_around_loop = 0;
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
913 if (pc_in_interrupt_handler (pc))
914 return read_memory_integer (frame->frame + PC_REGNUM * 4, 4) & ~0x3;
916 #ifdef FRAME_SAVED_PC_IN_SIGTRAMP
917 /* Deal with signal handler caller frames too. */
918 if (frame->signal_handler_caller)
921 FRAME_SAVED_PC_IN_SIGTRAMP (frame, &rp);
926 if (frameless_function_invocation (frame))
930 ret_regnum = find_return_regnum (pc);
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). */
937 && (frame->next->signal_handler_caller
938 || pc_in_interrupt_handler (frame->next->pc)))
940 struct frame_saved_regs saved_regs;
942 get_frame_saved_regs (frame->next, &saved_regs);
943 if (read_memory_integer (saved_regs.regs[FLAGS_REGNUM], 4) & 0x2)
945 pc = read_memory_integer (saved_regs.regs[31], 4) & ~0x3;
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. */
952 pc = read_memory_integer (saved_regs.regs[RP_REGNUM], 4) & ~0x3;
955 pc = read_memory_integer (saved_regs.regs[RP_REGNUM], 4) & ~0x3;
958 pc = read_register (ret_regnum) & ~0x3;
962 spun_around_loop = 0;
966 rp_offset = rp_saved (pc);
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. */
973 && (frame->next->signal_handler_caller
974 || pc_in_interrupt_handler (frame->next->pc)))
976 struct frame_saved_regs saved_regs;
978 get_frame_saved_regs (frame->next, &saved_regs);
979 if (read_memory_integer (saved_regs.regs[FLAGS_REGNUM], 4) & 0x2)
981 pc = read_memory_integer (saved_regs.regs[31], 4) & ~0x3;
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. */
988 pc = read_memory_integer (saved_regs.regs[RP_REGNUM], 4) & ~0x3;
991 pc = read_memory_integer (saved_regs.regs[RP_REGNUM], 4) & ~0x3;
993 else if (rp_offset == 0)
996 pc = read_register (RP_REGNUM) & ~0x3;
1001 pc = read_memory_integer (frame->frame + rp_offset, 4) & ~0x3;
1005 /* If PC is inside a linker stub, then dig out the address the stub
1008 Don't do this for long branch stubs. Why? For some unknown reason
1009 _start is marked as a long branch stub in hpux10. */
1010 u = find_unwind_entry (pc);
1011 if (u && u->stub_unwind.stub_type != 0
1012 && u->stub_unwind.stub_type != LONG_BRANCH)
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!.
1021 Else, try to dig the address the stub will return to in the normal
1023 insn = read_memory_integer (pc, 4);
1024 if ((insn & 0xfc00e000) == 0xe8000000)
1025 return (pc + extract_17 (insn) + 8) & ~0x3;
1031 if (spun_around_loop > 1)
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");
1045 /* We need to correct the PC and the FP for the outermost frame when we are
1046 in a system call. */
1049 init_extra_frame_info (fromleaf, frame)
1051 struct frame_info *frame;
1056 if (frame->next && !fromleaf)
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.) */
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)));
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
1072 if (framesize == -1)
1073 frame->frame = TARGET_READ_FP ();
1075 frame->frame -= framesize;
1079 flags = read_register (FLAGS_REGNUM);
1080 if (flags & 2) /* In system call? */
1081 frame->pc = read_register (31) & ~0x3;
1083 /* The outermost frame is always derived from PC-framesize
1085 One might think frameless innermost frames should have
1086 a frame->frame that is the same as the parent's frame->frame.
1087 That is wrong; frame->frame in that case should be the *high*
1088 address of the parent's frame. It's complicated as hell to
1089 explain, but the parent *always* creates some stack space for
1090 the child. So the child actually does have a frame of some
1091 sorts, and its base is the high address in its parent's frame. */
1092 framesize = find_proc_framesize(frame->pc);
1093 if (framesize == -1)
1094 frame->frame = TARGET_READ_FP ();
1096 frame->frame = read_register (SP_REGNUM) - framesize;
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.
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. */
1109 struct frame_info *frame;
1111 int my_framesize, caller_framesize;
1112 struct unwind_table_entry *u;
1113 CORE_ADDR frame_base;
1114 struct frame_info *tmp_frame;
1116 CORE_ADDR caller_pc;
1118 struct minimal_symbol *min_frame_symbol;
1119 struct symbol *frame_symbol;
1120 char *frame_symbol_name;
1122 /* If this is a threaded application, and we see the
1123 routine "__pthread_exit", treat it as the stack root
1125 min_frame_symbol = lookup_minimal_symbol_by_pc (frame->pc);
1126 frame_symbol = find_pc_function(frame->pc);
1128 if ((min_frame_symbol != 0) /* && (frame_symbol == 0) */)
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.
1134 If it weren't commented out, and you tried to debug the
1135 pthread library itself, you'd get errors.
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;
1147 } /* End of hacky code for threads. */
1149 /* Handle HPUX, BSD, and OSF1 style interrupt frames first. These
1150 are easy; at *sp we have a full save state strucutre which we can
1151 pull the old stack pointer from. Also see frame_saved_pc for
1152 code to dig a saved PC out of the save state structure. */
1153 if (pc_in_interrupt_handler (frame->pc))
1154 frame_base = read_memory_integer (frame->frame + SP_REGNUM * 4, 4);
1155 #ifdef FRAME_BASE_BEFORE_SIGTRAMP
1156 else if (frame->signal_handler_caller)
1158 FRAME_BASE_BEFORE_SIGTRAMP (frame, &frame_base);
1162 frame_base = frame->frame;
1164 /* Get frame sizes for the current frame and the frame of the
1166 my_framesize = find_proc_framesize (frame->pc);
1167 caller_pc = FRAME_SAVED_PC(frame);
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;
1175 caller_framesize = find_proc_framesize (FRAME_SAVED_PC(frame));
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)
1181 return frame_base - caller_framesize;
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)
1188 return read_memory_integer (frame_base, 4);
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.
1194 The previous frame pointer could be in a register, or in one of
1195 several areas on the stack.
1197 Walk from the current frame to the innermost frame examining
1198 unwind descriptors to determine if %r3 ever gets saved into the
1199 stack. If so return whatever value got saved into the stack.
1200 If it was never saved in the stack, then the value in %r3 is still
1203 We use information from unwind descriptors to determine if %r3
1204 is saved into the stack (Entry_GR field has this information). */
1209 u = find_unwind_entry (tmp_frame->pc);
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
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. */
1222 warning ("Unable to find unwind for PC 0x%x -- Help!", tmp_frame->pc);
1224 return (CORE_ADDR) 0;
1227 /* Entry_GR specifies the number of callee-saved general registers
1228 saved in the stack. It starts at %r3, so %r3 would be 1. */
1229 if (u->Entry_GR >= 1 || u->Save_SP
1230 || tmp_frame->signal_handler_caller
1231 || pc_in_interrupt_handler (tmp_frame->pc))
1234 tmp_frame = tmp_frame->next;
1239 /* We may have walked down the chain into a function with a frame
1242 && !tmp_frame->signal_handler_caller
1243 && !pc_in_interrupt_handler (tmp_frame->pc))
1245 return read_memory_integer (tmp_frame->frame, 4);
1247 /* %r3 was saved somewhere in the stack. Dig it out. */
1250 struct frame_saved_regs saved_regs;
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
1261 This scheme works well except for two cases:
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
1269 * Register state is not complete if the system call
1270 causes the process to core dump.
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. */
1278 get_frame_saved_regs (tmp_frame, &saved_regs);
1280 /* Abominable hack. */
1281 if (current_target.to_has_execution == 0
1282 && ((saved_regs.regs[FLAGS_REGNUM]
1283 && (read_memory_integer (saved_regs.regs[FLAGS_REGNUM], 4)
1285 || (saved_regs.regs[FLAGS_REGNUM] == 0
1286 && read_register (FLAGS_REGNUM) & 0x2)))
1288 u = find_unwind_entry (FRAME_SAVED_PC (frame));
1291 return read_memory_integer (saved_regs.regs[FP_REGNUM], 4);
1295 return frame_base - (u->Total_frame_size << 3);
1299 return read_memory_integer (saved_regs.regs[FP_REGNUM], 4);
1304 struct frame_saved_regs saved_regs;
1306 /* Get the innermost frame. */
1308 while (tmp_frame->next != NULL)
1309 tmp_frame = tmp_frame->next;
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)
1317 || (saved_regs.regs[FLAGS_REGNUM] == 0
1318 && read_register (FLAGS_REGNUM) & 0x2)))
1320 u = find_unwind_entry (FRAME_SAVED_PC (frame));
1323 return read_memory_integer (saved_regs.regs[FP_REGNUM], 4);
1327 return frame_base - (u->Total_frame_size << 3);
1331 /* The value in %r3 was never saved into the stack (thus %r3 still
1332 holds the value of the previous frame pointer). */
1333 return TARGET_READ_FP ();
1338 /* To see if a frame chain is valid, see if the caller looks like it
1339 was compiled with gcc. */
1342 hppa_frame_chain_valid (chain, thisframe)
1344 struct frame_info *thisframe;
1346 struct minimal_symbol *msym_us;
1347 struct minimal_symbol *msym_start;
1348 struct unwind_table_entry *u, *next_u = NULL;
1349 struct frame_info *next;
1354 u = find_unwind_entry (thisframe->pc);
1359 /* We can't just check that the same of msym_us is "_start", because
1360 someone idiotically decided that they were going to make a Ltext_end
1361 symbol with the same address. This Ltext_end symbol is totally
1362 indistinguishable (as nearly as I can tell) from the symbol for a function
1363 which is (legitimately, since it is in the user's namespace)
1364 named Ltext_end, so we can't just ignore it. */
1365 msym_us = lookup_minimal_symbol_by_pc (FRAME_SAVED_PC (thisframe));
1366 msym_start = lookup_minimal_symbol ("_start", NULL, NULL);
1369 && SYMBOL_VALUE_ADDRESS (msym_us) == SYMBOL_VALUE_ADDRESS (msym_start))
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);
1377 && SYMBOL_VALUE_ADDRESS (msym_us) == SYMBOL_VALUE_ADDRESS (msym_start))
1380 next = get_next_frame (thisframe);
1382 next_u = find_unwind_entry (next->pc);
1384 /* If this frame does not save SP, has no stack, isn't a stub,
1385 and doesn't "call" an interrupt routine or signal handler caller,
1386 then its not valid. */
1387 if (u->Save_SP || u->Total_frame_size || u->stub_unwind.stub_type != 0
1388 || (thisframe->next && thisframe->next->signal_handler_caller)
1389 || (next_u && next_u->HP_UX_interrupt_marker))
1392 if (pc_in_linker_stub (thisframe->pc))
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. */
1405 push_dummy_frame (inf_status)
1406 struct inferior_status *inf_status;
1408 CORE_ADDR sp, pc, pcspace;
1409 register int regnum;
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.
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
1422 pc = target_read_pc (inferior_pid);
1423 int_buffer = read_register (FLAGS_REGNUM);
1424 if (int_buffer & 0x2)
1428 write_inferior_status_register (inf_status, 0, int_buffer);
1429 write_inferior_status_register (inf_status, PCOQ_HEAD_REGNUM, pc + 0);
1430 write_inferior_status_register (inf_status, PCOQ_TAIL_REGNUM, pc + 4);
1431 sid = (pc >> 30) & 0x3;
1433 pcspace = read_register (SR4_REGNUM);
1435 pcspace = read_register (SR4_REGNUM + 4 + sid);
1436 write_inferior_status_register (inf_status, PCSQ_HEAD_REGNUM, pcspace);
1437 write_inferior_status_register (inf_status, PCSQ_TAIL_REGNUM, pcspace);
1440 pcspace = read_register (PCSQ_HEAD_REGNUM);
1442 /* Space for "arguments"; the RP goes in here. */
1443 sp = read_register (SP_REGNUM) + 48;
1444 int_buffer = read_register (RP_REGNUM) | 0x3;
1445 write_memory (sp - 20, (char *)&int_buffer, 4);
1447 int_buffer = TARGET_READ_FP ();
1448 write_memory (sp, (char *)&int_buffer, 4);
1450 write_register (FP_REGNUM, sp);
1454 for (regnum = 1; regnum < 32; regnum++)
1455 if (regnum != RP_REGNUM && regnum != FP_REGNUM)
1456 sp = push_word (sp, read_register (regnum));
1460 for (regnum = FP0_REGNUM; regnum < NUM_REGS; regnum++)
1462 read_register_bytes (REGISTER_BYTE (regnum), (char *)&freg_buffer, 8);
1463 sp = push_bytes (sp, (char *)&freg_buffer, 8);
1465 sp = push_word (sp, read_register (IPSW_REGNUM));
1466 sp = push_word (sp, read_register (SAR_REGNUM));
1467 sp = push_word (sp, pc);
1468 sp = push_word (sp, pcspace);
1469 sp = push_word (sp, pc + 4);
1470 sp = push_word (sp, pcspace);
1471 write_register (SP_REGNUM, sp);
1475 find_dummy_frame_regs (frame, frame_saved_regs)
1476 struct frame_info *frame;
1477 struct frame_saved_regs *frame_saved_regs;
1479 CORE_ADDR fp = frame->frame;
1482 frame_saved_regs->regs[RP_REGNUM] = (fp - 20) & ~0x3;
1483 frame_saved_regs->regs[FP_REGNUM] = fp;
1484 frame_saved_regs->regs[1] = fp + 8;
1486 for (fp += 12, i = 3; i < 32; i++)
1490 frame_saved_regs->regs[i] = fp;
1496 for (i = FP0_REGNUM; i < NUM_REGS; i++, fp += 8)
1497 frame_saved_regs->regs[i] = fp;
1499 frame_saved_regs->regs[IPSW_REGNUM] = fp;
1500 frame_saved_regs->regs[SAR_REGNUM] = fp + 4;
1501 frame_saved_regs->regs[PCOQ_HEAD_REGNUM] = fp + 8;
1502 frame_saved_regs->regs[PCSQ_HEAD_REGNUM] = fp + 12;
1503 frame_saved_regs->regs[PCOQ_TAIL_REGNUM] = fp + 16;
1504 frame_saved_regs->regs[PCSQ_TAIL_REGNUM] = fp + 20;
1510 register struct frame_info *frame = get_current_frame ();
1511 register CORE_ADDR fp, npc, target_pc;
1512 register int regnum;
1513 struct frame_saved_regs fsr;
1516 fp = FRAME_FP (frame);
1517 get_frame_saved_regs (frame, &fsr);
1519 #ifndef NO_PC_SPACE_QUEUE_RESTORE
1520 if (fsr.regs[IPSW_REGNUM]) /* Restoring a call dummy frame */
1521 restore_pc_queue (&fsr);
1524 for (regnum = 31; regnum > 0; regnum--)
1525 if (fsr.regs[regnum])
1526 write_register (regnum, read_memory_integer (fsr.regs[regnum], 4));
1528 for (regnum = NUM_REGS - 1; regnum >= FP0_REGNUM ; regnum--)
1529 if (fsr.regs[regnum])
1531 read_memory (fsr.regs[regnum], (char *)&freg_buffer, 8);
1532 write_register_bytes (REGISTER_BYTE (regnum), (char *)&freg_buffer, 8);
1535 if (fsr.regs[IPSW_REGNUM])
1536 write_register (IPSW_REGNUM,
1537 read_memory_integer (fsr.regs[IPSW_REGNUM], 4));
1539 if (fsr.regs[SAR_REGNUM])
1540 write_register (SAR_REGNUM,
1541 read_memory_integer (fsr.regs[SAR_REGNUM], 4));
1543 /* If the PC was explicitly saved, then just restore it. */
1544 if (fsr.regs[PCOQ_TAIL_REGNUM])
1546 npc = read_memory_integer (fsr.regs[PCOQ_TAIL_REGNUM], 4);
1547 write_register (PCOQ_TAIL_REGNUM, npc);
1549 /* Else use the value in %rp to set the new PC. */
1552 npc = read_register (RP_REGNUM);
1556 write_register (FP_REGNUM, read_memory_integer (fp, 4));
1558 if (fsr.regs[IPSW_REGNUM]) /* call dummy */
1559 write_register (SP_REGNUM, fp - 48);
1561 write_register (SP_REGNUM, fp);
1563 /* The PC we just restored may be inside a return trampoline. If so
1564 we want to restart the inferior and run it through the trampoline.
1566 Do this by setting a momentary breakpoint at the location the
1567 trampoline returns to.
1569 Don't skip through the trampoline if we're popping a dummy frame. */
1570 target_pc = SKIP_TRAMPOLINE_CODE (npc & ~0x3) & ~0x3;
1571 if (target_pc && !fsr.regs[IPSW_REGNUM])
1573 struct symtab_and_line sal;
1574 struct breakpoint *breakpoint;
1575 struct cleanup *old_chain;
1577 /* Set up our breakpoint. Set it to be silent as the MI code
1578 for "return_command" will print the frame we returned to. */
1579 sal = find_pc_line (target_pc, 0);
1581 breakpoint = set_momentary_breakpoint (sal, NULL, bp_finish);
1582 breakpoint->silent = 1;
1584 /* So we can clean things up. */
1585 old_chain = make_cleanup ((make_cleanup_func) delete_breakpoint, breakpoint);
1587 /* Start up the inferior. */
1588 clear_proceed_status ();
1589 proceed_to_finish = 1;
1590 proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
1592 /* Perform our cleanups. */
1593 do_cleanups (old_chain);
1595 flush_cached_frames ();
1598 /* After returning to a dummy on the stack, restore the instruction
1599 queue space registers. */
1602 restore_pc_queue (fsr)
1603 struct frame_saved_regs *fsr;
1605 CORE_ADDR pc = read_pc ();
1606 CORE_ADDR new_pc = read_memory_integer (fsr->regs[PCOQ_HEAD_REGNUM], 4);
1607 struct target_waitstatus w;
1610 /* Advance past break instruction in the call dummy. */
1611 write_register (PCOQ_HEAD_REGNUM, pc + 4);
1612 write_register (PCOQ_TAIL_REGNUM, pc + 8);
1614 /* HPUX doesn't let us set the space registers or the space
1615 registers of the PC queue through ptrace. Boo, hiss.
1616 Conveniently, the call dummy has this sequence of instructions
1621 So, load up the registers and single step until we are in the
1624 write_register (21, read_memory_integer (fsr->regs[PCSQ_HEAD_REGNUM], 4));
1625 write_register (22, new_pc);
1627 for (insn_count = 0; insn_count < 3; insn_count++)
1629 /* FIXME: What if the inferior gets a signal right now? Want to
1630 merge this into wait_for_inferior (as a special kind of
1631 watchpoint? By setting a breakpoint at the end? Is there
1632 any other choice? Is there *any* way to do this stuff with
1633 ptrace() or some equivalent?). */
1635 target_wait (inferior_pid, &w);
1637 if (w.kind == TARGET_WAITKIND_SIGNALLED)
1639 stop_signal = w.value.sig;
1640 terminal_ours_for_output ();
1641 printf_unfiltered ("\nProgram terminated with signal %s, %s.\n",
1642 target_signal_to_name (stop_signal),
1643 target_signal_to_string (stop_signal));
1644 gdb_flush (gdb_stdout);
1648 target_terminal_ours ();
1649 target_fetch_registers (-1);
1655 hppa_push_arguments (nargs, args, sp, struct_return, struct_addr)
1660 CORE_ADDR struct_addr;
1662 /* array of arguments' offsets */
1663 int *offset = (int *)alloca(nargs * sizeof (int));
1667 for (i = 0; i < nargs; i++)
1670 /* cum is the sum of the lengths in bytes of
1671 the arguments seen so far */
1672 cum += TYPE_LENGTH (VALUE_TYPE (args[i]));
1674 /* value must go at proper alignment. Assume alignment is a
1676 alignment = hppa_alignof (VALUE_TYPE (args[i]));
1678 if (cum % alignment)
1679 cum = (cum + alignment) & -alignment;
1683 sp += max ((cum + 7) & -8, 16);
1685 for (i = 0; i < nargs; i++)
1686 write_memory (sp + offset[i], VALUE_CONTENTS (args[i]),
1687 TYPE_LENGTH (VALUE_TYPE (args[i])));
1690 write_register (28, struct_addr);
1695 /* elz: I am rewriting this function, because the one above is a very
1696 obscure piece of code.
1697 This function pushes the arguments on the stack. The stack grows up
1699 Each argument goes in one (or more) word (4 bytes) on the stack.
1700 The first four words for the args must be allocated, even if they
1702 The 'topmost' arg is arg0, the 'bottom-most' is arg3. (if you think of
1703 them as 1 word long).
1704 Below these there can be any number of arguments, as needed by the function.
1705 If an arg is bigger than one word, it will be written on the stack
1706 occupying as many words as needed. Args that are bigger than 64bits
1707 are not copied on the stack, a pointer is passed instead.
1709 On top of the arg0 word there are other 8 words (32bytes) which are used
1710 for other purposes */
1713 hppa_push_arguments (nargs, args, sp, struct_return, struct_addr)
1718 CORE_ADDR struct_addr;
1720 /* array of arguments' offsets */
1721 int *offset = (int *)alloca(nargs * sizeof (int));
1722 /* array of arguments' lengths: real lengths in bytes, not aligned to word size */
1723 int *lengths = (int *)alloca(nargs * sizeof (int));
1725 int bytes_reserved; /* this is the number of bytes on the stack occupied by an
1726 argument. This will be always a multiple of 4 */
1728 int cum_bytes_reserved = 0; /* this is the total number of bytes reserved by the args
1729 seen so far. It is a multiple of 4 always */
1730 int cum_bytes_aligned = 0; /* same as above, but aligned on 8 bytes */
1733 /* When an arg does not occupy a whole word, for instance in bitfields:
1734 if the arg is x bits (0<x<32), it must be written
1735 starting from the (x-1)-th position down until the 0-th position.
1736 It is enough to align it to the word. */
1737 /* if an arg occupies 8 bytes, it must be aligned on the 64-bits
1738 high order word in odd arg word. */
1739 /* if an arg is larger than 64 bits, we need to pass a pointer to it, and
1740 copy the actual value on the stack, so that the callee can play with it.
1741 This is taken care of in valops.c in the call_function_by_hand function.
1742 The argument that is received in this function here has already be converted
1743 to a pointer to whatever is needed, so that it just can be pushed
1744 as a word argument */
1746 for (i = 0; i < nargs; i++)
1749 lengths[i] = TYPE_LENGTH (VALUE_TYPE (args[i]));
1752 bytes_reserved = (lengths[i] / 4) * 4 + 4;
1754 bytes_reserved = lengths[i];
1756 offset[i] = cum_bytes_reserved + lengths[i];
1758 if ((bytes_reserved == 8) && (offset[i] % 8)) /* if 64-bit arg is not 64 bit aligned */
1761 /* bytes_reserved is already aligned to the word, so we put it at one word
1762 more down the stack. This will leave one empty word on the
1763 stack, and one unused register. This is OK, see the calling
1765 /* the offset may have to be moved to the corresponding position
1766 one word down the stack, to maintain
1768 new_offset = (offset[i] / 8) * 8 + 8;
1769 if ((new_offset - offset[i]) >=4)
1771 bytes_reserved += 4;
1776 cum_bytes_reserved += bytes_reserved;
1780 /* now move up the sp to reserve at least 4 words required for the args,
1781 or more than this if needed */
1782 /* wee also need to keep the sp aligned to 8 bytes */
1783 cum_bytes_aligned = STACK_ALIGN (cum_bytes_reserved);
1784 sp += max (cum_bytes_aligned, 16);
1786 /* now write each of the args at the proper offset down the stack */
1787 for (i = 0; i < nargs; i++)
1788 write_memory (sp - offset[i], VALUE_CONTENTS (args[i]), lengths[i]);
1791 /* if a structure has to be returned, set up register 28 to hold its address */
1793 write_register (28, struct_addr);
1795 /* the stack will have other 8 words on top of the args */
1800 /* elz: this function returns a value which is built looking at the given address.
1801 It is called from call_function_by_hand, in case we need to return a
1802 value which is larger than 64 bits, and it is stored in the stack rather than
1803 in the registers r28 and r29 or fr4.
1804 This function does the same stuff as value_being_returned in values.c, but
1805 gets the value from the stack rather than from the buffer where all the
1806 registers were saved when the function called completed. */
1808 hppa_value_returned_from_stack (valtype , addr)
1809 register struct type *valtype;
1812 register value_ptr val;
1814 val = allocate_value (valtype);
1815 CHECK_TYPEDEF (valtype);
1816 target_read_memory(addr, VALUE_CONTENTS_RAW (val), TYPE_LENGTH (valtype));
1823 /* elz: Used to lookup a symbol in the shared libraries.
1824 This function calls shl_findsym, indirectly through a
1825 call to __d_shl_get. __d_shl_get is in end.c, which is always
1826 linked in by the hp compilers/linkers.
1827 The call to shl_findsym cannot be made directly because it needs
1828 to be active in target address space.
1829 inputs: - minimal symbol pointer for the function we want to look up
1830 - address in target space of the descriptor for the library
1831 where we want to look the symbol up.
1832 This address is retrieved using the
1833 som_solib_get_solib_by_pc function (somsolib.c).
1834 output: - real address in the library of the function.
1835 note: the handle can be null, in which case shl_findsym will look for
1836 the symbol in all the loaded shared libraries.
1837 files to look at if you need reference on this stuff:
1838 dld.c, dld_shl_findsym.c
1840 man entry for shl_findsym */
1843 find_stub_with_shl_get(function, handle)
1844 struct minimal_symbol *function;
1847 struct symbol *get_sym, *symbol2;
1848 struct minimal_symbol *buff_minsym, *msymbol;
1851 value_ptr funcval, val;
1853 int x, namelen, err_value, tmp = -1;
1854 CORE_ADDR endo_buff_addr, value_return_addr, errno_return_addr;
1855 CORE_ADDR stub_addr;
1858 args = (value_ptr *) alloca (sizeof (value_ptr) * 8); /* 6 for the arguments and one null one??? */
1859 funcval = find_function_in_inferior("__d_shl_get");
1860 get_sym = lookup_symbol("__d_shl_get", NULL, VAR_NAMESPACE, NULL, NULL);
1861 buff_minsym = lookup_minimal_symbol("__buffer", NULL, NULL);
1862 msymbol = lookup_minimal_symbol ("__shldp", NULL, NULL);
1863 symbol2 = lookup_symbol("__shldp", NULL, VAR_NAMESPACE, NULL, NULL);
1864 endo_buff_addr = SYMBOL_VALUE_ADDRESS (buff_minsym);
1865 namelen = strlen(SYMBOL_NAME(function));
1866 value_return_addr = endo_buff_addr + namelen;
1867 ftype = check_typedef(SYMBOL_TYPE(get_sym));
1870 if ((x=value_return_addr % 64) !=0)
1871 value_return_addr = value_return_addr + 64 - x;
1873 errno_return_addr = value_return_addr + 64;
1876 /* set up stuff needed by __d_shl_get in buffer in end.o */
1878 target_write_memory(endo_buff_addr, SYMBOL_NAME(function), namelen);
1880 target_write_memory(value_return_addr, (char *) &tmp, 4);
1882 target_write_memory(errno_return_addr, (char *) &tmp, 4);
1884 target_write_memory(SYMBOL_VALUE_ADDRESS(msymbol),
1885 (char *)&handle, 4);
1887 /* now prepare the arguments for the call */
1889 args[0] = value_from_longest (TYPE_FIELD_TYPE(ftype, 0), 12);
1890 args[1] = value_from_longest (TYPE_FIELD_TYPE(ftype, 1), SYMBOL_VALUE_ADDRESS(msymbol));
1891 args[2] = value_from_longest (TYPE_FIELD_TYPE(ftype, 2), endo_buff_addr);
1892 args[3] = value_from_longest (TYPE_FIELD_TYPE(ftype, 3), TYPE_PROCEDURE);
1893 args[4] = value_from_longest (TYPE_FIELD_TYPE(ftype, 4), value_return_addr);
1894 args[5] = value_from_longest (TYPE_FIELD_TYPE(ftype, 5), errno_return_addr);
1896 /* now call the function */
1898 val = call_function_by_hand(funcval, 6, args);
1900 /* now get the results */
1902 target_read_memory(errno_return_addr, (char *) &err_value, sizeof(err_value));
1904 target_read_memory(value_return_addr, (char *) &stub_addr, sizeof(stub_addr));
1906 error("call to __d_shl_get failed, error code is %d", err_value); /* purecov: deadcode */
1911 /* Cover routine for find_stub_with_shl_get to pass to catch_errors */
1913 cover_find_stub_with_shl_get (args)
1914 args_for_find_stub * args;
1916 return find_stub_with_shl_get (args->msym, args->solib_handle);
1920 /* Insert the specified number of args and function address
1921 into a call sequence of the above form stored at DUMMYNAME.
1923 On the hppa we need to call the stack dummy through $$dyncall.
1924 Therefore our version of FIX_CALL_DUMMY takes an extra argument,
1925 real_pc, which is the location where gdb should start up the
1926 inferior to do the function call. */
1929 hppa_fix_call_dummy (dummy, pc, fun, nargs, args, type, gcc_p)
1938 CORE_ADDR dyncall_addr;
1939 struct minimal_symbol *msymbol;
1940 struct minimal_symbol *trampoline;
1941 int flags = read_register (FLAGS_REGNUM);
1942 struct unwind_table_entry *u;
1943 CORE_ADDR new_stub=0;
1944 CORE_ADDR solib_handle=0;
1947 msymbol = lookup_minimal_symbol ("$$dyncall", NULL, NULL);
1948 if (msymbol == NULL)
1949 error ("Can't find an address for $$dyncall trampoline"); /* purecov: deadcode */
1951 dyncall_addr = SYMBOL_VALUE_ADDRESS (msymbol);
1953 /* FUN could be a procedure label, in which case we have to get
1954 its real address and the value of its GOT/DP. */
1957 /* Get the GOT/DP value for the target function. It's
1958 at *(fun+4). Note the call dummy is *NOT* allowed to
1959 trash %r19 before calling the target function. */
1960 write_register (19, read_memory_integer ((fun & ~0x3) + 4, 4));
1962 /* Now get the real address for the function we are calling, it's
1964 fun = (CORE_ADDR) read_memory_integer (fun & ~0x3, 4);
1969 #ifndef GDB_TARGET_IS_PA_ELF
1970 /* FUN could be either an export stub, or the real address of a
1971 function in a shared library. We must call an import stub
1972 rather than the export stub or real function for lazy binding
1973 to work correctly. */
1975 /* elz: let's see if fun is in a shared library */
1976 solib_handle = som_solib_get_solib_by_pc(fun);
1978 /* elz: for 10.30 and 11.00 the calls via __d_plt_call cannot be made
1979 via import stubs, only via plables, so this code here becomes useless.
1980 On 10.20, the plables mechanism works too, so we just ignore this import
1985 struct objfile *objfile;
1986 struct minimal_symbol *funsymbol, *stub_symbol;
1987 CORE_ADDR newfun = 0;
1989 funsymbol = lookup_minimal_symbol_by_pc (fun);
1991 error ("Unable to find minimal symbol for target fucntion.\n");
1993 /* Search all the object files for an import symbol with the
1995 ALL_OBJFILES (objfile)
1997 stub_symbol = lookup_minimal_symbol (SYMBOL_NAME (funsymbol),
1999 /* Found a symbol with the right name. */
2002 struct unwind_table_entry *u;
2003 /* It must be a shared library trampoline. */
2004 if (MSYMBOL_TYPE (stub_symbol) != mst_solib_trampoline)
2007 /* It must also be an import stub. */
2008 u = find_unwind_entry (SYMBOL_VALUE (stub_symbol));
2009 if (!u || u->stub_unwind.stub_type != IMPORT)
2012 /* OK. Looks like the correct import stub. */
2013 newfun = SYMBOL_VALUE (stub_symbol);
2018 write_register (19, som_solib_get_got_by_pc (fun));
2020 #endif /* end of if 0 */
2024 /* If we are calling an import stub (eg calling into a dynamic library)
2025 then have sr4export call the magic __d_plt_call routine which is linked
2026 in from end.o. (You can't use _sr4export to call the import stub as
2027 the value in sp-24 will get fried and you end up returning to the
2028 wrong location. You can't call the import stub directly as the code
2029 to bind the PLT entry to a function can't return to a stack address.) */
2032 There does not have to be an import stub to call a routine in a
2033 different load module (note: a "load module" is an a.out or a shared
2034 library). If you call a routine indirectly, going through $$dyncall (or
2035 $$dyncall_external), you won't go through an import stub. Import stubs
2036 are only used for direct calls to an imported routine.
2038 What you (wdb) need is to go through $$dyncall with a proper plabel for
2039 the imported routine. shl_findsym() returns you the address of a plabel
2040 suitable for use in making an indirect call through, e.g., through
2042 This is taken care below with the call to find_stub_.... */
2044 /* elz: this check here is not necessary if we are going to call stuff through
2045 plabels only, we just now check whether the function we call is in a shlib */
2046 u = find_unwind_entry (fun);
2048 if (u && u->stub_unwind.stub_type == IMPORT ||
2049 (!(u && u->stub_unwind.stub_type == IMPORT) && solib_handle))
2055 /* Prefer __gcc_plt_call over the HP supplied routine because
2056 __gcc_plt_call works for any number of arguments. */
2057 trampoline = lookup_minimal_symbol ("__gcc_plt_call", NULL, NULL);
2058 if (trampoline == NULL)
2059 trampoline = lookup_minimal_symbol ("__d_plt_call", NULL, NULL);
2061 if (trampoline == NULL)
2063 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)");
2065 /* This is where sr4export will jump to. */
2066 new_fun = SYMBOL_VALUE_ADDRESS (trampoline);
2068 if (strcmp (SYMBOL_NAME (trampoline), "__d_plt_call") == 0)
2070 /* if the function is in a shared library, but we have no import sub for
2071 it, we need to get the plabel from a call to __d_shl_get, which is a
2072 function in end.o. To call this function we need to set up various things */
2074 /* actually now we just use the plabel any time we make the call,
2075 because on 10.30 and 11.00 this is the only acceptable way. This also
2076 works fine for 10.20 */
2077 /* if (!(u && u->stub_unwind.stub_type == IMPORT) && solib_handle) */
2079 struct minimal_symbol *fmsymbol = lookup_minimal_symbol_by_pc(fun);
2081 new_stub = find_stub_with_shl_get(fmsymbol, solib_handle);
2083 if (new_stub == NULL)
2084 error("Can't find an import stub for %s", SYMBOL_NAME(fmsymbol)); /* purecov: deadcode */
2087 /* We have to store the address of the stub in __shlib_funcptr. */
2088 msymbol = lookup_minimal_symbol ("__shlib_funcptr", NULL,
2089 (struct objfile *)NULL);
2090 if (msymbol == NULL)
2091 error ("Can't find an address for __shlib_funcptr"); /* purecov: deadcode */
2093 /* if (new_stub != NULL) */
2094 target_write_memory (SYMBOL_VALUE_ADDRESS (msymbol), (char *)&new_stub, 4);
2095 /* this is no longer used */
2097 target_write_memory (SYMBOL_VALUE_ADDRESS (msymbol), (char *)&fun, 4); */
2099 /* We want sr4export to call __d_plt_call, so we claim it is
2100 the final target. Clear trampoline. */
2106 /* Store upper 21 bits of function address into ldil. fun will either be
2107 the final target (most cases) or __d_plt_call when calling into a shared
2108 library and __gcc_plt_call is not available. */
2109 store_unsigned_integer
2110 (&dummy[FUNC_LDIL_OFFSET],
2112 deposit_21 (fun >> 11,
2113 extract_unsigned_integer (&dummy[FUNC_LDIL_OFFSET],
2114 INSTRUCTION_SIZE)));
2116 /* Store lower 11 bits of function address into ldo */
2117 store_unsigned_integer
2118 (&dummy[FUNC_LDO_OFFSET],
2120 deposit_14 (fun & MASK_11,
2121 extract_unsigned_integer (&dummy[FUNC_LDO_OFFSET],
2122 INSTRUCTION_SIZE)));
2123 #ifdef SR4EXPORT_LDIL_OFFSET
2126 CORE_ADDR trampoline_addr;
2128 /* We may still need sr4export's address too. */
2130 if (trampoline == NULL)
2132 msymbol = lookup_minimal_symbol ("_sr4export", NULL, NULL);
2133 if (msymbol == NULL)
2134 error ("Can't find an address for _sr4export trampoline"); /* purecov: deadcode */
2136 trampoline_addr = SYMBOL_VALUE_ADDRESS (msymbol);
2139 trampoline_addr = SYMBOL_VALUE_ADDRESS (trampoline);
2142 /* Store upper 21 bits of trampoline's address into ldil */
2143 store_unsigned_integer
2144 (&dummy[SR4EXPORT_LDIL_OFFSET],
2146 deposit_21 (trampoline_addr >> 11,
2147 extract_unsigned_integer (&dummy[SR4EXPORT_LDIL_OFFSET],
2148 INSTRUCTION_SIZE)));
2150 /* Store lower 11 bits of trampoline's address into ldo */
2151 store_unsigned_integer
2152 (&dummy[SR4EXPORT_LDO_OFFSET],
2154 deposit_14 (trampoline_addr & MASK_11,
2155 extract_unsigned_integer (&dummy[SR4EXPORT_LDO_OFFSET],
2156 INSTRUCTION_SIZE)));
2160 write_register (22, pc);
2162 /* If we are in a syscall, then we should call the stack dummy
2163 directly. $$dyncall is not needed as the kernel sets up the
2164 space id registers properly based on the value in %r31. In
2165 fact calling $$dyncall will not work because the value in %r22
2166 will be clobbered on the syscall exit path.
2168 Similarly if the current PC is in a shared library. Note however,
2169 this scheme won't work if the shared library isn't mapped into
2170 the same space as the stack. */
2173 #ifndef GDB_TARGET_IS_PA_ELF
2174 else if (som_solib_get_got_by_pc (target_read_pc (inferior_pid)))
2178 return dyncall_addr;
2185 /* If the pid is in a syscall, then the FP register is not readable.
2186 We'll return zero in that case, rather than attempting to read it
2187 and cause a warning. */
2189 target_read_fp (pid)
2192 int flags = read_register (FLAGS_REGNUM);
2195 return (CORE_ADDR) 0;
2198 /* This is the only site that may directly read_register () the FP
2199 register. All others must use TARGET_READ_FP (). */
2200 return read_register (FP_REGNUM);
2204 /* Get the PC from %r31 if currently in a syscall. Also mask out privilege
2208 target_read_pc (pid)
2211 int flags = read_register_pid (FLAGS_REGNUM, pid);
2213 /* The following test does not belong here. It is OS-specific, and belongs
2215 /* Test SS_INSYSCALL */
2217 return read_register_pid (31, pid) & ~0x3;
2219 return read_register_pid (PC_REGNUM, pid) & ~0x3;
2222 /* Write out the PC. If currently in a syscall, then also write the new
2223 PC value into %r31. */
2226 target_write_pc (v, pid)
2230 int flags = read_register_pid (FLAGS_REGNUM, pid);
2232 /* The following test does not belong here. It is OS-specific, and belongs
2234 /* If in a syscall, then set %r31. Also make sure to get the
2235 privilege bits set correctly. */
2236 /* Test SS_INSYSCALL */
2238 write_register_pid (31, v | 0x3, pid);
2240 write_register_pid (PC_REGNUM, v, pid);
2241 write_register_pid (NPC_REGNUM, v + 4, pid);
2244 /* return the alignment of a type in bytes. Structures have the maximum
2245 alignment required by their fields. */
2251 int max_align, align, i;
2252 CHECK_TYPEDEF (type);
2253 switch (TYPE_CODE (type))
2258 return TYPE_LENGTH (type);
2259 case TYPE_CODE_ARRAY:
2260 return hppa_alignof (TYPE_FIELD_TYPE (type, 0));
2261 case TYPE_CODE_STRUCT:
2262 case TYPE_CODE_UNION:
2264 for (i = 0; i < TYPE_NFIELDS (type); i++)
2266 /* Bit fields have no real alignment. */
2267 /* if (!TYPE_FIELD_BITPOS (type, i)) */
2268 if (!TYPE_FIELD_BITSIZE (type, i)) /* elz: this should be bitsize */
2270 align = hppa_alignof (TYPE_FIELD_TYPE (type, i));
2271 max_align = max (max_align, align);
2280 /* Print the register regnum, or all registers if regnum is -1 */
2283 pa_do_registers_info (regnum, fpregs)
2287 char raw_regs [REGISTER_BYTES];
2290 /* Make a copy of gdb's save area (may cause actual
2291 reads from the target). */
2292 for (i = 0; i < NUM_REGS; i++)
2293 read_relative_register_raw_bytes (i, raw_regs + REGISTER_BYTE (i));
2296 pa_print_registers (raw_regs, regnum, fpregs);
2297 else if (regnum < FP4_REGNUM) {
2300 /* Why is the value not passed through "extract_signed_integer"
2301 as in "pa_print_registers" below? */
2302 pa_register_look_aside(raw_regs, regnum, ®_val[0]);
2305 printf_unfiltered ("%s %x\n", REGISTER_NAME (regnum), reg_val[1]);
2308 /* Fancy % formats to prevent leading zeros. */
2310 printf_unfiltered("%s %x\n", REGISTER_NAME (regnum), reg_val[1]);
2312 printf_unfiltered("%s %x%8.8x\n", REGISTER_NAME (regnum),
2313 reg_val[0], reg_val[1]);
2317 /* Note that real floating point values only start at
2318 FP4_REGNUM. FP0 and up are just status and error
2319 registers, which have integral (bit) values. */
2320 pa_print_fp_reg (regnum);
2323 /********** new function ********************/
2325 pa_do_strcat_registers_info (regnum, fpregs, stream, precision)
2329 enum precision_type precision;
2331 char raw_regs [REGISTER_BYTES];
2334 /* Make a copy of gdb's save area (may cause actual
2335 reads from the target). */
2336 for (i = 0; i < NUM_REGS; i++)
2337 read_relative_register_raw_bytes (i, raw_regs + REGISTER_BYTE (i));
2340 pa_strcat_registers (raw_regs, regnum, fpregs, stream);
2342 else if (regnum < FP4_REGNUM) {
2345 /* Why is the value not passed through "extract_signed_integer"
2346 as in "pa_print_registers" below? */
2347 pa_register_look_aside(raw_regs, regnum, ®_val[0]);
2350 fprintf_unfiltered (stream, "%s %x", REGISTER_NAME (regnum), reg_val[1]);
2353 /* Fancy % formats to prevent leading zeros. */
2355 fprintf_unfiltered(stream, "%s %x", REGISTER_NAME (regnum),
2358 fprintf_unfiltered(stream, "%s %x%8.8x", REGISTER_NAME (regnum),
2359 reg_val[0], reg_val[1]);
2363 /* Note that real floating point values only start at
2364 FP4_REGNUM. FP0 and up are just status and error
2365 registers, which have integral (bit) values. */
2366 pa_strcat_fp_reg (regnum, stream, precision);
2369 /* If this is a PA2.0 machine, fetch the real 64-bit register
2370 value. Otherwise use the info from gdb's saved register area.
2372 Note that reg_val is really expected to be an array of longs,
2373 with two elements. */
2375 pa_register_look_aside(raw_regs, regnum, raw_val)
2380 static int know_which = 0; /* False */
2383 unsigned int offset;
2388 char buf[MAX_REGISTER_RAW_SIZE];
2392 if(CPU_PA_RISC2_0 == sysconf(_SC_CPU_VERSION)) {
2396 know_which = 1; /* True */
2403 raw_val[1] = *(long *)(raw_regs + REGISTER_BYTE(regnum));
2407 /* Code below copied from hppah-nat.c, with fixes for wide
2408 registers, using different area of save_state, etc. */
2409 if (regnum == FLAGS_REGNUM || regnum >= FP0_REGNUM ||
2410 !HAVE_STRUCT_SAVE_STATE_T || !HAVE_STRUCT_MEMBER_SS_WIDE) {
2411 /* Use narrow regs area of save_state and default macro. */
2412 offset = U_REGS_OFFSET;
2413 regaddr = register_addr(regnum, offset);
2417 /* Use wide regs area, and calculate registers as 8 bytes wide.
2419 We'd like to do this, but current version of "C" doesn't
2422 offset = offsetof(save_state_t, ss_wide);
2424 Note that to avoid "C" doing typed pointer arithmetic, we
2425 have to cast away the type in our offset calculation:
2426 otherwise we get an offset of 1! */
2428 /* NB: save_state_t is not available before HPUX 9.
2429 The ss_wide field is not available previous to HPUX 10.20,
2430 so to avoid compile-time warnings, we only compile this for
2431 PA 2.0 processors. This control path should only be followed
2432 if we're debugging a PA 2.0 processor, so this should not cause
2435 /* #if the following code out so that this file can still be
2436 compiled on older HPUX boxes (< 10.20) which don't have
2437 this structure/structure member. */
2438 #if HAVE_STRUCT_SAVE_STATE_T == 1 && HAVE_STRUCT_MEMBER_SS_WIDE == 1
2441 offset = ((int) &temp.ss_wide) - ((int) &temp);
2442 regaddr = offset + regnum * 8;
2447 for(i = start; i < 2; i++)
2450 raw_val[i] = call_ptrace (PT_RUREGS, inferior_pid,
2451 (PTRACE_ARG3_TYPE) regaddr, 0);
2454 /* Warning, not error, in case we are attached; sometimes the
2455 kernel doesn't let us at the registers. */
2456 char *err = safe_strerror (errno);
2457 char *msg = alloca (strlen (err) + 128);
2458 sprintf (msg, "reading register %s: %s", REGISTER_NAME (regnum), err);
2463 regaddr += sizeof (long);
2466 if (regnum == PCOQ_HEAD_REGNUM || regnum == PCOQ_TAIL_REGNUM)
2467 raw_val[1] &= ~0x3; /* I think we're masking out space bits */
2473 /* "Info all-reg" command */
2476 pa_print_registers (raw_regs, regnum, fpregs)
2482 long raw_val[2]; /* Alas, we are compiled so that "long long" is 32 bits */
2485 for (i = 0; i < 18; i++)
2487 for (j = 0; j < 4; j++)
2489 /* Q: Why is the value passed through "extract_signed_integer",
2490 while above, in "pa_do_registers_info" it isn't?
2492 pa_register_look_aside(raw_regs, i+(j*18), &raw_val[0]);
2494 /* Even fancier % formats to prevent leading zeros
2495 and still maintain the output in columns. */
2497 /* Being big-endian, on this machine the low bits
2498 (the ones we want to look at) are in the second longword. */
2499 long_val = extract_signed_integer (&raw_val[1], 4);
2500 printf_filtered ("%8.8s: %8x ",
2501 REGISTER_NAME (i+(j*18)), long_val);
2504 /* raw_val = extract_signed_integer(&raw_val, 8); */
2506 printf_filtered("%8.8s: %8x ",
2507 REGISTER_NAME (i+(j*18)), raw_val[1]);
2509 printf_filtered("%8.8s: %8x%8.8x ", REGISTER_NAME (i+(j*18)),
2510 raw_val[0], raw_val[1]);
2513 printf_unfiltered ("\n");
2517 for (i = FP4_REGNUM; i < NUM_REGS; i++) /* FP4_REGNUM == 72 */
2518 pa_print_fp_reg (i);
2521 /************* new function ******************/
2523 pa_strcat_registers (raw_regs, regnum, fpregs, stream)
2530 long raw_val[2]; /* Alas, we are compiled so that "long long" is 32 bits */
2532 enum precision_type precision;
2534 precision = unspecified_precision;
2536 for (i = 0; i < 18; i++)
2538 for (j = 0; j < 4; j++)
2540 /* Q: Why is the value passed through "extract_signed_integer",
2541 while above, in "pa_do_registers_info" it isn't?
2543 pa_register_look_aside(raw_regs, i+(j*18), &raw_val[0]);
2545 /* Even fancier % formats to prevent leading zeros
2546 and still maintain the output in columns. */
2548 /* Being big-endian, on this machine the low bits
2549 (the ones we want to look at) are in the second longword. */
2550 long_val = extract_signed_integer(&raw_val[1], 4);
2551 fprintf_filtered (stream, "%8.8s: %8x ", REGISTER_NAME (i+(j*18)), long_val);
2554 /* raw_val = extract_signed_integer(&raw_val, 8); */
2556 fprintf_filtered(stream, "%8.8s: %8x ", REGISTER_NAME (i+(j*18)),
2559 fprintf_filtered(stream, "%8.8s: %8x%8.8x ", REGISTER_NAME (i+(j*18)),
2560 raw_val[0], raw_val[1]);
2563 fprintf_unfiltered (stream, "\n");
2567 for (i = FP4_REGNUM; i < NUM_REGS; i++) /* FP4_REGNUM == 72 */
2568 pa_strcat_fp_reg (i, stream, precision);
2575 char raw_buffer[MAX_REGISTER_RAW_SIZE];
2576 char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE];
2578 /* Get 32bits of data. */
2579 read_relative_register_raw_bytes (i, raw_buffer);
2581 /* Put it in the buffer. No conversions are ever necessary. */
2582 memcpy (virtual_buffer, raw_buffer, REGISTER_RAW_SIZE (i));
2584 fputs_filtered (REGISTER_NAME (i), gdb_stdout);
2585 print_spaces_filtered (8 - strlen (REGISTER_NAME (i)), gdb_stdout);
2586 fputs_filtered ("(single precision) ", gdb_stdout);
2588 val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0, 0, gdb_stdout, 0,
2589 1, 0, Val_pretty_default);
2590 printf_filtered ("\n");
2592 /* If "i" is even, then this register can also be a double-precision
2593 FP register. Dump it out as such. */
2596 /* Get the data in raw format for the 2nd half. */
2597 read_relative_register_raw_bytes (i + 1, raw_buffer);
2599 /* Copy it into the appropriate part of the virtual buffer. */
2600 memcpy (virtual_buffer + REGISTER_RAW_SIZE (i), raw_buffer,
2601 REGISTER_RAW_SIZE (i));
2603 /* Dump it as a double. */
2604 fputs_filtered (REGISTER_NAME (i), gdb_stdout);
2605 print_spaces_filtered (8 - strlen (REGISTER_NAME (i)), gdb_stdout);
2606 fputs_filtered ("(double precision) ", gdb_stdout);
2608 val_print (builtin_type_double, virtual_buffer, 0, 0, gdb_stdout, 0,
2609 1, 0, Val_pretty_default);
2610 printf_filtered ("\n");
2614 /*************** new function ***********************/
2616 pa_strcat_fp_reg (i, stream, precision)
2619 enum precision_type precision;
2621 char raw_buffer[MAX_REGISTER_RAW_SIZE];
2622 char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE];
2624 fputs_filtered (REGISTER_NAME (i), stream);
2625 print_spaces_filtered (8 - strlen (REGISTER_NAME (i)), stream);
2627 /* Get 32bits of data. */
2628 read_relative_register_raw_bytes (i, raw_buffer);
2630 /* Put it in the buffer. No conversions are ever necessary. */
2631 memcpy (virtual_buffer, raw_buffer, REGISTER_RAW_SIZE (i));
2633 if (precision == double_precision && (i % 2) == 0)
2636 char raw_buf[MAX_REGISTER_RAW_SIZE];
2638 /* Get the data in raw format for the 2nd half. */
2639 read_relative_register_raw_bytes (i + 1, raw_buf);
2641 /* Copy it into the appropriate part of the virtual buffer. */
2642 memcpy (virtual_buffer + REGISTER_RAW_SIZE(i), raw_buf, REGISTER_RAW_SIZE (i));
2644 val_print (builtin_type_double, virtual_buffer, 0, 0 , stream, 0,
2645 1, 0, Val_pretty_default);
2649 val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0, 0, stream, 0,
2650 1, 0, Val_pretty_default);
2655 /* Return one if PC is in the call path of a trampoline, else return zero.
2657 Note we return one for *any* call trampoline (long-call, arg-reloc), not
2658 just shared library trampolines (import, export). */
2661 in_solib_call_trampoline (pc, name)
2665 struct minimal_symbol *minsym;
2666 struct unwind_table_entry *u;
2667 static CORE_ADDR dyncall = 0;
2668 static CORE_ADDR sr4export = 0;
2670 /* FIXME XXX - dyncall and sr4export must be initialized whenever we get a
2673 /* First see if PC is in one of the two C-library trampolines. */
2676 minsym = lookup_minimal_symbol ("$$dyncall", NULL, NULL);
2678 dyncall = SYMBOL_VALUE_ADDRESS (minsym);
2685 minsym = lookup_minimal_symbol ("_sr4export", NULL, NULL);
2687 sr4export = SYMBOL_VALUE_ADDRESS (minsym);
2692 if (pc == dyncall || pc == sr4export)
2695 /* Get the unwind descriptor corresponding to PC, return zero
2696 if no unwind was found. */
2697 u = find_unwind_entry (pc);
2701 /* If this isn't a linker stub, then return now. */
2702 if (u->stub_unwind.stub_type == 0)
2705 /* By definition a long-branch stub is a call stub. */
2706 if (u->stub_unwind.stub_type == LONG_BRANCH)
2709 /* The call and return path execute the same instructions within
2710 an IMPORT stub! So an IMPORT stub is both a call and return
2712 if (u->stub_unwind.stub_type == IMPORT)
2715 /* Parameter relocation stubs always have a call path and may have a
2717 if (u->stub_unwind.stub_type == PARAMETER_RELOCATION
2718 || u->stub_unwind.stub_type == EXPORT)
2722 /* Search forward from the current PC until we hit a branch
2723 or the end of the stub. */
2724 for (addr = pc; addr <= u->region_end; addr += 4)
2728 insn = read_memory_integer (addr, 4);
2730 /* Does it look like a bl? If so then it's the call path, if
2731 we find a bv or be first, then we're on the return path. */
2732 if ((insn & 0xfc00e000) == 0xe8000000)
2734 else if ((insn & 0xfc00e001) == 0xe800c000
2735 || (insn & 0xfc000000) == 0xe0000000)
2739 /* Should never happen. */
2740 warning ("Unable to find branch in parameter relocation stub.\n"); /* purecov: deadcode */
2741 return 0; /* purecov: deadcode */
2744 /* Unknown stub type. For now, just return zero. */
2745 return 0; /* purecov: deadcode */
2748 /* Return one if PC is in the return path of a trampoline, else return zero.
2750 Note we return one for *any* call trampoline (long-call, arg-reloc), not
2751 just shared library trampolines (import, export). */
2754 in_solib_return_trampoline (pc, name)
2758 struct unwind_table_entry *u;
2760 /* Get the unwind descriptor corresponding to PC, return zero
2761 if no unwind was found. */
2762 u = find_unwind_entry (pc);
2766 /* If this isn't a linker stub or it's just a long branch stub, then
2768 if (u->stub_unwind.stub_type == 0 || u->stub_unwind.stub_type == LONG_BRANCH)
2771 /* The call and return path execute the same instructions within
2772 an IMPORT stub! So an IMPORT stub is both a call and return
2774 if (u->stub_unwind.stub_type == IMPORT)
2777 /* Parameter relocation stubs always have a call path and may have a
2779 if (u->stub_unwind.stub_type == PARAMETER_RELOCATION
2780 || u->stub_unwind.stub_type == EXPORT)
2784 /* Search forward from the current PC until we hit a branch
2785 or the end of the stub. */
2786 for (addr = pc; addr <= u->region_end; addr += 4)
2790 insn = read_memory_integer (addr, 4);
2792 /* Does it look like a bl? If so then it's the call path, if
2793 we find a bv or be first, then we're on the return path. */
2794 if ((insn & 0xfc00e000) == 0xe8000000)
2796 else if ((insn & 0xfc00e001) == 0xe800c000
2797 || (insn & 0xfc000000) == 0xe0000000)
2801 /* Should never happen. */
2802 warning ("Unable to find branch in parameter relocation stub.\n"); /* purecov: deadcode */
2803 return 0; /* purecov: deadcode */
2806 /* Unknown stub type. For now, just return zero. */
2807 return 0; /* purecov: deadcode */
2811 /* Figure out if PC is in a trampoline, and if so find out where
2812 the trampoline will jump to. If not in a trampoline, return zero.
2814 Simple code examination probably is not a good idea since the code
2815 sequences in trampolines can also appear in user code.
2817 We use unwinds and information from the minimal symbol table to
2818 determine when we're in a trampoline. This won't work for ELF
2819 (yet) since it doesn't create stub unwind entries. Whether or
2820 not ELF will create stub unwinds or normal unwinds for linker
2821 stubs is still being debated.
2823 This should handle simple calls through dyncall or sr4export,
2824 long calls, argument relocation stubs, and dyncall/sr4export
2825 calling an argument relocation stub. It even handles some stubs
2826 used in dynamic executables. */
2830 skip_trampoline_code (pc, name)
2834 return find_solib_trampoline_target(pc);
2840 skip_trampoline_code (pc, name)
2845 long prev_inst, curr_inst, loc;
2846 static CORE_ADDR dyncall = 0;
2847 static CORE_ADDR dyncall_external = 0;
2848 static CORE_ADDR sr4export = 0;
2849 struct minimal_symbol *msym;
2850 struct unwind_table_entry *u;
2853 /* FIXME XXX - dyncall and sr4export must be initialized whenever we get a
2858 msym = lookup_minimal_symbol ("$$dyncall", NULL, NULL);
2860 dyncall = SYMBOL_VALUE_ADDRESS (msym);
2865 if (!dyncall_external)
2867 msym = lookup_minimal_symbol ("$$dyncall_external", NULL, NULL);
2869 dyncall_external = SYMBOL_VALUE_ADDRESS (msym);
2871 dyncall_external = -1;
2876 msym = lookup_minimal_symbol ("_sr4export", NULL, NULL);
2878 sr4export = SYMBOL_VALUE_ADDRESS (msym);
2883 /* Addresses passed to dyncall may *NOT* be the actual address
2884 of the function. So we may have to do something special. */
2887 pc = (CORE_ADDR) read_register (22);
2889 /* If bit 30 (counting from the left) is on, then pc is the address of
2890 the PLT entry for this function, not the address of the function
2891 itself. Bit 31 has meaning too, but only for MPE. */
2893 pc = (CORE_ADDR) read_memory_integer (pc & ~0x3, 4);
2895 if (pc == dyncall_external)
2897 pc = (CORE_ADDR) read_register (22);
2898 pc = (CORE_ADDR) read_memory_integer (pc & ~0x3, 4);
2900 else if (pc == sr4export)
2901 pc = (CORE_ADDR) (read_register (22));
2903 /* Get the unwind descriptor corresponding to PC, return zero
2904 if no unwind was found. */
2905 u = find_unwind_entry (pc);
2909 /* If this isn't a linker stub, then return now. */
2910 /* elz: attention here! (FIXME) because of a compiler/linker
2911 error, some stubs which should have a non zero stub_unwind.stub_type
2912 have unfortunately a value of zero. So this function would return here
2913 as if we were not in a trampoline. To fix this, we go look at the partial
2914 symbol information, which reports this guy as a stub.
2915 (FIXME): Unfortunately, we are not that lucky: it turns out that the
2916 partial symbol information is also wrong sometimes. This is because
2917 when it is entered (somread.c::som_symtab_read()) it can happen that
2918 if the type of the symbol (from the som) is Entry, and the symbol is
2919 in a shared library, then it can also be a trampoline. This would
2920 be OK, except that I believe the way they decide if we are ina shared library
2921 does not work. SOOOO..., even if we have a regular function w/o trampolines
2922 its minimal symbol can be assigned type mst_solib_trampoline.
2923 Also, if we find that the symbol is a real stub, then we fix the unwind
2924 descriptor, and define the stub type to be EXPORT.
2925 Hopefully this is correct most of the times. */
2926 if (u->stub_unwind.stub_type == 0)
2929 /* elz: NOTE (FIXME!) once the problem with the unwind information is fixed
2930 we can delete all the code which appears between the lines */
2931 /*--------------------------------------------------------------------------*/
2932 msym = lookup_minimal_symbol_by_pc (pc);
2934 if (msym == NULL || MSYMBOL_TYPE (msym) != mst_solib_trampoline)
2935 return orig_pc == pc ? 0 : pc & ~0x3;
2937 else if (msym != NULL && MSYMBOL_TYPE (msym) == mst_solib_trampoline)
2939 struct objfile *objfile;
2940 struct minimal_symbol *msymbol;
2941 int function_found = 0;
2943 /* go look if there is another minimal symbol with the same name as
2944 this one, but with type mst_text. This would happen if the msym
2945 is an actual trampoline, in which case there would be another
2946 symbol with the same name corresponding to the real function */
2948 ALL_MSYMBOLS (objfile, msymbol)
2950 if (MSYMBOL_TYPE (msymbol) == mst_text
2951 && STREQ (SYMBOL_NAME (msymbol) , SYMBOL_NAME (msym)))
2959 /* the type of msym is correct (mst_solib_trampoline), but
2960 the unwind info is wrong, so set it to the correct value */
2961 u->stub_unwind.stub_type = EXPORT;
2963 /* the stub type info in the unwind is correct (this is not a
2964 trampoline), but the msym type information is wrong, it
2965 should be mst_text. So we need to fix the msym, and also
2966 get out of this function */
2968 MSYMBOL_TYPE (msym) = mst_text;
2969 return orig_pc == pc ? 0 : pc & ~0x3;
2973 /*--------------------------------------------------------------------------*/
2976 /* It's a stub. Search for a branch and figure out where it goes.
2977 Note we have to handle multi insn branch sequences like ldil;ble.
2978 Most (all?) other branches can be determined by examining the contents
2979 of certain registers and the stack. */
2986 /* Make sure we haven't walked outside the range of this stub. */
2987 if (u != find_unwind_entry (loc))
2989 warning ("Unable to find branch in linker stub");
2990 return orig_pc == pc ? 0 : pc & ~0x3;
2993 prev_inst = curr_inst;
2994 curr_inst = read_memory_integer (loc, 4);
2996 /* Does it look like a branch external using %r1? Then it's the
2997 branch from the stub to the actual function. */
2998 if ((curr_inst & 0xffe0e000) == 0xe0202000)
3000 /* Yup. See if the previous instruction loaded
3001 a value into %r1. If so compute and return the jump address. */
3002 if ((prev_inst & 0xffe00000) == 0x20200000)
3003 return (extract_21 (prev_inst) + extract_17 (curr_inst)) & ~0x3;
3006 warning ("Unable to find ldil X,%%r1 before ble Y(%%sr4,%%r1).");
3007 return orig_pc == pc ? 0 : pc & ~0x3;
3011 /* Does it look like a be 0(sr0,%r21)? OR
3012 Does it look like a be, n 0(sr0,%r21)? OR
3013 Does it look like a bve (r21)? (this is on PA2.0)
3014 Does it look like a bve, n(r21)? (this is also on PA2.0)
3015 That's the branch from an
3016 import stub to an export stub.
3018 It is impossible to determine the target of the branch via
3019 simple examination of instructions and/or data (consider
3020 that the address in the plabel may be the address of the
3021 bind-on-reference routine in the dynamic loader).
3023 So we have try an alternative approach.
3025 Get the name of the symbol at our current location; it should
3026 be a stub symbol with the same name as the symbol in the
3029 Then lookup a minimal symbol with the same name; we should
3030 get the minimal symbol for the target routine in the shared
3031 library as those take precedence of import/export stubs. */
3032 if ((curr_inst == 0xe2a00000) ||
3033 (curr_inst == 0xe2a00002) ||
3034 (curr_inst == 0xeaa0d000) ||
3035 (curr_inst == 0xeaa0d002))
3037 struct minimal_symbol *stubsym, *libsym;
3039 stubsym = lookup_minimal_symbol_by_pc (loc);
3040 if (stubsym == NULL)
3042 warning ("Unable to find symbol for 0x%x", loc);
3043 return orig_pc == pc ? 0 : pc & ~0x3;
3046 libsym = lookup_minimal_symbol (SYMBOL_NAME (stubsym), NULL, NULL);
3049 warning ("Unable to find library symbol for %s\n",
3050 SYMBOL_NAME (stubsym));
3051 return orig_pc == pc ? 0 : pc & ~0x3;
3054 return SYMBOL_VALUE (libsym);
3057 /* Does it look like bl X,%rp or bl X,%r0? Another way to do a
3058 branch from the stub to the actual function. */
3060 else if ((curr_inst & 0xffe0e000) == 0xe8400000
3061 || (curr_inst & 0xffe0e000) == 0xe8000000
3062 || (curr_inst & 0xffe0e000) == 0xe800A000)
3063 return (loc + extract_17 (curr_inst) + 8) & ~0x3;
3065 /* Does it look like bv (rp)? Note this depends on the
3066 current stack pointer being the same as the stack
3067 pointer in the stub itself! This is a branch on from the
3068 stub back to the original caller. */
3069 /*else if ((curr_inst & 0xffe0e000) == 0xe840c000)*/
3070 else if ((curr_inst & 0xffe0f000) == 0xe840c000)
3072 /* Yup. See if the previous instruction loaded
3074 if (prev_inst == 0x4bc23ff1)
3075 return (read_memory_integer
3076 (read_register (SP_REGNUM) - 8, 4)) & ~0x3;
3079 warning ("Unable to find restore of %%rp before bv (%%rp).");
3080 return orig_pc == pc ? 0 : pc & ~0x3;
3084 /* elz: added this case to capture the new instruction
3085 at the end of the return part of an export stub used by
3086 the PA2.0: BVE, n (rp) */
3087 else if ((curr_inst & 0xffe0f000) == 0xe840d000)
3089 return (read_memory_integer
3090 (read_register (SP_REGNUM) - 24, 4)) & ~0x3;
3093 /* What about be,n 0(sr0,%rp)? It's just another way we return to
3094 the original caller from the stub. Used in dynamic executables. */
3095 else if (curr_inst == 0xe0400002)
3097 /* The value we jump to is sitting in sp - 24. But that's
3098 loaded several instructions before the be instruction.
3099 I guess we could check for the previous instruction being
3100 mtsp %r1,%sr0 if we want to do sanity checking. */
3101 return (read_memory_integer
3102 (read_register (SP_REGNUM) - 24, 4)) & ~0x3;
3105 /* Haven't found the branch yet, but we're still in the stub.
3112 /* For the given instruction (INST), return any adjustment it makes
3113 to the stack pointer or zero for no adjustment.
3115 This only handles instructions commonly found in prologues. */
3118 prologue_inst_adjust_sp (inst)
3121 /* This must persist across calls. */
3122 static int save_high21;
3124 /* The most common way to perform a stack adjustment ldo X(sp),sp */
3125 if ((inst & 0xffffc000) == 0x37de0000)
3126 return extract_14 (inst);
3129 if ((inst & 0xffe00000) == 0x6fc00000)
3130 return extract_14 (inst);
3132 /* addil high21,%r1; ldo low11,(%r1),%r30)
3133 save high bits in save_high21 for later use. */
3134 if ((inst & 0xffe00000) == 0x28200000)
3136 save_high21 = extract_21 (inst);
3140 if ((inst & 0xffff0000) == 0x343e0000)
3141 return save_high21 + extract_14 (inst);
3143 /* fstws as used by the HP compilers. */
3144 if ((inst & 0xffffffe0) == 0x2fd01220)
3145 return extract_5_load (inst);
3147 /* No adjustment. */
3151 /* Return nonzero if INST is a branch of some kind, else return zero. */
3181 /* Return the register number for a GR which is saved by INST or
3182 zero it INST does not save a GR. */
3185 inst_saves_gr (inst)
3188 /* Does it look like a stw? */
3189 if ((inst >> 26) == 0x1a)
3190 return extract_5R_store (inst);
3192 /* Does it look like a stwm? GCC & HPC may use this in prologues. */
3193 if ((inst >> 26) == 0x1b)
3194 return extract_5R_store (inst);
3196 /* Does it look like sth or stb? HPC versions 9.0 and later use these
3198 if ((inst >> 26) == 0x19 || (inst >> 26) == 0x18)
3199 return extract_5R_store (inst);
3204 /* Return the register number for a FR which is saved by INST or
3205 zero it INST does not save a FR.
3207 Note we only care about full 64bit register stores (that's the only
3208 kind of stores the prologue will use).
3210 FIXME: What about argument stores with the HP compiler in ANSI mode? */
3213 inst_saves_fr (inst)
3216 /* is this an FSTDS ?*/
3217 if ((inst & 0xfc00dfc0) == 0x2c001200)
3218 return extract_5r_store (inst);
3219 /* is this an FSTWS ?*/
3220 if ((inst & 0xfc00df80) == 0x24001200)
3221 return extract_5r_store (inst);
3225 /* Advance PC across any function entry prologue instructions
3226 to reach some "real" code.
3228 Use information in the unwind table to determine what exactly should
3229 be in the prologue. */
3233 skip_prologue_hard_way (pc)
3237 CORE_ADDR orig_pc = pc;
3238 unsigned long inst, stack_remaining, save_gr, save_fr, save_rp, save_sp;
3239 unsigned long args_stored, status, i, restart_gr, restart_fr;
3240 struct unwind_table_entry *u;
3246 u = find_unwind_entry (pc);
3250 /* If we are not at the beginning of a function, then return now. */
3251 if ((pc & ~0x3) != u->region_start)
3254 /* This is how much of a frame adjustment we need to account for. */
3255 stack_remaining = u->Total_frame_size << 3;
3257 /* Magic register saves we want to know about. */
3258 save_rp = u->Save_RP;
3259 save_sp = u->Save_SP;
3261 /* An indication that args may be stored into the stack. Unfortunately
3262 the HPUX compilers tend to set this in cases where no args were
3266 /* Turn the Entry_GR field into a bitmask. */
3268 for (i = 3; i < u->Entry_GR + 3; i++)
3270 /* Frame pointer gets saved into a special location. */
3271 if (u->Save_SP && i == FP_REGNUM)
3274 save_gr |= (1 << i);
3276 save_gr &= ~restart_gr;
3278 /* Turn the Entry_FR field into a bitmask too. */
3280 for (i = 12; i < u->Entry_FR + 12; i++)
3281 save_fr |= (1 << i);
3282 save_fr &= ~restart_fr;
3284 /* Loop until we find everything of interest or hit a branch.
3286 For unoptimized GCC code and for any HP CC code this will never ever
3287 examine any user instructions.
3289 For optimzied GCC code we're faced with problems. GCC will schedule
3290 its prologue and make prologue instructions available for delay slot
3291 filling. The end result is user code gets mixed in with the prologue
3292 and a prologue instruction may be in the delay slot of the first branch
3295 Some unexpected things are expected with debugging optimized code, so
3296 we allow this routine to walk past user instructions in optimized
3298 while (save_gr || save_fr || save_rp || save_sp || stack_remaining > 0
3301 unsigned int reg_num;
3302 unsigned long old_stack_remaining, old_save_gr, old_save_fr;
3303 unsigned long old_save_rp, old_save_sp, next_inst;
3305 /* Save copies of all the triggers so we can compare them later
3307 old_save_gr = save_gr;
3308 old_save_fr = save_fr;
3309 old_save_rp = save_rp;
3310 old_save_sp = save_sp;
3311 old_stack_remaining = stack_remaining;
3313 status = target_read_memory (pc, buf, 4);
3314 inst = extract_unsigned_integer (buf, 4);
3320 /* Note the interesting effects of this instruction. */
3321 stack_remaining -= prologue_inst_adjust_sp (inst);
3323 /* There is only one instruction used for saving RP into the stack. */
3324 if (inst == 0x6bc23fd9)
3327 /* This is the only way we save SP into the stack. At this time
3328 the HP compilers never bother to save SP into the stack. */
3329 if ((inst & 0xffffc000) == 0x6fc10000)
3332 /* Account for general and floating-point register saves. */
3333 reg_num = inst_saves_gr (inst);
3334 save_gr &= ~(1 << reg_num);
3336 /* Ugh. Also account for argument stores into the stack.
3337 Unfortunately args_stored only tells us that some arguments
3338 where stored into the stack. Not how many or what kind!
3340 This is a kludge as on the HP compiler sets this bit and it
3341 never does prologue scheduling. So once we see one, skip past
3342 all of them. We have similar code for the fp arg stores below.
3344 FIXME. Can still die if we have a mix of GR and FR argument
3346 if (reg_num >= 23 && reg_num <= 26)
3348 while (reg_num >= 23 && reg_num <= 26)
3351 status = target_read_memory (pc, buf, 4);
3352 inst = extract_unsigned_integer (buf, 4);
3355 reg_num = inst_saves_gr (inst);
3361 reg_num = inst_saves_fr (inst);
3362 save_fr &= ~(1 << reg_num);
3364 status = target_read_memory (pc + 4, buf, 4);
3365 next_inst = extract_unsigned_integer (buf, 4);
3371 /* We've got to be read to handle the ldo before the fp register
3373 if ((inst & 0xfc000000) == 0x34000000
3374 && inst_saves_fr (next_inst) >= 4
3375 && inst_saves_fr (next_inst) <= 7)
3377 /* So we drop into the code below in a reasonable state. */
3378 reg_num = inst_saves_fr (next_inst);
3382 /* Ugh. Also account for argument stores into the stack.
3383 This is a kludge as on the HP compiler sets this bit and it
3384 never does prologue scheduling. So once we see one, skip past
3386 if (reg_num >= 4 && reg_num <= 7)
3388 while (reg_num >= 4 && reg_num <= 7)
3391 status = target_read_memory (pc, buf, 4);
3392 inst = extract_unsigned_integer (buf, 4);
3395 if ((inst & 0xfc000000) != 0x34000000)
3397 status = target_read_memory (pc + 4, buf, 4);
3398 next_inst = extract_unsigned_integer (buf, 4);
3401 reg_num = inst_saves_fr (next_inst);
3407 /* Quit if we hit any kind of branch. This can happen if a prologue
3408 instruction is in the delay slot of the first call/branch. */
3409 if (is_branch (inst))
3412 /* What a crock. The HP compilers set args_stored even if no
3413 arguments were stored into the stack (boo hiss). This could
3414 cause this code to then skip a bunch of user insns (up to the
3417 To combat this we try to identify when args_stored was bogusly
3418 set and clear it. We only do this when args_stored is nonzero,
3419 all other resources are accounted for, and nothing changed on
3422 && ! (save_gr || save_fr || save_rp || save_sp || stack_remaining > 0)
3423 && old_save_gr == save_gr && old_save_fr == save_fr
3424 && old_save_rp == save_rp && old_save_sp == save_sp
3425 && old_stack_remaining == stack_remaining)
3432 /* We've got a tenative location for the end of the prologue. However
3433 because of limitations in the unwind descriptor mechanism we may
3434 have went too far into user code looking for the save of a register
3435 that does not exist. So, if there registers we expected to be saved
3436 but never were, mask them out and restart.
3438 This should only happen in optimized code, and should be very rare. */
3439 if (save_gr || (save_fr && ! (restart_fr || restart_gr)))
3442 restart_gr = save_gr;
3443 restart_fr = save_fr;
3454 /* return 0 if we cannot determine the end of the prologue,
3455 return the new pc value if we know where the prologue ends */
3461 struct symtab_and_line sal;
3462 CORE_ADDR func_addr, func_end;
3465 if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
3466 return 0; /* Unknown */
3468 f = find_pc_function (pc);
3470 return 0; /* no debug info, do it the hard way! */
3472 sal = find_pc_line (func_addr, 0);
3474 if (sal.end < func_end)
3476 /* this happens when the function has no prologue, because the way
3477 find_pc_line works: elz. Note: this may not be a very good
3478 way to decide whether a function has a prologue or not, but
3479 it is the best I can do with the info available
3480 Also, this will work for functions like: int f()
3484 I.e. the bp will be inserted at the first open brace.
3485 For functions where the body is only one line written like this:
3488 this will make the breakpoint to be at the last brace, after the body
3489 has been executed already. What's the point of stepping through a function
3490 without any variables anyway?? */
3492 if ((SYMBOL_LINE(f) > 0) && (SYMBOL_LINE(f) < sal.line))
3493 return pc; /*no adjusment will be made*/
3495 return sal.end; /* this is the end of the prologue */
3497 /* The line after the prologue is after the end of the function. In this
3498 case, put the end of the prologue is the beginning of the function. */
3499 /* This should happen only when the function is prologueless and has no
3500 code in it. For instance void dumb(){} Note: this kind of function
3501 is used quite a lot in the test system */
3503 else return pc; /* no adjustment will be made */
3506 /* To skip prologues, I use this predicate. Returns either PC itself
3507 if the code at PC does not look like a function prologue; otherwise
3508 returns an address that (if we're lucky) follows the prologue. If
3509 LENIENT, then we must skip everything which is involved in setting
3510 up the frame (it's OK to skip more, just so long as we don't skip
3511 anything which might clobber the registers which are being saved.
3512 Currently we must not skip more on the alpha, but we might the lenient
3516 hppa_skip_prologue (pc)
3521 CORE_ADDR post_prologue_pc;
3524 #ifdef GDB_TARGET_HAS_SHARED_LIBS
3525 /* Silently return the unaltered pc upon memory errors.
3526 This could happen on OSF/1 if decode_line_1 tries to skip the
3527 prologue for quickstarted shared library functions when the
3528 shared library is not yet mapped in.
3529 Reading target memory is slow over serial lines, so we perform
3530 this check only if the target has shared libraries. */
3531 if (target_read_memory (pc, buf, 4))
3535 /* See if we can determine the end of the prologue via the symbol table.
3536 If so, then return either PC, or the PC after the prologue, whichever
3539 post_prologue_pc = after_prologue (pc);
3541 if (post_prologue_pc != 0)
3542 return max (pc, post_prologue_pc);
3545 /* Can't determine prologue from the symbol table, (this can happen if there
3546 is no debug information) so we need to fall back on the old code, which
3547 looks at the instructions */
3548 /* FIXME (elz) !!!!: this may create a problem if, once the bp is hit, the user says
3549 where: the backtrace info is not right: this is because the point at which we
3550 break is at the very first instruction of the function. At this time the stuff that
3551 needs to be saved on the stack, has not been saved yet, so the backtrace
3552 cannot know all it needs to know. This will need to be fixed in the
3553 actual backtrace code. (Note: this is what DDE does) */
3557 return (skip_prologue_hard_way(pc));
3560 /* elz: I am keeping this code around just in case, but remember, all the
3561 instructions are for alpha: you should change all to the hppa instructions */
3563 /* Can't determine prologue from the symbol table, need to examine
3566 /* Skip the typical prologue instructions. These are the stack adjustment
3567 instruction and the instructions that save registers on the stack
3568 or in the gcc frame. */
3569 for (offset = 0; offset < 100; offset += 4)
3573 status = read_memory_nobpt (pc + offset, buf, 4);
3575 memory_error (status, pc + offset);
3576 inst = extract_unsigned_integer (buf, 4);
3578 /* The alpha has no delay slots. But let's keep the lenient stuff,
3579 we might need it for something else in the future. */
3583 if ((inst & 0xffff0000) == 0x27bb0000) /* ldah $gp,n($t12) */
3585 if ((inst & 0xffff0000) == 0x23bd0000) /* lda $gp,n($gp) */
3587 if ((inst & 0xffff0000) == 0x23de0000) /* lda $sp,n($sp) */
3589 else if ((inst & 0xfc1f0000) == 0xb41e0000
3590 && (inst & 0xffff0000) != 0xb7fe0000)
3591 continue; /* stq reg,n($sp) */
3593 else if ((inst & 0xfc1f0000) == 0x9c1e0000
3594 && (inst & 0xffff0000) != 0x9ffe0000)
3595 continue; /* stt reg,n($sp) */
3597 else if (inst == 0x47de040f) /* bis sp,sp,fp */
3606 /* Put here the code to store, into a struct frame_saved_regs,
3607 the addresses of the saved registers of frame described by FRAME_INFO.
3608 This includes special registers such as pc and fp saved in special
3609 ways in the stack frame. sp is even more special:
3610 the address we return for it IS the sp for the next frame. */
3613 hppa_frame_find_saved_regs (frame_info, frame_saved_regs)
3614 struct frame_info *frame_info;
3615 struct frame_saved_regs *frame_saved_regs;
3618 struct unwind_table_entry *u;
3619 unsigned long inst, stack_remaining, save_gr, save_fr, save_rp, save_sp;
3624 /* Zero out everything. */
3625 memset (frame_saved_regs, '\0', sizeof (struct frame_saved_regs));
3627 /* Call dummy frames always look the same, so there's no need to
3628 examine the dummy code to determine locations of saved registers;
3629 instead, let find_dummy_frame_regs fill in the correct offsets
3630 for the saved registers. */
3631 if ((frame_info->pc >= frame_info->frame
3632 && frame_info->pc <= (frame_info->frame + CALL_DUMMY_LENGTH
3633 + 32 * 4 + (NUM_REGS - FP0_REGNUM) * 8
3635 find_dummy_frame_regs (frame_info, frame_saved_regs);
3637 /* Interrupt handlers are special too. They lay out the register
3638 state in the exact same order as the register numbers in GDB. */
3639 if (pc_in_interrupt_handler (frame_info->pc))
3641 for (i = 0; i < NUM_REGS; i++)
3643 /* SP is a little special. */
3645 frame_saved_regs->regs[SP_REGNUM]
3646 = read_memory_integer (frame_info->frame + SP_REGNUM * 4, 4);
3648 frame_saved_regs->regs[i] = frame_info->frame + i * 4;
3653 #ifdef FRAME_FIND_SAVED_REGS_IN_SIGTRAMP
3654 /* Handle signal handler callers. */
3655 if (frame_info->signal_handler_caller)
3657 FRAME_FIND_SAVED_REGS_IN_SIGTRAMP (frame_info, frame_saved_regs);
3662 /* Get the starting address of the function referred to by the PC
3664 pc = get_pc_function_start (frame_info->pc);
3667 u = find_unwind_entry (pc);
3671 /* This is how much of a frame adjustment we need to account for. */
3672 stack_remaining = u->Total_frame_size << 3;
3674 /* Magic register saves we want to know about. */
3675 save_rp = u->Save_RP;
3676 save_sp = u->Save_SP;
3678 /* Turn the Entry_GR field into a bitmask. */
3680 for (i = 3; i < u->Entry_GR + 3; i++)
3682 /* Frame pointer gets saved into a special location. */
3683 if (u->Save_SP && i == FP_REGNUM)
3686 save_gr |= (1 << i);
3689 /* Turn the Entry_FR field into a bitmask too. */
3691 for (i = 12; i < u->Entry_FR + 12; i++)
3692 save_fr |= (1 << i);
3694 /* The frame always represents the value of %sp at entry to the
3695 current function (and is thus equivalent to the "saved" stack
3697 frame_saved_regs->regs[SP_REGNUM] = frame_info->frame;
3699 /* Loop until we find everything of interest or hit a branch.
3701 For unoptimized GCC code and for any HP CC code this will never ever
3702 examine any user instructions.
3704 For optimzied GCC code we're faced with problems. GCC will schedule
3705 its prologue and make prologue instructions available for delay slot
3706 filling. The end result is user code gets mixed in with the prologue
3707 and a prologue instruction may be in the delay slot of the first branch
3710 Some unexpected things are expected with debugging optimized code, so
3711 we allow this routine to walk past user instructions in optimized
3713 while (save_gr || save_fr || save_rp || save_sp || stack_remaining > 0)
3715 status = target_read_memory (pc, buf, 4);
3716 inst = extract_unsigned_integer (buf, 4);
3722 /* Note the interesting effects of this instruction. */
3723 stack_remaining -= prologue_inst_adjust_sp (inst);
3725 /* There is only one instruction used for saving RP into the stack. */
3726 if (inst == 0x6bc23fd9)
3729 frame_saved_regs->regs[RP_REGNUM] = frame_info->frame - 20;
3732 /* Just note that we found the save of SP into the stack. The
3733 value for frame_saved_regs was computed above. */
3734 if ((inst & 0xffffc000) == 0x6fc10000)
3737 /* Account for general and floating-point register saves. */
3738 reg = inst_saves_gr (inst);
3739 if (reg >= 3 && reg <= 18
3740 && (!u->Save_SP || reg != FP_REGNUM))
3742 save_gr &= ~(1 << reg);
3744 /* stwm with a positive displacement is a *post modify*. */
3745 if ((inst >> 26) == 0x1b
3746 && extract_14 (inst) >= 0)
3747 frame_saved_regs->regs[reg] = frame_info->frame;
3750 /* Handle code with and without frame pointers. */
3752 frame_saved_regs->regs[reg]
3753 = frame_info->frame + extract_14 (inst);
3755 frame_saved_regs->regs[reg]
3756 = frame_info->frame + (u->Total_frame_size << 3)
3757 + extract_14 (inst);
3762 /* GCC handles callee saved FP regs a little differently.
3764 It emits an instruction to put the value of the start of
3765 the FP store area into %r1. It then uses fstds,ma with
3766 a basereg of %r1 for the stores.
3768 HP CC emits them at the current stack pointer modifying
3769 the stack pointer as it stores each register. */
3771 /* ldo X(%r3),%r1 or ldo X(%r30),%r1. */
3772 if ((inst & 0xffffc000) == 0x34610000
3773 || (inst & 0xffffc000) == 0x37c10000)
3774 fp_loc = extract_14 (inst);
3776 reg = inst_saves_fr (inst);
3777 if (reg >= 12 && reg <= 21)
3779 /* Note +4 braindamage below is necessary because the FP status
3780 registers are internally 8 registers rather than the expected
3782 save_fr &= ~(1 << reg);
3785 /* 1st HP CC FP register store. After this instruction
3786 we've set enough state that the GCC and HPCC code are
3787 both handled in the same manner. */
3788 frame_saved_regs->regs[reg + FP4_REGNUM + 4] = frame_info->frame;
3793 frame_saved_regs->regs[reg + FP0_REGNUM + 4]
3794 = frame_info->frame + fp_loc;
3799 /* Quit if we hit any kind of branch. This can happen if a prologue
3800 instruction is in the delay slot of the first call/branch. */
3801 if (is_branch (inst))
3810 /* Exception handling support for the HP-UX ANSI C++ compiler.
3811 The compiler (aCC) provides a callback for exception events;
3812 GDB can set a breakpoint on this callback and find out what
3813 exception event has occurred. */
3815 /* The name of the hook to be set to point to the callback function */
3816 static char HP_ACC_EH_notify_hook[] = "__eh_notify_hook";
3817 /* The name of the function to be used to set the hook value */
3818 static char HP_ACC_EH_set_hook_value[] = "__eh_set_hook_value";
3819 /* The name of the callback function in end.o */
3820 static char HP_ACC_EH_notify_callback[] = "__d_eh_notify_callback";
3821 /* Name of function in end.o on which a break is set (called by above) */
3822 static char HP_ACC_EH_break[] = "__d_eh_break";
3823 /* Name of flag (in end.o) that enables catching throws */
3824 static char HP_ACC_EH_catch_throw[] = "__d_eh_catch_throw";
3825 /* Name of flag (in end.o) that enables catching catching */
3826 static char HP_ACC_EH_catch_catch[] = "__d_eh_catch_catch";
3827 /* The enum used by aCC */
3831 } __eh_notification;
3833 /* Is exception-handling support available with this executable? */
3834 static int hp_cxx_exception_support = 0;
3835 /* Has the initialize function been run? */
3836 int hp_cxx_exception_support_initialized = 0;
3837 /* Similar to above, but imported from breakpoint.c -- non-target-specific */
3838 extern int exception_support_initialized;
3839 /* Address of __eh_notify_hook */
3840 static CORE_ADDR eh_notify_hook_addr = NULL;
3841 /* Address of __d_eh_notify_callback */
3842 static CORE_ADDR eh_notify_callback_addr = NULL;
3843 /* Address of __d_eh_break */
3844 static CORE_ADDR eh_break_addr = NULL;
3845 /* Address of __d_eh_catch_catch */
3846 static CORE_ADDR eh_catch_catch_addr = NULL;
3847 /* Address of __d_eh_catch_throw */
3848 static CORE_ADDR eh_catch_throw_addr = NULL;
3849 /* Sal for __d_eh_break */
3850 static struct symtab_and_line * break_callback_sal = NULL;
3852 /* Code in end.c expects __d_pid to be set in the inferior,
3853 otherwise __d_eh_notify_callback doesn't bother to call
3854 __d_eh_break! So we poke the pid into this symbol
3859 setup_d_pid_in_inferior ()
3862 struct minimal_symbol * msymbol;
3863 char buf[4]; /* FIXME 32x64? */
3865 /* Slam the pid of the process into __d_pid; failing is only a warning! */
3866 msymbol = lookup_minimal_symbol ("__d_pid", NULL, symfile_objfile);
3867 if (msymbol == NULL)
3869 warning ("Unable to find __d_pid symbol in object file.");
3870 warning ("Suggest linking executable with -g (links in /opt/langtools/lib/end.o).");
3874 anaddr = SYMBOL_VALUE_ADDRESS (msymbol);
3875 store_unsigned_integer (buf, 4, inferior_pid); /* FIXME 32x64? */
3876 if (target_write_memory (anaddr, buf, 4)) /* FIXME 32x64? */
3878 warning ("Unable to write __d_pid");
3879 warning ("Suggest linking executable with -g (links in /opt/langtools/lib/end.o).");
3885 /* Initialize exception catchpoint support by looking for the
3886 necessary hooks/callbacks in end.o, etc., and set the hook value to
3887 point to the required debug function
3893 initialize_hp_cxx_exception_support ()
3895 struct symtabs_and_lines sals;
3896 struct cleanup * old_chain;
3897 struct cleanup * canonical_strings_chain = NULL;
3900 char * addr_end = NULL;
3901 char ** canonical = (char **) NULL;
3903 struct symbol * sym = NULL;
3904 struct minimal_symbol * msym = NULL;
3905 struct objfile * objfile;
3906 asection *shlib_info;
3908 /* Detect and disallow recursion. On HP-UX with aCC, infinite
3909 recursion is a possibility because finding the hook for exception
3910 callbacks involves making a call in the inferior, which means
3911 re-inserting breakpoints which can re-invoke this code */
3913 static int recurse = 0;
3916 hp_cxx_exception_support_initialized = 0;
3917 exception_support_initialized = 0;
3921 hp_cxx_exception_support = 0;
3923 /* First check if we have seen any HP compiled objects; if not,
3924 it is very unlikely that HP's idiosyncratic callback mechanism
3925 for exception handling debug support will be available!
3926 This will percolate back up to breakpoint.c, where our callers
3927 will decide to try the g++ exception-handling support instead. */
3928 if (!hp_som_som_object_present)
3931 /* We have a SOM executable with SOM debug info; find the hooks */
3933 /* First look for the notify hook provided by aCC runtime libs */
3934 /* If we find this symbol, we conclude that the executable must
3935 have HP aCC exception support built in. If this symbol is not
3936 found, even though we're a HP SOM-SOM file, we may have been
3937 built with some other compiler (not aCC). This results percolates
3938 back up to our callers in breakpoint.c which can decide to
3939 try the g++ style of exception support instead.
3940 If this symbol is found but the other symbols we require are
3941 not found, there is something weird going on, and g++ support
3942 should *not* be tried as an alternative.
3944 ASSUMPTION: Only HP aCC code will have __eh_notify_hook defined.
3945 ASSUMPTION: HP aCC and g++ modules cannot be linked together. */
3947 /* libCsup has this hook; it'll usually be non-debuggable */
3948 msym = lookup_minimal_symbol (HP_ACC_EH_notify_hook, NULL, NULL);
3951 eh_notify_hook_addr = SYMBOL_VALUE_ADDRESS (msym);
3952 hp_cxx_exception_support = 1;
3956 warning ("Unable to find exception callback hook (%s).", HP_ACC_EH_notify_hook);
3957 warning ("Executable may not have been compiled debuggable with HP aCC.");
3958 warning ("GDB will be unable to intercept exception events.");
3959 eh_notify_hook_addr = 0;
3960 hp_cxx_exception_support = 0;
3964 #if 0 /* DEBUGGING */
3965 printf ("Hook addr found is %lx\n", eh_notify_hook_addr);
3968 /* Next look for the notify callback routine in end.o */
3969 /* This is always available in the SOM symbol dictionary if end.o is linked in */
3970 msym = lookup_minimal_symbol (HP_ACC_EH_notify_callback, NULL, NULL);
3973 eh_notify_callback_addr = SYMBOL_VALUE_ADDRESS (msym);
3974 hp_cxx_exception_support = 1;
3978 warning ("Unable to find exception callback routine (%s).", HP_ACC_EH_notify_callback);
3979 warning ("Suggest linking executable with -g (links in /opt/langtools/lib/end.o).");
3980 warning ("GDB will be unable to intercept exception events.");
3981 eh_notify_callback_addr = 0;
3985 /* Check whether the executable is dynamically linked or archive bound */
3986 /* With an archive-bound executable we can use the raw addresses we find
3987 for the callback function, etc. without modification. For an executable
3988 with shared libraries, we have to do more work to find the plabel, which
3989 can be the target of a call through $$dyncall from the aCC runtime support
3990 library (libCsup) which is linked shared by default by aCC. */
3991 /* This test below was copied from somsolib.c/somread.c. It may not be a very
3992 reliable one to test that an executable is linked shared. pai/1997-07-18 */
3993 shlib_info = bfd_get_section_by_name (symfile_objfile->obfd, "$SHLIB_INFO$");
3994 if (shlib_info && (bfd_section_size (symfile_objfile->obfd, shlib_info) != 0))
3996 /* The minsym we have has the local code address, but that's not the
3997 plabel that can be used by an inter-load-module call. */
3998 /* Find solib handle for main image (which has end.o), and use that
3999 and the min sym as arguments to __d_shl_get() (which does the equivalent
4000 of shl_findsym()) to find the plabel. */
4002 args_for_find_stub args;
4003 static char message[] = "Error while finding exception callback hook:\n";
4005 args.solib_handle = som_solib_get_solib_by_pc (eh_notify_callback_addr);
4009 eh_notify_callback_addr = catch_errors ((int (*) PARAMS ((char *))) cover_find_stub_with_shl_get,
4011 message, RETURN_MASK_ALL);
4014 #if 0 /* DEBUGGING */
4015 printf ("found plabel for eh notify callback: %x\n", eh_notify_callback_addr);
4018 exception_catchpoints_are_fragile = 1;
4020 if (!eh_notify_callback_addr)
4022 /* We can get here either if there is no plabel in the export list
4023 for the main image, or if something strange happened (??) */
4024 warning ("Couldn't find a plabel (indirect function label) for the exception callback.");
4025 warning ("GDB will not be able to intercept exception events.");
4030 exception_catchpoints_are_fragile = 0;
4032 #if 0 /* DEBUGGING */
4033 printf ("Cb addr found is %lx\n", eh_notify_callback_addr);
4036 /* Now, look for the breakpointable routine in end.o */
4037 /* This should also be available in the SOM symbol dict. if end.o linked in */
4038 msym = lookup_minimal_symbol (HP_ACC_EH_break, NULL, NULL);
4041 eh_break_addr = SYMBOL_VALUE_ADDRESS (msym);
4042 hp_cxx_exception_support = 1;
4046 warning ("Unable to find exception callback routine to set breakpoint (%s).", HP_ACC_EH_break);
4047 warning ("Suggest linking executable with -g (link in /opt/langtools/lib/end.o).");
4048 warning ("GDB will be unable to intercept exception events.");
4053 #if 0 /* DEBUGGING */
4054 printf ("break addr found is %lx\n", eh_break_addr);
4057 /* Next look for the catch enable flag provided in end.o */
4058 sym = lookup_symbol (HP_ACC_EH_catch_catch, (struct block *) NULL,
4059 VAR_NAMESPACE, 0, (struct symtab **) NULL);
4060 if (sym) /* sometimes present in debug info */
4062 eh_catch_catch_addr = SYMBOL_VALUE_ADDRESS (sym);
4063 hp_cxx_exception_support = 1;
4065 else /* otherwise look in SOM symbol dict. */
4067 msym = lookup_minimal_symbol (HP_ACC_EH_catch_catch, NULL, NULL);
4070 eh_catch_catch_addr = SYMBOL_VALUE_ADDRESS (msym);
4071 hp_cxx_exception_support = 1;
4075 warning ("Unable to enable interception of exception catches.");
4076 warning ("Executable may not have been compiled debuggable with HP aCC.");
4077 warning ("Suggest linking executable with -g (link in /opt/langtools/lib/end.o).");
4082 #if 0 /* DEBUGGING */
4083 printf ("catch catch addr found is %lx\n", eh_catch_catch_addr);
4086 /* Next look for the catch enable flag provided end.o */
4087 sym = lookup_symbol (HP_ACC_EH_catch_catch, (struct block *) NULL,
4088 VAR_NAMESPACE, 0, (struct symtab **) NULL);
4089 if (sym) /* sometimes present in debug info */
4091 eh_catch_throw_addr = SYMBOL_VALUE_ADDRESS (sym);
4092 hp_cxx_exception_support = 1;
4094 else /* otherwise look in SOM symbol dict. */
4096 msym = lookup_minimal_symbol (HP_ACC_EH_catch_throw, NULL, NULL);
4099 eh_catch_throw_addr = SYMBOL_VALUE_ADDRESS (msym);
4100 hp_cxx_exception_support = 1;
4104 warning ("Unable to enable interception of exception throws.");
4105 warning ("Executable may not have been compiled debuggable with HP aCC.");
4106 warning ("Suggest linking executable with -g (link in /opt/langtools/lib/end.o).");
4111 #if 0 /* DEBUGGING */
4112 printf ("catch throw addr found is %lx\n", eh_catch_throw_addr);
4116 hp_cxx_exception_support = 2; /* everything worked so far */
4117 hp_cxx_exception_support_initialized = 1;
4118 exception_support_initialized = 1;
4123 /* Target operation for enabling or disabling interception of
4125 KIND is either EX_EVENT_THROW or EX_EVENT_CATCH
4126 ENABLE is either 0 (disable) or 1 (enable).
4127 Return value is NULL if no support found;
4128 -1 if something went wrong,
4129 or a pointer to a symtab/line struct if the breakpointable
4130 address was found. */
4132 struct symtab_and_line *
4133 child_enable_exception_callback (kind, enable)
4134 enum exception_event_kind kind;
4139 if (!exception_support_initialized || !hp_cxx_exception_support_initialized)
4140 if (!initialize_hp_cxx_exception_support ())
4143 switch (hp_cxx_exception_support)
4146 /* Assuming no HP support at all */
4149 /* HP support should be present, but something went wrong */
4150 return (struct symtab_and_line *) -1; /* yuck! */
4151 /* there may be other cases in the future */
4154 /* Set the EH hook to point to the callback routine */
4155 store_unsigned_integer (buf, 4, enable ? eh_notify_callback_addr : 0); /* FIXME 32x64 problem */
4156 /* pai: (temp) FIXME should there be a pack operation first? */
4157 if (target_write_memory (eh_notify_hook_addr, buf, 4)) /* FIXME 32x64 problem */
4159 warning ("Could not write to target memory for exception event callback.");
4160 warning ("Interception of exception events may not work.");
4161 return (struct symtab_and_line *) -1;
4165 /* Ensure that __d_pid is set up correctly -- end.c code checks this. :-(*/
4166 if (inferior_pid > 0)
4168 if (setup_d_pid_in_inferior ())
4169 return (struct symtab_and_line *) -1;
4173 warning ("Internal error: Invalid inferior pid? Cannot intercept exception events."); /* purecov: deadcode */
4174 return (struct symtab_and_line *) -1; /* purecov: deadcode */
4180 case EX_EVENT_THROW:
4181 store_unsigned_integer (buf, 4, enable ? 1 : 0);
4182 if (target_write_memory (eh_catch_throw_addr, buf, 4)) /* FIXME 32x64? */
4184 warning ("Couldn't enable exception throw interception.");
4185 return (struct symtab_and_line *) -1;
4188 case EX_EVENT_CATCH:
4189 store_unsigned_integer (buf, 4, enable ? 1 : 0);
4190 if (target_write_memory (eh_catch_catch_addr, buf, 4)) /* FIXME 32x64? */
4192 warning ("Couldn't enable exception catch interception.");
4193 return (struct symtab_and_line *) -1;
4196 default: /* purecov: deadcode */
4197 error ("Request to enable unknown or unsupported exception event."); /* purecov: deadcode */
4200 /* Copy break address into new sal struct, malloc'ing if needed. */
4201 if (!break_callback_sal)
4203 break_callback_sal = (struct symtab_and_line *) xmalloc (sizeof (struct symtab_and_line));
4205 INIT_SAL(break_callback_sal);
4206 break_callback_sal->symtab = NULL;
4207 break_callback_sal->pc = eh_break_addr;
4208 break_callback_sal->line = 0;
4209 break_callback_sal->end = eh_break_addr;
4211 return break_callback_sal;
4214 /* Record some information about the current exception event */
4215 static struct exception_event_record current_ex_event;
4216 /* Convenience struct */
4217 static struct symtab_and_line null_symtab_and_line = { NULL, 0, 0, 0 };
4219 /* Report current exception event. Returns a pointer to a record
4220 that describes the kind of the event, where it was thrown from,
4221 and where it will be caught. More information may be reported
4223 struct exception_event_record *
4224 child_get_current_exception_event ()
4226 CORE_ADDR event_kind;
4227 CORE_ADDR throw_addr;
4228 CORE_ADDR catch_addr;
4229 struct frame_info *fi, *curr_frame;
4232 curr_frame = get_current_frame();
4234 return (struct exception_event_record *) NULL;
4236 /* Go up one frame to __d_eh_notify_callback, because at the
4237 point when this code is executed, there's garbage in the
4238 arguments of __d_eh_break. */
4239 fi = find_relative_frame (curr_frame, &level);
4241 return (struct exception_event_record *) NULL;
4243 select_frame (fi, -1);
4245 /* Read in the arguments */
4246 /* __d_eh_notify_callback() is called with 3 arguments:
4247 1. event kind catch or throw
4248 2. the target address if known
4249 3. a flag -- not sure what this is. pai/1997-07-17 */
4250 event_kind = read_register (ARG0_REGNUM);
4251 catch_addr = read_register (ARG1_REGNUM);
4253 /* Now go down to a user frame */
4254 /* For a throw, __d_eh_break is called by
4255 __d_eh_notify_callback which is called by
4256 __notify_throw which is called
4258 For a catch, __d_eh_break is called by
4259 __d_eh_notify_callback which is called by
4260 <stackwalking stuff> which is called by
4261 __throw__<stuff> or __rethrow_<stuff> which is called
4263 /* FIXME: Don't use such magic numbers; search for the frames */
4264 level = (event_kind == EX_EVENT_THROW) ? 3 : 4;
4265 fi = find_relative_frame (curr_frame, &level);
4267 return (struct exception_event_record *) NULL;
4269 select_frame (fi, -1);
4270 throw_addr = fi->pc;
4272 /* Go back to original (top) frame */
4273 select_frame (curr_frame, -1);
4275 current_ex_event.kind = (enum exception_event_kind) event_kind;
4276 current_ex_event.throw_sal = find_pc_line (throw_addr, 1);
4277 current_ex_event.catch_sal = find_pc_line (catch_addr, 1);
4279 return ¤t_ex_event;
4283 unwind_command (exp, from_tty)
4288 struct unwind_table_entry *u;
4290 /* If we have an expression, evaluate it and use it as the address. */
4292 if (exp != 0 && *exp != 0)
4293 address = parse_and_eval_address (exp);
4297 u = find_unwind_entry (address);
4301 printf_unfiltered ("Can't find unwind table entry for %s\n", exp);
4305 printf_unfiltered ("unwind_table_entry (0x%x):\n", u);
4307 printf_unfiltered ("\tregion_start = ");
4308 print_address (u->region_start, gdb_stdout);
4310 printf_unfiltered ("\n\tregion_end = ");
4311 print_address (u->region_end, gdb_stdout);
4314 #define pif(FLD) if (u->FLD) printf_unfiltered (" "#FLD);
4316 #define pif(FLD) if (u->FLD) printf_unfiltered (" FLD");
4319 printf_unfiltered ("\n\tflags =");
4320 pif (Cannot_unwind);
4322 pif (Millicode_save_sr0);
4325 pif (Variable_Frame);
4326 pif (Separate_Package_Body);
4327 pif (Frame_Extension_Millicode);
4328 pif (Stack_Overflow_Check);
4329 pif (Two_Instruction_SP_Increment);
4333 pif (Save_MRP_in_frame);
4334 pif (extn_ptr_defined);
4335 pif (Cleanup_defined);
4336 pif (MPE_XL_interrupt_marker);
4337 pif (HP_UX_interrupt_marker);
4340 putchar_unfiltered ('\n');
4343 #define pin(FLD) printf_unfiltered ("\t"#FLD" = 0x%x\n", u->FLD);
4345 #define pin(FLD) printf_unfiltered ("\tFLD = 0x%x\n", u->FLD);
4348 pin (Region_description);
4351 pin (Total_frame_size);
4354 #ifdef PREPARE_TO_PROCEED
4356 /* If the user has switched threads, and there is a breakpoint
4357 at the old thread's pc location, then switch to that thread
4358 and return TRUE, else return FALSE and don't do a thread
4359 switch (or rather, don't seem to have done a thread switch).
4361 Ptrace-based gdb will always return FALSE to the thread-switch
4362 query, and thus also to PREPARE_TO_PROCEED.
4364 The important thing is whether there is a BPT instruction,
4365 not how many user breakpoints there are. So we have to worry
4366 about things like these:
4370 o User hits bp, no switch -- NO
4372 o User hits bp, switches threads -- YES
4374 o User hits bp, deletes bp, switches threads -- NO
4376 o User hits bp, deletes one of two or more bps
4377 at that PC, user switches threads -- YES
4379 o Plus, since we're buffering events, the user may have hit a
4380 breakpoint, deleted the breakpoint and then gotten another
4381 hit on that same breakpoint on another thread which
4382 actually hit before the delete. (FIXME in breakpoint.c
4383 so that "dead" breakpoints are ignored?) -- NO
4385 For these reasons, we have to violate information hiding and
4386 call "breakpoint_here_p". If core gdb thinks there is a bpt
4387 here, that's what counts, as core gdb is the one which is
4388 putting the BPT instruction in and taking it out. */
4390 hppa_prepare_to_proceed()
4393 pid_t current_thread;
4395 old_thread = hppa_switched_threads(inferior_pid);
4396 if (old_thread != 0)
4398 /* Switched over from "old_thread". Try to do
4399 as little work as possible, 'cause mostly
4400 we're going to switch back. */
4402 CORE_ADDR old_pc = read_pc();
4404 /* Yuk, shouldn't use global to specify current
4405 thread. But that's how gdb does it. */
4406 current_thread = inferior_pid;
4407 inferior_pid = old_thread;
4410 if (new_pc != old_pc /* If at same pc, no need */
4411 && breakpoint_here_p (new_pc))
4413 /* User hasn't deleted the BP.
4414 Return TRUE, finishing switch to "old_thread". */
4415 flush_cached_frames ();
4416 registers_changed ();
4418 printf("---> PREPARE_TO_PROCEED (was %d, now %d)!\n",
4419 current_thread, inferior_pid);
4425 /* Otherwise switch back to the user-chosen thread. */
4426 inferior_pid = current_thread;
4427 new_pc = read_pc(); /* Re-prime register cache */
4432 #endif /* PREPARE_TO_PROCEED */
4435 _initialize_hppa_tdep ()
4437 tm_print_insn = print_insn_hppa;
4439 add_cmd ("unwind", class_maintenance, unwind_command,
4440 "Print unwind table entry at given address.",
4441 &maintenanceprintlist);