From b50db09ff9c0a5d2220e73ddcff3a05e2e887b0e Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Mon, 8 Mar 2021 07:27:57 -0700 Subject: [PATCH] Introduce string_operation This adds string_operation, which implements OP_STRING for most languages (C has its own variant). gdb/ChangeLog 2021-03-08 Tom Tromey * expop.h (class string_operation): New. * eval.c (eval_op_string): No longer static. --- gdb/ChangeLog | 5 +++++ gdb/eval.c | 2 +- gdb/expop.h | 24 ++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 05f67b855b7..ddf93421490 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2021-03-08 Tom Tromey + + * expop.h (class string_operation): New. + * eval.c (eval_op_string): No longer static. + 2021-03-08 Tom Tromey * expop.h (class internalvar_operation): New. diff --git a/gdb/eval.c b/gdb/eval.c index 4601c92ed5f..e68a93d15c7 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -1284,7 +1284,7 @@ eval_op_register (struct type *expect_type, struct expression *exp, /* Helper function that implements the body of OP_STRING. */ -static struct value * +struct value * eval_op_string (struct type *expect_type, struct expression *exp, enum noside noside, int len, const char *string) { diff --git a/gdb/expop.h b/gdb/expop.h index d143815a259..802be81bda7 100644 --- a/gdb/expop.h +++ b/gdb/expop.h @@ -61,6 +61,10 @@ extern struct value *eval_op_func_static_var (struct type *expect_type, extern struct value *eval_op_register (struct type *expect_type, struct expression *exp, enum noside noside, const char *name); +extern struct value *eval_op_string (struct type *expect_type, + struct expression *exp, + enum noside noside, int len, + const char *string); namespace expr { @@ -681,6 +685,26 @@ protected: override; }; +class string_operation + : public tuple_holding_operation +{ +public: + + using tuple_holding_operation::tuple_holding_operation; + + value *evaluate (struct type *expect_type, + struct expression *exp, + enum noside noside) override + { + const std::string &str = std::get<0> (m_storage); + return eval_op_string (expect_type, exp, noside, + str.size (), str.c_str ()); + } + + enum exp_opcode opcode () const override + { return OP_STRING; } +}; + } /* namespace expr */ #endif /* EXPOP_H */ -- 2.30.2