2004-08-13 Michael Chastain <mec.gnu@mindspring.com>
[deliverable/binutils-gdb.git] / gdb / dwarf2loc.c
index 8927e8798b52da0d33cf59cdcf6834c18d39367a..cdbeb10acf43eef6557822c49be23169406e1a54 100644 (file)
@@ -29,6 +29,7 @@
 #include "ax.h"
 #include "ax-gdb.h"
 #include "regcache.h"
+#include "objfiles.h"
 
 #include "elf/dwarf2.h"
 #include "dwarf2expr.h"
 
 static char *
 find_location_expression (struct dwarf2_loclist_baton *baton,
-                         int *locexpr_length, CORE_ADDR pc)
+                         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;
@@ -124,7 +128,9 @@ dwarf_expr_read_reg (void *baton, int dwarf_regnum)
 
   frame_register (debaton->frame, regnum, &optimized, &lval_type, &save_addr,
                  &realnum, buf);
-  result = extract_address (buf, regsize);
+  /* NOTE: cagney/2003-05-22: This extract is assuming that a DWARF 2
+     address is always unsigned.  That may or may not be true.  */
+  result = extract_unsigned_integer (buf, regsize);
 
   return result;
 }
@@ -151,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);
@@ -183,6 +189,8 @@ dwarf_expr_tls_address (void *baton, CORE_ADDR offset)
     addr = target_get_thread_local_address (inferior_ptid,
                                            debaton->objfile,
                                            offset);
+  /* It wouldn't be wrong here to try a gdbarch method, too; finding
+     TLS is an ABI-specific thing.  But we don't do that yet.  */
   else
     error ("Cannot find thread-local variables on this target");
 
@@ -223,7 +231,10 @@ dwarf2_evaluate_loc_desc (struct symbol *var, struct frame_info *frame,
   result = dwarf_expr_fetch (ctx, 0);
 
   if (ctx->in_reg)
-    retval = value_from_register (SYMBOL_TYPE (var), result, frame);
+    {
+      int regnum = DWARF2_REG_TO_REGNUM (result);
+      retval = value_from_register (SYMBOL_TYPE (var), regnum, frame);
+    }
   else
     {
       retval = allocate_value (SYMBOL_TYPE (var));
@@ -296,6 +307,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;
 
@@ -308,9 +320,11 @@ dwarf2_loc_desc_needs_frame (unsigned char *data, unsigned short size)
 
   dwarf_expr_eval (ctx, data, size);
 
+  in_reg = ctx->in_reg;
+
   free_dwarf_expr_context (ctx);
 
-  return baton.needs_frame;
+  return baton.needs_frame || in_reg;
 }
 
 static void
@@ -401,6 +415,34 @@ locexpr_describe_location (struct symbol *symbol, struct ui_file *stream)
       return 1;
     }
 
+  /* The location expression for a TLS variable looks like this (on a
+     64-bit LE machine):
+
+     DW_AT_location    : 10 byte block: 3 4 0 0 0 0 0 0 0 e0
+                        (DW_OP_addr: 4; DW_OP_GNU_push_tls_address)
+     
+     0x3 is the encoding for DW_OP_addr, which has an operand as long
+     as the size of an address on the target machine (here is 8
+     bytes).  0xe0 is the encoding for DW_OP_GNU_push_tls_address.
+     The operand represents the offset at which the variable is within
+     the thread local storage.  */
+
+  if (dlbaton->size > 1 
+      && dlbaton->data[dlbaton->size - 1] == DW_OP_GNU_push_tls_address)
+    if (dlbaton->data[0] == DW_OP_addr)
+      {
+       int bytes_read;
+       CORE_ADDR offset = dwarf2_read_address (&dlbaton->data[1],
+                                               &dlbaton->data[dlbaton->size - 1],
+                                               &bytes_read);
+       fprintf_filtered (stream, 
+                         "a thread-local variable at offset %s in the "
+                         "thread-local storage for `%s'",
+                         paddr_nz (offset), dlbaton->objfile->name);
+       return 1;
+      }
+  
+
   fprintf_filtered (stream,
                    "a variable with complex or multiple locations (DWARF2)");
   return 1;
@@ -426,7 +468,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,
@@ -445,7 +487,7 @@ loclist_read_variable (struct symbol *symbol, struct frame_info *frame)
   struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
   struct value *val;
   unsigned char *data;
-  int size;
+  size_t size;
 
   data = find_location_expression (dlbaton, &size,
                                   frame ? get_frame_pc (frame) : 0);
@@ -487,7 +529,7 @@ loclist_tracepoint_var_ref (struct symbol * symbol, struct agent_expr * ax,
 {
   struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
   unsigned char *data;
-  int size;
+  size_t size;
 
   data = find_location_expression (dlbaton, &size, ax->scope);
   if (data == NULL)
@@ -498,7 +540,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.025113 seconds and 4 git commands to generate.