From 11dd3dce4427792a89a851b8ed290b3c8124f282 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Mon, 8 Mar 2021 07:27:57 -0700 Subject: [PATCH] Introduce rust_unop_ind_operation This adds class rust_unop_ind_operation, which implements UNOP_IND for Rust. Rust requires a special case here to handle trait objects. gdb/ChangeLog 2021-03-08 Tom Tromey * rust-lang.c (eval_op_rust_ind): No longer static. Add "opcode" parameter. (rust_evaluate_subexp): Update. * rust-exp.h (class rust_unop_ind_operation): New. --- gdb/ChangeLog | 7 +++++++ gdb/rust-exp.h | 25 +++++++++++++++++++++++++ gdb/rust-lang.c | 5 +++-- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 06be5b918a..397a6067bf 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2021-03-08 Tom Tromey + + * rust-lang.c (eval_op_rust_ind): No longer static. Add "opcode" + parameter. + (rust_evaluate_subexp): Update. + * rust-exp.h (class rust_unop_ind_operation): New. + 2021-03-08 Tom Tromey * rust-lang.c (eval_op_rust_complement, eval_op_rust_array): No diff --git a/gdb/rust-exp.h b/gdb/rust-exp.h index cce1fd9a7d..d16f921ca0 100644 --- a/gdb/rust-exp.h +++ b/gdb/rust-exp.h @@ -33,6 +33,11 @@ extern struct value *eval_op_rust_array (struct type *expect_type, enum exp_opcode opcode, struct value *ncopies, struct value *elt); +extern struct value *eval_op_rust_ind (struct type *expect_type, + struct expression *exp, + enum noside noside, + enum exp_opcode opcode, + struct value *value); namespace expr { @@ -42,6 +47,26 @@ using rust_unop_compl_operation = unop_operation; +/* The Rust indirection operation. */ +class rust_unop_ind_operation + : public unop_ind_operation +{ +public: + + using unop_ind_operation::unop_ind_operation; + + value *evaluate (struct type *expect_type, + struct expression *exp, + enum noside noside) override + { + if (noside != EVAL_NORMAL) + return unop_ind_operation::evaluate (expect_type, exp, noside); + + value *arg1 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside); + return eval_op_rust_ind (expect_type, exp, noside, UNOP_IND, arg1); + } +}; + } /* namespace expr */ #endif /* RUST_EXP_H */ diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c index 63ea21b9e3..f1f4cd3340 100644 --- a/gdb/rust-lang.c +++ b/gdb/rust-lang.c @@ -1325,9 +1325,10 @@ rust_subscript (struct type *expect_type, struct expression *exp, /* A helper function for UNOP_IND. */ -static struct value * +struct value * eval_op_rust_ind (struct type *expect_type, struct expression *exp, enum noside noside, + enum exp_opcode opcode, struct value *value) { gdb_assert (noside == EVAL_NORMAL); @@ -1521,7 +1522,7 @@ rust_evaluate_subexp (struct type *expect_type, struct expression *exp, ++*pos; struct value *value = evaluate_subexp (expect_type, exp, pos, noside); - result = eval_op_rust_ind (expect_type, exp, noside, value); + result = eval_op_rust_ind (expect_type, exp, noside, op, value); } } break; -- 2.34.1