Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: gdb-patches@sourceware.org
Subject: [RFC] Signed/unsigned character arrays are not strings
Date: Thu, 25 Jan 2007 01:54:00 -0000	[thread overview]
Message-ID: <20070125015422.GA19113@host0.dyn.jankratochvil.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 1385 bytes --]

Hi,

currently all these types are printed as strings:
	char
	signed char
	unsigned char
the patch will reduce the printed strings only to
	char
and the signed/unsigned version gets printed as an array of byte values
(characters).  I hope nobody uses sign-specification for strings.
On the other hand byte arrays become unreadable if printed as strings.

Testsuite updated in multiple cases appropriately.
Bugreported by Ulrich Drepper.


Unpatched:
(gdb) p $xmm1
$1 = {v4_float = {1, 1.25, 1.5, 1.75}, v2_double = {0.031250007392372936, 0.50000011874362826}, 
  v16_int8 = "\000\000\200?\000\000�?\000\000�?\000\000�?", v8_int16 = {0, 16256, 0, 16288, 0, 16320, 0, 16352}, v4_int32 = {
    1065353216, 1067450368, 1069547520, 1071644672}, v2_int64 = {4584664421728518144, 4602678820242194432}, 
  uint128 = 0x3fe000003fc000003fa000003f800000}

Patched:
(gdb) p $xmm1
$1 = {v4_float = {1, 1.25, 1.5, 1.75}, v2_double = {0.031250007392372936, 0.50000011874362826}, v16_int8 = {0 '\0', 0 '\0', 
    -128 '\200', 63 '?', 0 '\0', 0 '\0', -96 '�', 63 '?', 0 '\0', 0 '\0', -64 '�', 63 '?', 0 '\0', 0 '\0', -32 '�', 63 '?'}, 
  v8_int16 = {0, 16256, 0, 16288, 0, 16320, 0, 16352}, v4_int32 = {1065353216, 1067450368, 1069547520, 1071644672}, 
  v2_int64 = {4584664421728518144, 4602678820242194432}, uint128 = 0x3fe000003fc000003fa000003f800000}



Regards,
Jan

[-- Attachment #2: gdb-cvs-nosign-array.patch --]
[-- Type: text/plain, Size: 5895 bytes --]

2007-01-25  Jan Kratochvil <jan.kratochvil@redhat.com>

	* c-valprint.c (c_val_print): Require strings to be of no-signed CHARs.

2007-01-25  Jan Kratochvil <jan.kratochvil@redhat.com>

	* gdb.arch/i386-sse.exp: Check $xmm $xmm.v16_int8 is a number array.
	* gdb.base/printcmds.exp: Sign-provided CHARs now became arrays.
	* gdb.base/setvar.exp: Likewise.


--- gdb/c-valprint.c	9 Jan 2007 17:58:50 -0000	1.41
+++ gdb/c-valprint.c	25 Jan 2007 01:40:56 -0000
@@ -96,7 +96,7 @@ c_val_print (struct type *type, const gd
 	    }
 	  /* For an array of chars, print with string syntax.  */
 	  if (eltlen == 1 &&
-	      ((TYPE_CODE (elttype) == TYPE_CODE_INT)
+	      ((TYPE_CODE (elttype) == TYPE_CODE_INT && TYPE_NOSIGN (elttype))
 	       || ((current_language->la_language == language_m2)
 		   && (TYPE_CODE (elttype) == TYPE_CODE_CHAR)))
 	      && (format == 0 || format == 's'))
--- gdb/testsuite/gdb.arch/i386-sse.exp	9 Jan 2007 17:59:09 -0000	1.5
+++ gdb/testsuite/gdb.arch/i386-sse.exp	25 Jan 2007 01:40:56 -0000
@@ -83,7 +83,10 @@ gdb_continue_to_breakpoint "continue to 
 foreach r {0 1 2 3 4 5 6 7} {
     gdb_test "print \$xmm$r.v4_float" \
         ".. = \\{$r, $r.25, $r.5, $r.75\\}.*" \
-        "check contents of %xmm$r"
+        "check float contents of %xmm$r"
+    gdb_test "print \$xmm$r.v16_int8" \
+        ".. = \\{(-?\[0-9\]+ '.*', ){15}-?\[0-9\]+ '.*'\\}.*" \
+        "check int8 contents of %xmm$r"
 }
 
 foreach r {0 1 2 3 4 5 6 7} {
--- gdb/testsuite/gdb.base/printcmds.exp	9 Jan 2007 17:59:11 -0000	1.14
+++ gdb/testsuite/gdb.base/printcmds.exp	25 Jan 2007 01:40:57 -0000
@@ -590,18 +590,18 @@ proc test_print_char_arrays {} {
     gdb_test "set print address on" ""
 
     gdb_test "p arrays" \
-	" = {array1 = \"abc\", array2 = \"d\", array3 = \"e\", array4 = \"fg\", array5 = \"hij\"}"
+	" = \\{array1 = \\{97 'a', 98 'b', 99 'c', 0 '\\\\0'\\}, array2 = \\{100 'd'\\}, array3 = \\{101 'e'\\}, array4 = \\{102 'f', 103 'g'\\}, array5 = \\{104 'h', 105 'i', 106 'j', 0 '\\\\0'\\}\\}"
 
     gdb_test "p parrays"		" = \\(struct some_arrays \\*\\) $hex"
-    gdb_test "p parrays->array1"	" = \"abc\""
+    gdb_test "p parrays->array1"	" = \\{97 'a', 98 'b', 99 'c', 0 '\\\\0'\\}"
     gdb_test "p &parrays->array1"	" = \\(unsigned char \\(\\*\\)\\\[4\\\]\\) $hex"
-    gdb_test "p parrays->array2"	" = \"d\""
+    gdb_test "p parrays->array2"	" = \\{100 'd'\\}"
     gdb_test "p &parrays->array2"	" = \\(unsigned char \\(\\*\\)\\\[1\\\]\\) $hex"
-    gdb_test "p parrays->array3"	" = \"e\""
+    gdb_test "p parrays->array3"	" = \\{101 'e'\\}"
     gdb_test "p &parrays->array3"	" = \\(unsigned char \\(\\*\\)\\\[1\\\]\\) $hex"
-    gdb_test "p parrays->array4"	" = \"fg\""
+    gdb_test "p parrays->array4"	" = \\{102 'f', 103 'g'\\}"
     gdb_test "p &parrays->array4"	" = \\(unsigned char \\(\\*\\)\\\[2\\\]\\) $hex"
-    gdb_test "p parrays->array5"	" = \"hij\""
+    gdb_test "p parrays->array5"	" = \\{104 'h', 105 'i', 106 'j', 0 '\\\\0'\\}"
     gdb_test "p &parrays->array5"	" = \\(unsigned char \\(\\*\\)\\\[4\\\]\\) $hex"
 
     gdb_test "set print address off" ""
--- gdb/testsuite/gdb.base/setvar.exp	9 Jan 2007 17:59:11 -0000	1.10
+++ gdb/testsuite/gdb.base/setvar.exp	25 Jan 2007 01:40:57 -0000
@@ -233,11 +233,11 @@ test_set "set variable v_char_array\[0\]
 #
 # test "set variable" for "signed char array[2]"
 #
-test_set "set variable v_signed_char_array\[0\]='h'" "set variable v_signed_char_array\[1\]='i'" "print v_signed_char_array" ".*.\[0-9\]* =.*\"hi\""        "set variable signed char array=\"hi\" (string)" 
+test_set "set variable v_signed_char_array\[0\]='h'" "set variable v_signed_char_array\[1\]='i'" "print v_signed_char_array" ".*.\[0-9\]* =.*\\{104 'h', 105 'i'\\}"        "set variable signed char array=\"hi\" (string)" 
 #
 # test "set variable" for "unsigned char array[2]"
 #
-test_set "set variable v_unsigned_char_array\[0\]='h'" "set variable v_unsigned_char_array\[1\]='i'" "print v_unsigned_char_array" ".*.\[0-9\]* =.*\"hi\""        "set variable unsigned char array=\"hi\" (string)" 
+test_set "set variable v_unsigned_char_array\[0\]='h'" "set variable v_unsigned_char_array\[1\]='i'" "print v_unsigned_char_array" ".*.\[0-9\]* =.*\\{104 'h', 105 'i'\\}"        "set variable unsigned char array=\"hi\" (string)" 
 #
 # test "set variable" for "short array[2]"
 #
@@ -289,11 +289,11 @@ test_set "set v_char_pointer=v_char_arra
 #
 # test "set variable" for type "signed char *"
 #
-test_set "set v_signed_char_pointer=v_signed_char_array" "set variable *(v_signed_char_pointer)='h'" "set variable *(v_signed_char_pointer+1)='i'" "print v_signed_char_array" ".*.\[0-9\]* =.*\"hi\""  "print *(v_signed_char_pointer+1)" ".*.\[0-9\]* = 105 \'i\'"     "set variable signed char pointer=\"hi\" (string)" 
+test_set "set v_signed_char_pointer=v_signed_char_array" "set variable *(v_signed_char_pointer)='h'" "set variable *(v_signed_char_pointer+1)='i'" "print v_signed_char_array" ".*.\[0-9\]* =.*\\{104 'h', 105 'i'\\}"  "print *(v_signed_char_pointer+1)" ".*.\[0-9\]* = 105 \'i\'"     "set variable signed char pointer=\"hi\" (string)" 
 #
 # test "set variable" for type "unsigned char *"
 #
-test_set "set v_unsigned_char_pointer=v_unsigned_char_array" "set variable *(v_unsigned_char_pointer)='h'" "set variable *(v_unsigned_char_pointer+1)='i'" "print v_unsigned_char_array" ".*.\[0-9\]* =.*\"hi\""  "print *(v_unsigned_char_pointer+1)" ".*.\[0-9\]* = 105 \'i\'"     "set variable unsigned char pointer=\"hi\" (string)" 
+test_set "set v_unsigned_char_pointer=v_unsigned_char_array" "set variable *(v_unsigned_char_pointer)='h'" "set variable *(v_unsigned_char_pointer+1)='i'" "print v_unsigned_char_array" ".*.\[0-9\]* =.*\\{104 'h', 105 'i'\\}"  "print *(v_unsigned_char_pointer+1)" ".*.\[0-9\]* = 105 \'i\'"     "set variable unsigned char pointer=\"hi\" (string)" 
 #
 # test "set variable" for type "short *"
 #

             reply	other threads:[~2007-01-25  1:54 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-25  1:54 Jan Kratochvil [this message]
2007-01-25  4:23 ` Eli Zaretskii
2007-01-25 11:32   ` Jan Kratochvil
2007-01-26  8:54     ` Eli Zaretskii
2007-01-26 10:37       ` Jan Kratochvil
2007-01-26 14:44         ` Eli Zaretskii
2007-02-12 22:15     ` Daniel Jacobowitz

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=20070125015422.GA19113@host0.dyn.jankratochvil.net \
    --to=jan.kratochvil@redhat.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