*** empty log message ***
[binutils-gdb.git] / gdb / dwarf2loc.c
index 41b67fb90677cbb58f9189a70126061412a8c5f0..79d22770d5f0696081dffa95a61e8b0643a72c4f 100644 (file)
@@ -44,7 +44,7 @@
 
 static void
 dwarf_expr_frame_base_1 (struct symbol *framefunc, CORE_ADDR pc,
-                        gdb_byte **start, size_t *length);
+                        const gdb_byte **start, size_t *length);
 
 /* A helper function for dealing with location lists.  Given a
    symbol baton (BATON) and a pc value (PC), find the appropriate
@@ -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);
@@ -153,7 +153,7 @@ dwarf_expr_read_mem (void *baton, gdb_byte *buf, CORE_ADDR addr, size_t len)
    describing the frame base.  Return a pointer to it in START and
    its length in LENGTH.  */
 static void
-dwarf_expr_frame_base (void *baton, gdb_byte **start, size_t * length)
+dwarf_expr_frame_base (void *baton, const gdb_byte **start, size_t * length)
 {
   /* FIXME: cagney/2003-03-26: This code should be using
      get_frame_base_address(), and then implement a dwarf2 specific
@@ -178,7 +178,7 @@ dwarf_expr_frame_base (void *baton, gdb_byte **start, size_t * length)
 
 static void
 dwarf_expr_frame_base_1 (struct symbol *framefunc, CORE_ADDR pc,
-                        gdb_byte **start, size_t *length)
+                        const gdb_byte **start, size_t *length)
 {
   if (SYMBOL_LOCATION_BATON (framefunc) == NULL)
     *start = NULL;
@@ -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);
@@ -463,7 +467,7 @@ read_pieced_value (struct value *v)
       struct dwarf_expr_piece *p = &c->pieces[i];
       size_t this_size, this_size_bits;
       long dest_offset_bits, source_offset_bits, source_offset;
-      gdb_byte *intermediate_buffer;
+      const gdb_byte *intermediate_buffer;
 
       /* Compute size, source, and destination offsets for copying, in
         bits.  */
@@ -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;
@@ -917,7 +926,7 @@ needs_frame_read_mem (void *baton, gdb_byte *buf, CORE_ADDR addr, size_t len)
 
 /* Frame-relative accesses do require a frame.  */
 static void
-needs_frame_frame_base (void *baton, gdb_byte **start, size_t * length)
+needs_frame_frame_base (void *baton, const gdb_byte **start, size_t * length)
 {
   static gdb_byte lit0 = DW_OP_lit0;
   struct needs_frame_baton *nf_baton = baton;
@@ -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;
@@ -1017,12 +1026,12 @@ struct axs_var_loc
   LONGEST offset;
 };
 
-static gdb_byte *
+static const gdb_byte *
 dwarf2_tracepoint_var_loc (struct symbol *symbol,
                           struct agent_expr *ax,
                           struct axs_var_loc *loc,
                           struct gdbarch *gdbarch,
-                          gdb_byte *data, gdb_byte *end)
+                          const gdb_byte *data, const gdb_byte *end)
 {
   if (data[0] >= DW_OP_reg0 && data[0] <= DW_OP_reg31)
     {
@@ -1044,7 +1053,7 @@ dwarf2_tracepoint_var_loc (struct symbol *symbol,
       struct symbol *framefunc;
       int frame_reg = 0;
       LONGEST frame_offset;
-      gdb_byte *base_data;
+      const gdb_byte *base_data;
       size_t base_size;
       LONGEST base_offset = 0;
 
@@ -1063,8 +1072,8 @@ dwarf2_tracepoint_var_loc (struct symbol *symbol,
 
       if (base_data[0] >= DW_OP_breg0 && base_data[0] <= DW_OP_breg31)
        {
-         gdb_byte *buf_end;
-         
+         const gdb_byte *buf_end;
+
          frame_reg = base_data[0] - DW_OP_breg0;
          buf_end = read_sleb128 (base_data + 1,
                                  base_data + base_size, &base_offset);
@@ -1143,9 +1152,9 @@ dwarf2_tracepoint_var_access (struct agent_expr *ax,
 static void
 dwarf2_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
                           struct agent_expr *ax, struct axs_value *value,
-                          gdb_byte *data, int size)
+                          const gdb_byte *data, int size)
 {
-  gdb_byte *end = data + size;
+  const gdb_byte *end = data + size;
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   /* In practice, a variable is not going to be spread across
      dozens of registers or memory locations.  If someone comes up
@@ -1285,10 +1294,11 @@ locexpr_read_needs_frame (struct symbol *symbol)
 /* Describe a single piece of a location, returning an updated
    position in the bytecode sequence.  */
 
-static gdb_byte *
+static const gdb_byte *
 locexpr_describe_location_piece (struct symbol *symbol, struct ui_file *stream,
                                 CORE_ADDR addr, struct objfile *objfile,
-                                gdb_byte *data, int size, unsigned int addr_size)
+                                const gdb_byte *data, int size,
+                                unsigned int addr_size)
 {
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
   int regno;
@@ -1315,7 +1325,7 @@ locexpr_describe_location_piece (struct symbol *symbol, struct ui_file *stream,
       struct symbol *framefunc;
       int frame_reg = 0;
       LONGEST frame_offset;
-      gdb_byte *base_data;
+      const gdb_byte *base_data;
       size_t base_size;
       LONGEST base_offset = 0;
 
@@ -1335,7 +1345,7 @@ locexpr_describe_location_piece (struct symbol *symbol, struct ui_file *stream,
 
       if (base_data[0] >= DW_OP_breg0 && base_data[0] <= DW_OP_breg31)
        {
-         gdb_byte *buf_end;
+         const gdb_byte *buf_end;
          
          frame_reg = base_data[0] - DW_OP_breg0;
          buf_end = read_sleb128 (base_data + 1,
@@ -1422,10 +1432,11 @@ locexpr_describe_location_piece (struct symbol *symbol, struct ui_file *stream,
 
 static void
 locexpr_describe_location_1 (struct symbol *symbol, CORE_ADDR addr,
-                            struct ui_file *stream, gdb_byte *data, int size,
+                            struct ui_file *stream,
+                            const gdb_byte *data, int size,
                             struct objfile *objfile, unsigned int addr_size)
 {
-  gdb_byte *end = data + size;
+  const gdb_byte *end = data + size;
   int piece_done = 0, first_piece = 1, bad = 0;
 
   /* A multi-piece description consists of multiple sequences of bytes
@@ -1513,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,
@@ -1555,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);
@@ -1637,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);