This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[commit/Ada] Fix printing of Wide_Wide_Strings


This fixes the printing of Wide_Wide_String objects.  For instance,
consider:

    My_WWS : Wide_Wide_String := " helo";

Before this patch is applied, GDB prints:

    (gdb) print my_wws
    $1 = " ["00"]h["00"]e"

There was a number of issues, not just one problem, but it can
summarized as: wide-wide character printing has never really been
implemented...

gdb/ChangeLog:

        * ada-valprint.c (ada_emit_char): Remove strange code.
        Check that c is <= UCHAR_MAX before passing it to isascii.
        (char_at): Do not assume that TYPE_LEN is either 1 or 2.

Tested on x86_64-linux.  Checked in.
A testcase is coming up as well, but I made it a separate patch
on its own, because there are other changes that need to be made,
but I'd like to give a chance for them to be reviewed, just in case.

---
 gdb/ChangeLog      |    6 ++++++
 gdb/ada-valprint.c |   22 ++++++++++++----------
 2 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index e8ba178..3490da1 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,11 @@
 2011-01-13  Joel Brobecker  <brobecker@adacore.com>
 
+	* ada-valprint.c (ada_emit_char): Remove strange code.
+	Check that c is <= UCHAR_MAX before passing it to isascii.
+	(char_at): Do not assume that TYPE_LEN is either 1 or 2.
+
+2011-01-13  Joel Brobecker  <brobecker@adacore.com>
+
 	* top.c (input_from_terminal_p): Restrict the use of interactive_mode
 	to the case where instream is stdin.
 
diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c
index c67266f..630ceb5 100644
--- a/gdb/ada-valprint.c
+++ b/gdb/ada-valprint.c
@@ -261,18 +261,19 @@ printable_val_type (struct type *type, const gdb_byte *valaddr)
 
 /* Print the character C on STREAM as part of the contents of a literal
    string whose delimiter is QUOTER.  TYPE_LEN is the length in bytes
-   (1 or 2) of the character.  */
+   of the character.  */
 
 void
 ada_emit_char (int c, struct type *type, struct ui_file *stream,
 	       int quoter, int type_len)
 {
-  if (type_len != 2)
-    type_len = 1;
-
-  c &= (1 << (type_len * TARGET_CHAR_BIT)) - 1;
-
-  if (isascii (c) && isprint (c))
+  /* If this character fits in the normal ASCII range, and is
+     a printable character, then print the character as if it was
+     an ASCII character, even if this is a wide character.
+     The UCHAR_MAX check is necessary because the isascii function
+     requires that its argument have a value of an unsigned char,
+     or EOF (EOF is obviously not printable).  */
+  if (c <= UCHAR_MAX && isascii (c) && isprint (c))
     {
       if (c == quoter && c == '"')
 	fprintf_filtered (stream, "\"\"");
@@ -283,8 +284,8 @@ ada_emit_char (int c, struct type *type, struct ui_file *stream,
     fprintf_filtered (stream, "[\"%0*x\"]", type_len * 2, c);
 }
 
-/* Character #I of STRING, given that TYPE_LEN is the size in bytes (1
-   or 2) of a character.  */
+/* Character #I of STRING, given that TYPE_LEN is the size in bytes
+   of a character.  */
 
 static int
 char_at (const gdb_byte *string, int i, int type_len,
@@ -293,7 +294,8 @@ char_at (const gdb_byte *string, int i, int type_len,
   if (type_len == 1)
     return string[i];
   else
-    return (int) extract_unsigned_integer (string + 2 * i, 2, byte_order);
+    return (int) extract_unsigned_integer (string + type_len * i,
+                                           type_len, byte_order);
 }
 
 /* Wrapper around memcpy to make it legal argument to ui_file_put.  */
-- 
1.7.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]