gdb: remove FIELD_TYPE macro
[deliverable/binutils-gdb.git] / gdb / dwarf2 / loc.c
index 033336028206b49c97a43fde31982df7a35017b4..400bb4d16fc7ad7d37bcf03e054d87db96277894 100644 (file)
 #include "gdbsupport/underlying.h"
 #include "gdbsupport/byte-vector.h"
 
-static struct value *dwarf2_evaluate_loc_desc_full (struct type *type,
-                                                   struct frame_info *frame,
-                                                   const gdb_byte *data,
-                                                   size_t size,
-                                                   struct dwarf2_per_cu_data *per_cu,
-                                                   struct type *subobj_type,
-                                                   LONGEST subobj_byte_offset);
+static struct value *dwarf2_evaluate_loc_desc_full
+  (struct type *type, struct frame_info *frame, const gdb_byte *data,
+   size_t size, dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile,
+   struct type *subobj_type, LONGEST subobj_byte_offset);
 
 static struct call_site_parameter *dwarf_expr_reg_to_entry_parameter
     (struct frame_info *frame,
      enum call_site_parameter_kind kind,
      union call_site_parameter_u kind_u,
-     struct dwarf2_per_cu_data **per_cu_return);
+     dwarf2_per_cu_data **per_cu_return,
+     dwarf2_per_objfile **per_objfile_return);
 
 static struct value *indirect_synthetic_pointer
   (sect_offset die, LONGEST byte_offset,
-   struct dwarf2_per_cu_data *per_cu,
+   dwarf2_per_cu_data *per_cu,
+   dwarf2_per_objfile *per_objfile,
    struct frame_info *frame,
    struct type *type, bool resolve_abstract_p = false);
 
@@ -92,6 +91,11 @@ enum debug_loc_kind
      as in .debug_loc.  */
   DEBUG_LOC_START_LENGTH = 3,
 
+  /* This is followed by two unsigned LEB128 operands. The values of these
+     operands are the starting and ending offsets, respectively, relative to
+     the applicable base address.  */
+  DEBUG_LOC_OFFSET_PAIR = 4,
+
   /* An internal value indicating there is insufficient data.  */
   DEBUG_LOC_BUFFER_OVERFLOW = -1,
 
@@ -158,7 +162,8 @@ decode_debug_loc_addresses (const gdb_byte *loc_ptr, const gdb_byte *buf_end,
    The result indicates the kind of entry found.  */
 
 static enum debug_loc_kind
-decode_debug_loclists_addresses (struct dwarf2_per_cu_data *per_cu,
+decode_debug_loclists_addresses (dwarf2_per_cu_data *per_cu,
+                                dwarf2_per_objfile *per_objfile,
                                 const gdb_byte *loc_ptr,
                                 const gdb_byte *buf_end,
                                 const gdb_byte **new_ptr,
@@ -179,14 +184,14 @@ decode_debug_loclists_addresses (struct dwarf2_per_cu_data *per_cu,
       loc_ptr = gdb_read_uleb128 (loc_ptr, buf_end, &u64);
       if (loc_ptr == NULL)
         return DEBUG_LOC_BUFFER_OVERFLOW;
-      *high = dwarf2_read_addr_index (per_cu, u64);
+      *high = dwarf2_read_addr_index (per_cu, per_objfile, u64);
       *new_ptr = loc_ptr;
       return DEBUG_LOC_BASE_ADDRESS;
     case DW_LLE_startx_length:
       loc_ptr = gdb_read_uleb128 (loc_ptr, buf_end, &u64);
       if (loc_ptr == NULL)
         return DEBUG_LOC_BUFFER_OVERFLOW;
-      *low = dwarf2_read_addr_index (per_cu, u64);
+      *low = dwarf2_read_addr_index (per_cu, per_objfile, u64);
       *high = *low;
       loc_ptr = gdb_read_uleb128 (loc_ptr, buf_end, &u64);
       if (loc_ptr == NULL)
@@ -232,7 +237,7 @@ decode_debug_loclists_addresses (struct dwarf2_per_cu_data *per_cu,
        return DEBUG_LOC_BUFFER_OVERFLOW;
       *high = u64;
       *new_ptr = loc_ptr;
-      return DEBUG_LOC_START_END;
+      return DEBUG_LOC_OFFSET_PAIR;
     /* Following cases are not supported yet.  */
     case DW_LLE_startx_endx:
     case DW_LLE_start_end:
@@ -248,7 +253,8 @@ decode_debug_loclists_addresses (struct dwarf2_per_cu_data *per_cu,
    The result indicates the kind of entry found.  */
 
 static enum debug_loc_kind
-decode_debug_loc_dwo_addresses (struct dwarf2_per_cu_data *per_cu,
+decode_debug_loc_dwo_addresses (dwarf2_per_cu_data *per_cu,
+                               dwarf2_per_objfile *per_objfile,
                                const gdb_byte *loc_ptr,
                                const gdb_byte *buf_end,
                                const gdb_byte **new_ptr,
@@ -270,25 +276,25 @@ decode_debug_loc_dwo_addresses (struct dwarf2_per_cu_data *per_cu,
       loc_ptr = gdb_read_uleb128 (loc_ptr, buf_end, &high_index);
       if (loc_ptr == NULL)
        return DEBUG_LOC_BUFFER_OVERFLOW;
-      *high = dwarf2_read_addr_index (per_cu, high_index);
+      *high = dwarf2_read_addr_index (per_cu, per_objfile, high_index);
       *new_ptr = loc_ptr;
       return DEBUG_LOC_BASE_ADDRESS;
     case DW_LLE_GNU_start_end_entry:
       loc_ptr = gdb_read_uleb128 (loc_ptr, buf_end, &low_index);
       if (loc_ptr == NULL)
        return DEBUG_LOC_BUFFER_OVERFLOW;
-      *low = dwarf2_read_addr_index (per_cu, low_index);
+      *low = dwarf2_read_addr_index (per_cu, per_objfile, low_index);
       loc_ptr = gdb_read_uleb128 (loc_ptr, buf_end, &high_index);
       if (loc_ptr == NULL)
        return DEBUG_LOC_BUFFER_OVERFLOW;
-      *high = dwarf2_read_addr_index (per_cu, high_index);
+      *high = dwarf2_read_addr_index (per_cu, per_objfile, high_index);
       *new_ptr = loc_ptr;
       return DEBUG_LOC_START_END;
     case DW_LLE_GNU_start_length_entry:
       loc_ptr = gdb_read_uleb128 (loc_ptr, buf_end, &low_index);
       if (loc_ptr == NULL)
        return DEBUG_LOC_BUFFER_OVERFLOW;
-      *low = dwarf2_read_addr_index (per_cu, low_index);
+      *low = dwarf2_read_addr_index (per_cu, per_objfile, low_index);
       if (loc_ptr + 4 > buf_end)
        return DEBUG_LOC_BUFFER_OVERFLOW;
       *high = *low;
@@ -312,13 +318,14 @@ const gdb_byte *
 dwarf2_find_location_expression (struct dwarf2_loclist_baton *baton,
                                 size_t *locexpr_length, CORE_ADDR pc)
 {
-  struct objfile *objfile = dwarf2_per_cu_objfile (baton->per_cu);
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  dwarf2_per_objfile *per_objfile = baton->per_objfile;
+  struct objfile *objfile = per_objfile->objfile;
+  struct gdbarch *gdbarch = objfile->arch ();
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  unsigned int addr_size = dwarf2_per_cu_addr_size (baton->per_cu);
+  unsigned int addr_size = baton->per_cu->addr_size ();
   int signed_addr_p = bfd_get_sign_extend_vma (objfile->obfd);
   /* Adjust base_address for relocatable objects.  */
-  CORE_ADDR base_offset = dwarf2_per_cu_text_offset (baton->per_cu);
+  CORE_ADDR base_offset = baton->per_objfile->objfile->text_section_offset ();
   CORE_ADDR base_address = baton->base_address + base_offset;
   const gdb_byte *loc_ptr, *buf_end;
 
@@ -332,17 +339,19 @@ dwarf2_find_location_expression (struct dwarf2_loclist_baton *baton,
       enum debug_loc_kind kind;
       const gdb_byte *new_ptr = NULL; /* init for gcc -Wall */
 
-      if (baton->from_dwo)
+      if (baton->per_cu->version () < 5 && baton->from_dwo)
        kind = decode_debug_loc_dwo_addresses (baton->per_cu,
+                                              baton->per_objfile,
                                               loc_ptr, buf_end, &new_ptr,
                                               &low, &high, byte_order);
-      else if (dwarf2_version (baton->per_cu) < 5)
+      else if (baton->per_cu->version () < 5)
        kind = decode_debug_loc_addresses (loc_ptr, buf_end, &new_ptr,
                                           &low, &high,
                                           byte_order, addr_size,
                                           signed_addr_p);
       else
        kind = decode_debug_loclists_addresses (baton->per_cu,
+                                               baton->per_objfile,
                                                loc_ptr, buf_end, &new_ptr,
                                                &low, &high, byte_order,
                                                addr_size, signed_addr_p);
@@ -358,6 +367,7 @@ dwarf2_find_location_expression (struct dwarf2_loclist_baton *baton,
          continue;
        case DEBUG_LOC_START_END:
        case DEBUG_LOC_START_LENGTH:
+       case DEBUG_LOC_OFFSET_PAIR:
          break;
        case DEBUG_LOC_BUFFER_OVERFLOW:
        case DEBUG_LOC_INVALID_ENTRY:
@@ -369,9 +379,11 @@ dwarf2_find_location_expression (struct dwarf2_loclist_baton *baton,
 
       /* Otherwise, a location expression entry.
         If the entry is from a DWO, don't add base address: the entry is from
-        .debug_addr which already has the DWARF "base address".  We still add
-        base_offset in case we're debugging a PIE executable.  */
-      if (baton->from_dwo)
+        .debug_addr which already has the DWARF "base address". We still add
+        base_offset in case we're debugging a PIE executable. However, if the
+        entry is DW_LLE_offset_pair from a DWO, add the base address as the
+        operands are offsets relative to the applicable base address.  */
+      if (baton->from_dwo && kind != DEBUG_LOC_OFFSET_PAIR)
        {
          low += base_offset;
          high += base_offset;
@@ -382,7 +394,7 @@ dwarf2_find_location_expression (struct dwarf2_loclist_baton *baton,
          high += base_address;
        }
 
-      if (dwarf2_version (baton->per_cu) < 5)
+      if (baton->per_cu->version () < 5)
        {
          length = extract_unsigned_integer (loc_ptr, 2, byte_order);
          loc_ptr += 2;
@@ -423,15 +435,6 @@ dwarf2_find_location_expression (struct dwarf2_loclist_baton *baton,
     }
 }
 
-/* This is the baton used when performing dwarf2 expression
-   evaluation.  */
-struct dwarf_expr_baton
-{
-  struct frame_info *frame;
-  struct dwarf2_per_cu_data *per_cu;
-  CORE_ADDR obj_address;
-};
-
 /* Implement find_frame_base_location method for LOC_BLOCK functions using
    DWARF expression for its DW_AT_frame_base.  */
 
@@ -471,7 +474,7 @@ locexpr_get_frame_base (struct symbol *framefunc, struct frame_info *frame)
   SYMBOL_BLOCK_OPS (framefunc)->find_frame_base_location
     (framefunc, get_frame_pc (frame), &start, &length);
   result = dwarf2_evaluate_loc_desc (type, frame, start, length,
-                                    dlbaton->per_cu);
+                                    dlbaton->per_cu, dlbaton->per_objfile);
 
   /* The DW_AT_frame_base attribute contains a location description which
      computes the base address itself.  However, the call to
@@ -528,7 +531,7 @@ loclist_get_frame_base (struct symbol *framefunc, struct frame_info *frame)
   SYMBOL_BLOCK_OPS (framefunc)->find_frame_base_location
     (framefunc, get_frame_pc (frame), &start, &length);
   result = dwarf2_evaluate_loc_desc (type, frame, start, length,
-                                    dlbaton->per_cu);
+                                    dlbaton->per_cu, dlbaton->per_objfile);
 
   /* The DW_AT_frame_base attribute contains a location description which
      computes the base address itself.  However, the call to
@@ -577,11 +580,11 @@ get_frame_pc_for_per_cu_dwarf_call (void *baton)
 
 static void
 per_cu_dwarf_call (struct dwarf_expr_context *ctx, cu_offset die_offset,
-                  struct dwarf2_per_cu_data *per_cu)
+                  dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile)
 {
   struct dwarf2_locexpr_baton block;
 
-  block = dwarf2_fetch_die_loc_cu_off (die_offset, per_cu,
+  block = dwarf2_fetch_die_loc_cu_off (die_offset, per_cu, per_objfile,
                                       get_frame_pc_for_per_cu_dwarf_call,
                                       ctx);
 
@@ -597,27 +600,33 @@ per_cu_dwarf_call (struct dwarf_expr_context *ctx, cu_offset die_offset,
 
 static struct value *
 sect_variable_value (struct dwarf_expr_context *ctx, sect_offset sect_off,
-                    struct dwarf2_per_cu_data *per_cu)
+                    dwarf2_per_cu_data *per_cu,
+                    dwarf2_per_objfile *per_objfile)
 {
-  struct type *die_type = dwarf2_fetch_die_type_sect_off (sect_off, per_cu);
+  struct type *die_type
+    = dwarf2_fetch_die_type_sect_off (sect_off, per_cu, per_objfile);
 
   if (die_type == NULL)
     error (_("Bad DW_OP_GNU_variable_value DIE."));
 
   /* Note: Things still work when the following test is removed.  This
      test and error is here to conform to the proposed specification.  */
-  if (TYPE_CODE (die_type) != TYPE_CODE_INT
-      && TYPE_CODE (die_type) != TYPE_CODE_PTR)
+  if (die_type->code () != TYPE_CODE_INT
+      && die_type->code () != TYPE_CODE_PTR)
     error (_("Type of DW_OP_GNU_variable_value DIE must be an integer or pointer."));
 
   struct type *type = lookup_pointer_type (die_type);
   struct frame_info *frame = get_selected_frame (_("No frame selected."));
-  return indirect_synthetic_pointer (sect_off, 0, per_cu, frame, type, true);
+  return indirect_synthetic_pointer (sect_off, 0, per_cu, per_objfile, frame,
+                                    type, true);
 }
 
 class dwarf_evaluate_loc_desc : public dwarf_expr_context
 {
- public:
+public:
+  dwarf_evaluate_loc_desc (dwarf2_per_objfile *per_objfile)
+    : dwarf_expr_context (per_objfile)
+  {}
 
   struct frame_info *frame;
   struct dwarf2_per_cu_data *per_cu;
@@ -643,9 +652,7 @@ class dwarf_evaluate_loc_desc : public dwarf_expr_context
      current thread's thread-local storage with offset OFFSET.  */
   CORE_ADDR get_tls_address (CORE_ADDR offset) override
   {
-    struct objfile *objfile = dwarf2_per_cu_objfile (per_cu);
-
-    return target_translate_tls_address (objfile, offset);
+    return target_translate_tls_address (per_objfile->objfile, offset);
   }
 
   /* Helper interface of per_cu_dwarf_call for
@@ -653,7 +660,7 @@ class dwarf_evaluate_loc_desc : public dwarf_expr_context
 
   void dwarf_call (cu_offset die_offset) override
   {
-    per_cu_dwarf_call (this, die_offset, per_cu);
+    per_cu_dwarf_call (this, die_offset, per_cu, per_objfile);
   }
 
   /* Helper interface of sect_variable_value for
@@ -661,12 +668,12 @@ class dwarf_evaluate_loc_desc : public dwarf_expr_context
 
   struct value *dwarf_variable_value (sect_offset sect_off) override
   {
-    return sect_variable_value (this, sect_off, per_cu);
+    return sect_variable_value (this, sect_off, per_cu, per_objfile);
   }
 
   struct type *get_base_type (cu_offset die_offset, int size) override
   {
-    struct type *result = dwarf2_get_die_type (die_offset, per_cu);
+    struct type *result = dwarf2_get_die_type (die_offset, per_cu, per_objfile);
     if (result == NULL)
       error (_("Could not find type for DW_OP_const_type"));
     if (size != 0 && TYPE_LENGTH (result) != size)
@@ -679,7 +686,7 @@ class dwarf_evaluate_loc_desc : public dwarf_expr_context
 
   CORE_ADDR get_addr_index (unsigned int index) override
   {
-    return dwarf2_read_addr_index (per_cu, index);
+    return dwarf2_read_addr_index (per_cu, per_objfile, index);
   }
 
   /* Callback function for get_object_address. Return the address of the VLA
@@ -705,7 +712,8 @@ class dwarf_evaluate_loc_desc : public dwarf_expr_context
                                   int deref_size) override
   {
     struct frame_info *caller_frame;
-    struct dwarf2_per_cu_data *caller_per_cu;
+    dwarf2_per_cu_data *caller_per_cu;
+    dwarf2_per_objfile *caller_per_objfile;
     struct call_site_parameter *parameter;
     const gdb_byte *data_src;
     size_t size;
@@ -713,7 +721,8 @@ class dwarf_evaluate_loc_desc : public dwarf_expr_context
     caller_frame = get_prev_frame (frame);
 
     parameter = dwarf_expr_reg_to_entry_parameter (frame, kind, kind_u,
-                                                  &caller_per_cu);
+                                                  &caller_per_cu,
+                                                  &caller_per_objfile);
     data_src = deref_size == -1 ? parameter->value : parameter->data_value;
     size = deref_size == -1 ? parameter->value_size : parameter->data_value_size;
 
@@ -722,20 +731,25 @@ class dwarf_evaluate_loc_desc : public dwarf_expr_context
       throw_error (NO_ENTRY_VALUE_ERROR,
                   _("Cannot resolve DW_AT_call_data_value"));
 
+    /* We are about to evaluate an expression in the context of the caller
+       of the current frame.  This evaluation context may be different from
+       the current (callee's) context), so temporarily set the caller's context.
+
+       It is possible for the caller to be from a different objfile from the
+       callee if the call is made through a function pointer.  */
     scoped_restore save_frame = make_scoped_restore (&this->frame,
                                                     caller_frame);
     scoped_restore save_per_cu = make_scoped_restore (&this->per_cu,
                                                      caller_per_cu);
     scoped_restore save_obj_addr = make_scoped_restore (&this->obj_address,
                                                        (CORE_ADDR) 0);
+    scoped_restore save_per_objfile = make_scoped_restore (&this->per_objfile,
+                                                          caller_per_objfile);
 
     scoped_restore save_arch = make_scoped_restore (&this->gdbarch);
-    this->gdbarch
-      = get_objfile_arch (dwarf2_per_cu_objfile (per_cu));
+    this->gdbarch = this->per_objfile->objfile->arch ();
     scoped_restore save_addr_size = make_scoped_restore (&this->addr_size);
-    this->addr_size = dwarf2_per_cu_addr_size (per_cu);
-    scoped_restore save_offset = make_scoped_restore (&this->offset);
-    this->offset = dwarf2_per_cu_text_offset (per_cu);
+    this->addr_size = this->per_cu->addr_size ();
 
     this->eval (data_src, size);
   }
@@ -861,7 +875,8 @@ call_site_to_target_addr (struct gdbarch *call_site_gdbarch,
        caller_core_addr_type = builtin_type (caller_arch)->builtin_func_ptr;
        val = dwarf2_evaluate_loc_desc (caller_core_addr_type, caller_frame,
                                        dwarf_block->data, dwarf_block->size,
-                                       dwarf_block->per_cu);
+                                       dwarf_block->per_cu,
+                                       dwarf_block->per_objfile);
        /* DW_AT_call_target is a DWARF expression, not a DWARF location.  */
        if (VALUE_LVAL (val) == lval_memory)
          return value_address (val);
@@ -917,7 +932,7 @@ func_addr_to_tail_call_list (struct gdbarch *gdbarch, CORE_ADDR addr)
                 paddress (gdbarch, addr));
 
   type = SYMBOL_TYPE (sym);
-  gdb_assert (TYPE_CODE (type) == TYPE_CODE_FUNC);
+  gdb_assert (type->code () == TYPE_CODE_FUNC);
   gdb_assert (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_FUNC);
 
   return sym;
@@ -1101,11 +1116,10 @@ chain_candidate (struct gdbarch *gdbarch,
 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC.  All the
    assumed frames between them use GDBARCH.  Use depth first search so we can
    keep single CHAIN of call_site's back to CALLER_PC.  Function recursion
-   would have needless GDB stack overhead.  Caller is responsible for xfree of
-   the returned result.  Any unreliability results in thrown
-   NO_ENTRY_VALUE_ERROR.  */
+   would have needless GDB stack overhead.  Any unreliability results
+   in thrown NO_ENTRY_VALUE_ERROR.  */
 
-static struct call_site_chain *
+static gdb::unique_xmalloc_ptr<call_site_chain>
 call_site_find_chain_1 (struct gdbarch *gdbarch, CORE_ADDR caller_pc,
                        CORE_ADDR callee_pc)
 {
@@ -1220,19 +1234,18 @@ call_site_find_chain_1 (struct gdbarch *gdbarch, CORE_ADDR caller_pc,
                   paddress (gdbarch, callee_pc));
     }
 
-  return retval.release ();
+  return retval;
 }
 
 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC.  All the
    assumed frames between them use GDBARCH.  If valid call_site_chain cannot be
-   constructed return NULL.  Caller is responsible for xfree of the returned
-   result.  */
+   constructed return NULL.  */
 
-struct call_site_chain *
+gdb::unique_xmalloc_ptr<call_site_chain>
 call_site_find_chain (struct gdbarch *gdbarch, CORE_ADDR caller_pc,
                      CORE_ADDR callee_pc)
 {
-  struct call_site_chain *retval = NULL;
+  gdb::unique_xmalloc_ptr<call_site_chain> retval;
 
   try
     {
@@ -1284,7 +1297,8 @@ static struct call_site_parameter *
 dwarf_expr_reg_to_entry_parameter (struct frame_info *frame,
                                   enum call_site_parameter_kind kind,
                                   union call_site_parameter_u kind_u,
-                                  struct dwarf2_per_cu_data **per_cu_return)
+                                  dwarf2_per_cu_data **per_cu_return,
+                                  dwarf2_per_objfile **per_objfile_return)
 {
   CORE_ADDR func_addr, caller_pc;
   struct gdbarch *gdbarch;
@@ -1375,6 +1389,7 @@ dwarf_expr_reg_to_entry_parameter (struct frame_info *frame,
     }
 
   *per_cu_return = call_site->per_cu;
+  *per_objfile_return = call_site->per_objfile;
   return parameter;
 }
 
@@ -1392,7 +1407,8 @@ static struct value *
 dwarf_entry_parameter_to_value (struct call_site_parameter *parameter,
                                CORE_ADDR deref_size, struct type *type,
                                struct frame_info *caller_frame,
-                               struct dwarf2_per_cu_data *per_cu)
+                               dwarf2_per_cu_data *per_cu,
+                               dwarf2_per_objfile *per_objfile)
 {
   const gdb_byte *data_src;
   gdb_byte *data;
@@ -1413,7 +1429,8 @@ dwarf_entry_parameter_to_value (struct call_site_parameter *parameter,
   memcpy (data, data_src, size);
   data[size] = DW_OP_stack_value;
 
-  return dwarf2_evaluate_loc_desc (type, caller_frame, data, size + 1, per_cu);
+  return dwarf2_evaluate_loc_desc (type, caller_frame, data, size + 1, per_cu,
+                                  per_objfile);
 }
 
 /* VALUE must be of type lval_computed with entry_data_value_funcs.  Perform
@@ -1487,14 +1504,17 @@ value_of_dwarf_reg_entry (struct type *type, struct frame_info *frame,
   struct frame_info *caller_frame = get_prev_frame (frame);
   struct value *outer_val, *target_val, *val;
   struct call_site_parameter *parameter;
-  struct dwarf2_per_cu_data *caller_per_cu;
+  dwarf2_per_cu_data *caller_per_cu;
+  dwarf2_per_objfile *caller_per_objfile;
 
   parameter = dwarf_expr_reg_to_entry_parameter (frame, kind, kind_u,
-                                                &caller_per_cu);
+                                                &caller_per_cu,
+                                                &caller_per_objfile);
 
   outer_val = dwarf_entry_parameter_to_value (parameter, -1 /* deref_size */,
                                              type, caller_frame,
-                                             caller_per_cu);
+                                             caller_per_cu,
+                                             caller_per_objfile);
 
   /* Check if DW_AT_call_data_value cannot be used.  If it should be
      used and it is not available do not fall back to OUTER_VAL - dereferencing
@@ -1508,7 +1528,8 @@ value_of_dwarf_reg_entry (struct type *type, struct frame_info *frame,
   target_val = dwarf_entry_parameter_to_value (parameter,
                                               TYPE_LENGTH (target_type),
                                               target_type, caller_frame,
-                                              caller_per_cu);
+                                              caller_per_cu,
+                                              caller_per_objfile);
 
   val = allocate_computed_value (type, &entry_data_value_funcs,
                                 release_value (target_val).release ());
@@ -1556,6 +1577,9 @@ struct piece_closure
   /* Reference count.  */
   int refc = 0;
 
+  /* The objfile from which this closure's expression came.  */
+  dwarf2_per_objfile *per_objfile = nullptr;
+
   /* The CU from which this closure's expression came.  */
   struct dwarf2_per_cu_data *per_cu = NULL;
 
@@ -1571,13 +1595,16 @@ struct piece_closure
    PIECES.  */
 
 static struct piece_closure *
-allocate_piece_closure (struct dwarf2_per_cu_data *per_cu,
+allocate_piece_closure (dwarf2_per_cu_data *per_cu,
+                       dwarf2_per_objfile *per_objfile,
                        std::vector<dwarf_expr_piece> &&pieces,
                        struct frame_info *frame)
 {
   struct piece_closure *c = new piece_closure;
 
   c->refc = 1;
+  /* We must capture this here due to sharing of DWARF state.  */
+  c->per_objfile = per_objfile;
   c->per_cu = per_cu;
   c->pieces = std::move (pieces);
   if (frame == NULL)
@@ -1819,8 +1846,7 @@ rw_pieced_value (struct value *v, struct value *from)
                break;
              }
 
-           struct objfile *objfile = dwarf2_per_cu_objfile (c->per_cu);
-           struct gdbarch *objfile_gdbarch = get_objfile_arch (objfile);
+           gdbarch *objfile_gdbarch = c->per_objfile->objfile->arch ();
            ULONGEST stack_value_size_bits
              = 8 * TYPE_LENGTH (value_type (p->v.value));
 
@@ -1955,7 +1981,8 @@ get_frame_address_in_block_wrapper (void *baton)
 
 static struct value *
 fetch_const_value_from_synthetic_pointer (sect_offset die, LONGEST byte_offset,
-                                         struct dwarf2_per_cu_data *per_cu,
+                                         dwarf2_per_cu_data *per_cu,
+                                         dwarf2_per_objfile *per_objfile,
                                          struct type *type)
 {
   struct value *result = NULL;
@@ -1963,7 +1990,8 @@ fetch_const_value_from_synthetic_pointer (sect_offset die, LONGEST byte_offset,
   LONGEST len;
 
   auto_obstack temp_obstack;
-  bytes = dwarf2_fetch_constant_bytes (die, per_cu, &temp_obstack, &len);
+  bytes = dwarf2_fetch_constant_bytes (die, per_cu, per_objfile,
+                                      &temp_obstack, &len);
 
   if (bytes != NULL)
     {
@@ -1986,18 +2014,20 @@ fetch_const_value_from_synthetic_pointer (sect_offset die, LONGEST byte_offset,
 
 static struct value *
 indirect_synthetic_pointer (sect_offset die, LONGEST byte_offset,
-                           struct dwarf2_per_cu_data *per_cu,
+                           dwarf2_per_cu_data *per_cu,
+                           dwarf2_per_objfile *per_objfile,
                            struct frame_info *frame, struct type *type,
                            bool resolve_abstract_p)
 {
   /* Fetch the location expression of the DIE we're pointing to.  */
   struct dwarf2_locexpr_baton baton
-    = dwarf2_fetch_die_loc_sect_off (die, per_cu,
+    = dwarf2_fetch_die_loc_sect_off (die, per_cu, per_objfile,
                                     get_frame_address_in_block_wrapper, frame,
                                     resolve_abstract_p);
 
   /* Get type of pointed-to DIE.  */
-  struct type *orig_type = dwarf2_fetch_die_type_sect_off (die, per_cu);
+  struct type *orig_type = dwarf2_fetch_die_type_sect_off (die, per_cu,
+                                                          per_objfile);
   if (orig_type == NULL)
     invalid_synthetic_pointer ();
 
@@ -2007,11 +2037,12 @@ indirect_synthetic_pointer (sect_offset die, LONGEST byte_offset,
   if (baton.data != NULL)
     return dwarf2_evaluate_loc_desc_full (orig_type, frame, baton.data,
                                          baton.size, baton.per_cu,
+                                         baton.per_objfile,
                                          TYPE_TARGET_TYPE (type),
                                          byte_offset);
   else
     return fetch_const_value_from_synthetic_pointer (die, byte_offset, per_cu,
-                                                    type);
+                                                    per_objfile, type);
 }
 
 /* An implementation of an lval_funcs method to indirect through a
@@ -2031,7 +2062,7 @@ indirect_pieced_value (struct value *value)
   enum bfd_endian byte_order;
 
   type = check_typedef (value_type (value));
-  if (TYPE_CODE (type) != TYPE_CODE_PTR)
+  if (type->code () != TYPE_CODE_PTR)
     return NULL;
 
   bit_length = 8 * TYPE_LENGTH (type);
@@ -2088,7 +2119,7 @@ indirect_pieced_value (struct value *value)
 
   return indirect_synthetic_pointer (piece->v.ptr.die_sect_off,
                                     byte_offset, c->per_cu,
-                                    frame, type);
+                                    c->per_objfile, frame, type);
 }
 
 /* Implementation of the coerce_ref method of lval_funcs for synthetic C++
@@ -2115,7 +2146,7 @@ coerce_pieced_ref (const struct value *value)
       return indirect_synthetic_pointer
        (closure->pieces[0].v.ptr.die_sect_off,
         closure->pieces[0].v.ptr.offset,
-        closure->per_cu, frame, type);
+        closure->per_cu, closure->per_objfile, frame, type);
     }
   else
     {
@@ -2171,12 +2202,12 @@ static const struct lval_funcs pieced_value_funcs = {
 static struct value *
 dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
                               const gdb_byte *data, size_t size,
-                              struct dwarf2_per_cu_data *per_cu,
+                              dwarf2_per_cu_data *per_cu,
+                              dwarf2_per_objfile *per_objfile,
                               struct type *subobj_type,
                               LONGEST subobj_byte_offset)
 {
   struct value *retval;
-  struct objfile *objfile = dwarf2_per_cu_objfile (per_cu);
 
   if (subobj_type == NULL)
     {
@@ -2189,17 +2220,16 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
   if (size == 0)
     return allocate_optimized_out_value (subobj_type);
 
-  dwarf_evaluate_loc_desc ctx;
+  dwarf_evaluate_loc_desc ctx (per_objfile);
   ctx.frame = frame;
   ctx.per_cu = per_cu;
   ctx.obj_address = 0;
 
   scoped_value_mark free_values;
 
-  ctx.gdbarch = get_objfile_arch (objfile);
-  ctx.addr_size = dwarf2_per_cu_addr_size (per_cu);
-  ctx.ref_addr_size = dwarf2_per_cu_ref_addr_size (per_cu);
-  ctx.offset = dwarf2_per_cu_text_offset (per_cu);
+  ctx.gdbarch = per_objfile->objfile->arch ();
+  ctx.addr_size = per_cu->addr_size ();
+  ctx.ref_addr_size = per_cu->ref_addr_size ();
 
   try
     {
@@ -2238,7 +2268,8 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
       if (bit_size > 8 * TYPE_LENGTH (type))
        invalid_synthetic_pointer ();
 
-      c = allocate_piece_closure (per_cu, std::move (ctx.pieces), frame);
+      c = allocate_piece_closure (per_cu, per_objfile, std::move (ctx.pieces),
+                                 frame);
       /* We must clean up the value chain after creating the piece
         closure but before allocating the result.  */
       free_values.free_to_mark ();
@@ -2293,7 +2324,7 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
               the operation.  Therefore, we do the conversion here
               since the type is readily available.  */
 
-           switch (TYPE_CODE (subobj_type))
+           switch (subobj_type->code ())
              {
                case TYPE_CODE_FUNC:
                case TYPE_CODE_METHOD:
@@ -2319,7 +2350,7 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
            size_t n = TYPE_LENGTH (value_type (value));
            size_t len = TYPE_LENGTH (subobj_type);
            size_t max = TYPE_LENGTH (type);
-           struct gdbarch *objfile_gdbarch = get_objfile_arch (objfile);
+           gdbarch *objfile_gdbarch = per_objfile->objfile->arch ();
 
            if (subobj_byte_offset + len > max)
              invalid_synthetic_pointer ();
@@ -2382,41 +2413,92 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
 struct value *
 dwarf2_evaluate_loc_desc (struct type *type, struct frame_info *frame,
                          const gdb_byte *data, size_t size,
-                         struct dwarf2_per_cu_data *per_cu)
+                         dwarf2_per_cu_data *per_cu,
+                         dwarf2_per_objfile *per_objfile)
 {
   return dwarf2_evaluate_loc_desc_full (type, frame, data, size, per_cu,
-                                       NULL, 0);
+                                       per_objfile, NULL, 0);
 }
 
-/* Evaluates a dwarf expression and stores the result in VAL, expecting
-   that the dwarf expression only produces a single CORE_ADDR.  FRAME is the
-   frame in which the expression is evaluated.  ADDR is a context (location of
-   a variable) and might be needed to evaluate the location expression.
-   Returns 1 on success, 0 otherwise.   */
+/* A specialization of dwarf_evaluate_loc_desc that is used by
+   dwarf2_locexpr_baton_eval.  This subclass exists to handle the case
+   where a caller of dwarf2_locexpr_baton_eval passes in some data,
+   but with the address being 0.  In this situation, we arrange for
+   memory reads to come from the passed-in buffer.  */
+
+struct evaluate_for_locexpr_baton : public dwarf_evaluate_loc_desc
+{
+  evaluate_for_locexpr_baton (dwarf2_per_objfile *per_objfile)
+    : dwarf_evaluate_loc_desc (per_objfile)
+  {}
+
+  /* The data that was passed in.  */
+  gdb::array_view<const gdb_byte> data_view;
+
+  CORE_ADDR get_object_address () override
+  {
+    if (data_view.data () == nullptr && obj_address == 0)
+      error (_("Location address is not set."));
+    return obj_address;
+  }
+
+  void read_mem (gdb_byte *buf, CORE_ADDR addr, size_t len) override
+  {
+    if (len == 0)
+      return;
+
+    /* Prefer the passed-in memory, if it exists.  */
+    CORE_ADDR offset = addr - obj_address;
+    if (offset < data_view.size () && offset + len <= data_view.size ())
+      {
+       memcpy (buf, data_view.data (), len);
+       return;
+      }
+
+    read_memory (addr, buf, len);
+  }
+};
+
+/* Evaluates a dwarf expression and stores the result in VAL,
+   expecting that the dwarf expression only produces a single
+   CORE_ADDR.  FRAME is the frame in which the expression is
+   evaluated.  ADDR_STACK is a context (location of a variable) and
+   might be needed to evaluate the location expression.
+   PUSH_INITIAL_VALUE is true if the address (either from ADDR_STACK,
+   or the default of 0) should be pushed on the DWARF expression
+   evaluation stack before evaluating the expression; this is required
+   by certain forms of DWARF expression.  Returns 1 on success, 0
+   otherwise.  */
 
 static int
 dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton *dlbaton,
                           struct frame_info *frame,
-                          CORE_ADDR addr,
-                          CORE_ADDR *valp)
+                          const struct property_addr_info *addr_stack,
+                          CORE_ADDR *valp,
+                          bool push_initial_value)
 {
-  struct objfile *objfile;
-
   if (dlbaton == NULL || dlbaton->size == 0)
     return 0;
 
-  dwarf_evaluate_loc_desc ctx;
+  dwarf2_per_objfile *per_objfile = dlbaton->per_objfile;
+  evaluate_for_locexpr_baton ctx (per_objfile);
 
   ctx.frame = frame;
   ctx.per_cu = dlbaton->per_cu;
-  ctx.obj_address = addr;
+  if (addr_stack == nullptr)
+    ctx.obj_address = 0;
+  else
+    {
+      ctx.obj_address = addr_stack->addr;
+      ctx.data_view = addr_stack->valaddr;
+    }
 
-  objfile = dwarf2_per_cu_objfile (dlbaton->per_cu);
+  ctx.gdbarch = per_objfile->objfile->arch ();
+  ctx.addr_size = dlbaton->per_cu->addr_size ();
+  ctx.ref_addr_size = dlbaton->per_cu->ref_addr_size ();
 
-  ctx.gdbarch = get_objfile_arch (objfile);
-  ctx.addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
-  ctx.ref_addr_size = dwarf2_per_cu_ref_addr_size (dlbaton->per_cu);
-  ctx.offset = dwarf2_per_cu_text_offset (dlbaton->per_cu);
+  if (push_initial_value)
+    ctx.push_address (ctx.obj_address, false);
 
   try
     {
@@ -2465,8 +2547,9 @@ dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton *dlbaton,
 bool
 dwarf2_evaluate_property (const struct dynamic_prop *prop,
                          struct frame_info *frame,
-                         struct property_addr_info *addr_stack,
-                         CORE_ADDR *value)
+                         const struct property_addr_info *addr_stack,
+                         CORE_ADDR *value,
+                         bool push_initial_value)
 {
   if (prop == NULL)
     return false;
@@ -2482,9 +2565,8 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop,
          = (const struct dwarf2_property_baton *) prop->data.baton;
        gdb_assert (baton->property_type != NULL);
 
-       if (dwarf2_locexpr_baton_eval (&baton->locexpr, frame,
-                                      addr_stack ? addr_stack->addr : 0,
-                                      value))
+       if (dwarf2_locexpr_baton_eval (&baton->locexpr, frame, addr_stack,
+                                      value, push_initial_value))
          {
            if (baton->locexpr.is_reference)
              {
@@ -2504,7 +2586,7 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop,
                       CORE_ADDR on 64bit machine has 8 bytes but address
                       size of an 32bit application is bytes.  */
                    const int addr_size
-                     = (dwarf2_per_cu_addr_size (baton->locexpr.per_cu)
+                     = (baton->locexpr.per_cu->addr_size ()
                         * TARGET_CHAR_BIT);
                    const CORE_ADDR neg_mask
                      = (~((CORE_ADDR) 0) <<  (addr_size - 1));
@@ -2523,16 +2605,21 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop,
       {
        struct dwarf2_property_baton *baton
          = (struct dwarf2_property_baton *) prop->data.baton;
-       CORE_ADDR pc = get_frame_address_in_block (frame);
+       CORE_ADDR pc;
        const gdb_byte *data;
        struct value *val;
        size_t size;
 
+       if (frame == NULL
+           || !get_frame_address_in_block_if_available (frame, &pc))
+         return false;
+
        data = dwarf2_find_location_expression (&baton->loclist, &size, pc);
        if (data != NULL)
          {
            val = dwarf2_evaluate_loc_desc (baton->property_type, frame, data,
-                                           size, baton->loclist.per_cu);
+                                           size, baton->loclist.per_cu,
+                                           baton->loclist.per_objfile);
            if (!value_optimized_out (val))
              {
                *value = value_as_address (val);
@@ -2550,7 +2637,7 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop,
       {
        struct dwarf2_property_baton *baton
          = (struct dwarf2_property_baton *) prop->data.baton;
-       struct property_addr_info *pinfo;
+       const struct property_addr_info *pinfo;
        struct value *val;
 
        for (pinfo = addr_stack; pinfo != NULL; pinfo = pinfo->next)
@@ -2562,10 +2649,10 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop,
          }
        if (pinfo == NULL)
          error (_("cannot find reference address for offset property"));
-       if (pinfo->valaddr != NULL)
+       if (pinfo->valaddr.data () != NULL)
          val = value_from_contents
                  (baton->offset_info.type,
-                  pinfo->valaddr + baton->offset_info.offset);
+                  pinfo->valaddr.data () + baton->offset_info.offset);
        else
          val = value_at (baton->offset_info.type,
                          pinfo->addr + baton->offset_info.offset);
@@ -2592,13 +2679,15 @@ dwarf2_compile_property_to_c (string_file *stream,
     = (struct dwarf2_property_baton *) prop->data.baton;
   const gdb_byte *data;
   size_t size;
-  struct dwarf2_per_cu_data *per_cu;
+  dwarf2_per_cu_data *per_cu;
+  dwarf2_per_objfile *per_objfile;
 
   if (prop->kind == PROP_LOCEXPR)
     {
       data = baton->locexpr.data;
       size = baton->locexpr.size;
       per_cu = baton->locexpr.per_cu;
+      per_objfile = baton->locexpr.per_objfile;
     }
   else
     {
@@ -2606,12 +2695,13 @@ dwarf2_compile_property_to_c (string_file *stream,
 
       data = dwarf2_find_location_expression (&baton->loclist, &size, pc);
       per_cu = baton->loclist.per_cu;
+      per_objfile = baton->loclist.per_objfile;
     }
 
   compile_dwarf_bounds_to_c (stream, result_name, prop, sym, pc,
                             gdbarch, registers_used,
-                            dwarf2_per_cu_addr_size (per_cu),
-                            data, data + size, per_cu);
+                            per_cu->addr_size (),
+                            data, data + size, per_cu, per_objfile);
 }
 
 \f
@@ -2619,7 +2709,10 @@ dwarf2_compile_property_to_c (string_file *stream,
 
 class symbol_needs_eval_context : public dwarf_expr_context
 {
- public:
+public:
+  symbol_needs_eval_context (dwarf2_per_objfile *per_objfile)
+    : dwarf_expr_context (per_objfile)
+  {}
 
   enum symbol_needs_kind needs;
   struct dwarf2_per_cu_data *per_cu;
@@ -2683,7 +2776,7 @@ class symbol_needs_eval_context : public dwarf_expr_context
 
   void dwarf_call (cu_offset die_offset) override
   {
-    per_cu_dwarf_call (this, die_offset, per_cu);
+    per_cu_dwarf_call (this, die_offset, per_cu, per_objfile);
   }
 
   /* Helper interface of sect_variable_value for
@@ -2691,7 +2784,7 @@ class symbol_needs_eval_context : public dwarf_expr_context
 
   struct value *dwarf_variable_value (sect_offset sect_off) override
   {
-    return sect_variable_value (this, sect_off, per_cu);
+    return sect_variable_value (this, sect_off, per_cu, per_objfile);
   }
 
   /* DW_OP_entry_value accesses require a caller, therefore a
@@ -2729,21 +2822,20 @@ class symbol_needs_eval_context : public dwarf_expr_context
 
 static enum symbol_needs_kind
 dwarf2_loc_desc_get_symbol_read_needs (const gdb_byte *data, size_t size,
-                                      struct dwarf2_per_cu_data *per_cu)
+                                      dwarf2_per_cu_data *per_cu,
+                                      dwarf2_per_objfile *per_objfile)
 {
   int in_reg;
-  struct objfile *objfile = dwarf2_per_cu_objfile (per_cu);
 
   scoped_value_mark free_values;
 
-  symbol_needs_eval_context ctx;
+  symbol_needs_eval_context ctx (per_objfile);
 
   ctx.needs = SYMBOL_NEEDS_NONE;
   ctx.per_cu = per_cu;
-  ctx.gdbarch = get_objfile_arch (objfile);
-  ctx.addr_size = dwarf2_per_cu_addr_size (per_cu);
-  ctx.ref_addr_size = dwarf2_per_cu_ref_addr_size (per_cu);
-  ctx.offset = dwarf2_per_cu_text_offset (per_cu);
+  ctx.gdbarch = per_objfile->objfile->arch ();
+  ctx.addr_size = per_cu->addr_size ();
+  ctx.ref_addr_size = per_cu->ref_addr_size ();
 
   ctx.eval (data, size);
 
@@ -2893,11 +2985,12 @@ get_ax_pc (void *baton)
    example, if the expression cannot be compiled, or if the expression
    is invalid.  */
 
-void
+static void
 dwarf2_compile_expr_to_ax (struct agent_expr *expr, struct axs_value *loc,
                           unsigned int addr_size, const gdb_byte *op_ptr,
                           const gdb_byte *op_end,
-                          struct dwarf2_per_cu_data *per_cu)
+                          dwarf2_per_cu_data *per_cu,
+                          dwarf2_per_objfile *per_objfile)
 {
   gdbarch *arch = expr->gdbarch;
   std::vector<int> dw_labels, patches;
@@ -2984,7 +3077,7 @@ dwarf2_compile_expr_to_ax (struct agent_expr *expr, struct axs_value *loc,
             index, not an address.  We don't support things like
             branching between the address and the TLS op.  */
          if (op_ptr >= op_end || *op_ptr != DW_OP_GNU_push_tls_address)
-           uoffset += dwarf2_per_cu_text_offset (per_cu);
+           uoffset += per_objfile->objfile->text_section_offset ();
          ax_const_l (expr, uoffset);
          break;
 
@@ -3175,7 +3268,8 @@ dwarf2_compile_expr_to_ax (struct agent_expr *expr, struct axs_value *loc,
 
            op_ptr = safe_read_sleb128 (op_ptr, op_end, &offset);
            dwarf2_compile_expr_to_ax (expr, loc, addr_size, datastart,
-                                      datastart + datalen, per_cu);
+                                      datastart + datalen, per_cu,
+                                      per_objfile);
            if (loc->kind == axs_lvalue_register)
              require_rvalue (expr, loc);
 
@@ -3401,7 +3495,7 @@ dwarf2_compile_expr_to_ax (struct agent_expr *expr, struct axs_value *loc,
                /* Another expression.  */
                ax_const_l (expr, text_offset);
                dwarf2_compile_expr_to_ax (expr, loc, addr_size, cfa_start,
-                                          cfa_end, per_cu);
+                                          cfa_end, per_cu, per_objfile);
              }
 
            loc->kind = axs_lvalue_memory;
@@ -3519,14 +3613,15 @@ dwarf2_compile_expr_to_ax (struct agent_expr *expr, struct axs_value *loc,
            op_ptr += size;
 
            cu_offset cuoffset = (cu_offset) uoffset;
-           block = dwarf2_fetch_die_loc_cu_off (cuoffset, per_cu,
+           block = dwarf2_fetch_die_loc_cu_off (cuoffset, per_cu, per_objfile,
                                                 get_ax_pc, expr);
 
            /* DW_OP_call_ref is currently not supported.  */
            gdb_assert (block.per_cu == per_cu);
 
            dwarf2_compile_expr_to_ax (expr, loc, addr_size, block.data,
-                                      block.data + block.size, per_cu);
+                                      block.data + block.size, per_cu,
+                                      per_objfile);
          }
          break;
 
@@ -3562,7 +3657,8 @@ locexpr_read_variable (struct symbol *symbol, struct frame_info *frame)
   struct value *val;
 
   val = dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol), frame, dlbaton->data,
-                                 dlbaton->size, dlbaton->per_cu);
+                                 dlbaton->size, dlbaton->per_cu,
+                                 dlbaton->per_objfile);
 
   return val;
 }
@@ -3591,7 +3687,8 @@ locexpr_get_symbol_read_needs (struct symbol *symbol)
     = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (symbol);
 
   return dwarf2_loc_desc_get_symbol_read_needs (dlbaton->data, dlbaton->size,
-                                               dlbaton->per_cu);
+                                               dlbaton->per_cu,
+                                               dlbaton->per_objfile);
 }
 
 /* Return true if DATA points to the end of a piece.  END is one past
@@ -3633,12 +3730,13 @@ locexpr_regname (struct gdbarch *gdbarch, int dwarf_regnum)
 
 static const gdb_byte *
 locexpr_describe_location_piece (struct symbol *symbol, struct ui_file *stream,
-                                CORE_ADDR addr, struct objfile *objfile,
-                                struct dwarf2_per_cu_data *per_cu,
+                                CORE_ADDR addr, dwarf2_per_cu_data *per_cu,
+                                dwarf2_per_objfile *per_objfile,
                                 const gdb_byte *data, const gdb_byte *end,
                                 unsigned int addr_size)
 {
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  objfile *objfile = per_objfile->objfile;
+  struct gdbarch *gdbarch = objfile->arch ();
   size_t leb128_size;
 
   if (data[0] >= DW_OP_reg0 && data[0] <= DW_OP_reg31)
@@ -3776,7 +3874,7 @@ locexpr_describe_location_piece (struct symbol *symbol, struct ui_file *stream,
       uint64_t offset;
 
       data = safe_read_uleb128 (data + 1, end, &offset);
-      offset = dwarf2_read_addr_index (per_cu, offset);
+      offset = dwarf2_read_addr_index (per_cu, per_objfile, offset);
       fprintf_filtered (stream, 
                        _("a thread-local variable at offset 0x%s "
                          "in the thread-local storage for `%s'"),
@@ -3809,7 +3907,8 @@ disassemble_dwarf_expression (struct ui_file *stream,
                              int offset_size, const gdb_byte *start,
                              const gdb_byte *data, const gdb_byte *end,
                              int indent, int all,
-                             struct dwarf2_per_cu_data *per_cu)
+                             dwarf2_per_cu_data *per_cu,
+                             dwarf2_per_objfile *per_objfile)
 {
   while (data < end
         && (all
@@ -4069,7 +4168,7 @@ disassemble_dwarf_expression (struct ui_file *stream,
 
            data = safe_read_uleb128 (data, end, &ul);
            cu_offset offset = (cu_offset) ul;
-           type = dwarf2_get_die_type (offset, per_cu);
+           type = dwarf2_get_die_type (offset, per_cu, per_objfile);
            fprintf_filtered (stream, "<");
            type_print (type, "", stream, -1);
            fprintf_filtered (stream, " [0x%s]> %d",
@@ -4085,11 +4184,17 @@ disassemble_dwarf_expression (struct ui_file *stream,
 
            data = safe_read_uleb128 (data, end, &ul);
            cu_offset type_die = (cu_offset) ul;
-           type = dwarf2_get_die_type (type_die, per_cu);
+           type = dwarf2_get_die_type (type_die, per_cu, per_objfile);
            fprintf_filtered (stream, "<");
            type_print (type, "", stream, -1);
            fprintf_filtered (stream, " [0x%s]>",
                              phex_nz (to_underlying (type_die), 0));
+
+           int n = *data++;
+           fprintf_filtered (stream, " %d byte block:", n);
+           for (int i = 0; i < n; ++i)
+             fprintf_filtered (stream, " %02x", data[i]);
+           data += n;
          }
          break;
 
@@ -4103,7 +4208,7 @@ disassemble_dwarf_expression (struct ui_file *stream,
            data = safe_read_uleb128 (data, end, &ul);
            cu_offset type_die = (cu_offset) ul;
 
-           type = dwarf2_get_die_type (type_die, per_cu);
+           type = dwarf2_get_die_type (type_die, per_cu, per_objfile);
            fprintf_filtered (stream, "<");
            type_print (type, "", stream, -1);
            fprintf_filtered (stream, " [0x%s]> [$%s]",
@@ -4126,7 +4231,7 @@ disassemble_dwarf_expression (struct ui_file *stream,
              {
                struct type *type;
 
-               type = dwarf2_get_die_type (type_die, per_cu);
+               type = dwarf2_get_die_type (type_die, per_cu, per_objfile);
                fprintf_filtered (stream, "<");
                type_print (type, "", stream, -1);
                fprintf_filtered (stream, " [0x%s]>",
@@ -4141,7 +4246,7 @@ disassemble_dwarf_expression (struct ui_file *stream,
          fputc_filtered ('\n', stream);
          disassemble_dwarf_expression (stream, arch, addr_size, offset_size,
                                        start, data, data + ul, indent + 2,
-                                       all, per_cu);
+                                       all, per_cu, per_objfile);
          data += ul;
          continue;
 
@@ -4154,12 +4259,12 @@ disassemble_dwarf_expression (struct ui_file *stream,
        case DW_OP_addrx:
        case DW_OP_GNU_addr_index:
          data = safe_read_uleb128 (data, end, &ul);
-         ul = dwarf2_read_addr_index (per_cu, ul);
+         ul = dwarf2_read_addr_index (per_cu, per_objfile, ul);
          fprintf_filtered (stream, " 0x%s", phex_nz (ul, addr_size));
          break;
        case DW_OP_GNU_const_index:
          data = safe_read_uleb128 (data, end, &ul);
-         ul = dwarf2_read_addr_index (per_cu, ul);
+         ul = dwarf2_read_addr_index (per_cu, per_objfile, ul);
          fprintf_filtered (stream, " %s", pulongest (ul));
          break;
 
@@ -4177,6 +4282,18 @@ disassemble_dwarf_expression (struct ui_file *stream,
   return data;
 }
 
+static bool dwarf_always_disassemble;
+
+static void
+show_dwarf_always_disassemble (struct ui_file *file, int from_tty,
+                              struct cmd_list_element *c, const char *value)
+{
+  fprintf_filtered (file,
+                   _("Whether to always disassemble "
+                     "DWARF expressions is %s.\n"),
+                   value);
+}
+
 /* Describe a single location, which may in turn consist of multiple
    pieces.  */
 
@@ -4184,11 +4301,13 @@ static void
 locexpr_describe_location_1 (struct symbol *symbol, CORE_ADDR addr,
                             struct ui_file *stream,
                             const gdb_byte *data, size_t size,
-                            struct objfile *objfile, unsigned int addr_size,
-                            int offset_size, struct dwarf2_per_cu_data *per_cu)
+                            unsigned int addr_size,
+                            int offset_size, dwarf2_per_cu_data *per_cu,
+                            dwarf2_per_objfile *per_objfile)
 {
   const gdb_byte *end = data + size;
   int first_piece = 1, bad = 0;
+  objfile *objfile = per_objfile->objfile;
 
   while (data < end)
     {
@@ -4203,7 +4322,7 @@ locexpr_describe_location_1 (struct symbol *symbol, CORE_ADDR addr,
       if (!dwarf_always_disassemble)
        {
          data = locexpr_describe_location_piece (symbol, stream,
-                                                 addr, objfile, per_cu,
+                                                 addr, per_cu, per_objfile,
                                                  data, end, addr_size);
          /* If we printed anything, or if we have an empty piece,
             then don't disassemble.  */
@@ -4216,11 +4335,11 @@ locexpr_describe_location_1 (struct symbol *symbol, CORE_ADDR addr,
        {
          fprintf_filtered (stream, _("a complex DWARF expression:\n"));
          data = disassemble_dwarf_expression (stream,
-                                              get_objfile_arch (objfile),
+                                              objfile->arch (),
                                               addr_size, offset_size, data,
                                               data, end, 0,
                                               dwarf_always_disassemble,
-                                              per_cu);
+                                              per_cu, per_objfile);
        }
 
       if (data < end)
@@ -4280,14 +4399,13 @@ locexpr_describe_location (struct symbol *symbol, CORE_ADDR addr,
 {
   struct dwarf2_locexpr_baton *dlbaton
     = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (symbol);
-  struct objfile *objfile = dwarf2_per_cu_objfile (dlbaton->per_cu);
-  unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
-  int offset_size = dwarf2_per_cu_offset_size (dlbaton->per_cu);
+  unsigned int addr_size = dlbaton->per_cu->addr_size ();
+  int offset_size = dlbaton->per_cu->offset_size ();
 
   locexpr_describe_location_1 (symbol, addr, stream,
                               dlbaton->data, dlbaton->size,
-                              objfile, addr_size, offset_size,
-                              dlbaton->per_cu);
+                              addr_size, offset_size,
+                              dlbaton->per_cu, dlbaton->per_objfile);
 }
 
 /* Describe the location of SYMBOL as an agent value in VALUE, generating
@@ -4299,13 +4417,14 @@ locexpr_tracepoint_var_ref (struct symbol *symbol, struct agent_expr *ax,
 {
   struct dwarf2_locexpr_baton *dlbaton
     = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (symbol);
-  unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
+  unsigned int addr_size = dlbaton->per_cu->addr_size ();
 
   if (dlbaton->size == 0)
     value->optimized_out = 1;
   else
     dwarf2_compile_expr_to_ax (ax, value, addr_size, dlbaton->data,
-                              dlbaton->data + dlbaton->size, dlbaton->per_cu);
+                              dlbaton->data + dlbaton->size, dlbaton->per_cu,
+                              dlbaton->per_objfile);
 }
 
 /* symbol_computed_ops 'generate_c_location' method.  */
@@ -4318,7 +4437,7 @@ locexpr_generate_c_location (struct symbol *sym, string_file *stream,
 {
   struct dwarf2_locexpr_baton *dlbaton
     = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (sym);
-  unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
+  unsigned int addr_size = dlbaton->per_cu->addr_size ();
 
   if (dlbaton->size == 0)
     error (_("symbol \"%s\" is optimized out"), sym->natural_name ());
@@ -4326,7 +4445,7 @@ locexpr_generate_c_location (struct symbol *sym, string_file *stream,
   compile_dwarf_expr_to_c (stream, result_name,
                           sym, pc, gdbarch, registers_used, addr_size,
                           dlbaton->data, dlbaton->data + dlbaton->size,
-                          dlbaton->per_cu);
+                          dlbaton->per_cu, dlbaton->per_objfile);
 }
 
 /* The set of location functions used with the DWARF-2 expression
@@ -4359,7 +4478,7 @@ loclist_read_variable (struct symbol *symbol, struct frame_info *frame)
 
   data = dwarf2_find_location_expression (dlbaton, &size, pc);
   val = dwarf2_evaluate_loc_desc (SYMBOL_TYPE (symbol), frame, data, size,
-                                 dlbaton->per_cu);
+                                 dlbaton->per_cu, dlbaton->per_objfile);
 
   return val;
 }
@@ -4417,14 +4536,15 @@ loclist_describe_location (struct symbol *symbol, CORE_ADDR addr,
   struct dwarf2_loclist_baton *dlbaton
     = (struct dwarf2_loclist_baton *) SYMBOL_LOCATION_BATON (symbol);
   const gdb_byte *loc_ptr, *buf_end;
-  struct objfile *objfile = dwarf2_per_cu_objfile (dlbaton->per_cu);
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  dwarf2_per_objfile *per_objfile = dlbaton->per_objfile;
+  struct objfile *objfile = per_objfile->objfile;
+  struct gdbarch *gdbarch = objfile->arch ();
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
-  int offset_size = dwarf2_per_cu_offset_size (dlbaton->per_cu);
+  unsigned int addr_size = dlbaton->per_cu->addr_size ();
+  int offset_size = dlbaton->per_cu->offset_size ();
   int signed_addr_p = bfd_get_sign_extend_vma (objfile->obfd);
   /* Adjust base_address for relocatable objects.  */
-  CORE_ADDR base_offset = dwarf2_per_cu_text_offset (dlbaton->per_cu);
+  CORE_ADDR base_offset = objfile->text_section_offset ();
   CORE_ADDR base_address = dlbaton->base_address + base_offset;
   int done = 0;
 
@@ -4441,15 +4561,22 @@ loclist_describe_location (struct symbol *symbol, CORE_ADDR addr,
       enum debug_loc_kind kind;
       const gdb_byte *new_ptr = NULL; /* init for gcc -Wall */
 
-      if (dlbaton->from_dwo)
+      if (dlbaton->per_cu->version () < 5 && dlbaton->from_dwo)
        kind = decode_debug_loc_dwo_addresses (dlbaton->per_cu,
+                                              dlbaton->per_objfile,
                                               loc_ptr, buf_end, &new_ptr,
                                               &low, &high, byte_order);
-      else
+      else if (dlbaton->per_cu->version () < 5)
        kind = decode_debug_loc_addresses (loc_ptr, buf_end, &new_ptr,
                                           &low, &high,
                                           byte_order, addr_size,
                                           signed_addr_p);
+      else
+       kind = decode_debug_loclists_addresses (dlbaton->per_cu,
+                                               dlbaton->per_objfile,
+                                               loc_ptr, buf_end, &new_ptr,
+                                               &low, &high, byte_order,
+                                               addr_size, signed_addr_p);
       loc_ptr = new_ptr;
       switch (kind)
        {
@@ -4463,6 +4590,7 @@ loclist_describe_location (struct symbol *symbol, CORE_ADDR addr,
          continue;
        case DEBUG_LOC_START_END:
        case DEBUG_LOC_START_LENGTH:
+       case DEBUG_LOC_OFFSET_PAIR:
          break;
        case DEBUG_LOC_BUFFER_OVERFLOW:
        case DEBUG_LOC_INVALID_ENTRY:
@@ -4479,8 +4607,17 @@ loclist_describe_location (struct symbol *symbol, CORE_ADDR addr,
       low = gdbarch_adjust_dwarf2_addr (gdbarch, low);
       high = gdbarch_adjust_dwarf2_addr (gdbarch, high);
 
-      length = extract_unsigned_integer (loc_ptr, 2, byte_order);
-      loc_ptr += 2;
+      if (dlbaton->per_cu->version () < 5)
+        {
+          length = extract_unsigned_integer (loc_ptr, 2, byte_order);
+          loc_ptr += 2;
+        }
+      else
+        {
+          unsigned int bytes_read;
+          length = read_unsigned_leb128 (NULL, loc_ptr, &bytes_read);
+          loc_ptr += bytes_read;
+        }
 
       /* (It would improve readability to print only the minimum
         necessary digits of the second number of the range.)  */
@@ -4489,8 +4626,8 @@ loclist_describe_location (struct symbol *symbol, CORE_ADDR addr,
 
       /* Now describe this particular location.  */
       locexpr_describe_location_1 (symbol, low, stream, loc_ptr, length,
-                                  objfile, addr_size, offset_size,
-                                  dlbaton->per_cu);
+                                  addr_size, offset_size,
+                                  dlbaton->per_cu, dlbaton->per_objfile);
 
       fprintf_filtered (stream, "\n");
 
@@ -4508,14 +4645,14 @@ loclist_tracepoint_var_ref (struct symbol *symbol, struct agent_expr *ax,
     = (struct dwarf2_loclist_baton *) SYMBOL_LOCATION_BATON (symbol);
   const gdb_byte *data;
   size_t size;
-  unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
+  unsigned int addr_size = dlbaton->per_cu->addr_size ();
 
   data = dwarf2_find_location_expression (dlbaton, &size, ax->scope);
   if (size == 0)
     value->optimized_out = 1;
   else
     dwarf2_compile_expr_to_ax (ax, value, addr_size, data, data + size,
-                              dlbaton->per_cu);
+                              dlbaton->per_cu, dlbaton->per_objfile);
 }
 
 /* symbol_computed_ops 'generate_c_location' method.  */
@@ -4528,7 +4665,7 @@ loclist_generate_c_location (struct symbol *sym, string_file *stream,
 {
   struct dwarf2_loclist_baton *dlbaton
     = (struct dwarf2_loclist_baton *) SYMBOL_LOCATION_BATON (sym);
-  unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
+  unsigned int addr_size = dlbaton->per_cu->addr_size ();
   const gdb_byte *data;
   size_t size;
 
@@ -4539,7 +4676,8 @@ loclist_generate_c_location (struct symbol *sym, string_file *stream,
   compile_dwarf_expr_to_c (stream, result_name,
                           sym, pc, gdbarch, registers_used, addr_size,
                           data, data + size,
-                          dlbaton->per_cu);
+                          dlbaton->per_cu,
+                          dlbaton->per_objfile);
 }
 
 /* The set of location functions used with the DWARF-2 expression
@@ -4570,4 +4708,16 @@ _initialize_dwarf2loc ()
                             NULL,
                             show_entry_values_debug,
                             &setdebuglist, &showdebuglist);
+
+  add_setshow_boolean_cmd ("always-disassemble", class_obscure,
+                          &dwarf_always_disassemble, _("\
+Set whether `info address' always disassembles DWARF expressions."), _("\
+Show whether `info address' always disassembles DWARF expressions."), _("\
+When enabled, DWARF expressions are always printed in an assembly-like\n\
+syntax.  When disabled, expressions will be printed in a more\n\
+conversational style, when possible."),
+                          NULL,
+                          show_dwarf_always_disassemble,
+                          &set_dwarf_cmdlist,
+                          &show_dwarf_cmdlist);
 }
This page took 0.043352 seconds and 4 git commands to generate.