Make mapped_debug_names independent of objfile
[deliverable/binutils-gdb.git] / gdb / dwarf2 / frame.c
index 7397a7fbeb28cc11df4105de3e69cd7bfd543b3c..a8748e4d7d3fb9b2faa6e5de3daf4b2e52774ca4 100644 (file)
@@ -137,16 +137,13 @@ typedef std::vector<dwarf2_fde *> dwarf2_fde_table;
 struct comp_unit
 {
   comp_unit (struct objfile *objf)
-    : abfd (objf->obfd),
-      objfile (objf)
+    : abfd (objf->obfd)
   {
   }
 
   /* Keep the bfd convenient.  */
   bfd *abfd;
 
-  struct objfile *objfile;
-
   /* Pointer to the .debug_frame section loaded into memory.  */
   const gdb_byte *dwarf_frame_buffer = nullptr;
 
@@ -169,8 +166,8 @@ struct comp_unit
   auto_obstack obstack;
 };
 
-static struct dwarf2_fde *dwarf2_frame_find_fde (CORE_ADDR *pc,
-                                                CORE_ADDR *out_offset);
+static struct dwarf2_fde *dwarf2_frame_find_fde
+  (CORE_ADDR *pc, dwarf2_per_objfile **out_per_objfile);
 
 static int dwarf2_frame_adjust_regnum (struct gdbarch *gdbarch, int regnum,
                                       int eh_frame_p);
@@ -240,7 +237,11 @@ register %s (#%d) at %s"),
 
 class dwarf_expr_executor : public dwarf_expr_context
 {
- public:
+public:
+
+  dwarf_expr_executor (dwarf2_per_objfile *per_objfile)
+    : dwarf_expr_context (per_objfile)
+  {}
 
   struct frame_info *this_frame;
 
@@ -314,19 +315,18 @@ class dwarf_expr_executor : public dwarf_expr_context
 
 static CORE_ADDR
 execute_stack_op (const gdb_byte *exp, ULONGEST len, int addr_size,
-                 CORE_ADDR offset, struct frame_info *this_frame,
-                 CORE_ADDR initial, int initial_in_stack_memory)
+                 struct frame_info *this_frame, CORE_ADDR initial,
+                 int initial_in_stack_memory, dwarf2_per_objfile *per_objfile)
 {
   CORE_ADDR result;
 
-  dwarf_expr_executor ctx;
+  dwarf_expr_executor ctx (per_objfile);
   scoped_value_mark free_values;
 
   ctx.this_frame = this_frame;
   ctx.gdbarch = get_frame_arch (this_frame);
   ctx.addr_size = addr_size;
   ctx.ref_addr_size = -1;
-  ctx.offset = offset;
 
   ctx.push_address (initial, initial_in_stack_memory);
   ctx.eval (exp, len);
@@ -355,7 +355,8 @@ Not implemented: computing unwound register using explicit value operator"));
 static const gdb_byte *
 execute_cfa_program (struct dwarf2_fde *fde, const gdb_byte *insn_ptr,
                     const gdb_byte *insn_end, struct gdbarch *gdbarch,
-                    CORE_ADDR pc, struct dwarf2_frame_state *fs)
+                    CORE_ADDR pc, struct dwarf2_frame_state *fs,
+                    CORE_ADDR text_offset)
 {
   int eh_frame_p = fde->eh_frame_p;
   unsigned int bytes_read;
@@ -392,8 +393,8 @@ execute_cfa_program (struct dwarf2_fde *fde, const gdb_byte *insn_ptr,
              fs->pc = read_encoded_value (fde->cie->unit, fde->cie->encoding,
                                           fde->cie->ptr_size, insn_ptr,
                                           &bytes_read, fde->initial_location);
-             /* Apply the objfile offset for relocatable objects.  */
-             fs->pc += fde->cie->unit->objfile->text_section_offset ();
+             /* Apply the text offset for relocatable objects.  */
+             fs->pc += text_offset;
              insn_ptr += bytes_read;
              break;
 
@@ -652,7 +653,7 @@ execute_cfa_program_test (struct gdbarch *gdbarch)
 
   const gdb_byte *insn_end = insns + sizeof (insns);
   const gdb_byte *out = execute_cfa_program (&fde, insns, insn_end, gdbarch,
-                                            0, &fs);
+                                            0, &fs, 0);
 
   SELF_CHECK (out == insn_end);
   SELF_CHECK (fs.pc == 0);
@@ -885,14 +886,16 @@ dwarf2_fetch_cfa_info (struct gdbarch *gdbarch, CORE_ADDR pc,
                       const gdb_byte **cfa_end_out)
 {
   struct dwarf2_fde *fde;
-  CORE_ADDR text_offset;
+  dwarf2_per_objfile *per_objfile;
   CORE_ADDR pc1 = pc;
 
   /* Find the correct FDE.  */
-  fde = dwarf2_frame_find_fde (&pc1, &text_offset);
+  fde = dwarf2_frame_find_fde (&pc1, &per_objfile);
   if (fde == NULL)
     error (_("Could not compute CFA; needed to translate this expression"));
 
+  gdb_assert (per_objfile != nullptr);
+
   dwarf2_frame_state fs (pc1, fde->cie);
 
   /* Check for "quirks" - known bugs in producers.  */
@@ -900,13 +903,15 @@ dwarf2_fetch_cfa_info (struct gdbarch *gdbarch, CORE_ADDR pc,
 
   /* First decode all the insns in the CIE.  */
   execute_cfa_program (fde, fde->cie->initial_instructions,
-                      fde->cie->end, gdbarch, pc, &fs);
+                      fde->cie->end, gdbarch, pc, &fs,
+                      per_objfile->objfile->text_section_offset ());
 
   /* Save the initialized register set.  */
   fs.initial = fs.regs;
 
   /* Then decode the insns in the FDE up to our target PC.  */
-  execute_cfa_program (fde, fde->instructions, fde->end, gdbarch, pc, &fs);
+  execute_cfa_program (fde, fde->instructions, fde->end, gdbarch, pc, &fs,
+                      per_objfile->objfile->text_section_offset ());
 
   /* Calculate the CFA.  */
   switch (fs.regs.cfa_how)
@@ -924,7 +929,7 @@ dwarf2_fetch_cfa_info (struct gdbarch *gdbarch, CORE_ADDR pc,
       }
 
     case CFA_EXP:
-      *text_offset_out = text_offset;
+      *text_offset_out = per_objfile->objfile->text_section_offset ();
       *cfa_start_out = fs.regs.cfa_exp;
       *cfa_end_out = fs.regs.cfa_exp + fs.regs.cfa_exp_len;
       return 0;
@@ -957,12 +962,8 @@ struct dwarf2_frame_cache
   /* Target address size in bytes.  */
   int addr_size;
 
-  /* The .text offset.  */
-  CORE_ADDR text_offset;
-
-  /* True if we already checked whether this frame is the bottom frame
-     of a virtual tail call frame chain.  */
-  int checked_tailcall_bottom;
+  /* The dwarf2_per_objfile from which this frame description came.  */
+  dwarf2_per_objfile *per_objfile;
 
   /* If not NULL then this frame is the bottom frame of a TAILCALL_FRAME
      sequence.  If NULL then it is a normal case with no TAILCALL_FRAME
@@ -970,12 +971,6 @@ struct dwarf2_frame_cache
      dwarf2_tailcall_frame_unwind unwinder so this field does not apply for
      them.  */
   void *tailcall_cache;
-
-  /* The number of bytes to subtract from TAILCALL_FRAME frames frame
-     base to get the SP, to simulate the return address pushed on the
-     stack.  */
-  LONGEST entry_cfa_sp_offset;
-  int entry_cfa_sp_offset_p;
 };
 
 static struct dwarf2_frame_cache *
@@ -1014,8 +1009,9 @@ dwarf2_frame_cache (struct frame_info *this_frame, void **this_cache)
   CORE_ADDR pc1 = get_frame_address_in_block (this_frame);
 
   /* Find the correct FDE.  */
-  fde = dwarf2_frame_find_fde (&pc1, &cache->text_offset);
+  fde = dwarf2_frame_find_fde (&pc1, &cache->per_objfile);
   gdb_assert (fde != NULL);
+  gdb_assert (cache->per_objfile != nullptr);
 
   /* Allocate and initialize the frame state.  */
   struct dwarf2_frame_state fs (pc1, fde->cie);
@@ -1028,7 +1024,8 @@ dwarf2_frame_cache (struct frame_info *this_frame, void **this_cache)
   /* First decode all the insns in the CIE.  */
   execute_cfa_program (fde, fde->cie->initial_instructions,
                       fde->cie->end, gdbarch,
-                      get_frame_address_in_block (this_frame), &fs);
+                      get_frame_address_in_block (this_frame), &fs,
+                      cache->per_objfile->objfile->text_section_offset ());
 
   /* Save the initialized register set.  */
   fs.initial = fs.regs;
@@ -1037,20 +1034,23 @@ dwarf2_frame_cache (struct frame_info *this_frame, void **this_cache)
      in an address that's within the range of FDE locations.  This
      is due to the possibility of the function occupying non-contiguous
      ranges.  */
+  LONGEST entry_cfa_sp_offset;
+  int entry_cfa_sp_offset_p = 0;
   if (get_frame_func_if_available (this_frame, &entry_pc)
       && fde->initial_location <= entry_pc
       && entry_pc < fde->initial_location + fde->address_range)
     {
       /* Decode the insns in the FDE up to the entry PC.  */
-      instr = execute_cfa_program (fde, fde->instructions, fde->end, gdbarch,
-                                  entry_pc, &fs);
+      instr = execute_cfa_program
+       (fde, fde->instructions, fde->end, gdbarch, entry_pc, &fs,
+        cache->per_objfile->objfile->text_section_offset ());
 
       if (fs.regs.cfa_how == CFA_REG_OFFSET
          && (dwarf_reg_to_regnum (gdbarch, fs.regs.cfa_reg)
              == gdbarch_sp_regnum (gdbarch)))
        {
-         cache->entry_cfa_sp_offset = fs.regs.cfa_offset;
-         cache->entry_cfa_sp_offset_p = 1;
+         entry_cfa_sp_offset = fs.regs.cfa_offset;
+         entry_cfa_sp_offset_p = 1;
        }
     }
   else
@@ -1058,7 +1058,8 @@ dwarf2_frame_cache (struct frame_info *this_frame, void **this_cache)
 
   /* Then decode the insns in the FDE up to our target PC.  */
   execute_cfa_program (fde, instr, fde->end, gdbarch,
-                      get_frame_address_in_block (this_frame), &fs);
+                      get_frame_address_in_block (this_frame), &fs,
+                      cache->per_objfile->objfile->text_section_offset ());
 
   try
     {
@@ -1076,8 +1077,8 @@ dwarf2_frame_cache (struct frame_info *this_frame, void **this_cache)
        case CFA_EXP:
          cache->cfa =
            execute_stack_op (fs.regs.cfa_exp, fs.regs.cfa_exp_len,
-                             cache->addr_size, cache->text_offset,
-                             this_frame, 0, 0);
+                             cache->addr_size, this_frame, 0, 0,
+                             cache->per_objfile);
          break;
 
        default:
@@ -1194,6 +1195,10 @@ incomplete CFI data; unspecified registers (e.g., %s) at %s"),
       && fs.regs.reg[fs.retaddr_column].how == DWARF2_FRAME_REG_UNDEFINED)
     cache->undefined_retaddr = 1;
 
+  dwarf2_tailcall_sniffer_first (this_frame, &cache->tailcall_cache,
+                                (entry_cfa_sp_offset_p
+                                 ? &entry_cfa_sp_offset : NULL));
+
   return cache;
 }
 
@@ -1238,16 +1243,6 @@ dwarf2_frame_prev_register (struct frame_info *this_frame, void **this_cache,
   CORE_ADDR addr;
   int realnum;
 
-  /* Check whether THIS_FRAME is the bottom frame of a virtual tail
-     call frame chain.  */
-  if (!cache->checked_tailcall_bottom)
-    {
-      cache->checked_tailcall_bottom = 1;
-      dwarf2_tailcall_sniffer_first (this_frame, &cache->tailcall_cache,
-                                    (cache->entry_cfa_sp_offset_p
-                                     ? &cache->entry_cfa_sp_offset : NULL));
-    }
-
   /* Non-bottom frames of a virtual tail call frames chain use
      dwarf2_tailcall_frame_unwind unwinder so this code does not apply for
      them.  If dwarf2_tailcall_prev_register_first does not have specific value
@@ -1283,8 +1278,9 @@ dwarf2_frame_prev_register (struct frame_info *this_frame, void **this_cache,
     case DWARF2_FRAME_REG_SAVED_EXP:
       addr = execute_stack_op (cache->reg[regnum].loc.exp.start,
                               cache->reg[regnum].loc.exp.len,
-                              cache->addr_size, cache->text_offset,
-                              this_frame, cache->cfa, 1);
+                              cache->addr_size,
+                              this_frame, cache->cfa, 1,
+                              cache->per_objfile);
       return frame_unwind_got_memory (this_frame, regnum, addr);
 
     case DWARF2_FRAME_REG_SAVED_VAL_OFFSET:
@@ -1294,8 +1290,9 @@ dwarf2_frame_prev_register (struct frame_info *this_frame, void **this_cache,
     case DWARF2_FRAME_REG_SAVED_VAL_EXP:
       addr = execute_stack_op (cache->reg[regnum].loc.exp.start,
                               cache->reg[regnum].loc.exp.len,
-                              cache->addr_size, cache->text_offset,
-                              this_frame, cache->cfa, 1);
+                              cache->addr_size,
+                              this_frame, cache->cfa, 1,
+                              cache->per_objfile);
       return frame_unwind_got_constant (this_frame, regnum, addr);
 
     case DWARF2_FRAME_REG_UNSPECIFIED:
@@ -1409,10 +1406,6 @@ static const struct frame_unwind dwarf2_signal_frame_unwind =
 void
 dwarf2_append_unwinders (struct gdbarch *gdbarch)
 {
-  /* TAILCALL_FRAME must be first to find the record by
-     dwarf2_tailcall_sniffer_first.  */
-  frame_unwind_append_unwinder (gdbarch, &dwarf2_tailcall_frame_unwind);
-
   frame_unwind_append_unwinder (gdbarch, &dwarf2_frame_unwind);
   frame_unwind_append_unwinder (gdbarch, &dwarf2_signal_frame_unwind);
 }
@@ -1479,8 +1472,14 @@ dwarf2_frame_cfa (struct frame_info *this_frame)
   return get_frame_base (this_frame);
 }
 \f
-static const struct objfile_key<comp_unit> dwarf2_frame_objfile_data;
-
+/* We store the frame data on the BFD.  This is only done if it is
+   independent of the address space and so can be shared.  */
+static const struct bfd_key<comp_unit> dwarf2_frame_bfd_data;
+
+/* If any BFD sections require relocations (note; really should be if
+   any debug info requires relocations), then we store the frame data
+   on the objfile instead, and do not share it.  */
+const struct objfile_key<comp_unit> dwarf2_frame_objfile_data;
 \f
 
 /* Pointer encoding helper functions.  */
@@ -1634,22 +1633,45 @@ bsearch_fde_cmp (const dwarf2_fde *fde, CORE_ADDR seek_pc)
   return 1;
 }
 
+/* Find an existing comp_unit for an objfile, if any.  */
+
+static comp_unit *
+find_comp_unit (struct objfile *objfile)
+{
+  bfd *abfd = objfile->obfd;
+  if (gdb_bfd_requires_relocations (abfd))
+    return dwarf2_frame_bfd_data.get (abfd);
+  return dwarf2_frame_objfile_data.get (objfile);
+}
+
+/* Store the comp_unit on OBJFILE, or the corresponding BFD, as
+   appropriate.  */
+
+static void
+set_comp_unit (struct objfile *objfile, struct comp_unit *unit)
+{
+  bfd *abfd = objfile->obfd;
+  if (gdb_bfd_requires_relocations (abfd))
+    return dwarf2_frame_bfd_data.set (abfd, unit);
+  return dwarf2_frame_objfile_data.set (objfile, unit);
+}
+
 /* Find the FDE for *PC.  Return a pointer to the FDE, and store the
    initial location associated with it into *PC.  */
 
 static struct dwarf2_fde *
-dwarf2_frame_find_fde (CORE_ADDR *pc, CORE_ADDR *out_offset)
+dwarf2_frame_find_fde (CORE_ADDR *pc, dwarf2_per_objfile **out_per_objfile)
 {
   for (objfile *objfile : current_program_space->objfiles ())
     {
       CORE_ADDR offset;
       CORE_ADDR seek_pc;
 
-      comp_unit *unit = dwarf2_frame_objfile_data.get (objfile);
+      comp_unit *unit = find_comp_unit (objfile);
       if (unit == NULL)
        {
          dwarf2_build_frame_info (objfile);
-         unit = dwarf2_frame_objfile_data.get (objfile);
+         unit = find_comp_unit (objfile);
        }
       gdb_assert (unit != NULL);
 
@@ -1670,8 +1692,9 @@ dwarf2_frame_find_fde (CORE_ADDR *pc, CORE_ADDR *out_offset)
       if (it != fde_table->end ())
         {
           *pc = (*it)->initial_location + offset;
-         if (out_offset)
-           *out_offset = offset;
+         if (out_per_objfile != nullptr)
+           *out_per_objfile = get_dwarf2_per_objfile (objfile);
+
           return *it;
         }
     }
@@ -2089,21 +2112,21 @@ decode_frame_entry (struct gdbarch *gdbarch,
     case ALIGN4:
       complaint (_("\
 Corrupt data in %s:%s; align 4 workaround apparently succeeded"),
-                unit->dwarf_frame_section->owner->filename,
-                unit->dwarf_frame_section->name);
+                bfd_get_filename (unit->dwarf_frame_section->owner),
+                bfd_section_name (unit->dwarf_frame_section));
       break;
 
     case ALIGN8:
       complaint (_("\
 Corrupt data in %s:%s; align 8 workaround apparently succeeded"),
-                unit->dwarf_frame_section->owner->filename,
-                unit->dwarf_frame_section->name);
+                bfd_get_filename (unit->dwarf_frame_section->owner),
+                bfd_section_name (unit->dwarf_frame_section));
       break;
 
     default:
       complaint (_("Corrupt data in %s:%s"),
-                unit->dwarf_frame_section->owner->filename,
-                unit->dwarf_frame_section->name);
+                bfd_get_filename (unit->dwarf_frame_section->owner),
+                bfd_section_name (unit->dwarf_frame_section));
       break;
     }
 
@@ -2135,7 +2158,7 @@ dwarf2_build_frame_info (struct objfile *objfile)
   dwarf2_cie_table cie_table;
   dwarf2_fde_table fde_table;
 
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
 
   /* Build a minimal decoding of the DWARF2 compilation unit.  */
   std::unique_ptr<comp_unit> unit (new comp_unit (objfile));
@@ -2261,7 +2284,7 @@ dwarf2_build_frame_info (struct objfile *objfile)
     }
   unit->fde_table.shrink_to_fit ();
 
-  dwarf2_frame_objfile_data.set (objfile, unit.release ());
+  set_comp_unit (objfile, unit.release ());
 }
 
 /* Handle 'maintenance show dwarf unwinders'.  */
This page took 0.04799 seconds and 4 git commands to generate.