From: Tom Tromey Date: Sun, 13 Feb 2022 18:05:46 +0000 (-0700) Subject: Change generic_emit_char to print the quotes X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8366bf9435b863491c9c7eba35112b58565aa28d;p=thirdparty%2Fbinutils-gdb.git Change generic_emit_char to print the quotes 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 --- diff --git a/gdb/c-lang.c b/gdb/c-lang.c index 67460a3d5ac..a8e3a467bec 100644 --- a/gdb/c-lang.c +++ b/gdb/c-lang.c @@ -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 diff --git a/gdb/f-lang.h b/gdb/f-lang.h index 52e9c7e9979..e8dc784f077 100644 --- a/gdb/f-lang.h +++ b/gdb/f-lang.h @@ -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. */ diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c index ab193139d64..83786ff6e85 100644 --- a/gdb/rust-lang.c +++ b/gdb/rust-lang.c @@ -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); diff --git a/gdb/valprint.c b/gdb/valprint.c index cd50f3c31c1..feb2a5296ae 100644 --- a/gdb/valprint.c +++ b/gdb/valprint.c @@ -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, diff --git a/gdb/valprint.h b/gdb/valprint.h index ef591d5820f..0ce3e0781f6 100644 --- a/gdb/valprint.h +++ b/gdb/valprint.h @@ -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,