[RFC] Signed/unsigned character arrays are not strings

Jan Kratochvil
2007-01-25T01:54:32Z

[-- 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 *"
#