* [RFC] Signed/unsigned character arrays are not strings
@ 2007-01-25 1:54 Jan Kratochvil
2007-01-25 4:23 ` Eli Zaretskii
0 siblings, 1 reply; 7+ messages in thread
From: Jan Kratochvil @ 2007-01-25 1:54 UTC (permalink / raw)
To: gdb-patches
[-- 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 *"
#
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC] Signed/unsigned character arrays are not strings
2007-01-25 1:54 [RFC] Signed/unsigned character arrays are not strings Jan Kratochvil
@ 2007-01-25 4:23 ` Eli Zaretskii
2007-01-25 11:32 ` Jan Kratochvil
0 siblings, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2007-01-25 4:23 UTC (permalink / raw)
To: Jan Kratochvil; +Cc: gdb-patches
> Date: Thu, 25 Jan 2007 02:54:22 +0100
> From: Jan Kratochvil <jan.kratochvil@redhat.com>
>
> 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.
I must say I'm uneasy about this. Signedness could be random. What
will happen on platforms where `char' is unsigned by default?
Anyway, this change should probably be reflected in the manual, and
perhaps also in NEWS.
> Bugreported by Ulrich Drepper.
What bug? can you show it?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC] Signed/unsigned character arrays are not strings
2007-01-25 4:23 ` Eli Zaretskii
@ 2007-01-25 11:32 ` Jan Kratochvil
2007-01-26 8:54 ` Eli Zaretskii
2007-02-12 22:15 ` Daniel Jacobowitz
0 siblings, 2 replies; 7+ messages in thread
From: Jan Kratochvil @ 2007-01-25 11:32 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 1600 bytes --]
Hi Eli,
On Thu, 25 Jan 2007 05:23:01 +0100, Eli Zaretskii wrote:
> > Date: Thu, 25 Jan 2007 02:54:22 +0100
> > From: Jan Kratochvil <jan.kratochvil@redhat.com>
> >
> > 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.
>
> I must say I'm uneasy about this. Signedness could be random. What
> will happen on platforms where `char' is unsigned by default?
I had to find an answer to your interesting comment now myself:
# The string identification works despite the compiler flags below due to
# gdbtypes.c:
# if (name && strcmp (name, "char") == 0)
# TYPE_FLAGS (type) |= TYPE_FLAG_NOSIGN;
Provided there now an additional explicit testcase targeting your comment.
> Anyway, this change should probably be reflected in the manual, and
> perhaps also in NEWS.
Provided if it is satisfactionary.
> What bug? can you show it?
Originally posted by personal mail only, formally submitted before as:
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=224128
Attaching also "gdb-cvs-nosign-char.patch" for possible comments.
It starts printing
$1 = {65 'A', 0 '\0'}
finally as
$1 = {65, 0}
Not submitting it for commit review as it breaks the whole testsuite.
Still if anybody could update the testsuite it would be IMO a helpful patch.
Currently GDB displays the variants " 'X'" in many inappropriate cases.
Regards,
Lace
[-- Attachment #2: gdb-cvs-nosign-array2.patch --]
[-- Type: text/plain, Size: 11322 bytes --]
2007-01-25 Jan Kratochvil <jan.kratochvil@redhat.com>
* c-valprint.c (c_val_print): Require strings to be of no-signed CHARs.
* NEWS: Describe CHAR array vs. string identifcation rules.
2007-01-25 Jan Kratochvil <jan.kratochvil@redhat.com>
* gdb.texinfo: Describe CHAR array vs. string identifcation rules.
2007-01-25 Jan Kratochvil <jan.kratochvil@redhat.com>
* gdb.base/charsign.exp, gdb.base/charsign.c: New files.
* gdb.arch/i386-sse.exp: Check $xmm.v16_int8 printing as a number array.
* gdb.base/printcmds.exp: Sign-provided CHARs now became arrays.
* gdb.base/setvar.exp: Likewise.
--- gdb/NEWS 21 Jan 2007 17:48:53 -0000 1.211
+++ gdb/NEWS 25 Jan 2007 11:24:45 -0000
@@ -15,6 +15,9 @@ frequency signals (e.g. SIGALRM) via the
target's overall architecture. GDB can read a description from
a local file or over the remote serial protocol.
+* Arrays of specifically SIGNED or UNSIGNED CHARs are now printed as arrays
+ of numbers.
+
* New commands
set mem inaccessible-by-default
--- gdb/c-valprint.c 9 Jan 2007 17:58:50 -0000 1.41
+++ gdb/c-valprint.c 25 Jan 2007 11:24:45 -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/doc/ChangeLog 20 Jan 2007 16:51:56 -0000 1.635
+++ gdb/doc/ChangeLog 25 Jan 2007 11:24:48 -0000
@@ -1,3 +1,7 @@
+2007-01-25 Jan Kratochvil <jan.kratochvil@redhat.com>
+
+ gdb.texinfo: Describe CHAR array vs. string identifcation rules.
+
2007-01-20 Ralf Wildenhues <Ralf.Wildenhues@gmx.de> (tiny change)
* agentexpr.texi: Fix typos.
--- gdb/doc/gdb.texinfo 20 Jan 2007 16:51:55 -0000 1.379
+++ gdb/doc/gdb.texinfo 25 Jan 2007 11:24:58 -0000
@@ -5632,6 +5632,26 @@ If you ask to print an object whose cont
by the debug information, @value{GDBN} will say @samp{<incomplete
type>}. @xref{Symbols, incomplete type}, for more about this.
+Strings are identified as arrays of @code{char} values without specified
+signedness. Arrays of either @code{signed char} or @code{unsigned char} get
+printed as arrays of 1 byte sized integers. @code{-fsigned-char} or
+@code{-funsigned-char} @value{GCC} options have no effect as @value{GDBN}
+defines literal string type @code{"char"} as @code{char} without a sign.
+For program code
+
+@smallexample
+char var0[] = "A";
+signed char var1[] = "A";
+@end smallexample
+
+You get during debugging
+@smallexample
+(gdb) print var0
+$1 = "A"
+(gdb) print var1
+$2 = @{65 'A', 0 '\0'@}
+@end smallexample
+
@node Arrays
@section Artificial arrays
--- 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 11:24:58 -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} {
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gdb/testsuite/gdb.base/charsign.c 25 Jan 2007 11:24:58 -0000
@@ -0,0 +1,37 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2007 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ Please email any bugs, comments, and/or additions to this file to:
+ bug-gdb@prep.ai.mit.edu */
+
+int main()
+{
+ return 0;
+}
+
+char n[]="A";
+signed char s[]="A";
+unsigned char u[]="A";
+
+typedef char char_n;
+typedef signed char char_s;
+typedef unsigned char char_u;
+
+char_n n_typed[]="A";
+char_s s_typed[]="A";
+char_u u_typed[]="A";
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gdb/testsuite/gdb.base/charsign.exp 25 Jan 2007 11:24:58 -0000
@@ -0,0 +1,70 @@
+# Copyright 2007 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+if $tracelevel then {
+ strace $tracelevel
+}
+
+set prms_id 0
+set bug_id 0
+
+set testfile charsign
+set srcfile ${testfile}.c
+set binfile ${objdir}/${subdir}/${testfile}
+
+proc do_test { cflags } {
+ global srcdir
+ global binfile
+ global subdir
+ global srcfile
+ global gdb_prompt
+
+ if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug additional_flags=$cflags]] != "" } {
+ untested "Couldn't compile test program"
+ return -1
+ }
+
+ # Get things started.
+
+ gdb_exit
+ gdb_start
+ gdb_reinitialize_dir $srcdir/$subdir
+ gdb_load ${binfile}
+
+ # For C programs, "start" should stop in main().
+
+ gdb_test "p n" \
+ "= \"A\""
+ gdb_test "p s" \
+ "= \\{65 'A', 0 '\\\\0'\\}"
+ gdb_test "p u" \
+ "= \\{65 'A', 0 '\\\\0'\\}"
+ gdb_test "p n_typed" \
+ "= \"A\""
+ gdb_test "p s_typed" \
+ "= \\{65 'A', 0 '\\\\0'\\}"
+ gdb_test "p u_typed" \
+ "= \\{65 'A', 0 '\\\\0'\\}"
+}
+
+# The string identification works despite the compiler flags below due to
+# gdbtypes.c:
+# if (name && strcmp (name, "char") == 0)
+# TYPE_FLAGS (type) |= TYPE_FLAG_NOSIGN;
+
+do_test {}
+do_test {-fsigned-char}
+do_test {-funsigned-char}
--- gdb/testsuite/gdb.base/printcmds.exp 9 Jan 2007 17:59:11 -0000 1.14
+++ gdb/testsuite/gdb.base/printcmds.exp 25 Jan 2007 11:24:58 -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 11:24:58 -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 *"
#
[-- Attachment #3: gdb-cvs-nosign-char.patch --]
[-- Type: text/plain, Size: 546 bytes --]
--- gdb/c-valprint.c 9 Jan 2007 17:58:50 -0000 1.41
+++ gdb/c-valprint.c 24 Jan 2007 22:14:49 -0000
@@ -398,7 +398,7 @@ c_val_print (struct type *type, const gd
Since we don't know whether the value is really intended to
be used as an integer or a character, print the character
equivalent as well. */
- if (TYPE_LENGTH (type) == 1)
+ if (TYPE_LENGTH (type) == 1 && TYPE_NOSIGN (elttype))
{
fputs_filtered (" ", stream);
LA_PRINT_CHAR ((unsigned char) unpack_long (type, valaddr + embedded_offset),
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC] Signed/unsigned character arrays are not strings
2007-01-25 11:32 ` Jan Kratochvil
@ 2007-01-26 8:54 ` Eli Zaretskii
2007-01-26 10:37 ` Jan Kratochvil
2007-02-12 22:15 ` Daniel Jacobowitz
1 sibling, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2007-01-26 8:54 UTC (permalink / raw)
To: Jan Kratochvil; +Cc: gdb-patches
> Date: Thu, 25 Jan 2007 12:32:06 +0100
> From: Jan Kratochvil <jan.kratochvil@redhat.com>
> Cc: gdb-patches@sourceware.org
> >
> > I must say I'm uneasy about this. Signedness could be random. What
> > will happen on platforms where `char' is unsigned by default?
>
> I had to find an answer to your interesting comment now myself:
>
> # The string identification works despite the compiler flags below due to
> # gdbtypes.c:
> # if (name && strcmp (name, "char") == 0)
> # TYPE_FLAGS (type) |= TYPE_FLAG_NOSIGN;
Thanks, I withdraw my objections.
> +@code{-funsigned-char} @value{GCC} options have no effect as @value{GDBN}
Please use @value{NGCC}, not @value{GCC}. The former produces output
similar to @value{GDBN}, the latter produces a literal lowercase "gcc".
> +* Arrays of specifically SIGNED or UNSIGNED CHARs are now printed as arrays
> + of numbers.
I think "explicitly SIGNED or UNSIGNED..." is a better wording.
Thanks.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC] Signed/unsigned character arrays are not strings
2007-01-26 8:54 ` Eli Zaretskii
@ 2007-01-26 10:37 ` Jan Kratochvil
2007-01-26 14:44 ` Eli Zaretskii
0 siblings, 1 reply; 7+ messages in thread
From: Jan Kratochvil @ 2007-01-26 10:37 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 542 bytes --]
Hi Eli,
patch updated - commit approval requested.
Thanks,
Jan
On Fri, 26 Jan 2007 09:54:08 +0100, Eli Zaretskii wrote:
...
> > +@code{-funsigned-char} @value{GCC} options have no effect as @value{GDBN}
>
> Please use @value{NGCC}, not @value{GCC}. The former produces output
> similar to @value{GDBN}, the latter produces a literal lowercase "gcc".
>
> > +* Arrays of specifically SIGNED or UNSIGNED CHARs are now printed as arrays
> > + of numbers.
>
> I think "explicitly SIGNED or UNSIGNED..." is a better wording.
>
> Thanks.
[-- Attachment #2: gdb-cvs-nosign-array3.patch --]
[-- Type: text/plain, Size: 11006 bytes --]
2007-01-26 Jan Kratochvil <jan.kratochvil@redhat.com>
* c-valprint.c (c_val_print): Require strings to be of no-signed CHARs.
* NEWS: Describe CHAR array vs. string identifcation rules.
2007-01-26 Jan Kratochvil <jan.kratochvil@redhat.com>
Eli Zaretskii <eliz@gnu.org>
* gdb.texinfo: Describe CHAR array vs. string identifcation rules.
2007-01-25 Jan Kratochvil <jan.kratochvil@redhat.com>
* gdb.base/charsign.exp, gdb.base/charsign.c: New files.
* gdb.arch/i386-sse.exp: Check $xmm.v16_int8 printing as a number array.
* gdb.base/printcmds.exp: Sign-provided CHARs now became arrays.
* gdb.base/setvar.exp: Likewise.
--- gdb/NEWS 21 Jan 2007 17:48:53 -0000 1.211
+++ gdb/NEWS 26 Jan 2007 10:31:48 -0000
@@ -15,6 +15,9 @@ frequency signals (e.g. SIGALRM) via the
target's overall architecture. GDB can read a description from
a local file or over the remote serial protocol.
+* Arrays of explicitly SIGNED or UNSIGNED CHARs are now printed as arrays
+ of numbers.
+
* New commands
set mem inaccessible-by-default
--- gdb/c-valprint.c 9 Jan 2007 17:58:50 -0000 1.41
+++ gdb/c-valprint.c 26 Jan 2007 10:31:48 -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/doc/gdb.texinfo 26 Jan 2007 08:54:01 -0000 1.380
+++ gdb/doc/gdb.texinfo 26 Jan 2007 10:32:00 -0000
@@ -5632,6 +5632,26 @@ If you ask to print an object whose cont
by the debug information, @value{GDBN} will say @samp{<incomplete
type>}. @xref{Symbols, incomplete type}, for more about this.
+Strings are identified as arrays of @code{char} values without specified
+signedness. Arrays of either @code{signed char} or @code{unsigned char} get
+printed as arrays of 1 byte sized integers. @code{-fsigned-char} or
+@code{-funsigned-char} @value{NGCC} options have no effect as @value{GDBN}
+defines literal string type @code{"char"} as @code{char} without a sign.
+For program code
+
+@smallexample
+char var0[] = "A";
+signed char var1[] = "A";
+@end smallexample
+
+You get during debugging
+@smallexample
+(gdb) print var0
+$1 = "A"
+(gdb) print var1
+$2 = @{65 'A', 0 '\0'@}
+@end smallexample
+
@node Arrays
@section Artificial arrays
--- gdb/testsuite/gdb.arch/i386-sse.exp 9 Jan 2007 17:59:09 -0000 1.5
+++ gdb/testsuite/gdb.arch/i386-sse.exp 26 Jan 2007 10:32:00 -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} {
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gdb/testsuite/gdb.base/charsign.c 26 Jan 2007 10:32:00 -0000
@@ -0,0 +1,37 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2007 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ Please email any bugs, comments, and/or additions to this file to:
+ bug-gdb@prep.ai.mit.edu */
+
+int main()
+{
+ return 0;
+}
+
+char n[]="A";
+signed char s[]="A";
+unsigned char u[]="A";
+
+typedef char char_n;
+typedef signed char char_s;
+typedef unsigned char char_u;
+
+char_n n_typed[]="A";
+char_s s_typed[]="A";
+char_u u_typed[]="A";
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gdb/testsuite/gdb.base/charsign.exp 26 Jan 2007 10:32:00 -0000
@@ -0,0 +1,70 @@
+# Copyright 2007 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+if $tracelevel then {
+ strace $tracelevel
+}
+
+set prms_id 0
+set bug_id 0
+
+set testfile charsign
+set srcfile ${testfile}.c
+set binfile ${objdir}/${subdir}/${testfile}
+
+proc do_test { cflags } {
+ global srcdir
+ global binfile
+ global subdir
+ global srcfile
+ global gdb_prompt
+
+ if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug additional_flags=$cflags]] != "" } {
+ untested "Couldn't compile test program"
+ return -1
+ }
+
+ # Get things started.
+
+ gdb_exit
+ gdb_start
+ gdb_reinitialize_dir $srcdir/$subdir
+ gdb_load ${binfile}
+
+ # For C programs, "start" should stop in main().
+
+ gdb_test "p n" \
+ "= \"A\""
+ gdb_test "p s" \
+ "= \\{65 'A', 0 '\\\\0'\\}"
+ gdb_test "p u" \
+ "= \\{65 'A', 0 '\\\\0'\\}"
+ gdb_test "p n_typed" \
+ "= \"A\""
+ gdb_test "p s_typed" \
+ "= \\{65 'A', 0 '\\\\0'\\}"
+ gdb_test "p u_typed" \
+ "= \\{65 'A', 0 '\\\\0'\\}"
+}
+
+# The string identification works despite the compiler flags below due to
+# gdbtypes.c:
+# if (name && strcmp (name, "char") == 0)
+# TYPE_FLAGS (type) |= TYPE_FLAG_NOSIGN;
+
+do_test {}
+do_test {-fsigned-char}
+do_test {-funsigned-char}
--- gdb/testsuite/gdb.base/printcmds.exp 9 Jan 2007 17:59:11 -0000 1.14
+++ gdb/testsuite/gdb.base/printcmds.exp 26 Jan 2007 10:32:01 -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 26 Jan 2007 10:32:01 -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 *"
#
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC] Signed/unsigned character arrays are not strings
2007-01-26 10:37 ` Jan Kratochvil
@ 2007-01-26 14:44 ` Eli Zaretskii
0 siblings, 0 replies; 7+ messages in thread
From: Eli Zaretskii @ 2007-01-26 14:44 UTC (permalink / raw)
To: Jan Kratochvil; +Cc: gdb-patches
> Date: Fri, 26 Jan 2007 11:36:46 +0100
> From: Jan Kratochvil <jan.kratochvil@redhat.com>
> Cc: gdb-patches@sourceware.org
>
> patch updated - commit approval requested.
Please do.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC] Signed/unsigned character arrays are not strings
2007-01-25 11:32 ` Jan Kratochvil
2007-01-26 8:54 ` Eli Zaretskii
@ 2007-02-12 22:15 ` Daniel Jacobowitz
1 sibling, 0 replies; 7+ messages in thread
From: Daniel Jacobowitz @ 2007-02-12 22:15 UTC (permalink / raw)
To: Jan Kratochvil; +Cc: Eli Zaretskii, gdb-patches
On Thu, Jan 25, 2007 at 12:32:06PM +0100, Jan Kratochvil wrote:
> Attaching also "gdb-cvs-nosign-char.patch" for possible comments.
> It starts printing
> $1 = {65 'A', 0 '\0'}
> finally as
> $1 = {65, 0}
> Not submitting it for commit review as it breaks the whole testsuite.
> Still if anybody could update the testsuite it would be IMO a helpful patch.
> Currently GDB displays the variants " 'X'" in many inappropriate cases.
I must have forgotten about this message when the other patch went in.
This would be a painful testsuite update... but I think it would be
really nice. Does anyone else have an opinion?
Before Jan's now committed patch, for strings:
(gdb) p $mm0.v8_int8
$1 = "\000\000\000\000\000\000\000"
After, i.e. CVS HEAD:
(gdb) p $mm0.v8_int8
$2 = {0 '\0', 0 '\0', 0 '\0', 0 '\0', 0 '\0', 0 '\0', 0 '\0', 0 '\0'}
That's better... but it really should be:
$2 = {0, 0, 0, 0, 0, 0, 0, 0}
This is int8_t, we know it's not a char, and when I'm trying to do
math with an eight-element integer vector the chars are confusing.
If this is a good idea, I'll take care of the testsuite updates for at
least two platforms. That will cover most of it, and then we can
fix the rest as they are noticed.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2007-02-12 22:15 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-25 1:54 [RFC] Signed/unsigned character arrays are not strings Jan Kratochvil
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox