[patch] Remove excessive DWARF block xmemdup by me [Re: [patch 02/12] entryval: Basic parameter values recovery]

Jan Kratochvil jan.kratochvil@redhat.com
Sun Jul 24 18:10:00 GMT 2011


On Tue, 19 Jul 2011 16:19:00 +0200, Tom Tromey wrote:
> >>>>> "Jan" == Jan Kratochvil <jan.kratochvil@redhat.com> writes:
> Jan> +/* Allocate a copy of BLK on CU's objfile_obstack (not comp_unit_obstack),
> Jan> +   including a copy of the BLK DWARF code.  */
> Jan> +
> Jan> +static struct dwarf2_locexpr_baton *
> Jan> +dlbaton_obstack_copy (const struct dwarf_block *blk, struct dwarf2_cu *cu)
> 
> I don't understand the need for this.
> 
> Once we have mapped in a DWARF section, we do not unmap it until the
> objfile is destroyed or reloaded.  At that point, the types are all
> destroyed as well.  So, the lifetimes are already in sync, and you can
> just store a pointer directly to the DWARF data.  We already rely on
> this in many cases.

I agree.  In such case my recently checked-in patch is also excessively memory
copying this way.
	[patch] Fix DW_OP_call2 and DW_OP_call4 for max-cache-age 0 #2
	http://sourceware.org/ml/gdb-patches/2011-07/msg00343.html
	f35c0b67e636d7ccddfee8ace6b462a73394b482

I will check it in.  No regressions on
{x86_64,x86_64-m32,i686}-fedora16pre-linux-gnu.


Thanks,
Jan


gdb/
2011-07-24  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Remove excessive DWARF expressions memory duplication.
	* dwarf2loc.c (per_cu_dwarf_call): Remove variable back_to and its use
	for block.data.
	(indirect_pieced_value): Remove variable result.  Remove variable
	back_to and its use for baton.data.
	(dwarf2_compile_expr_to_ax): Remove variable back_to and its use for
	block.data.
	* dwarf2read.c (dwarf2_fetch_die_location_block): Remove xmemdup.
	Update the function comment.

--- a/gdb/dwarf2loc.c
+++ b/gdb/dwarf2loc.c
@@ -265,19 +265,14 @@ per_cu_dwarf_call (struct dwarf_expr_context *ctx, size_t die_offset,
 		   void *baton)
 {
   struct dwarf2_locexpr_baton block;
-  struct cleanup *back_to;
 
   block = dwarf2_fetch_die_location_block (die_offset, per_cu,
 					   get_frame_pc, baton);
 
-  back_to = make_cleanup (xfree, (void *) block.data);
-
   /* DW_OP_call_ref is currently not supported.  */
   gdb_assert (block.per_cu == per_cu);
 
   dwarf_expr_eval (ctx, block.data, block.size);
-
-  do_cleanups (back_to);
 }
 
 /* Helper interface of per_cu_dwarf_call for dwarf2_evaluate_loc_desc.  */
@@ -969,9 +964,7 @@ indirect_pieced_value (struct value *value)
   struct dwarf2_locexpr_baton baton;
   int i, bit_offset, bit_length;
   struct dwarf_expr_piece *piece = NULL;
-  struct value *result;
   LONGEST byte_offset;
-  struct cleanup *back_to;
 
   type = check_typedef (value_type (value));
   if (TYPE_CODE (type) != TYPE_CODE_PTR)
@@ -1019,15 +1012,9 @@ indirect_pieced_value (struct value *value)
 					   get_frame_address_in_block_wrapper,
 					   frame);
 
-  back_to = make_cleanup (xfree, (void *) baton.data);
-
-  result = dwarf2_evaluate_loc_desc_full (TYPE_TARGET_TYPE (type), frame,
-					  baton.data, baton.size, baton.per_cu,
-					  byte_offset);
-
-  do_cleanups (back_to);
-
-  return result;
+  return dwarf2_evaluate_loc_desc_full (TYPE_TARGET_TYPE (type), frame,
+					baton.data, baton.size, baton.per_cu,
+					byte_offset);
 }
 
 static void *
@@ -2133,14 +2120,12 @@ dwarf2_compile_expr_to_ax (struct agent_expr *expr, struct axs_value *loc,
 	  {
 	    struct dwarf2_locexpr_baton block;
 	    int size = (op == DW_OP_call2 ? 2 : 4);
-	    struct cleanup *back_to;
 
 	    uoffset = extract_unsigned_integer (op_ptr, size, byte_order);
 	    op_ptr += size;
 
 	    block = dwarf2_fetch_die_location_block (uoffset, per_cu,
 						     get_ax_pc, expr);
-	    back_to = make_cleanup (xfree, (void *) block.data);
 
 	    /* DW_OP_call_ref is currently not supported.  */
 	    gdb_assert (block.per_cu == per_cu);
@@ -2148,8 +2133,6 @@ dwarf2_compile_expr_to_ax (struct agent_expr *expr, struct axs_value *loc,
 	    dwarf2_compile_expr_to_ax (expr, loc, arch, addr_size,
 				       block.data, block.data + block.size,
 				       per_cu);
-
-	    do_cleanups (back_to);
 	  }
 	  break;
 
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -13892,9 +13892,9 @@ follow_die_ref (struct die_info *src_die, struct attribute *attr,
   return die;
 }
 
-/* Return DWARF block and its CU referenced by OFFSET at PER_CU.  Returned
-   value is intended for DW_OP_call*.  You must call xfree on returned
-   dwarf2_locexpr_baton->data.  */
+/* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
+   Returned value is intended for DW_OP_call*.  Returned
+   dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE.  */
 
 struct dwarf2_locexpr_baton
 dwarf2_fetch_die_location_block (unsigned int offset,
@@ -13950,9 +13950,6 @@ dwarf2_fetch_die_location_block (unsigned int offset,
     }
   retval.per_cu = cu->per_cu;
 
-  if (retval.data)
-    retval.data = xmemdup (retval.data, retval.size, retval.size);
-
   age_cached_comp_units ();
 
   return retval;



More information about the Gdb-patches mailing list