*** empty log message ***
[binutils-gdb.git] / gdb / dwarf2loc.c
index 481501b9a0ff8c289299e66a36277d5b80f481fc..79d22770d5f0696081dffa95a61e8b0643a72c4f 100644 (file)
@@ -54,12 +54,12 @@ dwarf_expr_frame_base_1 (struct symbol *framefunc, CORE_ADDR pc,
    For now, only return the first matching location expression; there
    can be more than one in the list.  */
 
-static gdb_byte *
+static const gdb_byte *
 find_location_expression (struct dwarf2_loclist_baton *baton,
                          size_t *locexpr_length, CORE_ADDR pc)
 {
   CORE_ADDR low, high;
-  gdb_byte *loc_ptr, *buf_end;
+  const gdb_byte *loc_ptr, *buf_end;
   int length;
   struct objfile *objfile = dwarf2_per_cu_objfile (baton->per_cu);
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
@@ -231,6 +231,9 @@ dwarf_expr_tls_address (void *baton, CORE_ADDR offset)
 
 struct piece_closure
 {
+  /* Reference count.  */
+  int refc;
+
   /* The number of pieces used to describe this variable.  */
   int n_pieces;
 
@@ -250,6 +253,7 @@ allocate_piece_closure (int n_pieces, struct dwarf_expr_piece *pieces,
 {
   struct piece_closure *c = XZALLOC (struct piece_closure);
 
+  c->refc = 1;
   c->n_pieces = n_pieces;
   c->addr_size = addr_size;
   c->pieces = XCALLOC (n_pieces, struct dwarf_expr_piece);
@@ -747,7 +751,8 @@ copy_pieced_value_closure (struct value *v)
 {
   struct piece_closure *c = (struct piece_closure *) value_computed_closure (v);
   
-  return allocate_piece_closure (c->n_pieces, c->pieces, c->addr_size);
+  ++c->refc;
+  return c;
 }
 
 static void
@@ -755,8 +760,12 @@ free_pieced_value_closure (struct value *v)
 {
   struct piece_closure *c = (struct piece_closure *) value_computed_closure (v);
 
-  xfree (c->pieces);
-  xfree (c);
+  --c->refc;
+  if (c->refc == 0)
+    {
+      xfree (c->pieces);
+      xfree (c);
+    }
 }
 
 /* Functions for accessing a variable described by DW_OP_piece.  */
@@ -773,7 +782,7 @@ static struct lval_funcs pieced_value_funcs = {
 
 static struct value *
 dwarf2_evaluate_loc_desc (struct type *type, struct frame_info *frame,
-                         gdb_byte *data, unsigned short size,
+                         const gdb_byte *data, unsigned short size,
                          struct dwarf2_per_cu_data *per_cu)
 {
   struct value *retval;
@@ -953,7 +962,7 @@ needs_frame_tls_address (void *baton, CORE_ADDR offset)
    requires a frame to evaluate.  */
 
 static int
-dwarf2_loc_desc_needs_frame (gdb_byte *data, unsigned short size,
+dwarf2_loc_desc_needs_frame (const gdb_byte *data, unsigned short size,
                             struct dwarf2_per_cu_data *per_cu)
 {
   struct needs_frame_baton baton;
@@ -1515,7 +1524,7 @@ loclist_read_variable (struct symbol *symbol, struct frame_info *frame)
 {
   struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
   struct value *val;
-  gdb_byte *data;
+  const gdb_byte *data;
   size_t size;
 
   data = find_location_expression (dlbaton, &size,
@@ -1557,7 +1566,7 @@ loclist_describe_location (struct symbol *symbol, CORE_ADDR addr,
 {
   struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
   CORE_ADDR low, high;
-  gdb_byte *loc_ptr, *buf_end;
+  const gdb_byte *loc_ptr, *buf_end;
   int length, first = 1;
   struct objfile *objfile = dwarf2_per_cu_objfile (dlbaton->per_cu);
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
@@ -1639,7 +1648,7 @@ loclist_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
                            struct agent_expr *ax, struct axs_value *value)
 {
   struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
-  gdb_byte *data;
+  const gdb_byte *data;
   size_t size;
 
   data = find_location_expression (dlbaton, &size, ax->scope);