/* Low level packing and unpacking of values for GDB, the GNU Debugger.
- Copyright (C) 1986-2016 Free Software Foundation, Inc.
+ Copyright (C) 1986-2017 Free Software Foundation, Inc.
This file is part of GDB.
#include "language.h"
#include "demangle.h"
#include "doublest.h"
+#include "floatformat.h"
#include "regcache.h"
#include "block.h"
#include "dfp.h"
#include "tracepoint.h"
#include "cp-abi.h"
#include "user-regs.h"
-
-/* Prototypes for exported functions. */
-
-void _initialize_values (void);
+#include <algorithm>
+#include "completer.h"
/* Definition of a user function. */
struct internal_function
{
ULONGEST h, l;
- l = max (offset1, offset2);
- h = min (offset1 + len1, offset2 + len2);
+ l = std::max (offset1, offset2);
+ h = std::min (offset1 + len1, offset2 + len2);
return (l < h);
}
/* If the value has been released. */
unsigned int released : 1;
- /* Register number if the value is from a register. */
- short regnum;
-
/* Location of value (if lval). */
union
{
- /* If lval == lval_memory, this is the address in the inferior.
- If lval == lval_register, this is the byte offset into the
- registers structure. */
+ /* If lval == lval_memory, this is the address in the inferior */
CORE_ADDR address;
+ /*If lval == lval_register, the value is from a register. */
+ struct
+ {
+ /* Register number. */
+ int regnum;
+ /* Frame ID of "next" frame to which a register value is relative.
+ If the register value is found relative to frame F, then the
+ frame id of F->next will be stored in next_frame_id. */
+ struct frame_id next_frame_id;
+ } reg;
+
/* Pointer to internal variable. */
struct internalvar *internalvar;
} location;
/* Describes offset of a value within lval of a structure in target
- addressable memory units. If lval == lval_memory, this is an offset to
- the address. If lval == lval_register, this is a further offset from
- location.address within the registers structure. Note also the member
- embedded_offset below. */
+ addressable memory units. Note also the member embedded_offset
+ below. */
LONGEST offset;
/* Only used for bitfields; number of bits contained in them. */
bitfields. */
struct value *parent;
- /* Frame register value is relative to. This will be described in
- the lval enum above as "lval_register". */
- struct frame_id frame_id;
-
/* Type of the value. */
struct type *type;
if (ranges_overlap (bef->offset, bef->length, offset, length))
{
/* #1 */
- ULONGEST l = min (bef->offset, offset);
- ULONGEST h = max (bef->offset + bef->length, offset + length);
+ ULONGEST l = std::min (bef->offset, offset);
+ ULONGEST h = std::max (bef->offset + bef->length, offset + length);
bef->offset = l;
bef->length = h - l;
{
ULONGEST l, h;
- l = min (t->offset, r->offset);
- h = max (t->offset + t->length, r->offset + r->length);
+ l = std::min (t->offset, r->offset);
+ h = std::max (t->offset + t->length, r->offset + r->length);
t->offset = l;
t->length = h - l;
/* Get the unavailable windows intersected by the incoming
ranges. The first and last ranges that overlap the argument
range may be wider than said incoming arguments ranges. */
- l1 = max (offset1, r1->offset);
- h1 = min (offset1 + length, r1->offset + r1->length);
+ l1 = std::max (offset1, r1->offset);
+ h1 = std::min (offset1 + length, r1->offset + r1->length);
- l2 = max (offset2, r2->offset);
- h2 = min (offset2 + length, offset2 + r2->length);
+ l2 = std::max (offset2, r2->offset);
+ h2 = std::min (offset2 + length, offset2 + r2->length);
/* Make them relative to the respective start offsets, so we can
compare them for equality. */
static void show_values (char *, int);
-static void show_convenience (char *, int);
-
/* The value-history records all the values printed
by print commands during this session. Each chunk
val->enclosing_type = type;
VALUE_LVAL (val) = not_lval;
val->location.address = 0;
- VALUE_FRAME_ID (val) = null_frame_id;
val->offset = 0;
val->bitpos = 0;
val->bitsize = 0;
- VALUE_REGNUM (val) = -1;
val->lazy = 1;
val->embedded_offset = 0;
val->pointed_to_offset = 0;
{
/* If result's target type is TYPE_CODE_STRUCT, proceed to
fetch its rtti type. */
- if ((TYPE_CODE (result) == TYPE_CODE_PTR
- || TYPE_CODE (result) == TYPE_CODE_REF)
+ if ((TYPE_CODE (result) == TYPE_CODE_PTR || TYPE_IS_REFERENCE (result))
&& TYPE_CODE (check_typedef (TYPE_TARGET_TYPE (result)))
== TYPE_CODE_STRUCT
&& !value_optimized_out (value))
{
ULONGEST h, l;
- l = max (r->offset, src_bit_offset);
- h = min (r->offset + r->length, src_bit_offset + bit_length);
+ l = std::max (r->offset, (LONGEST) src_bit_offset);
+ h = std::min (r->offset + r->length,
+ (LONGEST) src_bit_offset + bit_length);
if (l < h)
insert_into_bit_range_vector (dst_range,
CORE_ADDR
value_address (const struct value *value)
{
- if (value->lval == lval_internalvar
- || value->lval == lval_internalvar_component
- || value->lval == lval_xcallable)
+ if (value->lval != lval_memory)
return 0;
if (value->parent != NULL)
return value_address (value->parent) + value->offset;
CORE_ADDR
value_raw_address (const struct value *value)
{
- if (value->lval == lval_internalvar
- || value->lval == lval_internalvar_component
- || value->lval == lval_xcallable)
+ if (value->lval != lval_memory)
return 0;
return value->location.address;
}
void
set_value_address (struct value *value, CORE_ADDR addr)
{
- gdb_assert (value->lval != lval_internalvar
- && value->lval != lval_internalvar_component
- && value->lval != lval_xcallable);
+ gdb_assert (value->lval == lval_memory);
value->location.address = addr;
}
}
struct frame_id *
-deprecated_value_frame_id_hack (struct value *value)
+deprecated_value_next_frame_id_hack (struct value *value)
{
- return &value->frame_id;
+ gdb_assert (value->lval == lval_register);
+ return &value->location.reg.next_frame_id;
}
-short *
+int *
deprecated_value_regnum_hack (struct value *value)
{
- return &value->regnum;
+ gdb_assert (value->lval == lval_register);
+ return &value->location.reg.regnum;
}
int
val->offset = arg->offset;
val->bitpos = arg->bitpos;
val->bitsize = arg->bitsize;
- VALUE_FRAME_ID (val) = VALUE_FRAME_ID (arg);
- VALUE_REGNUM (val) = VALUE_REGNUM (arg);
val->lazy = arg->lazy;
val->embedded_offset = value_embedded_offset (arg);
val->pointed_to_offset = arg->pointed_to_offset;
struct internalvar* intvar;
/* Parse the expression - this is taken from set_command(). */
- struct expression *expr = parse_expression (args);
- register struct cleanup *old_chain =
- make_cleanup (free_current_contents, &expr);
+ expression_up expr = parse_expression (args);
/* Validate the expression.
Was the expression an assignment?
/* Only evaluate the expression if the lvalue is void.
This may still fail if the expresssion is invalid. */
if (intvar->kind == INTERNALVAR_VOID)
- evaluate_expression (expr);
-
- do_cleanups (old_chain);
+ evaluate_expression (expr.get ());
}
return NULL;
}
-/* Complete NAME by comparing it to the names of internal variables.
- Returns a vector of newly allocated strings, or NULL if no matches
- were found. */
+/* Complete NAME by comparing it to the names of internal
+ variables. */
-VEC (char_ptr) *
-complete_internalvar (const char *name)
+void
+complete_internalvar (completion_tracker &tracker, const char *name)
{
- VEC (char_ptr) *result = NULL;
struct internalvar *var;
int len;
for (var = internalvars; var; var = var->next)
if (strncmp (var->name, name, len) == 0)
{
- char *r = xstrdup (var->name);
+ gdb::unique_xmalloc_ptr<char> copy (xstrdup (var->name));
- VEC_safe_push (char_ptr, result, r);
+ tracker.add_completion (std::move (copy));
}
-
- return result;
}
/* Create an internal variable with name NAME and with a void value.
the implementation of the sub-command that is created when
registering an internal function. */
static void
-function_command (char *command, int from_tty)
+function_command (const char *command, int from_tty)
{
/* Do nothing. */
}
}
static void
-show_convenience (char *ignore, int from_tty)
+show_convenience (const char *ignore, int from_tty)
{
struct gdbarch *gdbarch = get_current_arch ();
struct internalvar *var;
ABI-specific code is a more reasonable place to handle it. */
if (TYPE_CODE (value_type (val)) != TYPE_CODE_PTR
- && TYPE_CODE (value_type (val)) != TYPE_CODE_REF
+ && !TYPE_IS_REFERENCE (value_type (val))
&& gdbarch_integer_to_address_p (gdbarch))
return gdbarch_integer_to_address (gdbarch, value_type (val),
value_contents (val));
return (LONGEST) extract_typed_floating (valaddr, type);
case TYPE_CODE_DECFLOAT:
- /* libdecnumber has a function to convert from decimal to integer, but
- it doesn't work when the decimal number has a fractional part. */
- return (LONGEST) decimal_to_doublest (valaddr, len, byte_order);
+ return decimal_to_longest (valaddr, len, byte_order);
case TYPE_CODE_PTR:
case TYPE_CODE_REF:
+ case TYPE_CODE_RVALUE_REF:
/* Assume a CORE_ADDR can fit in a LONGEST (for now). Not sure
whether we want this to be true eventually. */
return extract_typed_address (valaddr, type);
+ value_embedded_offset (arg1));
}
set_value_component_location (v, arg1);
- VALUE_REGNUM (v) = VALUE_REGNUM (arg1);
- VALUE_FRAME_ID (v) = VALUE_FRAME_ID (arg1);
return v;
}
}
v = allocate_value (ftype);
+ VALUE_LVAL (v) = lval_memory;
if (sym)
{
set_value_address (v, BLOCK_START (SYMBOL_BLOCK_VALUE (sym)));
enum bfd_endian byte_order;
int src_bit_offset;
int dst_bit_offset;
- LONGEST num;
struct type *field_type = value_type (dest_val);
- /* First, unpack and sign extend the bitfield as if it was wholly
- available. Invalid/unavailable bits are read as zero, but that's
- OK, as they'll end up marked below. */
byte_order = gdbarch_byte_order (get_type_arch (field_type));
- num = unpack_bits_as_long (field_type, valaddr + embedded_offset,
- bitpos, bitsize);
- store_signed_integer (value_contents_raw (dest_val),
- TYPE_LENGTH (field_type), byte_order, num);
+
+ /* First, unpack and sign extend the bitfield as if it was wholly
+ valid. Optimized out/unavailable bits are read as zero, but
+ that's OK, as they'll end up marked below. If the VAL is
+ wholly-invalid we may have skipped allocating its contents,
+ though. See allocate_optimized_out_value. */
+ if (valaddr != NULL)
+ {
+ LONGEST num;
+
+ num = unpack_bits_as_long (field_type, valaddr + embedded_offset,
+ bitpos, bitsize);
+ store_signed_integer (value_contents_raw (dest_val),
+ TYPE_LENGTH (field_type), byte_order, num);
+ }
/* Now copy the optimized out / unavailability ranges to the right
bits. */
break;
case TYPE_CODE_REF:
+ case TYPE_CODE_RVALUE_REF:
case TYPE_CODE_PTR:
store_typed_address (buf, type, (CORE_ADDR) num);
break;
break;
case TYPE_CODE_REF:
+ case TYPE_CODE_RVALUE_REF:
case TYPE_CODE_PTR:
store_typed_address (buf, type, (CORE_ADDR) num);
break;
v = allocate_value_lazy (type);
else
v = value_from_contents (type, valaddr);
- set_value_address (v, address);
VALUE_LVAL (v) = lval_memory;
+ set_value_address (v, address);
return v;
}
if (TYPE_DATA_LOCATION (resolved_type_no_typedef) != NULL
&& TYPE_DATA_LOCATION_KIND (resolved_type_no_typedef) == PROP_CONST)
address = TYPE_DATA_LOCATION_ADDR (resolved_type_no_typedef);
- set_value_address (v, address);
VALUE_LVAL (v) = lval_memory;
+ set_value_address (v, address);
return v;
}
return access_value_history (index);
}
+/* Get the component value (offset by OFFSET bytes) of a struct or
+ union WHOLE. Component's type is TYPE. */
+
+struct value *
+value_from_component (struct value *whole, struct type *type, LONGEST offset)
+{
+ struct value *v;
+
+ if (VALUE_LVAL (whole) == lval_memory && value_lazy (whole))
+ v = allocate_value_lazy (type);
+ else
+ {
+ v = allocate_value (type);
+ value_contents_copy (v, value_embedded_offset (v),
+ whole, value_embedded_offset (whole) + offset,
+ type_length_units (type));
+ }
+ v->offset = value_offset (whole) + offset + value_embedded_offset (whole);
+ set_value_component_location (v, whole);
+
+ return v;
+}
+
struct value *
coerce_ref_if_computed (const struct value *arg)
{
const struct lval_funcs *funcs;
- if (TYPE_CODE (check_typedef (value_type (arg))) != TYPE_CODE_REF)
+ if (!TYPE_IS_REFERENCE (check_typedef (value_type (arg))))
return NULL;
if (value_lval_const (arg) != lval_computed)
if (retval)
return retval;
- if (TYPE_CODE (value_type_arg_tmp) != TYPE_CODE_REF)
+ if (!TYPE_IS_REFERENCE (value_type_arg_tmp))
return arg;
enc_type = check_typedef (value_enclosing_type (arg));
}
else if (VALUE_LVAL (val) == lval_register)
{
- struct frame_info *frame;
+ struct frame_info *next_frame;
int regnum;
struct type *type = check_typedef (value_type (val));
struct value *new_val = val, *mark = value_mark ();
while (VALUE_LVAL (new_val) == lval_register && value_lazy (new_val))
{
- struct frame_id frame_id = VALUE_FRAME_ID (new_val);
+ struct frame_id next_frame_id = VALUE_NEXT_FRAME_ID (new_val);
- frame = frame_find_by_id (frame_id);
+ next_frame = frame_find_by_id (next_frame_id);
regnum = VALUE_REGNUM (new_val);
- gdb_assert (frame != NULL);
+ gdb_assert (next_frame != NULL);
/* Convertible register routines are used for multi-register
values and for interpretation in different types
(e.g. float or int from a double register). Lazy
register values should have the register's natural type,
so they do not apply. */
- gdb_assert (!gdbarch_convert_register_p (get_frame_arch (frame),
+ gdb_assert (!gdbarch_convert_register_p (get_frame_arch (next_frame),
regnum, type));
- new_val = get_frame_register_value (frame, regnum);
+ /* FRAME was obtained, above, via VALUE_NEXT_FRAME_ID.
+ Since a "->next" operation was performed when setting
+ this field, we do not need to perform a "next" operation
+ again when unwinding the register. That's why
+ frame_unwind_register_value() is called here instead of
+ get_frame_register_value(). */
+ new_val = frame_unwind_register_value (next_frame, regnum);
/* If we get another lazy lval_register value, it means the
- register is found by reading it from the next frame.
- get_frame_register_value should never return a value with
- the frame id pointing to FRAME. If it does, it means we
+ register is found by reading it from NEXT_FRAME's next frame.
+ frame_unwind_register_value should never return a value with
+ the frame id pointing to NEXT_FRAME. If it does, it means we
either have two consecutive frames with the same frame id
in the frame chain, or some code is trying to unwind
behind get_prev_frame's back (e.g., a frame unwind
in this situation. */
if (VALUE_LVAL (new_val) == lval_register
&& value_lazy (new_val)
- && frame_id_eq (VALUE_FRAME_ID (new_val), frame_id))
+ && frame_id_eq (VALUE_NEXT_FRAME_ID (new_val), next_frame_id))
internal_error (__FILE__, __LINE__,
_("infinite loop while fetching a register"));
}
if (frame_debug)
{
struct gdbarch *gdbarch;
+ struct frame_info *frame;
+ /* VALUE_FRAME_ID is used here, instead of VALUE_NEXT_FRAME_ID,
+ so that the frame level will be shown correctly. */
frame = frame_find_by_id (VALUE_FRAME_ID (val));
regnum = VALUE_REGNUM (val);
gdbarch = get_frame_arch (frame);