Restrict checking value.lval on using address

With the previous change, value.location.address is only valid for
lval_memory.  This patch restrict some checking on value.lval on
using address.  Since we have a check on VALUE_VAL in
set_value_address, we need to set VALUE_VAL properly before
set_value_address too.

gdb:

2016-11-25  Yao Qi  <yao.qi@linaro.org>

	* ada-lang.c (ensure_lval): Call set_value_address after setting
	VALUE_LVAL.
	* elfread.c (elf_gnu_ifunc_resolve_addr): Set VALUE_LVAL to
	lval_memory.
	(elf_gnu_ifunc_resolver_return_stop): Likewise.
	* value.c (value_fn_field): Likewise.
	(value_from_contents_and_address_unresolved): Likewise.
	(value_from_contents_and_address): Likewise.
	(value_address): Check value->lval isn't
	lval_memory.
	(value_raw_address): Likewise.
	(set_value_address): Assert value->lval is lval_memory.
This commit is contained in:
Yao Qi 2016-11-28 17:09:26 +00:00
parent 7dc54575d9
commit 1a08844158
3 changed files with 9 additions and 12 deletions

View File

@ -4473,8 +4473,8 @@ ensure_lval (struct value *val)
const CORE_ADDR addr = const CORE_ADDR addr =
value_as_long (value_allocate_space_in_inferior (len)); value_as_long (value_allocate_space_in_inferior (len));
set_value_address (val, addr);
VALUE_LVAL (val) = lval_memory; VALUE_LVAL (val) = lval_memory;
set_value_address (val, addr);
write_memory (addr, value_contents (val), len); write_memory (addr, value_contents (val), len);
} }

View File

@ -879,6 +879,7 @@ elf_gnu_ifunc_resolve_addr (struct gdbarch *gdbarch, CORE_ADDR pc)
name_at_pc = NULL; name_at_pc = NULL;
function = allocate_value (func_func_type); function = allocate_value (func_func_type);
VALUE_LVAL (function) = lval_memory;
set_value_address (function, pc); set_value_address (function, pc);
/* STT_GNU_IFUNC resolver functions usually receive the HWCAP vector as /* STT_GNU_IFUNC resolver functions usually receive the HWCAP vector as
@ -992,6 +993,7 @@ elf_gnu_ifunc_resolver_return_stop (struct breakpoint *b)
gdb_assert (b->loc->next == NULL); gdb_assert (b->loc->next == NULL);
func_func = allocate_value (func_func_type); func_func = allocate_value (func_func_type);
VALUE_LVAL (func_func) = lval_memory;
set_value_address (func_func, b->loc->related_address); set_value_address (func_func, b->loc->related_address);
value = allocate_value (value_type); value = allocate_value (value_type);

View File

@ -1539,9 +1539,7 @@ value_lval_const (const struct value *value)
CORE_ADDR CORE_ADDR
value_address (const struct value *value) value_address (const struct value *value)
{ {
if (value->lval == lval_internalvar if (value->lval != lval_memory)
|| value->lval == lval_internalvar_component
|| value->lval == lval_xcallable)
return 0; return 0;
if (value->parent != NULL) if (value->parent != NULL)
return value_address (value->parent) + value->offset; return value_address (value->parent) + value->offset;
@ -1557,9 +1555,7 @@ value_address (const struct value *value)
CORE_ADDR CORE_ADDR
value_raw_address (const struct value *value) value_raw_address (const struct value *value)
{ {
if (value->lval == lval_internalvar if (value->lval != lval_memory)
|| value->lval == lval_internalvar_component
|| value->lval == lval_xcallable)
return 0; return 0;
return value->location.address; return value->location.address;
} }
@ -1567,9 +1563,7 @@ value_raw_address (const struct value *value)
void void
set_value_address (struct value *value, CORE_ADDR addr) set_value_address (struct value *value, CORE_ADDR addr)
{ {
gdb_assert (value->lval != lval_internalvar gdb_assert (value->lval == lval_memory);
&& value->lval != lval_internalvar_component
&& value->lval != lval_xcallable);
value->location.address = addr; value->location.address = addr;
} }
@ -3268,6 +3262,7 @@ value_fn_field (struct value **arg1p, struct fn_field *f,
} }
v = allocate_value (ftype); v = allocate_value (ftype);
VALUE_LVAL (v) = lval_memory;
if (sym) if (sym)
{ {
set_value_address (v, BLOCK_START (SYMBOL_BLOCK_VALUE (sym))); set_value_address (v, BLOCK_START (SYMBOL_BLOCK_VALUE (sym)));
@ -3654,8 +3649,8 @@ value_from_contents_and_address_unresolved (struct type *type,
v = allocate_value_lazy (type); v = allocate_value_lazy (type);
else else
v = value_from_contents (type, valaddr); v = value_from_contents (type, valaddr);
set_value_address (v, address);
VALUE_LVAL (v) = lval_memory; VALUE_LVAL (v) = lval_memory;
set_value_address (v, address);
return v; return v;
} }
@ -3680,8 +3675,8 @@ value_from_contents_and_address (struct type *type,
if (TYPE_DATA_LOCATION (resolved_type_no_typedef) != NULL if (TYPE_DATA_LOCATION (resolved_type_no_typedef) != NULL
&& TYPE_DATA_LOCATION_KIND (resolved_type_no_typedef) == PROP_CONST) && TYPE_DATA_LOCATION_KIND (resolved_type_no_typedef) == PROP_CONST)
address = TYPE_DATA_LOCATION_ADDR (resolved_type_no_typedef); address = TYPE_DATA_LOCATION_ADDR (resolved_type_no_typedef);
set_value_address (v, address);
VALUE_LVAL (v) = lval_memory; VALUE_LVAL (v) = lval_memory;
set_value_address (v, address);
return v; return v;
} }