.
[deliverable/binutils-gdb.git] / gdb / hppa-tdep.c
index a983745d992e42b69eafc12b6e9b2491d8206666..d219429b2b77f4078f206be005d84739eaf6fe51 100644 (file)
    Boston, MA 02111-1307, USA.  */
 
 #include "defs.h"
-#include "frame.h"
 #include "bfd.h"
 #include "inferior.h"
-#include "value.h"
 #include "regcache.h"
 #include "completer.h"
-#include "language.h"
 #include "osabi.h"
 #include "gdb_assert.h"
-#include "infttrace.h"
 #include "arch-utils.h"
 /* For argument passing to the inferior */
 #include "symtab.h"
-#include "infcall.h"
 #include "dis-asm.h"
 #include "trad-frame.h"
 #include "frame-unwind.h"
 #include "frame-base.h"
 
-#include "gdb_stat.h"
-#include "gdb_wait.h"
-
 #include "gdbcore.h"
 #include "gdbcmd.h"
-#include "target.h"
-#include "symfile.h"
 #include "objfiles.h"
 #include "hppa-tdep.h"
 
@@ -74,11 +64,6 @@ const struct objfile_data *hppa_objfile_priv_data = NULL;
 #define MASK_14 0x3fff
 #define MASK_21 0x1fffff
 
-/* Define offsets into the call dummy for the _sr4export address.
-   See comments related to CALL_DUMMY for more info.  */
-#define SR4EXPORT_LDIL_OFFSET (HPPA_INSTRUCTION_SIZE * 12)
-#define SR4EXPORT_LDO_OFFSET (HPPA_INSTRUCTION_SIZE * 13)
-
 /* Sizes (in bytes) of the native unwind entries.  */
 #define UNWIND_ENTRY_SIZE 16
 #define STUB_UNWIND_ENTRY_SIZE 8
@@ -800,7 +785,7 @@ hppa32_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr,
                 the higher-ordered word is stored in the lower-ordered
                 argument, and even though it is a 8-byte quantity the
                 registers need not be 8-byte aligned.  */
-             if (param_len > 4)
+             if (param_len > 4 && param_len < 8)
                small_struct = 1;
            }
 
@@ -1735,6 +1720,7 @@ hppa_frame_cache (struct frame_info *next_frame, void **this_cache)
        the current function (and is thus equivalent to the "saved"
        stack pointer.  */
     CORE_ADDR this_sp = frame_unwind_register_unsigned (next_frame, HPPA_SP_REGNUM);
+    CORE_ADDR fp;
 
     if (hppa_debug)
       fprintf_unfiltered (gdb_stdlog, " (this_sp=0x%s, pc=0x%s, "
@@ -1743,7 +1729,38 @@ hppa_frame_cache (struct frame_info *next_frame, void **this_cache)
                          paddr_nz (frame_pc_unwind (next_frame)),
                          paddr_nz (prologue_end));
 
-    if (frame_pc_unwind (next_frame) >= prologue_end)
+     /* Check to see if a frame pointer is available, and use it for
+        frame unwinding if it is.
+        There are some situations where we need to rely on the frame
+        pointer to do stack unwinding.  For example, if a function calls
+        alloca (), the stack pointer can get adjusted inside the body of
+        the function.  In this case, the ABI requires that the compiler
+        maintain a frame pointer for the function.
+        The unwind record has a flag (alloca_frame) that indicates that
+        a function has a variable frame; unfortunately, gcc/binutils 
+        does not set this flag.  Instead, whenever a frame pointer is used
+        and saved on the stack, the Save_SP flag is set.  We use this to
+        decide whether to use the frame pointer for unwinding.
+       
+       fp should never be zero here; checking just in case. 
+       
+        TODO: For the HP compiler, maybe we should use the alloca_frame flag 
+       instead of Save_SP.  */
+     fp = frame_unwind_register_unsigned (next_frame, HPPA_FP_REGNUM);
+     if (frame_pc_unwind (next_frame) >= prologue_end
+         && u->Save_SP && fp != 0)
+      {
+       cache->base = fp;
+       if (hppa_debug)
+         fprintf_unfiltered (gdb_stdlog, " (base=0x%s) [frame pointer] }",
+           paddr_nz (cache->base));
+      }
+     else if (frame_pc_unwind (next_frame) >= prologue_end)
       {
         if (u->Save_SP && trad_frame_addr_p (cache->saved_regs, HPPA_SP_REGNUM))
           {
@@ -1785,7 +1802,7 @@ hppa_frame_cache (struct frame_info *next_frame, void **this_cache)
      as the return register while normal code uses "rp".  */
   if (u->Millicode)
     {
-      if (trad_frame_addr_p (cache->saved_regs, HPPA_RP_REGNUM))
+      if (trad_frame_addr_p (cache->saved_regs, 31))
         cache->saved_regs[HPPA_PCOQ_HEAD_REGNUM] = cache->saved_regs[31];
       else
        {
@@ -1870,6 +1887,7 @@ static struct hppa_frame_cache *
 hppa_fallback_frame_cache (struct frame_info *next_frame, void **this_cache)
 {
   struct hppa_frame_cache *cache;
+  unsigned int frame_size;
   CORE_ADDR pc, start_pc, end_pc, cur_pc;
 
   cache = FRAME_OBSTACK_ZALLOC (struct hppa_frame_cache);
@@ -1878,6 +1896,7 @@ hppa_fallback_frame_cache (struct frame_info *next_frame, void **this_cache)
 
   pc = frame_func_unwind (next_frame);
   cur_pc = frame_pc_unwind (next_frame);
+  frame_size = 0;
 
   find_pc_partial_function (pc, NULL, &start_pc, &end_pc);
 
@@ -1897,21 +1916,18 @@ hppa_fallback_frame_cache (struct frame_info *next_frame, void **this_cache)
 
       insn = read_memory_unsigned_integer (pc, 4);
 
+      frame_size += prologue_inst_adjust_sp (insn);
+
       /* There are limited ways to store the return pointer into the
         stack.  */
       if (insn == 0x6bc23fd9) /* stw rp,-0x14(sr0,sp) */
-       {
-         cache->saved_regs[HPPA_RP_REGNUM].addr = -20;
-         break;
-       }
+        cache->saved_regs[HPPA_RP_REGNUM].addr = -20;
       else if (insn == 0x0fc212c1) /* std rp,-0x10(sr0,sp) */
-       {
-         cache->saved_regs[HPPA_RP_REGNUM].addr = -16;
-         break;
-       }
+        cache->saved_regs[HPPA_RP_REGNUM].addr = -16;
     }
 
-  cache->base = frame_unwind_register_unsigned (next_frame, HPPA_SP_REGNUM);
+  cache->base = frame_unwind_register_unsigned (next_frame, HPPA_SP_REGNUM) - frame_size;
+  trad_frame_set_value (cache->saved_regs, HPPA_SP_REGNUM, cache->base);
 
   if (trad_frame_addr_p (cache->saved_regs, HPPA_RP_REGNUM))
     {
@@ -1997,6 +2013,7 @@ hppa_stub_frame_unwind_cache (struct frame_info *next_frame,
 {
   struct gdbarch *gdbarch = get_frame_arch (next_frame);
   struct hppa_stub_unwind_cache *info;
+  struct unwind_table_entry *u;
 
   if (*this_cache)
     return *this_cache;
@@ -2005,9 +2022,26 @@ hppa_stub_frame_unwind_cache (struct frame_info *next_frame,
   *this_cache = info;
   info->saved_regs = trad_frame_alloc_saved_regs (next_frame);
 
-  info->saved_regs[HPPA_PCOQ_HEAD_REGNUM].realreg = HPPA_RP_REGNUM;
   info->base = frame_unwind_register_unsigned (next_frame, HPPA_SP_REGNUM);
 
+  if (gdbarch_osabi (gdbarch) == GDB_OSABI_HPUX_SOM)
+    {
+      /* HPUX uses export stubs in function calls; the export stub clobbers
+         the return value of the caller, and, later restores it from the
+        stack.  */
+      u = find_unwind_entry (frame_pc_unwind (next_frame));
+
+      if (u && u->stub_unwind.stub_type == EXPORT)
+       {
+          info->saved_regs[HPPA_PCOQ_HEAD_REGNUM].addr = info->base - 24;
+
+         return info;
+       }
+    }
+
+  /* By default we assume that stubs do not change the rp.  */
+  info->saved_regs[HPPA_PCOQ_HEAD_REGNUM].realreg = HPPA_RP_REGNUM;
+
   return info;
 }
 
@@ -2045,7 +2079,8 @@ hppa_stub_unwind_sniffer (struct frame_info *next_frame)
 {
   CORE_ADDR pc = frame_pc_unwind (next_frame);
 
-  if (IN_SOLIB_CALL_TRAMPOLINE (pc, NULL)
+  if (pc == 0
+      || IN_SOLIB_CALL_TRAMPOLINE (pc, NULL)
       || IN_SOLIB_RETURN_TRAMPOLINE (pc, NULL))
     return &hppa_stub_frame_unwind;
   return NULL;
@@ -2281,20 +2316,32 @@ hppa_frame_prev_register_helper (struct frame_info *next_frame,
                                 enum lval_type *lvalp, CORE_ADDR *addrp,
                                 int *realnump, void *valuep)
 {
-  int pcoqt = (regnum == HPPA_PCOQ_TAIL_REGNUM);
-  struct gdbarch *gdbarch = get_frame_arch (next_frame);
-  int regsize = register_size (gdbarch, HPPA_PCOQ_HEAD_REGNUM);
+  if (regnum == HPPA_PCOQ_TAIL_REGNUM)
+    {
+      if (valuep)
+       {
+         CORE_ADDR pc;
+
+         trad_frame_prev_register (next_frame, saved_regs,
+                                   HPPA_PCOQ_HEAD_REGNUM, optimizedp,
+                                   lvalp, addrp, realnump, valuep);
 
-  if (pcoqt)
-    regnum = HPPA_PCOQ_HEAD_REGNUM;
+         pc = extract_unsigned_integer (valuep, 4);
+         store_unsigned_integer (valuep, 4, pc + 4);
+       }
+
+      /* It's a computed value.  */
+      *optimizedp = 0;
+      *lvalp = not_lval;
+      *addrp = 0;
+      *realnump = -1;
+      return;
+    }
 
   trad_frame_prev_register (next_frame, saved_regs, regnum,
                             optimizedp, lvalp, addrp, realnump, valuep);
-
-  if (pcoqt)
-    store_unsigned_integer (valuep, regsize, 
-                           extract_unsigned_integer (valuep, regsize) + 4);
 }
+\f
 
 /* Here is a table of C type sizes on hppa with various compiles
    and options.  I measured this on PA 9000/800 with HP-UX 11.11
@@ -2524,4 +2571,3 @@ be no argument or the argument must be a depth.\n"), NULL);
                                  &hppa_debug, "Set hppa debugging.\n\
 When non-zero, hppa specific debugging is enabled.", &setdebuglist), &showdebuglist);
 }
-
This page took 0.02788 seconds and 4 git commands to generate.