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, 2010 Free Software Foundation, Inc.
+ 2009, 2010, 2011 Free Software Foundation, Inc.
This file is part of GDB.
#include "python/python.h"
-/* Prototypes for exported functions. */
+#include "tracepoint.h"
+
+/* Prototypes for exported functions. */
void _initialize_values (void);
/* Only used for bitfields; position of start of field. For
gdbarch_bits_big_endian=0 targets, it is the position of the LSB. For
- gdbarch_bits_big_endian=1 targets, it is the position of the MSB. */
+ gdbarch_bits_big_endian=1 targets, it is the position of the MSB. */
int bitpos;
/* Only used for bitfields; the containing value. This allows a
int reference_count;
};
-/* Prototypes for local functions. */
+/* Prototypes for local functions. */
static void show_values (char *, int);
static struct value_history_chunk *value_history_chain;
-static int value_history_count; /* Abs number of last entry stored */
+static int value_history_count; /* Abs number of last entry stored. */
\f
/* List of all value objects currently allocated
struct lval_funcs *funcs,
void *closure)
{
- struct value *v = allocate_value (type);
+ struct value *v = allocate_value_lazy (type);
VALUE_LVAL (v) = lval_computed;
v->location.computed.funcs = funcs;
v->location.computed.closure = closure;
- set_value_lazy (v, 1);
return v;
}
}
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)
{
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_any_valid)
+ 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_bits_synthetic_pointer (const struct value *value,
+ int offset, int length)
+{
+ if (value == NULL || value->lval != lval_computed
+ || !value->location.computed.funcs->check_synthetic_pointer)
+ return 0;
+ return value->location.computed.funcs->check_synthetic_pointer (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;
}
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;
/* Now absnum is always absolute and origin zero. */
chunk = value_history_chain;
- for (i = (value_history_count - 1) / VALUE_HISTORY_CHUNK - absnum / VALUE_HISTORY_CHUNK;
+ for (i = (value_history_count - 1) / VALUE_HISTORY_CHUNK
+ - absnum / VALUE_HISTORY_CHUNK;
i > 0; i--)
chunk = chunk->next;
static struct internalvar *internalvars;
-/* If the variable does not already exist create it and give it the value given.
- If no value is given then the default is zero. */
+/* If the variable does not already exist create it and give it the
+ value given. If no value is given then the default is zero. */
static void
init_if_undefined_command (char* args, int from_tty)
{
/* Extract the variable from the parsed expression.
In the case of an assign the lvalue will be in elts[1] and elts[2]. */
if (expr->elts[1].opcode != OP_INTERNALVAR)
- error (_("The first parameter to init-if-undefined should be a GDB variable."));
+ error (_("The first parameter to init-if-undefined "
+ "should be a GDB variable."));
intvar = expr->elts[2].internalvar;
/* Only evaluate the expression if the lvalue is void.
value_of_internalvar (struct gdbarch *gdbarch, struct internalvar *var)
{
struct value *val;
+ struct trace_state_variable *tsv;
+
+ /* If there is a trace state variable of the same name, assume that
+ is what we really want to see. */
+ tsv = find_trace_state_variable (var->name);
+ if (tsv)
+ {
+ tsv->value_known = target_get_trace_state_variable_value (tsv->number,
+ &(tsv->value));
+ if (tsv->value_known)
+ val = value_from_longest (builtin_type (gdbarch)->builtin_int64,
+ tsv->value);
+ else
+ val = allocate_value (builtin_type (gdbarch)->builtin_void);
+ return val;
+ }
switch (var->kind)
{
break;
default:
- internal_error (__FILE__, __LINE__, "bad kind");
+ internal_error (__FILE__, __LINE__, _("bad kind"));
}
/* Change the VALUE_LVAL to lval_internalvar so that future operations
default:
/* We can never get a component of any other kind. */
- internal_error (__FILE__, __LINE__, "set_internalvar_component");
+ internal_error (__FILE__, __LINE__, _("set_internalvar_component"));
}
}
printf_filtered (("\n"));
}
if (!varseen)
- printf_unfiltered (_("\
-No debugger convenience variables now defined.\n\
-Convenience variables have names starting with \"$\";\n\
-use \"set\" as in \"set $foo = 5\" to define them.\n"));
+ printf_unfiltered (_("No debugger convenience variables now defined.\n"
+ "Convenience variables have "
+ "names starting with \"$\";\n"
+ "use \"set\" as in \"set "
+ "$foo = 5\" to define them.\n"));
}
\f
/* Extract a value as a C number (either long or double).
return foo;
}
-/* Extract a value as a C pointer. Does not deallocate the value.
+/* Extract a value as a C pointer. Does not deallocate the value.
Note that val's type may not actually be a pointer; value_as_long
handles all the cases. */
CORE_ADDR
int len;
int nosign;
- *invp = 0; /* Assume valid. */
+ *invp = 0; /* Assume valid. */
CHECK_TYPEDEF (type);
code = TYPE_CODE (type);
len = TYPE_LENGTH (type);
}
\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. */
+ optimized out. */
struct value *
value_static_field (struct type *type, int fieldno)
{
struct value *retval;
- if (TYPE_FIELD_LOC_KIND (type, fieldno) == FIELD_LOC_KIND_PHYSADDR)
+ switch (TYPE_FIELD_LOC_KIND (type, fieldno))
{
+ case FIELD_LOC_KIND_PHYSADDR:
retval = value_at_lazy (TYPE_FIELD_TYPE (type, fieldno),
TYPE_FIELD_STATIC_PHYSADDR (type, fieldno));
- }
- else
+ break;
+ case FIELD_LOC_KIND_PHYSNAME:
{
char *phys_name = TYPE_FIELD_STATIC_PHYSNAME (type, fieldno);
- /*TYPE_FIELD_NAME (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 */
+ reported as non-debuggable symbols. */
struct minimal_symbol *msym = lookup_minimal_symbol (phys_name,
NULL, NULL);
}
}
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;
}
-/* Change the enclosing type of a value object VAL to NEW_ENCL_TYPE.
- You have to be careful here, since the size of the data area for the value
- is set by the length of the enclosing type. So if NEW_ENCL_TYPE is bigger
- than the old enclosing type, you have to allocate more space for the data.
- The return value is a pointer to the new version of this value structure. */
+/* Change the enclosing type of a value object VAL to NEW_ENCL_TYPE.
+ You have to be careful here, since the size of the data area for the value
+ is set by the length of the enclosing type. So if NEW_ENCL_TYPE is bigger
+ than the old enclosing type, you have to allocate more space for the
+ data. */
-struct value *
-value_change_enclosing_type (struct value *val, struct type *new_encl_type)
+void
+set_value_enclosing_type (struct value *val, struct type *new_encl_type)
{
if (TYPE_LENGTH (new_encl_type) > TYPE_LENGTH (value_enclosing_type (val)))
val->contents =
(gdb_byte *) xrealloc (val->contents, TYPE_LENGTH (new_encl_type));
val->enclosing_type = new_encl_type;
- return val;
}
/* Given a value ARG1 (offset by OFFSET bytes)
of a struct or union type ARG_TYPE,
extract and return the value of one of its (non-static) fields.
- FIELDNO says which field. */
+ FIELDNO says which field. */
struct value *
value_primitive_field (struct value *arg1, int offset,
v->bitpos = bitpos % container_bitsize;
else
v->bitpos = bitpos % 8;
- v->offset = 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))
/* Given a value ARG1 of a struct or union type,
extract and return the value of one of its (non-static) fields.
- FIELDNO says which field. */
+ FIELDNO says which field. */
struct value *
value_field (struct value *arg1, int fieldno)
J is an index into F which provides the desired method.
We only use the symbol for its address, so be happy with either a
- full symbol or a minimal symbol.
- */
+ full symbol or a minimal symbol. */
struct value *
-value_fn_field (struct value **arg1p, struct fn_field *f, int j, struct type *type,
+value_fn_field (struct value **arg1p, struct fn_field *f,
+ int j, struct type *type,
int offset)
{
struct value *v;
value_addr (*arg1p)));
/* Move the `this' pointer according to the offset.
- VALUE_OFFSET (*arg1p) += offset;
- */
+ VALUE_OFFSET (*arg1p) += offset; */
}
return v;
number of bits from the LSB of the anonymous object to the LSB of the
bitfield.
- If the field is signed, we also do sign extension. */
+ If the field is signed, we also do sign extension. */
LONGEST
unpack_bits_as_long (struct type *field_type, const gdb_byte *valaddr,
val = extract_unsigned_integer (valaddr + bitpos / 8,
bytes_read, byte_order);
- /* Extract bits. See comment above. */
+ /* Extract bits. See comment above. */
if (gdbarch_bits_big_endian (get_type_arch (field_type)))
lsbcount = (bytes_read * 8 - bitpos % 8 - bitsize);
val >>= lsbcount;
/* If the field does not entirely fill a LONGEST, then zero the sign bits.
- If the field is signed, and is negative, then sign extend. */
+ If the field is signed, and is negative, then sign extend. */
if ((bitsize > 0) && (bitsize < 8 * (int) sizeof (val)))
{
/* Modify the value of a bitfield. ADDR points to a block of memory in
target byte order; the bitfield starts in the byte pointed to. FIELDVAL
is the desired value of the field, in host byte order. BITPOS and BITSIZE
- indicate which bits (in target bit order) comprise the bitfield.
- Requires 0 < BITSIZE <= lbits, 0 <= BITPOS+BITSIZE <= lbits, and
+ indicate which bits (in target bit order) comprise the bitfield.
+ Requires 0 < BITSIZE <= lbits, 0 <= BITPOS % 8 + BITSIZE <= lbits, and
0 <= BITPOS, where lbits is the size of a LONGEST in bits. */
void
enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
ULONGEST oword;
ULONGEST mask = (ULONGEST) -1 >> (8 * sizeof (ULONGEST) - bitsize);
+ int bytesize;
+
+ /* Normalize BITPOS. */
+ addr += bitpos / 8;
+ bitpos %= 8;
/* If a negative fieldval fits in the field in question, chop
off the sign extension bits. */
fieldval &= mask;
}
- oword = extract_unsigned_integer (addr, sizeof oword, byte_order);
+ /* Ensure no bytes outside of the modified ones get accessed as it may cause
+ false valgrind reports. */
+
+ bytesize = (bitpos + bitsize + 7) / 8;
+ oword = extract_unsigned_integer (addr, bytesize, byte_order);
/* Shifting for bit field depends on endianness of the target machine. */
if (gdbarch_bits_big_endian (get_type_arch (type)))
- bitpos = sizeof (oword) * 8 - bitpos - bitsize;
+ bitpos = bytesize * 8 - bitpos - bitsize;
oword &= ~(mask << bitpos);
oword |= fieldval << bitpos;
- store_unsigned_integer (addr, sizeof oword, byte_order, oword);
+ store_unsigned_integer (addr, bytesize, byte_order, oword);
}
\f
/* Pack NUM into BUF using a target format of TYPE. */
}
+/* 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 *
}
+/* 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;
+}
+
+
/* Create a value representing a pointer of type TYPE to the address
ADDR. */
struct value *
const gdb_byte *valaddr,
CORE_ADDR address)
{
- struct value *v = allocate_value (type);
+ struct value *v;
if (valaddr == NULL)
- set_value_lazy (v, 1);
+ v = allocate_value_lazy (type);
else
- memcpy (value_contents_raw (v), valaddr, TYPE_LENGTH (type));
+ {
+ v = allocate_value (type);
+ memcpy (value_contents_raw (v), valaddr, TYPE_LENGTH (type));
+ }
set_value_address (v, address);
VALUE_LVAL (v) = lval_memory;
return v;
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:
\"$__\" holds the contents of the last address examined with \"x\"."),
&showlist);
- add_cmd ("values", no_class, show_values,
- _("Elements of value history around item number IDX (or last ten)."),
+ add_cmd ("values", no_class, show_values, _("\
+Elements of value history around item number IDX (or last ten)."),
&showlist);
add_com ("init-if-undefined", class_vars, init_if_undefined_command, _("\