return value->parent;
}
+/* See value.h. */
+
+void
+set_value_parent (struct value *value, struct value *parent)
+{
+ value->parent = parent;
+}
+
gdb_byte *
value_contents_raw (struct value *value)
{
return value->enclosing_type;
}
+/* Look at value.h for description. */
+
+struct type *
+value_actual_type (struct value *value, int resolve_simple_types,
+ int *real_type_found)
+{
+ struct value_print_options opts;
+ struct type *result;
+
+ get_user_print_options (&opts);
+
+ if (real_type_found)
+ *real_type_found = 0;
+ result = value_type (value);
+ if (opts.objectprint)
+ {
+ /* 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)
+ && TYPE_CODE (check_typedef (TYPE_TARGET_TYPE (result)))
+ == TYPE_CODE_STRUCT)
+ {
+ struct type *real_type;
+
+ real_type = value_rtti_indirect_type (value, NULL, NULL, NULL);
+ if (real_type)
+ {
+ if (real_type_found)
+ *real_type_found = 1;
+ result = real_type;
+ }
+ }
+ else if (resolve_simple_types)
+ {
+ if (real_type_found)
+ *real_type_found = 1;
+ result = value_enclosing_type (value);
+ }
+ }
+
+ return result;
+}
+
static void
require_not_optimized_out (const struct value *value)
{
{
struct type *type1;
struct type *type2;
- int len;
type1 = check_typedef (value_type (val1));
type2 = check_typedef (value_type (val2));
- len = TYPE_LENGTH (type1);
- if (len != TYPE_LENGTH (type2))
+ if (TYPE_LENGTH (type1) != TYPE_LENGTH (type2))
return 0;
- return (memcmp (value_contents (val1), value_contents (val2), len) == 0);
+ return (memcmp (value_contents (val1), value_contents (val2),
+ TYPE_LENGTH (type1)) == 0);
}
int
if (value->lval == lval_internalvar
|| value->lval == lval_internalvar_component)
return 0;
- return value->location.address + value->offset;
+ if (value->parent != NULL)
+ return value_address (value->parent) + value->offset;
+ else
+ return value->location.address + value->offset;
}
CORE_ADDR
struct value *value;
/* The call-back routine used with INTERNALVAR_MAKE_VALUE. */
- internalvar_make_value make_value;
+ struct
+ {
+ /* The functions to call. */
+ const struct internalvar_funcs *functions;
+
+ /* The function's user-data. */
+ void *data;
+ } make_value;
/* The internal function used with INTERNALVAR_FUNCTION. */
struct
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. */
+
+VEC (char_ptr) *
+complete_internalvar (const char *name)
+{
+ VEC (char_ptr) *result = NULL;
+ struct internalvar *var;
+ int len;
+
+ len = strlen (name);
+
+ for (var = internalvars; var; var = var->next)
+ if (strncmp (var->name, name, len) == 0)
+ {
+ char *r = xstrdup (var->name);
+
+ VEC_safe_push (char_ptr, result, r);
+ }
+
+ return result;
+}
/* Create an internal variable with name NAME and with a void value.
NAME should not normally include a dollar sign. */
/* Create an internal variable with name NAME and register FUN as the
function that value_of_internalvar uses to create a value whenever
this variable is referenced. NAME should not normally include a
- dollar sign. */
+ dollar sign. DATA is passed uninterpreted to FUN when it is
+ called. CLEANUP, if not NULL, is called when the internal variable
+ is destroyed. It is passed DATA as its only argument. */
struct internalvar *
-create_internalvar_type_lazy (char *name, internalvar_make_value fun)
+create_internalvar_type_lazy (const char *name,
+ const struct internalvar_funcs *funcs,
+ void *data)
{
struct internalvar *var = create_internalvar (name);
var->kind = INTERNALVAR_MAKE_VALUE;
- var->u.make_value = fun;
+ var->u.make_value.functions = funcs;
+ var->u.make_value.data = data;
return var;
}
+/* See documentation in value.h. */
+
+int
+compile_internalvar_to_ax (struct internalvar *var,
+ struct agent_expr *expr,
+ struct axs_value *value)
+{
+ if (var->kind != INTERNALVAR_MAKE_VALUE
+ || var->u.make_value.functions->compile_to_ax == NULL)
+ return 0;
+
+ var->u.make_value.functions->compile_to_ax (var, expr, value,
+ var->u.make_value.data);
+ return 1;
+}
+
/* Look up an internal variable with name NAME. NAME should not
normally include a dollar sign.
break;
case INTERNALVAR_MAKE_VALUE:
- val = (*var->u.make_value) (gdbarch, var);
+ val = (*var->u.make_value.functions->make_value) (gdbarch, var,
+ var->u.make_value.data);
break;
default:
xfree (var->u.string);
break;
+ case INTERNALVAR_MAKE_VALUE:
+ if (var->u.make_value.functions->destroy != NULL)
+ var->u.make_value.functions->destroy (var->u.make_value.data);
+ break;
+
default:
break;
}
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"));
+ {
+ /* This text does not mention convenience functions on purpose.
+ The user can't create them except via Python, and if Python support
+ is installed this message will never be printed ($_streq will
+ exist). */
+ 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).
int
using_struct_return (struct gdbarch *gdbarch,
- struct type *func_type, struct type *value_type)
+ struct value *function, struct type *value_type)
{
enum type_code code = TYPE_CODE (value_type);
return 0;
/* Probe the architecture for the return-value convention. */
- return (gdbarch_return_value (gdbarch, func_type, value_type,
+ return (gdbarch_return_value (gdbarch, function, value_type,
NULL, NULL, NULL)
!= RETURN_VALUE_REGISTER_CONVENTION);
}
_initialize_values (void)
{
add_cmd ("convenience", no_class, show_convenience, _("\
-Debugger convenience (\"$foo\") variables.\n\
-These variables are created when you assign them values;\n\
-thus, \"print $foo=1\" gives \"$foo\" the value 1. Values may be any type.\n\
+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\
\n\
A few convenience variables are given values automatically:\n\
\"$_\"holds the last address examined with \"x\" or \"info lines\",\n\
-\"$__\" holds the contents of the last address examined with \"x\"."),
- &showlist);
+\"$__\" holds the contents of the last address examined with \"x\"."
+#ifdef HAVE_PYTHON
+"\n\n\
+Convenience functions are defined via the Python API."
+#endif
+ ), &showlist);
add_cmd ("values", no_set_class, show_values, _("\
Elements of value history around item number IDX (or last ten)."),