From efd7ff149a42c865cac422e3bafdf386c91c5373 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Tue, 15 Dec 2020 18:35:13 -0700 Subject: [PATCH] Add expected type parameter to evaluate_expression While working on the expression rewrite, I found a few spots that called the internal functions of the expression evaluator, just to pass in an expected type. This patch adds a parameter to evaluate_expression so that these functions can avoid this dependency. Regression tested on x86-64 Fedora 28. gdb/ChangeLog 2020-12-15 Tom Tromey * stap-probe.c (stap_probe::evaluate_argument): Use evaluate_expression. * dtrace-probe.c (dtrace_probe::evaluate_argument): Use evaluate_expression. * value.h (evaluate_expression): Add expect_type parameter. * objc-lang.c (print_object_command): Call evaluate_expression. * eval.c (evaluate_expression): Add expect_type parameter. --- gdb/ChangeLog | 10 ++++++++++ gdb/dtrace-probe.c | 4 +--- gdb/eval.c | 8 +++----- gdb/objc-lang.c | 6 +++--- gdb/stap-probe.c | 4 +--- gdb/value.h | 9 ++++++++- 6 files changed, 26 insertions(+), 15 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 58075c921bb..91bf0a22815 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,13 @@ +2020-12-15 Tom Tromey + + * stap-probe.c (stap_probe::evaluate_argument): Use + evaluate_expression. + * dtrace-probe.c (dtrace_probe::evaluate_argument): Use + evaluate_expression. + * value.h (evaluate_expression): Add expect_type parameter. + * objc-lang.c (print_object_command): Call evaluate_expression. + * eval.c (evaluate_expression): Add expect_type parameter. + 2020-12-15 Tom Tromey * varobj.c (varobj_create): Use first_opcode. diff --git a/gdb/dtrace-probe.c b/gdb/dtrace-probe.c index b709390039f..c105763ad11 100644 --- a/gdb/dtrace-probe.c +++ b/gdb/dtrace-probe.c @@ -714,11 +714,9 @@ dtrace_probe::evaluate_argument (unsigned n, { struct gdbarch *gdbarch = this->get_gdbarch (); struct dtrace_probe_arg *arg; - int pos = 0; arg = this->get_arg_by_number (n, gdbarch); - return evaluate_subexp_standard (arg->type, arg->expr.get (), &pos, - EVAL_NORMAL); + return evaluate_expression (arg->expr.get (), arg->type); } /* Implementation of the compile_to_ax method. */ diff --git a/gdb/eval.c b/gdb/eval.c index 2d088c8818d..c781fde0614 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -120,17 +120,15 @@ parse_to_comma_and_eval (const char **expp) return evaluate_expression (expr.get ()); } -/* Evaluate an expression in internal prefix form - such as is constructed by parse.y. - See expression.h for info on the format of an expression. */ +/* See value.h. */ struct value * -evaluate_expression (struct expression *exp) +evaluate_expression (struct expression *exp, struct type *expect_type) { int pc = 0; - return evaluate_subexp (nullptr, exp, &pc, EVAL_NORMAL); + return evaluate_subexp (expect_type, exp, &pc, EVAL_NORMAL); } /* Evaluate an expression, avoiding all memory references diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c index 4cd853249aa..10220c81ec3 100644 --- a/gdb/objc-lang.c +++ b/gdb/objc-lang.c @@ -1194,10 +1194,10 @@ print_object_command (const char *args, int from_tty) { expression_up expr = parse_expression (args); - int pc = 0; - object = evaluate_subexp (builtin_type (expr->gdbarch)->builtin_data_ptr, - expr.get (), &pc, EVAL_NORMAL); + object + = evaluate_expression (expr.get (), + builtin_type (expr->gdbarch)->builtin_data_ptr); } /* Validate the address for sanity. */ diff --git a/gdb/stap-probe.c b/gdb/stap-probe.c index 9a704716c3e..ffcded3c317 100644 --- a/gdb/stap-probe.c +++ b/gdb/stap-probe.c @@ -1389,12 +1389,10 @@ struct value * stap_probe::evaluate_argument (unsigned n, struct frame_info *frame) { struct stap_probe_arg *arg; - int pos = 0; struct gdbarch *gdbarch = get_frame_arch (frame); arg = this->get_arg_by_number (n, gdbarch); - return evaluate_subexp_standard (arg->atype, arg->aexpr.get (), &pos, - EVAL_NORMAL); + return evaluate_expression (arg->aexpr.get (), arg->atype); } /* Compile the probe's argument N (indexed from 0) to agent expression. diff --git a/gdb/value.h b/gdb/value.h index 25937f3c297..98012a5e3ae 100644 --- a/gdb/value.h +++ b/gdb/value.h @@ -905,7 +905,14 @@ extern int using_struct_return (struct gdbarch *gdbarch, struct value *function, struct type *value_type); -extern struct value *evaluate_expression (struct expression *exp); +/* 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); -- 2.30.2