/* Low level packing and unpacking of values for GDB, the GNU Debugger.
- Copyright (C) 1986-2020 Free Software Foundation, Inc.
+ Copyright (C) 1986-2021 Free Software Foundation, Inc.
This file is part of GDB.
#include "gdbsupport/selftest.h"
#include "gdbsupport/array-view.h"
#include "cli/cli-style.h"
+#include "expop.h"
+#include "inferior.h"
/* Definition of a user function. */
struct internal_function
struct gdbarch *
get_value_arch (const struct value *value)
{
- return get_type_arch (value_type (value));
+ return value_type (value)->arch ();
}
int
It is assumed the contents of DST in the [DST_OFFSET,
DST_OFFSET+LENGTH) range are wholly available. */
-void
+static void
value_contents_copy_raw (struct value *dst, LONGEST dst_offset,
struct value *src, LONGEST src_offset, LONGEST length)
{
component->location.computed.closure = funcs->copy_closure (whole);
}
- /* If type has a dynamic resolved location property
- update it's value address. */
+ /* If the WHOLE value has a dynamically resolved location property then
+ update the address of the COMPONENT. */
type = value_type (whole);
if (NULL != TYPE_DATA_LOCATION (type)
&& TYPE_DATA_LOCATION_KIND (type) == PROP_CONST)
set_value_address (component, TYPE_DATA_LOCATION_ADDR (type));
+
+ /* Similarly, if the COMPONENT value has a dynamically resolved location
+ property then update its address. */
+ type = value_type (component);
+ if (NULL != TYPE_DATA_LOCATION (type)
+ && TYPE_DATA_LOCATION_KIND (type) == PROP_CONST)
+ {
+ /* If the COMPONENT has a dynamic location, and is an
+ lval_internalvar_component, then we change it to a lval_memory.
+
+ Usually a component of an internalvar is created non-lazy, and has
+ its content immediately copied from the parent internalvar.
+ However, for components with a dynamic location, the content of
+ the component is not contained within the parent, but is instead
+ accessed indirectly. Further, the component will be created as a
+ lazy value.
+
+ By changing the type of the component to lval_memory we ensure
+ that value_fetch_lazy can successfully load the component.
+
+ This solution isn't ideal, but a real fix would require values to
+ carry around both the parent value contents, and the contents of
+ any dynamic fields within the parent. This is a substantial
+ change to how values work in GDB. */
+ if (VALUE_LVAL (component) == lval_internalvar_component)
+ {
+ gdb_assert (value_lazy (component));
+ VALUE_LVAL (component) = lval_memory;
+ }
+ else
+ gdb_assert (VALUE_LVAL (component) == lval_memory);
+ set_value_address (component, TYPE_DATA_LOCATION_ADDR (type));
+ }
}
/* Access to the value history. */
static void
init_if_undefined_command (const char* args, int from_tty)
{
- struct internalvar* intvar;
+ struct internalvar *intvar = nullptr;
/* Parse the expression - this is taken from set_command(). */
expression_up expr = parse_expression (args);
/* Validate the expression.
Was the expression an assignment?
Or even an expression at all? */
- if (expr->nelts == 0 || expr->elts[0].opcode != BINOP_ASSIGN)
+ if (expr->first_opcode () != BINOP_ASSIGN)
error (_("Init-if-undefined requires an assignment expression."));
- /* 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)
+ /* Extract the variable from the parsed expression. */
+ expr::assign_operation *assign
+ = dynamic_cast<expr::assign_operation *> (expr->op.get ());
+ if (assign != nullptr)
+ {
+ expr::operation *lhs = assign->get_lhs ();
+ expr::internalvar_operation *ivarop
+ = dynamic_cast<expr::internalvar_operation *> (lhs);
+ if (ivarop != nullptr)
+ intvar = ivarop->get_internalvar ();
+ }
+
+ if (intvar == nullptr)
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.
This may still fail if the expression is invalid. */
preserve_one_value (struct value *value, struct objfile *objfile,
htab_t copied_types)
{
- if (TYPE_OBJFILE (value->type) == objfile)
+ if (value->type->objfile_owner () == objfile)
value->type = copy_type_recursive (objfile, value->type, copied_types);
- if (TYPE_OBJFILE (value->enclosing_type) == objfile)
+ if (value->enclosing_type->objfile_owner () == objfile)
value->enclosing_type = copy_type_recursive (objfile,
value->enclosing_type,
copied_types);
switch (var->kind)
{
case INTERNALVAR_INTEGER:
- if (var->u.integer.type && TYPE_OBJFILE (var->u.integer.type) == objfile)
+ if (var->u.integer.type
+ && var->u.integer.type->objfile_owner () == objfile)
var->u.integer.type
= copy_type_recursive (objfile, var->u.integer.type, copied_types);
break;
CORE_ADDR
value_as_address (struct value *val)
{
- struct gdbarch *gdbarch = get_type_arch (value_type (val));
+ struct gdbarch *gdbarch = value_type (val)->arch ();
/* Assume a CORE_ADDR can fit in a LONGEST (for now). Not sure
whether we want this to be true eventually. */
set_value_address (v,
gdbarch_convert_from_func_ptr_addr
- (gdbarch, BMSYMBOL_VALUE_ADDRESS (msym), current_top_target ()));
+ (gdbarch, BMSYMBOL_VALUE_ADDRESS (msym),
+ current_inferior ()->top_target ()));
}
if (arg1p)
void
_initialize_values ()
{
- add_cmd ("convenience", no_class, show_convenience, _("\
+ cmd_list_element *show_convenience_cmd
+ = add_cmd ("convenience", no_class, show_convenience, _("\
Debugger convenience (\"$foo\") variables and functions.\n\
Convenience variables are created when you assign them values;\n\
thus, \"set $foo=1\" gives \"$foo\" the value 1. Values may be any type.\n\
Convenience functions are defined via the Python API."
#endif
), &showlist);
- add_alias_cmd ("conv", "convenience", no_class, 1, &showlist);
+ add_alias_cmd ("conv", show_convenience_cmd, no_class, 1, &showlist);
add_cmd ("values", no_set_class, show_values, _("\
Elements of value history around item number IDX (or last ten)."),
add_prefix_cmd ("function", no_class, function_command, _("\
Placeholder command for showing help on convenience functions."),
- &functionlist, "function ", 0, &cmdlist);
+ &functionlist, 0, &cmdlist);
add_internal_function ("_isvoid", _("\
Check whether an expression is void.\n\