* configure.ac: Use AC_CHECK_DECLS instead of gcc_AC_CHECK_DECLS
[deliverable/binutils-gdb.git] / gdb / dwarf2-frame.c
index 1012f440003c79f2e1696dd67de5de59d4054d8c..fc0ac8b709eb996f759a7efcb096d668b47824af 100644 (file)
@@ -162,7 +162,7 @@ dwarf2_frame_state_alloc_regs (struct dwarf2_frame_state_reg_info *rs,
 static struct dwarf2_frame_state_reg *
 dwarf2_frame_state_copy_regs (struct dwarf2_frame_state_reg_info *rs)
 {
-  size_t size = rs->num_regs * sizeof (struct dwarf2_frame_state_reg_info);
+  size_t size = rs->num_regs * sizeof (struct dwarf2_frame_state_reg);
   struct dwarf2_frame_state_reg *reg;
 
   reg = (struct dwarf2_frame_state_reg *) xmalloc (size);
@@ -372,11 +372,17 @@ execute_cfa_program (unsigned char *insn_ptr, unsigned char *insn_end,
              {
                struct dwarf2_frame_state_reg_info *old_rs = fs->regs.prev;
 
-               gdb_assert (old_rs);
-
-               xfree (fs->regs.reg);
-               fs->regs = *old_rs;
-               xfree (old_rs);
+               if (old_rs == NULL)
+                 {
+                   complaint (&symfile_complaints, "\
+bad CFI data; mismatched DW_CFA_restore_state at 0x%s", paddr (fs->pc));
+                 }
+               else
+                 {
+                   xfree (fs->regs.reg);
+                   fs->regs = *old_rs;
+                   xfree (old_rs);
+                 }
              }
              break;
 
@@ -420,7 +426,7 @@ execute_cfa_program (unsigned char *insn_ptr, unsigned char *insn_end,
            case DW_CFA_offset_extended_sf:
              insn_ptr = read_uleb128 (insn_ptr, insn_end, &reg);
              insn_ptr = read_sleb128 (insn_ptr, insn_end, &offset);
-             offset += fs->data_align;
+             offset *= fs->data_align;
              dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
              fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_OFFSET;
              fs->regs.reg[reg].loc.offset = offset;
@@ -465,6 +471,10 @@ struct dwarf2_frame_ops
 {
   /* Pre-initialize the register state REG for register REGNUM.  */
   void (*init_reg) (struct gdbarch *, int, struct dwarf2_frame_state_reg *);
+
+  /* Check whether the frame preceding NEXT_FRAME will be a signal
+     trampoline.  */
+  int (*signal_frame_p) (struct gdbarch *, struct frame_info *);
 };
 
 /* Default architecture-specific register state initialization
@@ -509,11 +519,11 @@ dwarf2_frame_default_init_reg (struct gdbarch *gdbarch, int regnum,
 /* Return a default for the architecture-specific operations.  */
 
 static void *
-dwarf2_frame_init (struct gdbarch *gdbarch)
+dwarf2_frame_init (struct obstack *obstack)
 {
   struct dwarf2_frame_ops *ops;
   
-  ops = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct dwarf2_frame_ops);
+  ops = OBSTACK_ZALLOC (obstack, struct dwarf2_frame_ops);
   ops->init_reg = dwarf2_frame_default_init_reg;
   return ops;
 }
@@ -526,9 +536,8 @@ dwarf2_frame_set_init_reg (struct gdbarch *gdbarch,
                           void (*init_reg) (struct gdbarch *, int,
                                             struct dwarf2_frame_state_reg *))
 {
-  struct dwarf2_frame_ops *ops;
+  struct dwarf2_frame_ops *ops = gdbarch_data (gdbarch, dwarf2_frame_data);
 
-  ops = gdbarch_data (gdbarch, dwarf2_frame_data);
   ops->init_reg = init_reg;
 }
 
@@ -538,11 +547,37 @@ static void
 dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
                       struct dwarf2_frame_state_reg *reg)
 {
-  struct dwarf2_frame_ops *ops;
+  struct dwarf2_frame_ops *ops = gdbarch_data (gdbarch, dwarf2_frame_data);
 
-  ops = gdbarch_data (gdbarch, dwarf2_frame_data);
   ops->init_reg (gdbarch, regnum, reg);
 }
+
+/* Set the architecture-specific signal trampoline recognition
+   function for GDBARCH to SIGNAL_FRAME_P.  */
+
+void
+dwarf2_frame_set_signal_frame_p (struct gdbarch *gdbarch,
+                                int (*signal_frame_p) (struct gdbarch *,
+                                                       struct frame_info *))
+{
+  struct dwarf2_frame_ops *ops = gdbarch_data (gdbarch, dwarf2_frame_data);
+
+  ops->signal_frame_p = signal_frame_p;
+}
+
+/* Query the architecture-specific signal frame recognizer for
+   NEXT_FRAME.  */
+
+static int
+dwarf2_frame_signal_frame_p (struct gdbarch *gdbarch,
+                            struct frame_info *next_frame)
+{
+  struct dwarf2_frame_ops *ops = gdbarch_data (gdbarch, dwarf2_frame_data);
+
+  if (ops->signal_frame_p == NULL)
+    return 0;
+  return ops->signal_frame_p (gdbarch, next_frame);
+}
 \f
 
 struct dwarf2_frame_cache
@@ -670,9 +705,13 @@ dwarf2_frame_cache (struct frame_info *next_frame, void **this_cache)
           table.  We need a way of iterating through all the valid
           DWARF2 register numbers.  */
        if (fs->regs.reg[column].how == DWARF2_FRAME_REG_UNSPECIFIED)
-         complaint (&symfile_complaints,
-                    "Incomplete CFI data; unspecified registers at 0x%s",
-                    paddr (fs->pc));
+         {
+           if (cache->reg[regnum].how == DWARF2_FRAME_REG_UNSPECIFIED)
+             complaint (&symfile_complaints, "\
+incomplete CFI data; unspecified registers (e.g., %s) at 0x%s",
+                        gdbarch_register_name (gdbarch, regnum),
+                        paddr_nz (fs->pc));
+         }
        else
          cache->reg[regnum] = fs->regs.reg[column];
       }
@@ -766,9 +805,12 @@ dwarf2_frame_prev_register (struct frame_info *next_frame, void **this_cache,
       break;
 
     case DWARF2_FRAME_REG_SAVED_REG:
-      regnum = DWARF2_REG_TO_REGNUM (cache->reg[regnum].loc.reg);
-      frame_register_unwind (next_frame, regnum,
-                            optimizedp, lvalp, addrp, realnump, valuep);
+      *optimizedp = 0;
+      *lvalp = lval_register;
+      *addrp = 0;
+      *realnump = DWARF2_REG_TO_REGNUM (cache->reg[regnum].loc.reg);
+      if (valuep)
+       frame_unwind_register (next_frame, (*realnump), valuep);
       break;
 
     case DWARF2_FRAME_REG_SAVED_EXP:
@@ -793,13 +835,21 @@ dwarf2_frame_prev_register (struct frame_info *next_frame, void **this_cache,
         "undefined").  Code above issues a complaint about this.
         Here just fudge the books, assume GCC, and that the value is
         more inner on the stack.  */
-      frame_register_unwind (next_frame, regnum,
-                            optimizedp, lvalp, addrp, realnump, valuep);
+      *optimizedp = 0;
+      *lvalp = lval_register;
+      *addrp = 0;
+      *realnump = regnum;
+      if (valuep)
+       frame_unwind_register (next_frame, (*realnump), valuep);
       break;
 
     case DWARF2_FRAME_REG_SAME_VALUE:
-      frame_register_unwind (next_frame, regnum,
-                            optimizedp, lvalp, addrp, realnump, valuep);
+      *optimizedp = 0;
+      *lvalp = lval_register;
+      *addrp = 0;
+      *realnump = regnum;
+      if (valuep)
+       frame_unwind_register (next_frame, (*realnump), valuep);
       break;
 
     case DWARF2_FRAME_REG_CFA:
@@ -826,6 +876,13 @@ static const struct frame_unwind dwarf2_frame_unwind =
   dwarf2_frame_prev_register
 };
 
+static const struct frame_unwind dwarf2_signal_frame_unwind =
+{
+  SIGTRAMP_FRAME,
+  dwarf2_frame_this_id,
+  dwarf2_frame_prev_register
+};
+
 const struct frame_unwind *
 dwarf2_frame_sniffer (struct frame_info *next_frame)
 {
@@ -833,10 +890,18 @@ dwarf2_frame_sniffer (struct frame_info *next_frame)
      function.  frame_pc_unwind(), for a no-return next function, can
      end up returning something past the end of this function's body.  */
   CORE_ADDR block_addr = frame_unwind_address_in_block (next_frame);
-  if (dwarf2_frame_find_fde (&block_addr))
-    return &dwarf2_frame_unwind;
+  if (!dwarf2_frame_find_fde (&block_addr))
+    return NULL;
 
-  return NULL;
+  /* On some targets, signal trampolines may have unwind information.
+     We need to recognize them so that we set the frame type
+     correctly.  */
+
+  if (dwarf2_frame_signal_frame_p (get_frame_arch (next_frame),
+                                  next_frame))
+    return &dwarf2_signal_frame_unwind;
+
+  return &dwarf2_frame_unwind;
 }
 \f
 
@@ -886,9 +951,6 @@ struct comp_unit
   /* Linked list of CIEs for this object.  */
   struct dwarf2_cie *cie;
 
-  /* Address size for this unit - from unit header.  */
-  unsigned char addr_size;
-
   /* Pointer to the .debug_frame section loaded into memory.  */
   char *dwarf_frame_buffer;
 
@@ -1055,7 +1117,7 @@ size_of_encoded_value (unsigned char encoding)
 
 static CORE_ADDR
 read_encoded_value (struct comp_unit *unit, unsigned char encoding,
-                   char *buf, unsigned int *bytes_read_ptr)
+                   unsigned char *buf, unsigned int *bytes_read_ptr)
 {
   int ptr_len = size_of_encoded_value (DW_EH_PE_absptr);
   ptrdiff_t offset;
@@ -1076,7 +1138,7 @@ read_encoded_value (struct comp_unit *unit, unsigned char encoding,
       break;
     case DW_EH_PE_pcrel:
       base = bfd_get_section_vma (unit->bfd, unit->dwarf_frame_section);
-      base += (buf - unit->dwarf_frame_buffer);
+      base += ((char *) buf - unit->dwarf_frame_buffer);
       break;
     case DW_EH_PE_datarel:
       base = unit->dbase;
@@ -1084,9 +1146,17 @@ read_encoded_value (struct comp_unit *unit, unsigned char encoding,
     case DW_EH_PE_textrel:
       base = unit->tbase;
       break;
+    case DW_EH_PE_funcrel:
+      /* FIXME: kettenis/20040501: For now just pretend
+         DW_EH_PE_funcrel is equivalent to DW_EH_PE_absptr.  For
+         reading the initial location of an FDE it should be treated
+         as such, and currently that's the only place where this code
+         is used.  */
+      base = 0;
+      break;
     case DW_EH_PE_aligned:
       base = 0;
-      offset = buf - unit->dwarf_frame_buffer;
+      offset = (char *) buf - unit->dwarf_frame_buffer;
       if ((offset % ptr_len) != 0)
        {
          *bytes_read_ptr = ptr_len - (offset % ptr_len);
@@ -1097,11 +1167,18 @@ read_encoded_value (struct comp_unit *unit, unsigned char encoding,
       internal_error (__FILE__, __LINE__, "Invalid or unsupported encoding");
     }
 
-  if ((encoding & 0x0f) == 0x00)
+  if ((encoding & 0x07) == 0x00)
     encoding |= encoding_for_size (ptr_len);
 
   switch (encoding & 0x0f)
     {
+    case DW_EH_PE_uleb128:
+      {
+       ULONGEST value;
+       unsigned char *end_buf = buf + (sizeof (value) + 1) * 8 / 7;
+       *bytes_read_ptr += read_uleb128 (buf, end_buf, &value) - buf;
+       return base + value;
+      }
     case DW_EH_PE_udata2:
       *bytes_read_ptr += 2;
       return (base + bfd_get_16 (unit->abfd, (bfd_byte *) buf));
@@ -1111,6 +1188,13 @@ read_encoded_value (struct comp_unit *unit, unsigned char encoding,
     case DW_EH_PE_udata8:
       *bytes_read_ptr += 8;
       return (base + bfd_get_64 (unit->abfd, (bfd_byte *) buf));
+    case DW_EH_PE_sleb128:
+      {
+       LONGEST value;
+       char *end_buf = buf + (sizeof (value) + 1) * 8 / 7;
+       *bytes_read_ptr += read_sleb128 (buf, end_buf, &value) - buf;
+       return base + value;
+      }
     case DW_EH_PE_sdata2:
       *bytes_read_ptr += 2;
       return (base + bfd_get_signed_16 (unit->abfd, (bfd_byte *) buf));
@@ -1256,6 +1340,7 @@ decode_frame_entry_1 (struct comp_unit *unit, char *start, int eh_frame_p)
       /* This is a CIE.  */
       struct dwarf2_cie *cie;
       char *augmentation;
+      unsigned int cie_version;
 
       /* Record the offset into the .debug_frame section of this CIE.  */
       cie_pointer = start - unit->dwarf_frame_buffer;
@@ -1271,12 +1356,12 @@ decode_frame_entry_1 (struct comp_unit *unit, char *start, int eh_frame_p)
       cie->cie_pointer = cie_pointer;
 
       /* The encoding for FDE's in a normal .debug_frame section
-         depends on the target address size as specified in the
-         Compilation Unit Header.  */
-      cie->encoding = encoding_for_size (unit->addr_size);
+         depends on the target address size.  */
+      cie->encoding = DW_EH_PE_absptr;
 
       /* Check version number.  */
-      if (read_1_byte (unit->abfd, buf) != DW_CIE_VERSION)
+      cie_version = read_1_byte (unit->abfd, buf);
+      if (cie_version != 1 && cie_version != 3)
        return NULL;
       buf += 1;
 
@@ -1302,8 +1387,15 @@ decode_frame_entry_1 (struct comp_unit *unit, char *start, int eh_frame_p)
        read_signed_leb128 (unit->abfd, buf, &bytes_read);
       buf += bytes_read;
 
-      cie->return_address_register = read_1_byte (unit->abfd, buf);
-      buf += 1;
+      if (cie_version == 1)
+       {
+         cie->return_address_register = read_1_byte (unit->abfd, buf);
+         bytes_read = 1;
+       }
+      else
+       cie->return_address_register = read_unsigned_leb128 (unit->abfd, buf,
+                                                            &bytes_read);
+      buf += bytes_read;
 
       cie->saw_z_augmentation = (*augmentation == 'z');
       if (cie->saw_z_augmentation)
@@ -1338,8 +1430,10 @@ decode_frame_entry_1 (struct comp_unit *unit, char *start, int eh_frame_p)
          /* "P" indicates a personality routine in the CIE augmentation.  */
          else if (*augmentation == 'P')
            {
-             /* Skip.  */
-             buf += size_of_encoded_value (*buf++);
+             /* Skip.  Avoid indirection since we throw away the result.  */
+             unsigned char encoding = (*buf++) & ~DW_EH_PE_indirect;
+             read_encoded_value (unit, encoding, buf, &bytes_read);
+             buf += bytes_read;
              augmentation++;
            }
 
@@ -1536,7 +1630,6 @@ dwarf2_build_frame_info (struct objfile *objfile)
   /* Build a minimal decoding of the DWARF2 compilation unit.  */
   unit.abfd = objfile->obfd;
   unit.objfile = objfile;
-  unit.addr_size = objfile->obfd->arch_info->bits_per_address / 8;
   unit.dbase = 0;
   unit.tbase = 0;
 
@@ -1550,8 +1643,7 @@ dwarf2_build_frame_info (struct objfile *objfile)
       unit.dwarf_frame_buffer = dwarf2_read_section (objfile,
                                                     dwarf_eh_frame_section);
 
-      unit.dwarf_frame_size
-       = bfd_get_section_size_before_reloc (dwarf_eh_frame_section);
+      unit.dwarf_frame_size = bfd_get_section_size (dwarf_eh_frame_section);
       unit.dwarf_frame_section = dwarf_eh_frame_section;
 
       /* FIXME: kettenis/20030602: This is the DW_EH_PE_datarel base
@@ -1578,8 +1670,7 @@ dwarf2_build_frame_info (struct objfile *objfile)
       unit.cie = NULL;
       unit.dwarf_frame_buffer = dwarf2_read_section (objfile,
                                                     dwarf_frame_section);
-      unit.dwarf_frame_size
-       = bfd_get_section_size_before_reloc (dwarf_frame_section);
+      unit.dwarf_frame_size = bfd_get_section_size (dwarf_frame_section);
       unit.dwarf_frame_section = dwarf_frame_section;
 
       frame_ptr = unit.dwarf_frame_buffer;
@@ -1594,6 +1685,6 @@ void _initialize_dwarf2_frame (void);
 void
 _initialize_dwarf2_frame (void)
 {
-  dwarf2_frame_data = register_gdbarch_data (dwarf2_frame_init);
+  dwarf2_frame_data = gdbarch_data_register_pre_init (dwarf2_frame_init);
   dwarf2_frame_objfile_data = register_objfile_data ();
 }
This page took 0.028244 seconds and 4 git commands to generate.