]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Change generic_emit_char to print the quotes
authorTom Tromey <tom@tromey.com>
Sun, 13 Feb 2022 18:05:46 +0000 (11:05 -0700)
committerTom Tromey <tom@tromey.com>
Sat, 31 Jan 2026 18:38:46 +0000 (11:38 -0700)
All callers of generic_emit_char print the quotes around the
character, then pass the quote character to the function.  It seemed
better to just have generic_emit_char print the quotes itself.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
gdb/c-lang.c
gdb/f-lang.h
gdb/rust-lang.c
gdb/valprint.c
gdb/valprint.h

index 67460a3d5ace32a91d2b88115d641e4d8b6bd332..a8e3a467bec41f9ddd592466372e79131c576c94 100644 (file)
@@ -160,9 +160,7 @@ language_defn::printchar (int c, struct type *type,
       break;
     }
 
-  gdb_putc ('\'', stream);
-  generic_emit_char (c, type, stream, '\'', encoding);
-  gdb_putc ('\'', stream);
+  generic_emit_char (c, type, stream, encoding);
 }
 
 /* Print the character string STRING, printing at most LENGTH
index 52e9c7e9979d0da55ac2b27eb755c7e1309cb012..e8dc784f0775670541e77f8520c9e44a802b8094 100644 (file)
@@ -161,10 +161,8 @@ public:
   void printchar (int ch, struct type *chtype,
                  struct ui_file *stream) const override
   {
-    gdb_puts ("'", stream);
     const char *encoding = get_encoding (chtype);
-    generic_emit_char (ch, chtype, stream, '\'', encoding);
-    gdb_puts ("'", stream);
+    generic_emit_char (ch, chtype, stream, encoding);
   }
 
   /* See language.h.  */
index ab193139d64d659de7eabb8677b564b94937723a..83786ff6e85a3e8de4c7d3f6b0959c2821a6f4c3 100644 (file)
@@ -1775,11 +1775,14 @@ void
 rust_language::printchar (int ch, struct type *chtype,
                          struct ui_file *stream) const
 {
-  fputs_filtered ("'", stream);
   if (!rust_chartype_p (chtype))
-    generic_emit_char (ch, chtype, stream, '\'',
-                      target_charset (chtype->arch ()));
-  else if (ch == '\\')
+    {
+      generic_emit_char (ch, chtype, stream,
+                        target_charset (chtype->arch ()));
+      return;
+    }
+  gdb_puts ("'", stream);
+  if (ch == '\\')
     gdb_printf (stream, "\\%c", ch);
   else if (ch == '\n')
     gdb_puts ("\\n", stream);
index cd50f3c31c1451baec891feaca1eb64b255dac54..feb2a5296ae0aad0a47582be13c6700bf4cb163f 100644 (file)
@@ -2267,13 +2267,16 @@ print_wchar (gdb_wint_t w, const gdb_byte *orig,
 }
 
 /* Print the character C on STREAM as part of the contents of a
-   literal string whose delimiter is QUOTER.  ENCODING names the
-   encoding of C.  */
+   literal string whose delimiter is a single quote.  ENCODING names
+   the encoding of C.  */
 
 void
 generic_emit_char (int c, struct type *type, struct ui_file *stream,
-                  int quoter, const char *encoding)
+                  const char *encoding)
 {
+  /* The quote character.  */
+  constexpr int quoter = '\'';
+
   enum bfd_endian byte_order
     = type_byte_order (type);
   gdb_byte *c_buf;
@@ -2282,6 +2285,7 @@ generic_emit_char (int c, struct type *type, struct ui_file *stream,
   c_buf = (gdb_byte *) alloca (type->length ());
   pack_long (c_buf, type, c);
 
+  gdb_putc (quoter, stream);
   wchar_iterator iter (c_buf, type->length (), encoding, type->length ());
 
   /* This holds the printable form of the wchar_t data.  */
@@ -2341,6 +2345,7 @@ generic_emit_char (int c, struct type *type, struct ui_file *stream,
   obstack_1grow (&output, '\0');
 
   gdb_puts ((const char *) obstack_base (&output), stream);
+  gdb_putc (quoter, stream);
 }
 
 /* Return the repeat count of the next character/byte in ITER,
index ef591d5820f78d1ab028b0377341f72b99eca620..0ce3e0781f68839603925ae329833151352300ea 100644 (file)
@@ -258,7 +258,7 @@ extern void generic_value_print (struct value *val, struct ui_file *stream,
                                 const struct generic_val_print_decorations *d);
 
 extern void generic_emit_char (int c, struct type *type, struct ui_file *stream,
-                              int quoter, const char *encoding);
+                              const char *encoding);
 
 extern void generic_printstr (struct ui_file *stream, struct type *type,
                              const gdb_byte *string, unsigned int length,