[PATCH 2/3] cleanup: use value_lazy_at instead of allocate_value_lazy/attribute setter
Sanimir Agovic
sanimir.agovic@intel.com
Wed Aug 28 13:52:00 GMT 2013
I came across a pattern used to construct a value in the following way:
struct value *val = allocate_value_lazy (type);
VALUE_LVAL (val) = lval_memory;
set_value_address (val, address);
Instead we could fold the three calls into a single one:
value_at_lazy (type, addr);
I thought about renaming the function to value_from_address to streamline
the way we construct values but I left it as is.
e.g:
value_from_contents_and_address (...)
value_from_contents (...)
value_from_address (...) // instead of value_at (...)
2013-08-27 Sanimir Agovic <sanimir.agovic@intel.com>
* dwarf2loc.c (dwarf2_evaluate_loc_desc_full): Use value_at_lazy instead
of assembling value via allocate_value_lazy and attribute setter.
* findvar.c (default_read_var_value): Use value_at_lazy instead of
assembling value via allocate_value_lazy and attribute setter.
* valops.c (do_search_struct_field): Use value_at_lazy instead of
assembling value via allocate_value_lazy and attribute setter.
Change-Id: I32c6e12ba12c87fae7b7b9bd3426a8ea7e033b3e
---
gdb/dwarf2loc.c | 4 +---
gdb/findvar.c | 10 +---------
gdb/valops.c | 6 ++----
3 files changed, 4 insertions(+), 16 deletions(-)
diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
index 02afcdf..a1a384a 100644
--- a/gdb/dwarf2loc.c
+++ b/gdb/dwarf2loc.c
@@ -2303,11 +2303,9 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
int in_stack_memory = dwarf_expr_fetch_in_stack_memory (ctx, 0);
do_cleanups (value_chain);
- retval = allocate_value_lazy (type);
- VALUE_LVAL (retval) = lval_memory;
+ retval = value_at_lazy (type, address + byte_offset);
if (in_stack_memory)
set_value_stack (retval, 1);
- set_value_address (retval, address + byte_offset);
}
break;
diff --git a/gdb/findvar.c b/gdb/findvar.c
index f586ce2..d59bee1 100644
--- a/gdb/findvar.c
+++ b/gdb/findvar.c
@@ -502,7 +502,6 @@ default_read_var_value (struct symbol *var, struct frame_info *frame)
return v;
case LOC_STATIC:
- v = allocate_value_lazy (type);
if (overlay_debugging)
addr = symbol_overlayed_address (SYMBOL_VALUE_ADDRESS (var),
SYMBOL_OBJ_SECTION (SYMBOL_OBJFILE (var),
@@ -517,7 +516,6 @@ default_read_var_value (struct symbol *var, struct frame_info *frame)
error (_("Unknown argument list address for `%s'."),
SYMBOL_PRINT_NAME (var));
addr += SYMBOL_VALUE (var);
- v = allocate_value_lazy (type);
break;
case LOC_REF_ARG:
@@ -532,14 +530,12 @@ default_read_var_value (struct symbol *var, struct frame_info *frame)
argref += SYMBOL_VALUE (var);
ref = value_at (lookup_pointer_type (type), argref);
addr = value_as_address (ref);
- v = allocate_value_lazy (type);
break;
}
case LOC_LOCAL:
addr = get_frame_locals_address (frame);
addr += SYMBOL_VALUE (var);
- v = allocate_value_lazy (type);
break;
case LOC_TYPEDEF:
@@ -548,7 +544,6 @@ default_read_var_value (struct symbol *var, struct frame_info *frame)
break;
case LOC_BLOCK:
- v = allocate_value_lazy (type);
if (overlay_debugging)
addr = symbol_overlayed_address
(BLOCK_START (SYMBOL_BLOCK_VALUE (var)), SYMBOL_OBJ_SECTION (SYMBOL_OBJFILE (var),
@@ -575,7 +570,6 @@ default_read_var_value (struct symbol *var, struct frame_info *frame)
SYMBOL_PRINT_NAME (var));
addr = value_as_address (regval);
- v = allocate_value_lazy (type);
}
else
{
@@ -620,7 +614,6 @@ default_read_var_value (struct symbol *var, struct frame_info *frame)
if (obj_section
&& (obj_section->the_bfd_section->flags & SEC_THREAD_LOCAL) != 0)
addr = target_translate_tls_address (obj_section->objfile, addr);
- v = allocate_value_lazy (type);
}
break;
@@ -633,8 +626,7 @@ default_read_var_value (struct symbol *var, struct frame_info *frame)
break;
}
- VALUE_LVAL (v) = lval_memory;
- set_value_address (v, addr);
+ v = value_at_lazy (type, addr);
return v;
}
diff --git a/gdb/valops.c b/gdb/valops.c
index f86b283..890735e 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -1950,14 +1950,12 @@ do_search_struct_field (const char *name, struct value *arg1, int offset,
{
CORE_ADDR base_addr;
- v2 = allocate_value (basetype);
base_addr = value_address (arg1) + boffset;
+ v2 = value_at_lazy (basetype, base_addr);
if (target_read_memory (base_addr,
value_contents_raw (v2),
- TYPE_LENGTH (basetype)) != 0)
+ TYPE_LENGTH (value_type (basetype))) != 0)
error (_("virtual baseclass botch"));
- VALUE_LVAL (v2) = lval_memory;
- set_value_address (v2, base_addr);
}
else
{
--
1.7.1.1
More information about the Gdb-patches
mailing list