[PATCH 123/203] Introduce objc_msgcall_operation

Tom Tromey
2021-01-01T21:48:58Z

This adds class objc_msgcall_operation, which implements
OP_OBJC_MSGCALL.

gdb/ChangeLog
2021-01-01 Tom Tromey <tom@tromey.com>

* eval.c (objc_msgcall_operation::evaluate): New method.
* c-exp.h (class objc_msgcall_operation): New.
---
gdb/ChangeLog | 5 +++++
gdb/c-exp.h | 17 +++++++++++++++++
gdb/eval.c | 39 +++++++++++++++++++++++++++++++++++++++
3 files changed, 61 insertions(+)

diff --git a/gdb/c-exp.h b/gdb/c-exp.h
index dcb4557b2d5..2d224c8c633 100644
--- a/gdb/c-exp.h
+++ b/gdb/c-exp.h
@@ -88,6 +88,23 @@ class objc_selector_operation
{ return OP_OBJC_SELECTOR; }
};

+/* An Objective C message call. */
+class objc_msgcall_operation
+ : public tuple_holding_operation<CORE_ADDR, operation_up,
+ std::vector<operation_up>>
+{
+public:
+
+ using tuple_holding_operation::tuple_holding_operation;
+
+ value *evaluate (struct type *expect_type,
+ struct expression *exp,
+ enum noside noside) override;
+
+ enum exp_opcode opcode () const override
+ { return OP_OBJC_MSGCALL; }
+};
+
}/* namespace expr */

#endif /* C_EXP_H */
diff --git a/gdb/eval.c b/gdb/eval.c
index 4b12875f00c..05fc1972a0e 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -2411,6 +2411,45 @@ eval_multi_subscript (struct type *expect_type, struct expression *exp,
return (arg1);
}

+namespace expr
+{
+
+value *
+objc_msgcall_operation::evaluate (struct type *expect_type,
+ struct expression *exp,
+ enum noside noside)
+{
+ enum noside sub_no_side = EVAL_NORMAL;
+ struct type *selector_type = builtin_type (exp->gdbarch)->builtin_data_ptr;
+
+ if (noside == EVAL_AVOID_SIDE_EFFECTS)
+ sub_no_side = EVAL_NORMAL;
+ else
+ sub_no_side = noside;
+ value *target
+ = std::get<1> (m_storage)->evaluate (selector_type, exp, sub_no_side);
+
+ if (value_as_long (target) == 0)
+ sub_no_side = EVAL_AVOID_SIDE_EFFECTS;
+ else
+ sub_no_side = noside;
+ std::vector<operation_up> &args = std::get<2> (m_storage);
+ value **argvec = XALLOCAVEC (struct value *, args.size () + 3);
+ argvec[0] = nullptr;
+ argvec[1] = nullptr;
+ for (int i = 0; i < args.size (); ++i)
+ argvec[i + 2] = args[i]->evaluate_with_coercion (exp, sub_no_side);
+ argvec[args.size () + 2] = nullptr;
+
+ return eval_op_objc_msgcall (expect_type, exp, noside, std::
+ get<0> (m_storage), target,
+ gdb::make_array_view (argvec,
+ args.size () + 3));
+}
+
+}
+
+
struct value *
evaluate_subexp_standard (struct type *expect_type,
struct expression *exp, int *pos,
--
2.26.2