From: Tom Tromey Date: Sun, 16 Nov 2025 21:01:42 +0000 (-0700) Subject: Remove a couple Objective-C expression helpers X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=55f723947e552cafd50db83acf45397a4593601b;p=thirdparty%2Fbinutils-gdb.git Remove a couple Objective-C expression helpers The Objective-C expression code has a couple of helper functions with just a single caller. This patch unifies them with the appropriate evaluate method. --- diff --git a/gdb/c-exp.h b/gdb/c-exp.h index f15185f4da0..8dbbce0f406 100644 --- a/gdb/c-exp.h +++ b/gdb/c-exp.h @@ -23,10 +23,6 @@ #include "expop.h" #include "objc-lang.h" -extern struct value *eval_op_objc_selector (struct type *expect_type, - struct expression *exp, - enum noside noside, - const char *sel); extern struct value *opencl_value_cast (struct type *type, struct value *arg); extern struct value *eval_opencl_assign (struct type *expect_type, struct expression *exp, @@ -72,11 +68,7 @@ public: value *evaluate (struct type *expect_type, struct expression *exp, - enum noside noside) override - { - const std::string &str = std::get<0> (m_storage); - return value_nsstring (exp->gdbarch, str.c_str (), str.size () + 1); - } + enum noside noside) override; enum exp_opcode opcode () const override { return OP_OBJC_NSSTRING; } @@ -91,11 +83,7 @@ public: value *evaluate (struct type *expect_type, struct expression *exp, - enum noside noside) override - { - return eval_op_objc_selector (expect_type, exp, noside, - std::get<0> (m_storage).c_str ()); - } + enum noside noside) override; enum exp_opcode opcode () const override { return OP_OBJC_SELECTOR; } diff --git a/gdb/eval.c b/gdb/eval.c index 9aa9665e959..530d5871a9c 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -1185,20 +1185,19 @@ ternop_slice_operation::evaluate (struct type *expect_type, return value_slice (array, lowbound, upperbound - lowbound + 1); } -} /* namespace expr */ - -/* Helper function that implements the body of OP_OBJC_SELECTOR. */ - struct value * -eval_op_objc_selector (struct type *expect_type, struct expression *exp, - enum noside noside, - const char *sel) +objc_selector_operation::evaluate (struct type *expect_type, + struct expression *exp, + enum noside noside) { + const char *sel = std::get<0> (m_storage).c_str (); struct type *selector_type = builtin_type (exp->gdbarch)->builtin_data_ptr; return value_from_longest (selector_type, lookup_child_selector (exp->gdbarch, sel)); } +} /* namespace expr */ + /* A helper function for STRUCTOP_STRUCT. */ struct value * diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c index b307a0022b5..a6abcd60089 100644 --- a/gdb/objc-lang.c +++ b/gdb/objc-lang.c @@ -151,9 +151,17 @@ lookup_child_selector (struct gdbarch *gdbarch, const char *selname) return value_as_long (call_function_by_hand (function, NULL, selstring)); } +namespace expr +{ + struct value * -value_nsstring (struct gdbarch *gdbarch, const char *ptr, int len) +objc_nsstring_operation::evaluate (struct type *expect_type, + struct expression *exp, + enum noside noside) { + const std::string &str = std::get<0> (m_storage); + struct gdbarch *gdbarch = exp->gdbarch; + struct type *char_type = builtin_type (gdbarch)->builtin_char; struct value *stringValue[3]; struct value *function, *nsstringValue; @@ -163,8 +171,8 @@ value_nsstring (struct gdbarch *gdbarch, const char *ptr, int len) if (!target_has_execution ()) return 0; /* Can't call into inferior to create NSString. */ - stringValue[2] = value_string(ptr, len, char_type); - stringValue[2] = value_coerce_array(stringValue[2]); + stringValue[2] = value_string (str.c_str (), str.size () + 1, char_type); + stringValue[2] = value_coerce_array (stringValue[2]); /* _NSNewStringFromCString replaces "istr" after Lantern2A. */ if (lookup_minimal_symbol (current_program_space, "_NSNewStringFromCString").minsym != nullptr) @@ -207,6 +215,8 @@ value_nsstring (struct gdbarch *gdbarch, const char *ptr, int len) return nsstringValue; } +} /* namespace expr */ + /* Class representing the Objective-C language. */ class objc_language : public language_defn diff --git a/gdb/objc-lang.h b/gdb/objc-lang.h index d6a7509f21a..a472556d019 100644 --- a/gdb/objc-lang.h +++ b/gdb/objc-lang.h @@ -36,9 +36,6 @@ extern int find_objc_msgcall (CORE_ADDR pc, CORE_ADDR *new_pc); extern const char *find_imps (const char *method, std::vector *symbol_names); -extern struct value *value_nsstring (struct gdbarch *gdbarch, - const char *ptr, int len); - /* for parsing Objective C */ extern void start_msglist (void); extern void add_msglist (struct stoken *str, int addcolon);