diff options
author | Tom Tromey <tom@tromey.com> | 2021-03-08 07:27:57 -0700 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2021-03-08 07:28:37 -0700 |
commit | 413403fc34156cf695b09553fca91e0990520787 (patch) | |
tree | bf463e2ea8f074b198caca43014951dca5253d5c /gdb/value.c | |
parent | b0f9164cc6d738db3a71c1ea83aa6567f0387bca (diff) | |
download | gdb-413403fc34156cf695b09553fca91e0990520787.zip gdb-413403fc34156cf695b09553fca91e0990520787.tar.gz gdb-413403fc34156cf695b09553fca91e0990520787.tar.bz2 |
Add an expr::operation_up to struct expression
This adds an expr::operation_up to struct expression, and then
modifies various parts of GDB to use this member when it is non-null.
The list of such spots was a bit surprising to me, and found only
after writing most of the code and then noticing what no longer
compiled.
In a few spots, new accessor methods are added to operation
subclasses, so that code that dissects an expression will work with
the new scheme.
After this change, code that constructs an expression can be switched
to the new form without breaking.
gdb/ChangeLog
2021-03-08 Tom Tromey <tom@tromey.com>
* ada-exp.h (class ada_var_value_operation) <get_symbol>: Remove;
now in superclass.
* value.h (fetch_subexp_value): Add "op" parameter.
* value.c (init_if_undefined_command): Update.
* tracepoint.c (validate_actionline, encode_actions_1): Update.
* stap-probe.c (stap_probe::compile_to_ax): Update.
* printcmd.c (set_command): Update.
* ppc-linux-nat.c (ppc_linux_nat_target::check_condition):
Update.
* parser-defs.h (struct expr_builder) <set_operation>: New
method.
* parse.c (parse_exp_in_context, exp_uses_objfile): Update.
* expression.h (struct expression) <first_opcode>: Update.
<op>: New member.
* expprint.c (dump_raw_expression, dump_prefix_expression):
Update.
* expop.h (class var_value_operation) <get_symbol>: New method.
(class register_operation) <get_name>: New method.
(class equal_operation): No longer a typedef, now a subclass.
(class unop_memval_operation) <get_type>: New method.
(class assign_operation) <get_lhs>: New method.
(class unop_cast_operation) <get_type>: New method.
* eval.c (evaluate_expression, evaluate_type)
(evaluate_subexpression_type): Update.
(fetch_subexp_value): Add "op" parameter.
(parse_and_eval_type): Update.
* dtrace-probe.c (dtrace_probe::compile_to_ax): Update.
* breakpoint.c (update_watchpoint, watchpoint_check)
(watchpoint_exp_is_const, watch_command_1): Update.
* ax-gdb.c (gen_trace_for_expr, gen_eval_for_expr, gen_printf):
Update.
Diffstat (limited to 'gdb/value.c')
-rw-r--r-- | gdb/value.c | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/gdb/value.c b/gdb/value.c index bddf9a4..89b612e 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -44,6 +44,7 @@ #include "gdbsupport/selftest.h" #include "gdbsupport/array-view.h" #include "cli/cli-style.h" +#include "expop.h" /* Definition of a user function. */ struct internal_function @@ -2006,7 +2007,7 @@ static struct internalvar *internalvars; 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); @@ -2014,15 +2015,34 @@ init_if_undefined_command (const char* args, int from_tty) /* Validate the expression. Was the expression an assignment? Or even an expression at all? */ - if (expr->nelts == 0 || expr->first_opcode () != BINOP_ASSIGN) + if ((expr->nelts == 0 && expr->op == nullptr) + || 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) + if (expr->op == nullptr) + { + if (expr->elts[1].opcode == OP_INTERNALVAR) + intvar = expr->elts[2].internalvar; + } + else + { + 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. */ |