Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
- 2009 Free Software Foundation, Inc.
+ 2009, 2010 Free Software Foundation, Inc.
This file is part of GDB.
/* If value is a variable, is it initialized or not. */
int initialized;
+ /* If value is from the stack. If this is set, read_stack will be
+ used instead of read_memory to enable extra caching. */
+ int stack;
+
/* Actual contents of the value. Target byte-order. NULL or not
valid if lazy is nonzero. */
gdb_byte *contents;
allocate_value_lazy (struct type *type)
{
struct value *val;
- struct type *atype = check_typedef (type);
+
+ /* Call check_typedef on our type to make sure that, if TYPE
+ is a TYPE_CODE_TYPEDEF, its length is set to the length
+ of the target type instead of zero. However, we do not
+ replace the typedef type by the target type, because we want
+ to keep the typedef in order to be able to set the VAL's type
+ description correctly. */
+ check_typedef (type);
val = (struct value *) xzalloc (sizeof (struct value));
val->contents = NULL;
allocate_value (struct type *type)
{
struct value *val = allocate_value_lazy (type);
+
allocate_value_contents (val);
val->lazy = 0;
return val;
done with it. */
struct type *array_type
= lookup_array_range_type (type, low_bound, count + low_bound - 1);
- return allocate_value (array_type);
-}
-
-/* Needed if another module needs to maintain its on list of values. */
-void
-value_prepend_to_list (struct value **head, struct value *val)
-{
- val->next = *head;
- *head = val;
-}
-/* Needed if another module needs to maintain its on list of values. */
-void
-value_remove_from_list (struct value **head, struct value *val)
-{
- struct value *prev;
-
- if (*head == val)
- *head = (*head)->next;
- else
- for (prev = *head; prev->next; prev = prev->next)
- if (prev->next == val)
- {
- prev->next = val->next;
- break;
- }
+ return allocate_value (array_type);
}
struct value *
void *closure)
{
struct value *v = allocate_value (type);
+
VALUE_LVAL (v) = lval_computed;
v->location.computed.funcs = funcs;
v->location.computed.closure = closure;
}
struct type *
-value_type (struct value *value)
+value_type (const struct value *value)
{
return value->type;
}
}
int
-value_offset (struct value *value)
+value_offset (const struct value *value)
{
return value->offset;
}
}
int
-value_bitpos (struct value *value)
+value_bitpos (const struct value *value)
{
return value->bitpos;
}
}
int
-value_bitsize (struct value *value)
+value_bitsize (const struct value *value)
{
return value->bitsize;
}
return value->enclosing_type;
}
+static void
+require_not_optimized_out (struct value *value)
+{
+ if (value->optimized_out)
+ error (_("value has been optimized out"));
+}
+
const gdb_byte *
-value_contents_all (struct value *value)
+value_contents_for_printing (struct value *value)
{
if (value->lazy)
value_fetch_lazy (value);
return value->contents;
}
+const gdb_byte *
+value_contents_all (struct value *value)
+{
+ const gdb_byte *result = value_contents_for_printing (value);
+ require_not_optimized_out (value);
+ return result;
+}
+
int
value_lazy (struct value *value)
{
value->lazy = val;
}
+int
+value_stack (struct value *value)
+{
+ return value->stack;
+}
+
+void
+set_value_stack (struct value *value, int val)
+{
+ value->stack = val;
+}
+
const gdb_byte *
value_contents (struct value *value)
{
- return value_contents_writeable (value);
+ const gdb_byte *result = value_contents_writeable (value);
+ require_not_optimized_out (value);
+ return result;
}
gdb_byte *
value->optimized_out = val;
}
+int
+value_entirely_optimized_out (const struct value *value)
+{
+ if (!value->optimized_out)
+ return 0;
+ if (value->lval != lval_computed
+ || !value->location.computed.funcs->check_validity)
+ return 1;
+ return !value->location.computed.funcs->check_any_valid (value);
+}
+
+int
+value_bits_valid (const struct value *value, int offset, int length)
+{
+ if (value == NULL || !value->optimized_out)
+ return 1;
+ if (value->lval != lval_computed
+ || !value->location.computed.funcs->check_validity)
+ return 0;
+ return value->location.computed.funcs->check_validity (value, offset,
+ length);
+}
+
int
value_embedded_offset (struct value *value)
{
}
void *
-value_computed_closure (struct value *v)
+value_computed_closure (const struct value *v)
{
- gdb_assert (VALUE_LVAL (v) == lval_computed);
+ gdb_assert (v->lval == lval_computed);
return v->location.computed.closure;
}
}
/* Free all the values that have been allocated (except for those released).
- Called after each command, successful or not. */
+ Call after each command, successful or not.
+ In practice this is called before each command, which is sufficient. */
void
free_all_values (void)
all_values = 0;
}
+/* Frees all the elements in a chain of values. */
+
+void
+free_value_chain (struct value *v)
+{
+ struct value *next;
+
+ for (; v; v = next)
+ {
+ next = value_next (v);
+ value_free (v);
+ }
+}
+
/* Remove VAL from the chain all_values
so it will not be freed automatically. */
if (all_values == val)
{
all_values = val->next;
+ val->next = NULL;
return;
}
if (v->next == val)
{
v->next = val->next;
+ val->next = NULL;
break;
}
}
return val;
}
+/* Return a version of ARG that is non-lvalue. */
+
+struct value *
+value_non_lval (struct value *arg)
+{
+ if (VALUE_LVAL (arg) != not_lval)
+ {
+ struct type *enc_type = value_enclosing_type (arg);
+ struct value *val = allocate_value (enc_type);
+
+ memcpy (value_contents_all_raw (val), value_contents_all (arg),
+ TYPE_LENGTH (enc_type));
+ val->type = arg->type;
+ set_value_embedded_offset (val, value_embedded_offset (arg));
+ set_value_pointed_to_offset (val, value_pointed_to_offset (arg));
+ return val;
+ }
+ return arg;
+}
+
void
-set_value_component_location (struct value *component, struct value *whole)
+set_value_component_location (struct value *component,
+ const struct value *whole)
{
- if (VALUE_LVAL (whole) == lval_internalvar)
+ if (whole->lval == lval_internalvar)
VALUE_LVAL (component) = lval_internalvar_component;
else
- VALUE_LVAL (component) = VALUE_LVAL (whole);
+ VALUE_LVAL (component) = whole->lval;
component->location = whole->location;
- if (VALUE_LVAL (whole) == lval_computed)
+ if (whole->lval == lval_computed)
{
struct lval_funcs *funcs = whole->location.computed.funcs;
if (i == 0)
{
struct value_history_chunk *new
- = (struct value_history_chunk *)
+ = (struct value_history_chunk *)
+
xmalloc (sizeof (struct value_history_chunk));
memset (new->values, 0, sizeof new->values);
new->next = value_history_chain;
for (i = num; i < num + 10 && i <= value_history_count; i++)
{
struct value_print_options opts;
+
val = access_value_history (i);
printf_filtered (("$%d = "), i);
get_user_print_options (&opts);
/* The internal variable holds a GDB internal convenience function. */
INTERNALVAR_FUNCTION,
- /* The variable holds a simple scalar value. */
- INTERNALVAR_SCALAR,
+ /* The variable holds an integer value. */
+ INTERNALVAR_INTEGER,
+
+ /* The variable holds a pointer value. */
+ INTERNALVAR_POINTER,
/* The variable holds a GDB-provided string. */
INTERNALVAR_STRING,
int canonical;
} fn;
- /* A scalar value used with INTERNALVAR_SCALAR. */
+ /* An integer value used with INTERNALVAR_INTEGER. */
struct
{
/* If type is non-NULL, it will be used as the type to generate
a value for this internal variable. If type is NULL, a default
integer type for the architecture is used. */
struct type *type;
- union
- {
- LONGEST l; /* Used with TYPE_CODE_INT and NULL types. */
- CORE_ADDR a; /* Used with TYPE_CODE_PTR types. */
- } val;
- } scalar;
+ LONGEST val;
+ } integer;
+
+ /* A pointer value used with INTERNALVAR_POINTER. */
+ struct
+ {
+ struct type *type;
+ CORE_ADDR val;
+ } pointer;
/* A string value used with INTERNALVAR_STRING. */
char *string;
create_internalvar (const char *name)
{
struct internalvar *var;
+
var = (struct internalvar *) xmalloc (sizeof (struct internalvar));
var->name = concat (name, (char *)NULL);
var->kind = INTERNALVAR_VOID;
create_internalvar_type_lazy (char *name, internalvar_make_value fun)
{
struct internalvar *var = create_internalvar (name);
+
var->kind = INTERNALVAR_MAKE_VALUE;
var->u.make_value = fun;
return var;
val = allocate_value (builtin_type (gdbarch)->internal_fn);
break;
- case INTERNALVAR_SCALAR:
- if (!var->u.scalar.type)
+ case INTERNALVAR_INTEGER:
+ if (!var->u.integer.type)
val = value_from_longest (builtin_type (gdbarch)->builtin_int,
- var->u.scalar.val.l);
- else if (TYPE_CODE (var->u.scalar.type) == TYPE_CODE_INT)
- val = value_from_longest (var->u.scalar.type, var->u.scalar.val.l);
- else if (TYPE_CODE (var->u.scalar.type) == TYPE_CODE_PTR)
- val = value_from_pointer (var->u.scalar.type, var->u.scalar.val.a);
+ var->u.integer.val);
else
- internal_error (__FILE__, __LINE__, "bad type");
+ val = value_from_longest (var->u.integer.type, var->u.integer.val);
+ break;
+
+ case INTERNALVAR_POINTER:
+ val = value_from_pointer (var->u.pointer.type, var->u.pointer.val);
break;
case INTERNALVAR_STRING:
{
switch (var->kind)
{
- case INTERNALVAR_SCALAR:
- if (var->u.scalar.type == NULL
- || TYPE_CODE (var->u.scalar.type) == TYPE_CODE_INT)
- {
- *result = var->u.scalar.val.l;
- return 1;
- }
- /* Fall through. */
+ case INTERNALVAR_INTEGER:
+ *result = var->u.integer.val;
+ return 1;
default:
return 0;
break;
case TYPE_CODE_INT:
- new_kind = INTERNALVAR_SCALAR;
- new_data.scalar.type = value_type (val);
- new_data.scalar.val.l = value_as_long (val);
+ new_kind = INTERNALVAR_INTEGER;
+ new_data.integer.type = value_type (val);
+ new_data.integer.val = value_as_long (val);
break;
case TYPE_CODE_PTR:
- new_kind = INTERNALVAR_SCALAR;
- new_data.scalar.type = value_type (val);
- new_data.scalar.val.a = value_as_address (val);
+ new_kind = INTERNALVAR_POINTER;
+ new_data.pointer.type = value_type (val);
+ new_data.pointer.val = value_as_address (val);
break;
default:
/* Clean up old contents. */
clear_internalvar (var);
- var->kind = INTERNALVAR_SCALAR;
- var->u.scalar.type = NULL;
- var->u.scalar.val.l = l;
+ var->kind = INTERNALVAR_INTEGER;
+ var->u.integer.type = NULL;
+ var->u.integer.val = l;
}
void
internal_function_fn handler, void *cookie)
{
struct internal_function *ifn = XNEW (struct internal_function);
+
ifn->name = xstrdup (name);
ifn->handler = handler;
ifn->cookie = cookie;
/* Update VALUE before discarding OBJFILE. COPIED_TYPES is used to
prevent cycles / duplicates. */
-static void
+void
preserve_one_value (struct value *value, struct objfile *objfile,
htab_t copied_types)
{
{
switch (var->kind)
{
- case INTERNALVAR_SCALAR:
- if (var->u.scalar.type && TYPE_OBJFILE (var->u.scalar.type) == objfile)
- var->u.scalar.type
- = copy_type_recursive (objfile, var->u.scalar.type, copied_types);
+ case INTERNALVAR_INTEGER:
+ if (var->u.integer.type && TYPE_OBJFILE (var->u.integer.type) == objfile)
+ var->u.integer.type
+ = copy_type_recursive (objfile, var->u.integer.type, copied_types);
+ break;
+
+ case INTERNALVAR_POINTER:
+ if (TYPE_OBJFILE (var->u.pointer.type) == objfile)
+ var->u.pointer.type
+ = copy_type_recursive (objfile, var->u.pointer.type, copied_types);
break;
case INTERNALVAR_VALUE:
htab_t copied_types;
struct value_history_chunk *cur;
struct internalvar *var;
- struct value *val;
int i;
/* Create the hash table. We allocate on the objfile's obstack, since
for (var = internalvars; var; var = var->next)
preserve_one_internalvar (var, objfile, copied_types);
- for (val = values_in_python; val; val = val->next)
- preserve_one_value (val, objfile, copied_types);
+ preserve_python_values (objfile, copied_types);
htab_delete (copied_types);
}
}
\f
-/* Get the value of the FIELDN'th field (which must be static) of
+/* Get the value of the FIELDNO'th field (which must be static) of
TYPE. Return NULL if the field doesn't exist or has been
optimized out. */
{
struct value *retval;
- if (TYPE_FIELD_LOC_KIND (type, fieldno) == FIELD_LOC_KIND_PHYSADDR)
+ switch (TYPE_FIELD_LOC_KIND (type, fieldno))
{
- retval = value_at (TYPE_FIELD_TYPE (type, fieldno),
- TYPE_FIELD_STATIC_PHYSADDR (type, fieldno));
- }
- else
+ case FIELD_LOC_KIND_PHYSADDR:
+ retval = value_at_lazy (TYPE_FIELD_TYPE (type, fieldno),
+ TYPE_FIELD_STATIC_PHYSADDR (type, fieldno));
+ break;
+ case FIELD_LOC_KIND_PHYSNAME:
{
char *phys_name = TYPE_FIELD_STATIC_PHYSNAME (type, fieldno);
+ /*TYPE_FIELD_NAME (type, fieldno);*/
struct symbol *sym = lookup_symbol (phys_name, 0, VAR_DOMAIN, 0);
+
if (sym == NULL)
{
- /* With some compilers, e.g. HP aCC, static data members are reported
- as non-debuggable symbols */
- struct minimal_symbol *msym = lookup_minimal_symbol (phys_name, NULL, NULL);
+ /* With some compilers, e.g. HP aCC, static data members are
+ reported as non-debuggable symbols */
+ struct minimal_symbol *msym = lookup_minimal_symbol (phys_name,
+ NULL, NULL);
+
if (!msym)
return NULL;
else
{
- retval = value_at (TYPE_FIELD_TYPE (type, fieldno),
- SYMBOL_VALUE_ADDRESS (msym));
+ retval = value_at_lazy (TYPE_FIELD_TYPE (type, fieldno),
+ SYMBOL_VALUE_ADDRESS (msym));
}
}
else
- {
- /* SYM should never have a SYMBOL_CLASS which will require
- read_var_value to use the FRAME parameter. */
- if (symbol_read_needs_frame (sym))
- warning (_("static field's value depends on the current "
- "frame - bad debug info?"));
- retval = read_var_value (sym, NULL);
- }
- if (retval && VALUE_LVAL (retval) == lval_memory)
- SET_FIELD_PHYSADDR (TYPE_FIELD (type, fieldno),
- value_address (retval));
+ retval = value_of_variable (sym, NULL);
+ break;
+ }
+ default:
+ gdb_assert_not_reached ("unexpected field location kind");
}
+
return retval;
}
CHECK_TYPEDEF (arg_type);
type = TYPE_FIELD_TYPE (arg_type, fieldno);
+ /* Call check_typedef on our type to make sure that, if TYPE
+ is a TYPE_CODE_TYPEDEF, its length is set to the length
+ of the target type instead of zero. However, we do not
+ replace the typedef type by the target type, because we want
+ to keep the typedef in order to be able to print the type
+ description correctly. */
+ check_typedef (type);
+
/* Handle packed fields */
if (TYPE_FIELD_BITSIZE (arg_type, fieldno))
v->bitpos = bitpos % container_bitsize;
else
v->bitpos = bitpos % 8;
- v->offset = value_offset (arg1) + value_embedded_offset (arg1)
- + (bitpos - v->bitpos) / 8;
+ v->offset = (value_embedded_offset (arg1)
+ + offset
+ + (bitpos - v->bitpos) / 8);
v->parent = arg1;
value_incref (v->parent);
if (!value_lazy (arg1))
ULONGEST val;
ULONGEST valmask;
int lsbcount;
+ int bytes_read;
- val = extract_unsigned_integer (valaddr + bitpos / 8,
- sizeof (val), byte_order);
+ /* Read the minimum number of bytes required; there may not be
+ enough bytes to read an entire ULONGEST. */
CHECK_TYPEDEF (field_type);
+ if (bitsize)
+ bytes_read = ((bitpos % 8) + bitsize + 7) / 8;
+ else
+ bytes_read = TYPE_LENGTH (field_type);
+
+ val = extract_unsigned_integer (valaddr + bitpos / 8,
+ bytes_read, byte_order);
/* Extract bits. See comment above. */
if (gdbarch_bits_big_endian (get_type_arch (field_type)))
- lsbcount = (sizeof val * 8 - bitpos % 8 - bitsize);
+ lsbcount = (bytes_read * 8 - bitpos % 8 - bitsize);
else
lsbcount = (bitpos % 8);
val >>= lsbcount;
}
+/* Pack NUM into BUF using a target format of TYPE. */
+
+void
+pack_unsigned_long (gdb_byte *buf, struct type *type, ULONGEST num)
+{
+ int len;
+ enum bfd_endian byte_order;
+
+ type = check_typedef (type);
+ len = TYPE_LENGTH (type);
+ byte_order = gdbarch_byte_order (get_type_arch (type));
+
+ switch (TYPE_CODE (type))
+ {
+ case TYPE_CODE_INT:
+ case TYPE_CODE_CHAR:
+ case TYPE_CODE_ENUM:
+ case TYPE_CODE_FLAGS:
+ case TYPE_CODE_BOOL:
+ case TYPE_CODE_RANGE:
+ case TYPE_CODE_MEMBERPTR:
+ store_unsigned_integer (buf, len, byte_order, num);
+ break;
+
+ case TYPE_CODE_REF:
+ case TYPE_CODE_PTR:
+ store_typed_address (buf, type, (CORE_ADDR) num);
+ break;
+
+ default:
+ error (_("\
+Unexpected type (%d) encountered for unsigned integer constant."),
+ TYPE_CODE (type));
+ }
+}
+
+
/* Convert C numbers into newly allocated values. */
struct value *
struct value *val = allocate_value (type);
pack_long (value_contents_raw (val), type, num);
+ return val;
+}
+
+
+/* Convert C unsigned numbers into newly allocated values. */
+
+struct value *
+value_from_ulongest (struct type *type, ULONGEST num)
+{
+ struct value *val = allocate_value (type);
+
+ pack_unsigned_long (value_contents_raw (val), type, num);
return val;
}
value_from_pointer (struct type *type, CORE_ADDR addr)
{
struct value *val = allocate_value (type);
- store_typed_address (value_contents_raw (val), type, addr);
+
+ store_typed_address (value_contents_raw (val), check_typedef (type), addr);
return val;
}
CORE_ADDR address)
{
struct value *v = allocate_value (type);
+
if (valaddr == NULL)
set_value_lazy (v, 1);
else
struct value *val = allocate_value (type);
struct type *base_type = check_typedef (type);
enum type_code code = TYPE_CODE (base_type);
- int len = TYPE_LENGTH (base_type);
if (code == TYPE_CODE_FLT)
{
struct value *val = allocate_value (type);
memcpy (value_contents_raw (val), dec, TYPE_LENGTH (type));
-
return val;
}
coerce_ref (struct value *arg)
{
struct type *value_type_arg_tmp = check_typedef (value_type (arg));
+
if (TYPE_CODE (value_type_arg_tmp) == TYPE_CODE_REF)
arg = value_at_lazy (TYPE_TARGET_TYPE (value_type_arg_tmp),
unpack_pointer (value_type (arg),
switch (TYPE_CODE (type))
{
case TYPE_CODE_ARRAY:
- if (current_language->c_style_arrays)
+ if (!TYPE_VECTOR (type) && current_language->c_style_arrays)
arg = value_coerce_array (arg);
break;
case TYPE_CODE_FUNC: