From patchwork Fri Apr 28 16:02:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 68502 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A4944385701D for ; Fri, 28 Apr 2023 16:03:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A4944385701D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1682697809; bh=hYAeRkoj4zWP9feyIQ5n1iXrVqijdL7bAvEkEHFSA/k=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=w2qeTQv6j+/BaabqPdtNU1HgtMS7XKWieGkvTkLhVQ5npc5JZI0CaMF0G/rw0YaAq r3JxK2YjKRPu+rYZIZ+mVmg/Z8N9xJuIYQYblx156zjVmqVVMfDMBcGZvivh2dEK1u g83ZjEta2P1Uj+M668BbWSa/L4xparNeIvbULOas= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x132.google.com (mail-il1-x132.google.com [IPv6:2607:f8b0:4864:20::132]) by sourceware.org (Postfix) with ESMTPS id 410953858C83 for ; Fri, 28 Apr 2023 16:02:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 410953858C83 Received: by mail-il1-x132.google.com with SMTP id e9e14a558f8ab-32b4e379000so26038735ab.2 for ; Fri, 28 Apr 2023 09:02:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682697776; x=1685289776; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hYAeRkoj4zWP9feyIQ5n1iXrVqijdL7bAvEkEHFSA/k=; b=SK8vDGniITgsy+I6VclA5q+0ZvTiB3EYkn1si7S484r/MBjGInnPquyMau7bWzoOfF Ls/UMo0BZw4eamEW4WxcnM9ns7ggSIxjEapynuleujV79L4Gg3ROSlRuxlSzyX56OnV5 DuCrhKL7+LoA57RRiMsbA4g9b/hRUy4JkKhtprLVK88utWavkVXzNMrFPIlrQAeA9GhT ynbuwv7fw168Dd44aLHLil1n947z3LIpXbjB2GfVgPfxytZnfIovXPcKY/ln3hhBNlbm bdtvDVHum7iRsZ6mOWjOwbM8ddKSkYtVFF7TND32chCOvm/t5whVCKZOiXs2SQiRyKVj Lj0g== X-Gm-Message-State: AC+VfDxF+v1uROgfoH9wVj3lbrTf6pnEoWGCd4Ml5Jzr1E3mWIraXbeb s+9adbdXiOKY1CACwhZ6Dnk84SOAT6QQdwbabyI1pA== X-Google-Smtp-Source: ACHHUZ5Ku2AofPdeKKjnkOoQsnl725P8fv9+irhbydrSG+2+SiFT0h5QSGAl/XC7kQRakZU4LzI1PQ== X-Received: by 2002:a92:d1cc:0:b0:325:b32a:60fc with SMTP id u12-20020a92d1cc000000b00325b32a60fcmr3987369ilg.5.1682697775618; Fri, 28 Apr 2023 09:02:55 -0700 (PDT) Received: from localhost.localdomain (71-211-191-82.hlrn.qwest.net. [71.211.191.82]) by smtp.gmail.com with ESMTPSA id a17-20020a92d351000000b0032f2f3e5edesm1022997ilh.8.2023.04.28.09.02.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Apr 2023 09:02:55 -0700 (PDT) Date: Fri, 28 Apr 2023 10:02:52 -0600 Subject: [PATCH 2/3] Remove evaluate_expression MIME-Version: 1.0 Message-Id: <20230428-minor-expr-cleanuups-v1-2-0a634e8d5c25@adacore.com> References: <20230428-minor-expr-cleanuups-v1-0-0a634e8d5c25@adacore.com> In-Reply-To: <20230428-minor-expr-cleanuups-v1-0-0a634e8d5c25@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" evaluate_expression is just a little wrapper for a method on expression. Removing it also removes a lot of ugly (IMO) calls to get(). --- gdb/ada-lang.c | 4 ++-- gdb/arc-tdep.c | 2 +- gdb/breakpoint.c | 2 +- gdb/cli/cli-script.c | 4 ++-- gdb/darwin-nat-info.c | 2 +- gdb/dtrace-probe.c | 2 +- gdb/eval.c | 16 ++++------------ gdb/expression.h | 3 ++- gdb/linux-thread-db.c | 2 +- gdb/mi/mi-main.c | 4 ++-- gdb/objc-lang.c | 4 +--- gdb/printcmd.c | 12 ++++++------ gdb/stack.c | 2 +- gdb/stap-probe.c | 2 +- gdb/tracepoint.c | 2 +- gdb/value.c | 2 +- gdb/value.h | 9 --------- gdb/varobj.c | 12 ++++++------ 18 files changed, 34 insertions(+), 52 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 3a9f554ce4c..50d5c6f9697 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -4339,7 +4339,7 @@ ada_read_renaming_var_value (struct symbol *renaming_sym, sym_name = renaming_sym->linkage_name (); expression_up expr = parse_exp_1 (&sym_name, 0, block, 0); - return evaluate_expression (expr.get ()); + return expr->evaluate (); } @@ -12318,7 +12318,7 @@ should_stop_exception (const struct bp_location *bl) try { scoped_value_mark mark; - stop = value_true (evaluate_expression (ada_loc->excep_cond_expr.get ())); + stop = value_true (ada_loc->excep_cond_expr->evaluate ()); } catch (const gdb_exception_error &ex) { diff --git a/gdb/arc-tdep.c b/gdb/arc-tdep.c index bbf4846a8f8..0b541c6335a 100644 --- a/gdb/arc-tdep.c +++ b/gdb/arc-tdep.c @@ -2434,7 +2434,7 @@ dump_arc_instruction_command (const char *args, int from_tty) { struct value *val; if (args != NULL && strlen (args) > 0) - val = evaluate_expression (parse_expression (args).get ()); + val = parse_expression (args)->evaluate (); else val = access_value_history (0); val->record_latest (); diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 46287da5f87..20e016e8cb3 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -4984,7 +4984,7 @@ static bool breakpoint_cond_eval (expression *exp) { scoped_value_mark mark; - return value_true (evaluate_expression (exp)); + return value_true (exp->evaluate ()); } /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c index 294a5f18fe6..b96dd74330c 100644 --- a/gdb/cli/cli-script.c +++ b/gdb/cli/cli-script.c @@ -567,7 +567,7 @@ execute_control_command_1 (struct command_line *cmd, int from_tty) /* Evaluate the expression. */ { scoped_value_mark mark; - value *val = evaluate_expression (expr.get ()); + value *val = expr->evaluate (); cond_result = value_true (val); } @@ -622,7 +622,7 @@ execute_control_command_1 (struct command_line *cmd, int from_tty) /* Evaluate the conditional. */ { scoped_value_mark mark; - value *val = evaluate_expression (expr.get ()); + value *val = expr->evaluate (); /* Choose which arm to take commands from based on the value of the conditional expression. */ diff --git a/gdb/darwin-nat-info.c b/gdb/darwin-nat-info.c index 9e562074cf8..d5f633bccae 100644 --- a/gdb/darwin-nat-info.c +++ b/gdb/darwin-nat-info.c @@ -723,7 +723,7 @@ info_mach_region_command (const char *exp, int from_tty) struct inferior *inf; expression_up expr = parse_expression (exp); - val = evaluate_expression (expr.get ()); + val = expr->evaluate (); if (TYPE_IS_REFERENCE (val->type ())) { val = value_ind (val); diff --git a/gdb/dtrace-probe.c b/gdb/dtrace-probe.c index 70fa1a9413e..dad15df5b99 100644 --- a/gdb/dtrace-probe.c +++ b/gdb/dtrace-probe.c @@ -714,7 +714,7 @@ dtrace_probe::evaluate_argument (unsigned n, struct dtrace_probe_arg *arg; arg = this->get_arg_by_number (n, gdbarch); - return evaluate_expression (arg->expr.get (), arg->type); + return arg->expr->evaluate (arg->type); } /* Implementation of the compile_to_ax method. */ diff --git a/gdb/eval.c b/gdb/eval.c index 6b362f46424..a8d5c78e09e 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -53,7 +53,7 @@ parse_and_eval_address (const char *exp) { expression_up expr = parse_expression (exp); - return value_as_address (evaluate_expression (expr.get ())); + return value_as_address (expr->evaluate ()); } /* Like parse_and_eval_address, but treats the value of the expression @@ -63,7 +63,7 @@ parse_and_eval_long (const char *exp) { expression_up expr = parse_expression (exp); - return value_as_long (evaluate_expression (expr.get ())); + return value_as_long (expr->evaluate ()); } struct value * @@ -71,7 +71,7 @@ parse_and_eval (const char *exp) { expression_up expr = parse_expression (exp); - return evaluate_expression (expr.get ()); + return expr->evaluate (); } /* Parse up to a comma (or to a closeparen) @@ -83,7 +83,7 @@ parse_to_comma_and_eval (const char **expp) { expression_up expr = parse_exp_1 (expp, 0, nullptr, 1); - return evaluate_expression (expr.get ()); + return expr->evaluate (); } @@ -116,14 +116,6 @@ expression::evaluate (struct type *expect_type, enum noside noside) return retval; } -/* See value.h. */ - -struct value * -evaluate_expression (struct expression *exp, struct type *expect_type) -{ - return exp->evaluate (expect_type, EVAL_NORMAL); -} - /* Evaluate an expression, avoiding all memory references and getting a value whose type alone is correct. */ diff --git a/gdb/expression.h b/gdb/expression.h index 77949ddaf4b..5bfb051a393 100644 --- a/gdb/expression.h +++ b/gdb/expression.h @@ -222,7 +222,8 @@ struct expression /* Evaluate the expression. EXPECT_TYPE is the context type of the expression; normally this should be nullptr. NOSIDE controls how evaluation is performed. */ - struct value *evaluate (struct type *expect_type, enum noside noside); + struct value *evaluate (struct type *expect_type = nullptr, + enum noside noside = EVAL_NORMAL); /* Language it was entered in. */ const struct language_defn *language_defn; diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c index 0e190f94266..71a81aa0cb9 100644 --- a/gdb/linux-thread-db.c +++ b/gdb/linux-thread-db.c @@ -694,7 +694,7 @@ check_thread_db_callback (const td_thrhandle_t *th, void *arg) switch_to_thread (thread_info); expression_up expr = parse_expression ("(int) errno"); - struct value *val = evaluate_expression (expr.get ()); + struct value *val = expr->evaluate (); if (tdb_testinfo->log_progress) { diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c index 0013e5dfafd..683d36d93d5 100644 --- a/gdb/mi/mi-main.c +++ b/gdb/mi/mi-main.c @@ -1189,7 +1189,7 @@ mi_cmd_data_evaluate_expression (const char *command, char **argv, int argc) expression_up expr = parse_expression (argv[0]); - val = evaluate_expression (expr.get ()); + val = expr->evaluate (); string_file stb; @@ -2468,7 +2468,7 @@ print_variable_or_computed (const char *expression, enum print_values values) if (values == PRINT_SIMPLE_VALUES) val = evaluate_type (expr.get ()); else - val = evaluate_expression (expr.get ()); + val = expr->evaluate (); gdb::optional tuple_emitter; if (values != PRINT_NO_VALUES) diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c index 4a9dee44dd7..ccbe7c19729 100644 --- a/gdb/objc-lang.c +++ b/gdb/objc-lang.c @@ -1164,9 +1164,7 @@ print_object_command (const char *args, int from_tty) { expression_up expr = parse_expression (args); - object - = evaluate_expression (expr.get (), - builtin_type (expr->gdbarch)->builtin_data_ptr); + object = expr->evaluate (builtin_type (expr->gdbarch)->builtin_data_ptr); } /* Validate the address for sanity. */ diff --git a/gdb/printcmd.c b/gdb/printcmd.c index dd92e31d31b..693d1a8a93c 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -1316,7 +1316,7 @@ process_print_command_args (const char *args, value_print_options *print_opts, /* VOIDPRINT is true to indicate that we do want to print a void value, so invert it for parse_expression. */ expression_up expr = parse_expression (exp, nullptr, !voidprint); - return evaluate_expression (expr.get ()); + return expr->evaluate (); } return access_value_history (0); @@ -1495,7 +1495,7 @@ output_command (const char *exp, int from_tty) expression_up expr = parse_expression (exp); - val = evaluate_expression (expr.get ()); + val = expr->evaluate (); annotate_value_begin (val->type ()); @@ -1534,7 +1534,7 @@ set_command (const char *exp, int from_tty) (_("Expression is not an assignment (and might have no effect)")); } - evaluate_expression (expr.get ()); + expr->evaluate (); } static void @@ -1900,7 +1900,7 @@ x_command (const char *exp, int from_tty) command's definition. */ if (from_tty) set_repeat_arguments (""); - val = evaluate_expression (expr.get ()); + val = expr->evaluate (); if (TYPE_IS_REFERENCE (val->type ())) val = coerce_ref (val); /* In rvalue contexts, such as this, functions are coerced into @@ -2188,7 +2188,7 @@ do_one_display (struct display *d) struct value *val; CORE_ADDR addr; - val = evaluate_expression (d->exp.get ()); + val = d->exp->evaluate (); addr = value_as_address (val); if (d->format.format == 'i') addr = gdbarch_addr_bits_remove (d->exp->gdbarch, addr); @@ -2226,7 +2226,7 @@ do_one_display (struct display *d) { struct value *val; - val = evaluate_expression (d->exp.get ()); + val = d->exp->evaluate (); print_formatted (val, d->format.size, &opts, gdb_stdout); } catch (const gdb_exception_error &ex) diff --git a/gdb/stack.c b/gdb/stack.c index 03e903d901b..b1b25aa1c7e 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -2722,7 +2722,7 @@ return_command (const char *retval_exp, int from_tty) /* Compute the return value. Should the computation fail, this call throws an error. */ - return_value = evaluate_expression (retval_expr.get ()); + return_value = retval_expr->evaluate (); /* Cast return value to the return type of the function. Should the cast fail, this call throws an error. */ diff --git a/gdb/stap-probe.c b/gdb/stap-probe.c index c7ad35db06f..756e90d2192 100644 --- a/gdb/stap-probe.c +++ b/gdb/stap-probe.c @@ -1444,7 +1444,7 @@ stap_probe::evaluate_argument (unsigned n, frame_info_ptr frame) struct gdbarch *gdbarch = get_frame_arch (frame); arg = this->get_arg_by_number (n, gdbarch); - return evaluate_expression (arg->aexpr.get (), arg->atype); + return arg->aexpr->evaluate (arg->atype); } /* Compile the probe's argument N (indexed from 0) to agent expression. diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c index c8bac7a0122..ffda4a6439e 100644 --- a/gdb/tracepoint.c +++ b/gdb/tracepoint.c @@ -1375,7 +1375,7 @@ encode_actions_1 (struct command_line *action, case UNOP_MEMVAL: { /* Safe because we know it's a simple expression. */ - tempval = evaluate_expression (exp.get ()); + tempval = exp->evaluate (); addr = tempval->address (); expr::unop_memval_operation *memop = (gdb::checked_static_cast diff --git a/gdb/value.c b/gdb/value.c index eab1933b256..01c30eb3f93 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -1896,7 +1896,7 @@ init_if_undefined_command (const char* args, int from_tty) /* Only evaluate the expression if the lvalue is void. This may still fail if the expression is invalid. */ if (intvar->kind == INTERNALVAR_VOID) - evaluate_expression (expr.get ()); + expr->evaluate (); } diff --git a/gdb/value.h b/gdb/value.h index e13f92c397b..f6092aba5a4 100644 --- a/gdb/value.h +++ b/gdb/value.h @@ -1299,15 +1299,6 @@ extern int using_struct_return (struct gdbarch *gdbarch, struct value *function, struct type *value_type); -/* Evaluate the expression EXP. If set, EXPECT_TYPE is passed to the - outermost operation's evaluation. This is ignored by most - operations, but may be used, e.g., to determine the type of an - otherwise untyped symbol. The caller should not assume that the - returned value has this type. */ - -extern struct value *evaluate_expression (struct expression *exp, - struct type *expect_type = nullptr); - extern struct value *evaluate_type (struct expression *exp); extern value *evaluate_var_value (enum noside noside, const block *blk, diff --git a/gdb/varobj.c b/gdb/varobj.c index 5a5e55c2d82..75b4d44b109 100644 --- a/gdb/varobj.c +++ b/gdb/varobj.c @@ -364,12 +364,12 @@ varobj_create (const char *objname, select_frame (fi); } - /* We definitely need to catch errors here. - If evaluate_expression succeeds we got the value we wanted. - But if it fails, we still go on with a call to evaluate_type(). */ + /* We definitely need to catch errors here. If evaluation of + the expression succeeds, we got the value we wanted. But if + it fails, we still go on with a call to evaluate_type(). */ try { - value = evaluate_expression (var->root->exp.get ()); + value = var->root->exp->evaluate (); } catch (const gdb_exception_error &except) { @@ -979,7 +979,7 @@ varobj_set_value (struct varobj *var, const char *expression) expression_up exp = parse_exp_1 (&s, 0, 0, 0); try { - value = evaluate_expression (exp.get ()); + value = exp->evaluate (); } catch (const gdb_exception_error &except) @@ -1995,7 +1995,7 @@ value_of_root_1 (struct varobj **var_handle) expression fails we want to just return NULL. */ try { - new_val = evaluate_expression (var->root->exp.get ()); + new_val = var->root->exp->evaluate (); } catch (const gdb_exception_error &except) {