2004-09-12 Andrew Cagney <cagney@gnu.org>
[deliverable/binutils-gdb.git] / gdb / dwarf2loc.c
index a4141a0432c0e9de640388e5803de09654c1be30..c281642ced82a93fc64b1aebaaf489ba11608933 100644 (file)
@@ -53,11 +53,14 @@ static char *
 find_location_expression (struct dwarf2_loclist_baton *baton,
                          size_t *locexpr_length, CORE_ADDR pc)
 {
-  CORE_ADDR base_address = baton->base_address;
   CORE_ADDR low, high;
   char *loc_ptr, *buf_end;
   unsigned int addr_size = TARGET_ADDR_BIT / TARGET_CHAR_BIT, length;
   CORE_ADDR base_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
+  /* Adjust base_address for relocatable objects.  */
+  CORE_ADDR base_offset = ANOFFSET (baton->objfile->section_offsets,
+                                   SECT_OFF_TEXT (baton->objfile));
+  CORE_ADDR base_address = baton->base_address + base_offset;
 
   loc_ptr = baton->data;
   buf_end = baton->data + baton->size;
@@ -154,7 +157,7 @@ dwarf_expr_frame_base (void *baton, unsigned char **start, size_t * length)
 
   framefunc = get_frame_function (debaton->frame);
 
-  if (SYMBOL_LOCATION_FUNCS (framefunc) == &dwarf2_loclist_funcs)
+  if (SYMBOL_OPS (framefunc) == &dwarf2_loclist_funcs)
     {
       struct dwarf2_loclist_baton *symbaton;
       symbaton = SYMBOL_LOCATION_BATON (framefunc);
@@ -202,7 +205,7 @@ dwarf2_evaluate_loc_desc (struct symbol *var, struct frame_info *frame,
                          unsigned char *data, unsigned short size,
                          struct objfile *objfile)
 {
-  CORE_ADDR result;
+  struct gdbarch *arch = get_frame_arch (frame);
   struct value *retval;
   struct dwarf_expr_baton baton;
   struct dwarf_expr_context *ctx;
@@ -225,21 +228,30 @@ dwarf2_evaluate_loc_desc (struct symbol *var, struct frame_info *frame,
   ctx->get_tls_address = dwarf_expr_tls_address;
 
   dwarf_expr_eval (ctx, data, size);
-  result = dwarf_expr_fetch (ctx, 0);
-
-  if (ctx->in_reg)
+  if (ctx->num_pieces > 0)
+    {
+      /* We haven't implemented splicing together pieces from
+         arbitrary sources yet.  */
+      error ("The value of variable '%s' is distributed across several\n"
+             "locations, and GDB cannot access its value.\n",
+             SYMBOL_NATURAL_NAME (var));
+    }
+  else if (ctx->in_reg)
     {
-      int regnum = DWARF2_REG_TO_REGNUM (result);
-      retval = value_from_register (SYMBOL_TYPE (var), regnum, frame);
+      CORE_ADDR dwarf_regnum = dwarf_expr_fetch (ctx, 0);
+      int gdb_regnum = DWARF2_REG_TO_REGNUM (dwarf_regnum);
+      retval = value_from_register (SYMBOL_TYPE (var), gdb_regnum, frame);
     }
   else
     {
+      CORE_ADDR address = dwarf_expr_fetch (ctx, 0);
+
       retval = allocate_value (SYMBOL_TYPE (var));
       VALUE_BFD_SECTION (retval) = SYMBOL_BFD_SECTION (var);
 
       VALUE_LVAL (retval) = lval_memory;
       VALUE_LAZY (retval) = 1;
-      VALUE_ADDRESS (retval) = result;
+      VALUE_ADDRESS (retval) = address;
     }
 
   free_dwarf_expr_context (ctx);
@@ -304,6 +316,7 @@ dwarf2_loc_desc_needs_frame (unsigned char *data, unsigned short size)
 {
   struct needs_frame_baton baton;
   struct dwarf_expr_context *ctx;
+  int in_reg;
 
   baton.needs_frame = 0;
 
@@ -316,9 +329,22 @@ dwarf2_loc_desc_needs_frame (unsigned char *data, unsigned short size)
 
   dwarf_expr_eval (ctx, data, size);
 
+  in_reg = ctx->in_reg;
+
+  if (ctx->num_pieces > 0)
+    {
+      int i;
+
+      /* If the location has several pieces, and any of them are in
+         registers, then we will need a frame to fetch them from.  */
+      for (i = 0; i < ctx->num_pieces; i++)
+        if (ctx->pieces[i].in_reg)
+          in_reg = 1;
+    }
+
   free_dwarf_expr_context (ctx);
 
-  return baton.needs_frame;
+  return baton.needs_frame || in_reg;
 }
 
 static void
@@ -462,7 +488,7 @@ locexpr_tracepoint_var_ref (struct symbol * symbol, struct agent_expr * ax,
 
 /* The set of location functions used with the DWARF-2 expression
    evaluator.  */
-struct location_funcs dwarf2_locexpr_funcs = {
+const struct symbol_ops dwarf2_locexpr_funcs = {
   locexpr_read_variable,
   locexpr_read_needs_frame,
   locexpr_describe_location,
@@ -534,7 +560,7 @@ loclist_tracepoint_var_ref (struct symbol * symbol, struct agent_expr * ax,
 
 /* The set of location functions used with the DWARF-2 expression
    evaluator and location lists.  */
-struct location_funcs dwarf2_loclist_funcs = {
+const struct symbol_ops dwarf2_loclist_funcs = {
   loclist_read_variable,
   loclist_read_needs_frame,
   loclist_describe_location,
This page took 0.025135 seconds and 4 git commands to generate.