Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 5/7] Remove a couple Objective-C expression helpers
Date: Sun, 16 Nov 2025 18:27:04 -0700	[thread overview]
Message-ID: <20251117012752.2657208-6-tom@tromey.com> (raw)
In-Reply-To: <20251117012752.2657208-1-tom@tromey.com>

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.
---
 gdb/c-exp.h     | 16 ++--------------
 gdb/eval.c      | 13 ++++++-------
 gdb/objc-lang.c | 16 +++++++++++++---
 gdb/objc-lang.h |  3 ---
 4 files changed, 21 insertions(+), 27 deletions(-)

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 @@ class objc_nsstring_operation
 
   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 @@ class objc_selector_operation
 
   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<const char *> *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);
-- 
2.49.0


  parent reply	other threads:[~2025-11-17  1:35 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-17  1:26 [PATCH 0/7] Objective-C fixes Tom Tromey
2025-11-17  1:27 ` [PATCH 1/7] Reformat gdb.objc tests Tom Tromey
2025-11-17  1:27 ` [PATCH 2/7] Make the gdb.objc tests compile Tom Tromey
2025-11-17 10:09   ` Matt Rice
2025-11-18  0:51     ` Tom Tromey
2025-11-18  1:12       ` Matt Rice
2025-12-02 16:20         ` Tom Tromey
2025-12-03 15:24           ` Matt Rice
2025-11-17  1:27 ` [PATCH 3/7] Minor fixes to make gdb.objc tests pass Tom Tromey
2025-11-17  1:27 ` [PATCH 4/7] Rename lookup_struct_typedef Tom Tromey
2025-11-17  1:27 ` Tom Tromey [this message]
2025-11-17  1:27 ` [PATCH 6/7] Avoid crash with "NSString" literals Tom Tromey
2025-11-17  1:27 ` [PATCH 7/7] Rewrite the @selector code Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251117012752.2657208-6-tom@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox