public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* Re: [RFC] Allow explicit 16 or 32 char in 'x /s'
       [not found] <11484.4708740295$1268865815@news.gmane.org>
@ 2010-03-18 22:08 ` Tom Tromey
  2010-03-19  7:32   ` Eli Zaretskii
  0 siblings, 1 reply; 20+ messages in thread
From: Tom Tromey @ 2010-03-18 22:08 UTC (permalink / raw)
  To: Pierre Muller; +Cc: gdb-patches

>>>>> "Pierre" == Pierre Muller <pierre.muller@ics-cnrs.unistra.fr> writes:

Pierre>   The patch below allows to 
Pierre> print strings that are made of 16 bit or 32 bit char 
Pierre> using:
Pierre> 'x /hs ' or 'x /ws ' commands.

It seems like a good idea to me.

Pierre>   I tried to enable this feature, keeping it to a minimum:
Pierre>   The size modifier is not remembered for /s format,
Pierre> thus any subsequent use of /s alone will still 
Pierre> print out byte char strings.

If the user types 'x/2hs' and then 'x/2', does the second invocation
still print wide strings?  I think it should.

Pierre> -      if (!strcmp (name, "char16_t"))
Pierre> +      /* Also recognize the type used by 'x /hs' command.  */
Pierre> +      if (!strcmp (name, "char16_t")
Pierre> +          || (TYPE_CODE (elttype) == TYPE_CODE_INT
Pierre> +              && TYPE_LENGTH (elttype) == 2))
Pierre>  	{
Pierre>  	  result = C_CHAR_16;
Pierre>  	  goto done;
Pierre>  	}

I am a little concerned that this code can confuse the user.
If sizeof(wchar_t) == 2, then sometimes you could end up printing a
wchar_t using UTF-16 -- which may or may not be appropriate.

I'm not sure how much this matters in practice.  However, it seems like
it may be cleaner to override classify_type's decision based directly on
the format character, instead of on the implied type.  What do you think
of that?  This would also let us introduce a new format character
meaning "wchar_t".

I think the documentation should reflect that the user can't choose the
encoding used here.

Pierre> +     The case of strings is handled n decode_format, only explicit

Typo, s/n/in/

Finally, please add some test cases.

Tom

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC] Allow explicit 16 or 32 char in 'x /s'
  2010-03-18 22:08 ` [RFC] Allow explicit 16 or 32 char in 'x /s' Tom Tromey
@ 2010-03-19  7:32   ` Eli Zaretskii
  2010-03-22 22:54     ` Pierre Muller
       [not found]     ` <15103.6087111153$1269298497@news.gmane.org>
  0 siblings, 2 replies; 20+ messages in thread
From: Eli Zaretskii @ 2010-03-19  7:32 UTC (permalink / raw)
  To: tromey; +Cc: pierre.muller, gdb-patches

> From: Tom Tromey <tromey@redhat.com>
> Cc: <gdb-patches@sourceware.org>
> Date: Thu, 18 Mar 2010 16:08:27 -0600
> 
> I think the documentation should reflect that the user can't choose the
> encoding used here.

I agree.  It should also say which encoding is used by GDB in this
case.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* RE: [RFC] Allow explicit 16 or 32 char in 'x /s'
  2010-03-19  7:32   ` Eli Zaretskii
@ 2010-03-22 22:54     ` Pierre Muller
       [not found]     ` <15103.6087111153$1269298497@news.gmane.org>
  1 sibling, 0 replies; 20+ messages in thread
From: Pierre Muller @ 2010-03-22 22:54 UTC (permalink / raw)
  To: 'Eli Zaretskii', tromey; +Cc: gdb-patches



> -----Message d'origine-----
> De : gdb-patches-owner@sourceware.org [mailto:gdb-patches-
> owner@sourceware.org] De la part de Eli Zaretskii
> Envoyé : Friday, March 19, 2010 8:32 AM
> À : tromey@redhat.com
> Cc : pierre.muller@ics-cnrs.unistra.fr; gdb-patches@sourceware.org
> Objet : Re: [RFC] Allow explicit 16 or 32 char in 'x /s'
> 
> > From: Tom Tromey <tromey@redhat.com>
> > Cc: <gdb-patches@sourceware.org>
> > Date: Thu, 18 Mar 2010 16:08:27 -0600
> >
> > I think the documentation should reflect that the user can't choose
> the
> > encoding used here.
> 
> I agree.  It should also say which encoding is used by GDB in this
> case.

  Not that I do not agree with you, but I would like to 
stress that how the string is displayed also depend on the current language,
so that, for C or any other language using c_printstr function,
/hs will use UTF-16LE or UTF-16BE according to current gdbarch endianess.
/ws will use UTF-32LE or UTF-32BE.

  But I don't know exactly for other languages and I would like to be sure
about
what you want me to add to the docs...
  Furthermore if you look into charset_for_string_type
function in c-lang.c source, you will see that there are two FIXME
just right at the position of these charset name settings.

  To answer Tom's concern about the change in classify_type function,
I modified my patch to change the elttype in do_examine to match exactly
what is expected by charset_for_string_type function.
Thus this new version has no modification in c-lang.c file.

  I also added a very basic check for string display using 'x /hs' and 'x
/ws'.

Pierre Muller



2010-03-22  Pierre Muller  <muller@ics.u-strasbg.fr>

	* printcmd.c (decode_format): Set char size to byte
	for strings unless explicit size is given.
	(print_formatted): Correct calculation of NEXT_ADDRESS
	for 16 or 32 bit strings.
	(do_examine): Do not force byte size for strings.
	Use 'char16_t' and 'char32_t' types to allow
	for correct recognition in classify_type.
	
2010-03-22  Pierre Muller  <muller@ics.u-strasbg.fr>

	* gdb.base/charset.c (Strin16, String32): New variables.
	* gdb.base/charset.exp (gdb_test): Test correct display
	of 16 or 32 bit strings.

Index: printcmd.c
===================================================================
RCS file: /cvs/src/src/gdb/printcmd.c,v
retrieving revision 1.173
diff -u -p -r1.173 printcmd.c
--- printcmd.c	5 Mar 2010 20:18:14 -0000	1.173
+++ printcmd.c	22 Mar 2010 22:25:34 -0000
@@ -260,6 +260,11 @@ decode_format (char **string_ptr, int of
 	/* Characters default to one byte.  */
 	val.size = osize ? 'b' : osize;
 	break;
+      case 's':
+	/* Display strings with byte size chars unless explicitly specified.
*/
+	val.size = 'b';
+	break;
+
       default:
 	/* The default is the size most recently specified.  */
 	val.size = osize;
@@ -295,7 +300,7 @@ print_formatted (struct value *val, int 
 	    next_address = (value_address (val)
 			    + val_print_string (elttype,
 						value_address (val), -1,
-						stream, options));
+						stream, options) * len);
 	  }
 	  return;
 
@@ -802,9 +807,11 @@ do_examine (struct format_data fmt, stru
   next_gdbarch = gdbarch;
   next_address = addr;
 
-  /* String or instruction format implies fetch single bytes
-     regardless of the specified size.  */
-  if (format == 's' || format == 'i')
+  /* Instruction format implies fetch single bytes
+     regardless of the specified size.
+     The case of strings is handled n decode_format, only explicit
+     size operator are not changed to 'b'.  */
+  if (format == 'i')
     size = 'b';
 
   if (size == 'a')
@@ -831,6 +838,36 @@ do_examine (struct format_data fmt, stru
   else if (size == 'g')
     val_type = builtin_type (next_gdbarch)->builtin_int64;
 
+  if (format == 's')
+    {
+      struct type *char_type;
+      if (size == 'h')
+	{
+	  char_type = lookup_typename (current_language, next_gdbarch,
+				       "char16_t", NULL, 1);
+	  if (!char_type)
+	    char_type = arch_type (next_gdbarch, TYPE_CODE_INT, 2,
"char16_t");
+	  check_typedef (char_type);
+	  if (TYPE_LENGTH (char_type) == 2)
+	    val_type = char_type;
+	}
+      else if (size == 'w')
+	{
+	  char_type = lookup_typename (current_language, next_gdbarch,
+				       "char32_t", NULL, 1);
+	  if (!char_type)
+	    char_type = arch_type (next_gdbarch, TYPE_CODE_INT, 4,
"char32_t");
+	  check_typedef (char_type);
+	  if (char_type && TYPE_LENGTH (char_type) == 4)
+	    val_type = char_type;
+	}
+      else
+        {
+	  size = 'b';
+	  val_type = builtin_type (next_gdbarch)->builtin_int8;
+        }
+    }
+
   maxelts = 8;
   if (size == 'w')
     maxelts = 4;
Index: testsuite/gdb.base/charset.c
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/charset.c,v
retrieving revision 1.12
diff -u -p -r1.12 charset.c
--- testsuite/gdb.base/charset.c	1 Jan 2010 07:32:00 -0000	1.12
+++ testsuite/gdb.base/charset.c	22 Mar 2010 22:25:34 -0000
@@ -65,6 +65,9 @@ typedef unsigned int char32_t;
 char16_t uvar;
 char32_t Uvar;
 
+char16_t *String16;
+char32_t *String32;
+
 /* A typedef to a typedef should also work.  */
 typedef wchar_t my_wchar_t;
 my_wchar_t myvar;
Index: testsuite/gdb.base/charset.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/charset.exp,v
retrieving revision 1.21
diff -u -p -r1.21 charset.exp
--- testsuite/gdb.base/charset.exp	17 Feb 2010 22:05:58 -0000	1.21
+++ testsuite/gdb.base/charset.exp	22 Mar 2010 22:25:35 -0000
@@ -616,4 +616,21 @@ gdb_test "print 'a' == 'a' || 'b' == 'b'
   ".* = 1" \
   "EVAL_SKIP cleanup handling regression test"
 
+
+proc string_display { var_name set_prefix x_size x_type} {
+  gdb_test "set ${var_name} = ${set_prefix}\"Test String\\0with zeroes\""
"" "Assign ${var_name} with prefix ${set_prefix}"
+  gdb_test "x /2${x_size}s ${var_name}" ".* ${x_type}\"Test
String\"\[\r\n\]+.* ${x_type}\"with zeroes\"" "Display String ${var_name}
with x/${x_size}s"
+}
+
+string_display String16 u h u
+if {$wchar_size == 2} {
+  string_display String16 L h u
+}
+ 
+string_display String32 U w U
+if {$wchar_size == 4} {
+  string_display String32 L w U
+}
+
+
 gdb_exit 

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC] Allow explicit 16 or 32 char in 'x /s'
       [not found]     ` <15103.6087111153$1269298497@news.gmane.org>
@ 2010-03-30 20:33       ` Tom Tromey
  2010-03-31 16:11         ` [RFC-v2] " Pierre Muller
       [not found]         ` <006101cad0ec$cb7915d0$626b4170$%muller@ics-cnrs.unistra.fr>
  0 siblings, 2 replies; 20+ messages in thread
From: Tom Tromey @ 2010-03-30 20:33 UTC (permalink / raw)
  To: Pierre Muller; +Cc: 'Eli Zaretskii', gdb-patches

>>>>> "Pierre" == Pierre Muller <pierre.muller@ics-cnrs.unistra.fr> writes:

Pierre>   But I don't know exactly for other languages and I would like
Pierre> to be sure about what you want me to add to the docs...

I think no other language has been updated to deal with wide characters.

Pierre>   Furthermore if you look into charset_for_string_type
Pierre> function in c-lang.c source, you will see that there are two FIXME
Pierre> just right at the position of these charset name settings.

Yeah ... those are actually pedantic FIXMEs, in that (IIRC) nothing
guarantees that char16_t==UTF-16, even though that is the common
meaning.

Pierre>   To answer Tom's concern about the change in classify_type function,
Pierre> I modified my patch to change the elttype in do_examine to match exactly
Pierre> what is expected by charset_for_string_type function.
Pierre> Thus this new version has no modification in c-lang.c file.

Suppose the inferior does not define char16_t.  Won't this new code
allocate a new type each time the user uses x/hs?  That seems bad.

What about passing the desired encoding to LA_PRINT_STRING, via a new
argument to val_print_string?  That makes the patch a lot bigger, though
it is mostly mechanical.

Pierre>   I also added a very basic check for string display using 'x
Pierre> /hs' and 'x /ws'.

Thanks.

Pierre> +      case 's':
Pierre> +	/* Display strings with byte size chars unless explicitly specified.
Pierre> */
Pierre> +	val.size = 'b';
Pierre> +	break;

I think x/hs followed by x should probably print another wide string.
I couldn't tell offhand if it does this or not.

Tom

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [RFC-v2] Allow explicit 16 or 32 char in 'x /s'
  2010-03-30 20:33       ` Tom Tromey
@ 2010-03-31 16:11         ` Pierre Muller
       [not found]         ` <006101cad0ec$cb7915d0$626b4170$%muller@ics-cnrs.unistra.fr>
  1 sibling, 0 replies; 20+ messages in thread
From: Pierre Muller @ 2010-03-31 16:11 UTC (permalink / raw)
  To: tromey; +Cc: 'Eli Zaretskii', gdb-patches



> -----Message d'origine-----
> De : gdb-patches-owner@sourceware.org [mailto:gdb-patches-
> owner@sourceware.org] De la part de Tom Tromey
> Envoyé : Tuesday, March 30, 2010 10:33 PM
> À : Pierre Muller
> Cc : 'Eli Zaretskii'; gdb-patches@sourceware.org
> Objet : Re: [RFC] Allow explicit 16 or 32 char in 'x /s'
> 
> >>>>> "Pierre" == Pierre Muller <pierre.muller@ics-cnrs.unistra.fr>
> writes:
> 
> Pierre>   But I don't know exactly for other languages and I would like
> Pierre> to be sure about what you want me to add to the docs...
> 
> I think no other language has been updated to deal with wide
> characters.

  At least pascal language was able to display
"simple" wide characters correctly (i.e. 16-bit strings with numeric values
in the 32-127 range)
before the patch that explicitly discarded the size modifier for /s.
 
> Pierre>   Furthermore if you look into charset_for_string_type
> Pierre> function in c-lang.c source, you will see that there are two
> FIXME
> Pierre> just right at the position of these charset name settings.
> 
> Yeah ... those are actually pedantic FIXMEs, in that (IIRC) nothing
> guarantees that char16_t==UTF-16, even though that is the common
> meaning.
> 
> Pierre>   To answer Tom's concern about the change in classify_type
> function,
> Pierre> I modified my patch to change the elttype in do_examine to
> match exactly
> Pierre> what is expected by charset_for_string_type function.
> Pierre> Thus this new version has no modification in c-lang.c file.
> 
> Suppose the inferior does not define char16_t.  Won't this new code
> allocate a new type each time the user uses x/hs?  That seems bad.
 
  Well, I supposed (wrongly) that the arch_type call would
make that newly defined type accessible to the next call to lookup_typename
but, after verification, it appears that you are right
and that the newly type is lost...
  I don't know how we should handle this case, but I don't think that it is 
the first time we use arch_type function inside GDB.
  Should I add two new fields to builtin_type struct?
  That is what I tried below.
 
> What about passing the desired encoding to LA_PRINT_STRING, via a new
> argument to val_print_string?  That makes the patch a lot bigger,
> though
> it is mostly mechanical.
> 
> Pierre>   I also added a very basic check for string display using 'x
> Pierre> /hs' and 'x /ws'.
> 
> Thanks.
> 
> Pierre> +      case 's':
> Pierre> +	/* Display strings with byte size chars unless explicitly
> specified.
> Pierre> */
> Pierre> +	val.size = 'b';
> Pierre> +	break;
> 
> I think x/hs followed by x should probably print another wide string.
> I couldn't tell offhand if it does this or not.

  This is what I wrote in the documentation part of the patch,
the idea was to limit the behavior change as compared to previous versions
of GDB: 
  only 'x /hs' or 'x /ws' would display 16 or 32 bit strings,
any use without the explicit size specifier would fall back to implicit 'x
/bs'
this of course also would happen if you use 'x ' command without any
specifier
at all. It seems nevertheless that the patch I sent out finally 
failed to do this properly. This new version seems to be closer to the
documentation I gave.

  Here is a new version of the patch
using builtin_char16 and builtin_char32.

Pierre


2010-03-31  Pierre Muller  <muller@ics.u-strasbg.fr>

	* gdbtypes.h (builtin_type): Add BUILTIN_CHAR16 and BUILTIN_CHAR32
	fields.
	* gdbtypes.c (gdbtypes_post_init): Set BUILTIN_CHAR16 and 
	BUILTIN_CHAR32 fields.
	* printcmd.c (decode_format): Set char size to '\0'
	for strings unless explicit size is given.
	(print_formatted): Correct calculation of NEXT_ADDRESS
	for 16 or 32 bit strings.
	(do_examine): Do not force byte size for strings.
	Use builtin_char16 and builtin_char32 types to display
	16 or 32 bit-wide strings. 
	(x_command): Set LAST_SIZE to 'b' for string type.


2010-03-31  Pierre Muller  <muller@ics.u-strasbg.fr>

      * gdb.texinfo (Examining memory): Update for
	change in string display with explicit size.

2010-03-31  Pierre Muller  <muller@ics.u-strasbg.fr>

	* gdb.base/charset.c (Strin16, String32): New variables.
	* gdb.base/charset.exp (gdb_test): Test correct display
	of 16 or 32 bit strings.
	
Index: src/gdb/gdbtypes.h
===================================================================
RCS file: /cvs/src/src/gdb/gdbtypes.h,v
retrieving revision 1.125
diff -u -p -r1.125 gdbtypes.h
--- src/gdb/gdbtypes.h	15 Mar 2010 02:42:54 -0000	1.125
+++ src/gdb/gdbtypes.h	31 Mar 2010 12:57:26 -0000
@@ -1099,6 +1099,9 @@ struct builtin_type
   struct type *builtin_int128;
   struct type *builtin_uint128;
 
+  /* Multi-byte character types.  */
+  struct type *builtin_char16;
+  struct type *builtin_char32;
 
   /* Pointer types.  */
 
Index: src/gdb/gdbtypes.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtypes.c,v
retrieving revision 1.188
diff -u -p -r1.188 gdbtypes.c
--- src/gdb/gdbtypes.c	1 Mar 2010 17:19:22 -0000	1.188
+++ src/gdb/gdbtypes.c	31 Mar 2010 12:57:25 -0000
@@ -3474,6 +3474,13 @@ gdbtypes_post_init (struct gdbarch *gdba
   TYPE_NOTTEXT (builtin_type->builtin_int8) = 1;
   TYPE_NOTTEXT (builtin_type->builtin_uint8) = 1;
 
+  /* Multi-byte character types.  */
+  builtin_type->builtin_char16
+    = arch_integer_type (gdbarch, 16, 0, "char16_t");
+  builtin_type->builtin_char32
+    = arch_integer_type (gdbarch, 32, 0, "char32_t");
+	
+
   /* Default data/code pointer types.  */
   builtin_type->builtin_data_ptr
     = lookup_pointer_type (builtin_type->builtin_void);
Index: src/gdb/printcmd.c
===================================================================
RCS file: /cvs/src/src/gdb/printcmd.c,v
retrieving revision 1.173
diff -u -p -r1.173 printcmd.c
--- src/gdb/printcmd.c	5 Mar 2010 20:18:14 -0000	1.173
+++ src/gdb/printcmd.c	31 Mar 2010 15:20:22 -0000
@@ -260,6 +260,11 @@ decode_format (char **string_ptr, int of
 	/* Characters default to one byte.  */
 	val.size = osize ? 'b' : osize;
 	break;
+      case 's':
+	/* Display strings with byte size chars unless explicitly specified.
*/
+	val.size = '\0';
+	break;
+
       default:
 	/* The default is the size most recently specified.  */
 	val.size = osize;
@@ -295,7 +300,7 @@ print_formatted (struct value *val, int 
 	    next_address = (value_address (val)
 			    + val_print_string (elttype,
 						value_address (val), -1,
-						stream, options));
+						stream, options) * len);
 	  }
 	  return;
 
@@ -802,9 +807,11 @@ do_examine (struct format_data fmt, stru
   next_gdbarch = gdbarch;
   next_address = addr;
 
-  /* String or instruction format implies fetch single bytes
-     regardless of the specified size.  */
-  if (format == 's' || format == 'i')
+  /* Instruction format implies fetch single bytes
+     regardless of the specified size.
+     The case of strings is handled n decode_format, only explicit
+     size operator are not changed to 'b'.  */
+  if (format == 'i')
     size = 'b';
 
   if (size == 'a')
@@ -831,6 +838,27 @@ do_examine (struct format_data fmt, stru
   else if (size == 'g')
     val_type = builtin_type (next_gdbarch)->builtin_int64;
 
+  if (format == 's')
+    {
+      struct type *char_type = NULL;
+      /* Search for "char16_t"  or "char32_t" types or fall back to 8-bit
char
+	 if type is not found.  */
+      if (size == 'h')
+	char_type = builtin_type (next_gdbarch)->builtin_char16;
+      else if (size == 'w')
+	char_type = builtin_type (next_gdbarch)->builtin_char32;
+      if (char_type)
+        val_type = char_type;
+      else
+        {
+	  if (size != '\0' && size != 'b')
+	    warning (_("Unable to display strings with size '%c', using 'b'
\
+instead."), size);
+	  size = 'b';
+	  val_type = builtin_type (next_gdbarch)->builtin_int8;
+        }
+    }
+
   maxelts = 8;
   if (size == 'w')
     maxelts = 4;
@@ -1412,8 +1440,11 @@ x_command (char *exp, int from_tty)
   do_examine (fmt, next_gdbarch, next_address);
 
   /* If the examine succeeds, we remember its size and format for next
-     time.  */
-  last_size = fmt.size;
+     time.  Set last_size to 'b' for strings.  */
+  if (fmt.format == 's')
+    last_size = 'b'
+  else
+    last_size = fmt.size;
   last_format = fmt.format;
 
   /* Set a couple of internal variables if appropriate. */
Index: src/gdb/doc/gdb.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.680
diff -u -p -r1.680 gdb.texinfo
--- src/gdb/doc/gdb.texinfo     12 Mar 2010 19:15:52 -0000      1.680
+++ src/gdb/doc/gdb.texinfo     18 Mar 2010 20:43:12 -0000
@@ -7236,8 +7236,11 @@ Giant words (eight bytes).
 @end table

 Each time you specify a unit size with @code{x}, that size becomes the
-default unit the next time you use @code{x}.  (For the @samp{s} and
-@samp{i} formats, the unit size is ignored and is normally not written.)
+default unit the next time you use @code{x}.  For the @samp{i} format,
+the unit size is ignored and is normally not written.  For the @samp{s}
format,
+the unit size defaults to @samp{b}, unless it is explicitly given.
+Use @kbd{x /hs} to display 16-bit char strings and @kbd{x /ws} to display
+32-bit strings.  The next use of @kbd{x /s} will again display 8-bit
strings.

 @item @var{addr}, starting display address
 @var{addr} is the address where you want @value{GDBN} to begin displaying
Index: src/gdb/testsuite/gdb.base/charset.c
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/charset.c,v
retrieving revision 1.12
diff -u -p -r1.12 charset.c
--- src/gdb/testsuite/gdb.base/charset.c	1 Jan 2010 07:32:00 -0000
1.12
+++ src/gdb/testsuite/gdb.base/charset.c	22 Mar 2010 22:25:34 -0000
@@ -65,6 +65,9 @@ typedef unsigned int char32_t;
 char16_t uvar;
 char32_t Uvar;
 
+char16_t *String16;
+char32_t *String32;
+
 /* A typedef to a typedef should also work.  */
 typedef wchar_t my_wchar_t;
 my_wchar_t myvar;
Index: src/gdb/testsuite/gdb.base/charset.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/charset.exp,v
retrieving revision 1.21
diff -u -p -r1.21 charset.exp
--- src/gdb/testsuite/gdb.base/charset.exp	17 Feb 2010 22:05:58 -0000
1.21
+++ src/gdb/testsuite/gdb.base/charset.exp	22 Mar 2010 22:25:35 -0000
@@ -616,4 +616,21 @@ gdb_test "print 'a' == 'a' || 'b' == 'b'
   ".* = 1" \
   "EVAL_SKIP cleanup handling regression test"
 
+
+proc string_display { var_name set_prefix x_size x_type} {
+  gdb_test "set ${var_name} = ${set_prefix}\"Test String\\0with zeroes\""
"" "Assign ${var_name} with prefix ${set_prefix}"
+  gdb_test "x /2${x_size}s ${var_name}" ".* ${x_type}\"Test
String\"\[\r\n\]+.* ${x_type}\"with zeroes\"" "Display String ${var_name}
with x/${x_size}s"
+}
+
+string_display String16 u h u
+if {$wchar_size == 2} {
+  string_display String16 L h u
+}
+ 
+string_display String32 U w U
+if {$wchar_size == 4} {
+  string_display String32 L w U
+}
+
+
 gdb_exit 

  

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC-v2] Allow explicit 16 or 32 char in 'x /s'
       [not found]         ` <006101cad0ec$cb7915d0$626b4170$%muller@ics-cnrs.unistra.fr>
@ 2010-03-31 16:17           ` Eli Zaretskii
  2010-04-01  9:34             ` Pierre Muller
       [not found]             ` <000f01cad17e$7686f140$6394d3c0$%muller@ics-cnrs.unistra.fr>
  0 siblings, 2 replies; 20+ messages in thread
From: Eli Zaretskii @ 2010-03-31 16:17 UTC (permalink / raw)
  To: Pierre Muller; +Cc: tromey, gdb-patches

> From: "Pierre Muller" <pierre.muller@ics-cnrs.unistra.fr>
> Cc: "'Eli Zaretskii'" <eliz@gnu.org>, <gdb-patches@sourceware.org>
> Date: Wed, 31 Mar 2010 18:11:17 +0200
> 
> --- src/gdb/doc/gdb.texinfo     12 Mar 2010 19:15:52 -0000      1.680
> +++ src/gdb/doc/gdb.texinfo     18 Mar 2010 20:43:12 -0000
> @@ -7236,8 +7236,11 @@ Giant words (eight bytes).
>  @end table
> 
>  Each time you specify a unit size with @code{x}, that size becomes the
> -default unit the next time you use @code{x}.  (For the @samp{s} and
> -@samp{i} formats, the unit size is ignored and is normally not written.)
> +default unit the next time you use @code{x}.  For the @samp{i} format,
> +the unit size is ignored and is normally not written.  For the @samp{s}
> format,
> +the unit size defaults to @samp{b}, unless it is explicitly given.
> +Use @kbd{x /hs} to display 16-bit char strings and @kbd{x /ws} to display
> +32-bit strings.  The next use of @kbd{x /s} will again display 8-bit
> strings.

This is okay, but I still think we should mention that the encoding is
UTF-16 and UCS-4, respectively, and that it cannot be changed.

Thanks.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* RE: [RFC-v2] Allow explicit 16 or 32 char in 'x /s'
  2010-03-31 16:17           ` Eli Zaretskii
@ 2010-04-01  9:34             ` Pierre Muller
       [not found]             ` <000f01cad17e$7686f140$6394d3c0$%muller@ics-cnrs.unistra.fr>
  1 sibling, 0 replies; 20+ messages in thread
From: Pierre Muller @ 2010-04-01  9:34 UTC (permalink / raw)
  To: 'Eli Zaretskii'; +Cc: tromey, gdb-patches



> -----Message d'origine-----
> De : gdb-patches-owner@sourceware.org [mailto:gdb-patches-
> owner@sourceware.org] De la part de Eli Zaretskii
> > +the unit size defaults to @samp{b}, unless it is explicitly given.
> > +Use @kbd{x /hs} to display 16-bit char strings and @kbd{x /ws} to
> display
> > +32-bit strings.  The next use of @kbd{x /s} will again display 8-bit
> > strings.
> 
> This is okay, but I still think we should mention that the encoding is
> UTF-16 and UCS-4, respectively, and that it cannot be changed.


   According to c_emit_char function, it is 
UTF-16 (LE or BE depending on target endianess)
or UTF-32 (LE or BE also).
  Is UCS-4 exactly the same as UTF-32?
  Furthermore, this is c_emit_char, which means that this
is a language specific output.
  Several languages have their own emit_char functions,
several of them start by a 
  c &= 0xFF;
line, which discards higher bytes of the character value.
(found in f-lang.c:86, m2-lang.c:45, objc-lang.c:287 and p-lang.c:161)
Of course these implementations would benefit from 
using the more up to date c-lang.c implementation, but that is another
story.

  This means that UTF-16 and UTF-32 will only be used
for c, cplus, assembler, minimal. 
  Java language seems to use another scheme to represent 
extended characters: it uses 
  fprintf_unfiltered (stream, "\\u%.4x", (unsigned int) c);

  To summarize, I don't think that saying that ' /hs'  uses UTF-16
without specifying that this is language specific is correct.

  Should I just mention that the output is language dependent
and uses UTF-16 or UTF-32 for c, cplus, assembler and minimal languages?

Pierre Muller

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC-v2] Allow explicit 16 or 32 char in 'x /s'
       [not found]             ` <000f01cad17e$7686f140$6394d3c0$%muller@ics-cnrs.unistra.fr>
@ 2010-04-01 13:17               ` Eli Zaretskii
  2010-04-05 23:01                 ` Pierre Muller
       [not found]                 ` <002701cad513$e44a7420$acdf5c60$%muller@ics-cnrs.unistra.fr>
  0 siblings, 2 replies; 20+ messages in thread
From: Eli Zaretskii @ 2010-04-01 13:17 UTC (permalink / raw)
  To: Pierre Muller; +Cc: tromey, gdb-patches

> From: "Pierre Muller" <pierre.muller@ics-cnrs.unistra.fr>
> Cc: <tromey@redhat.com>, <gdb-patches@sourceware.org>
> Date: Thu, 1 Apr 2010 11:34:00 +0200
> 
>   Should I just mention that the output is language dependent
> and uses UTF-16 or UTF-32 for c, cplus, assembler and minimal languages?

Yes, I think so.  Most importantly, we should say that this encoding
cannot be controlled by the user.

Thanks.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* RE: [RFC-v2] Allow explicit 16 or 32 char in 'x /s'
  2010-04-01 13:17               ` Eli Zaretskii
@ 2010-04-05 23:01                 ` Pierre Muller
       [not found]                 ` <002701cad513$e44a7420$acdf5c60$%muller@ics-cnrs.unistra.fr>
  1 sibling, 0 replies; 20+ messages in thread
From: Pierre Muller @ 2010-04-05 23:01 UTC (permalink / raw)
  To: 'Eli Zaretskii'; +Cc: tromey, gdb-patches



> -----Message d'origine-----
> De : gdb-patches-owner@sourceware.org [mailto:gdb-patches-
> owner@sourceware.org] De la part de Eli Zaretskii
> Envoyé : Thursday, April 01, 2010 3:16 PM
> À : Pierre Muller
> Cc : tromey@redhat.com; gdb-patches@sourceware.org
> Objet : Re: [RFC-v2] Allow explicit 16 or 32 char in 'x /s'
> 
> > From: "Pierre Muller" <pierre.muller@ics-cnrs.unistra.fr>
> > Cc: <tromey@redhat.com>, <gdb-patches@sourceware.org>
> > Date: Thu, 1 Apr 2010 11:34:00 +0200
> >
> >   Should I just mention that the output is language dependent
> > and uses UTF-16 or UTF-32 for c, cplus, assembler and minimal
> languages?
> 
> Yes, I think so.  Most importantly, we should say that this encoding
> cannot be controlled by the user.
I tried to write something for 
the C output for 'x /hs',
but I don't know if C as the language needs to be written especially,
and likewise for UTF-16 and UTF-32.

  Eli, could you please take a look?

Thanks in advance,

Pierre


2010-04-06  Pierre Muller  <muller@ics.u-strasbg.fr>

	* gdbtypes.h (builtin_type): Add BUILTIN_CHAR16 and BUILTIN_CHAR32
	fields.
	* gdbtypes.c (gdbtypes_post_init): Set BUILTIN_CHAR16 and 
	BUILTIN_CHAR32 fields.
	* printcmd.c (decode_format): Set char size to '\0'
	for strings unless explicit size is given.
	(print_formatted): Correct calculation of NEXT_ADDRESS
	for 16 or 32 bit strings.
	(do_examine): Do not force byte size for strings.
	Use builtin_char16 and builtin_char32 types to display
	16 or 32 bit-wide strings. 
	(x_command): Set LAST_SIZE to 'b' for string type.

2010-04-06  Pierre Muller  <muller@ics.u-strasbg.fr>

      * gdb.texinfo (Examining memory): Update for
	change in string display with explicit size.

2010-04-06  Pierre Muller  <muller@ics.u-strasbg.fr>

	* gdb.base/charset.c (Strin16, String32): New variables.
	* gdb.base/charset.exp (gdb_test): Test correct display
	of 16 or 32 bit strings.
Index: src/gdb/gdbtypes.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtypes.c,v
retrieving revision 1.188
diff -u -p -r1.188 gdbtypes.c
--- src/gdb/gdbtypes.c	1 Mar 2010 17:19:22 -0000	1.188
+++ src/gdb/gdbtypes.c	5 Apr 2010 22:53:39 -0000
@@ -3474,6 +3474,13 @@ gdbtypes_post_init (struct gdbarch *gdba
   TYPE_NOTTEXT (builtin_type->builtin_int8) = 1;
   TYPE_NOTTEXT (builtin_type->builtin_uint8) = 1;
 
+  /* Multi-byte character types.  */
+  builtin_type->builtin_char16
+    = arch_integer_type (gdbarch, 16, 0, "char16_t");
+  builtin_type->builtin_char32
+    = arch_integer_type (gdbarch, 32, 0, "char32_t");
+	
+
   /* Default data/code pointer types.  */
   builtin_type->builtin_data_ptr
     = lookup_pointer_type (builtin_type->builtin_void);
Index: src/gdb/gdbtypes.h
===================================================================
RCS file: /cvs/src/src/gdb/gdbtypes.h,v
retrieving revision 1.125
diff -u -p -r1.125 gdbtypes.h
--- src/gdb/gdbtypes.h	15 Mar 2010 02:42:54 -0000	1.125
+++ src/gdb/gdbtypes.h	5 Apr 2010 22:53:39 -0000
@@ -1099,6 +1099,9 @@ struct builtin_type
   struct type *builtin_int128;
   struct type *builtin_uint128;
 
+  /* Multi-byte character types.  */
+  struct type *builtin_char16;
+  struct type *builtin_char32;
 
   /* Pointer types.  */
 
Index: src/gdb/printcmd.c
===================================================================
RCS file: /cvs/src/src/gdb/printcmd.c,v
retrieving revision 1.173
diff -u -p -r1.173 printcmd.c
--- src/gdb/printcmd.c	5 Mar 2010 20:18:14 -0000	1.173
+++ src/gdb/printcmd.c	5 Apr 2010 22:53:40 -0000
@@ -260,6 +260,11 @@ decode_format (char **string_ptr, int of
 	/* Characters default to one byte.  */
 	val.size = osize ? 'b' : osize;
 	break;
+      case 's':
+	/* Display strings with byte size chars unless explicitly specified.
*/
+	val.size = '\0';
+	break;
+
       default:
 	/* The default is the size most recently specified.  */
 	val.size = osize;
@@ -295,7 +300,7 @@ print_formatted (struct value *val, int 
 	    next_address = (value_address (val)
 			    + val_print_string (elttype,
 						value_address (val), -1,
-						stream, options));
+						stream, options) * len);
 	  }
 	  return;
 
@@ -802,9 +807,11 @@ do_examine (struct format_data fmt, stru
   next_gdbarch = gdbarch;
   next_address = addr;
 
-  /* String or instruction format implies fetch single bytes
-     regardless of the specified size.  */
-  if (format == 's' || format == 'i')
+  /* Instruction format implies fetch single bytes
+     regardless of the specified size.
+     The case of strings is handled n decode_format, only explicit
+     size operator are not changed to 'b'.  */
+  if (format == 'i')
     size = 'b';
 
   if (size == 'a')
@@ -831,6 +838,27 @@ do_examine (struct format_data fmt, stru
   else if (size == 'g')
     val_type = builtin_type (next_gdbarch)->builtin_int64;
 
+  if (format == 's')
+    {
+      struct type *char_type = NULL;
+      /* Search for "char16_t"  or "char32_t" types or fall back to 8-bit
char
+	 if type is not found.  */
+      if (size == 'h')
+	char_type = builtin_type (next_gdbarch)->builtin_char16;
+      else if (size == 'w')
+	char_type = builtin_type (next_gdbarch)->builtin_char32;
+      if (char_type)
+        val_type = char_type;
+      else
+        {
+	  if (size != '\0' && size != 'b')
+	    warning (_("Unable to display strings with size '%c', using 'b'
\
+instead."), size);
+	  size = 'b';
+	  val_type = builtin_type (next_gdbarch)->builtin_int8;
+        }
+    }
+
   maxelts = 8;
   if (size == 'w')
     maxelts = 4;
@@ -1412,8 +1440,11 @@ x_command (char *exp, int from_tty)
   do_examine (fmt, next_gdbarch, next_address);
 
   /* If the examine succeeds, we remember its size and format for next
-     time.  */
-  last_size = fmt.size;
+     time.  Set last_size to 'b' for strings.  */
+  if (fmt.format == 's')
+    last_size = 'b';
+  else
+    last_size = fmt.size;
   last_format = fmt.format;
 
   /* Set a couple of internal variables if appropriate. */
Index: src/gdb/doc/gdb.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.696
diff -u -p -r1.696 gdb.texinfo
--- src/gdb/doc/gdb.texinfo	5 Apr 2010 17:14:57 -0000	1.696
+++ src/gdb/doc/gdb.texinfo	5 Apr 2010 22:53:53 -0000
@@ -7236,8 +7236,14 @@ Giant words (eight bytes).
 @end table
 
 Each time you specify a unit size with @code{x}, that size becomes the
-default unit the next time you use @code{x}.  (For the @samp{s} and
-@samp{i} formats, the unit size is ignored and is normally not written.)
+default unit the next time you use @code{x}.  For the @samp{i} format,
+the unit size is ignored and is normally not written.  For the @samp{s}
format,
+the unit size defaults to @samp{b}, unless it is explicitly given.
+Use @kbd{x /hs} to display 16-bit char strings and @kbd{x /ws} to display
+32-bit strings.  The next use of @kbd{x /s} will again display 8-bit
strings.
+Note that the display may vary with current language. If current language
is
+C, @samp{h} (respectively @samp{w}) modifier will use UTF-16 charset 
+(respectively UTF-32 charset).  These charsets can not be modified.
 
 @item @var{addr}, starting display address
 @var{addr} is the address where you want @value{GDBN} to begin displaying
Index: src/gdb/testsuite/gdb.base/charset.c
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/charset.c,v
retrieving revision 1.12
diff -u -p -r1.12 charset.c
--- src/gdb/testsuite/gdb.base/charset.c	1 Jan 2010 07:32:00 -0000
1.12
+++ src/gdb/testsuite/gdb.base/charset.c	5 Apr 2010 22:53:54 -0000
@@ -65,6 +65,9 @@ typedef unsigned int char32_t;
 char16_t uvar;
 char32_t Uvar;
 
+char16_t *String16;
+char32_t *String32;
+
 /* A typedef to a typedef should also work.  */
 typedef wchar_t my_wchar_t;
 my_wchar_t myvar;
Index: src/gdb/testsuite/gdb.base/charset.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/charset.exp,v
retrieving revision 1.21
diff -u -p -r1.21 charset.exp
--- src/gdb/testsuite/gdb.base/charset.exp	17 Feb 2010 22:05:58 -0000
1.21
+++ src/gdb/testsuite/gdb.base/charset.exp	5 Apr 2010 22:53:54 -0000
@@ -616,4 +616,21 @@ gdb_test "print 'a' == 'a' || 'b' == 'b'
   ".* = 1" \
   "EVAL_SKIP cleanup handling regression test"
 
+
+proc string_display { var_name set_prefix x_size x_type} {
+  gdb_test "set ${var_name} = ${set_prefix}\"Test String\\0with zeroes\""
"" "Assign ${var_name} with prefix ${set_prefix}"
+  gdb_test "x /2${x_size}s ${var_name}" ".* ${x_type}\"Test
String\"\[\r\n\]+.* ${x_type}\"with zeroes\"" "Display String ${var_name}
with x/${x_size}s"
+}
+
+string_display String16 u h u
+if {$wchar_size == 2} {
+  string_display String16 L h u
+}
+ 
+string_display String32 U w U
+if {$wchar_size == 4} {
+  string_display String32 L w U
+}
+
+
 gdb_exit 

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC-v2] Allow explicit 16 or 32 char in 'x /s'
       [not found]                 ` <002701cad513$e44a7420$acdf5c60$%muller@ics-cnrs.unistra.fr>
@ 2010-04-06 17:51                   ` Eli Zaretskii
  2010-04-08 20:58                     ` [RFA-v3] " Pierre Muller
  0 siblings, 1 reply; 20+ messages in thread
From: Eli Zaretskii @ 2010-04-06 17:51 UTC (permalink / raw)
  To: Pierre Muller; +Cc: tromey, gdb-patches

> From: "Pierre Muller" <pierre.muller@ics-cnrs.unistra.fr>
> Cc: <tromey@redhat.com>, <gdb-patches@sourceware.org>
> Date: Tue, 6 Apr 2010 01:01:12 +0200
> 
> +Note that the display may vary with current language. If current language
> is
> +C, @samp{h} (respectively @samp{w}) modifier will use UTF-16 charset 
> +(respectively UTF-32 charset).  These charsets can not be modified.

Thanks.  I suggest the following rewording:

  Note that the results depend on the programming language of the
  current compilation unit.  If the language is C, the @samp{s}
  modifier will use the UTF-16 encoding while @samp{w} will use
  UTF-32.  The encoding is set by the programming language and cannot
  be altered.

Please also keep 2 spaces between sentences, when you commit these
changes.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [RFA-v3] Allow explicit 16 or 32 char in 'x /s'
  2010-04-06 17:51                   ` Eli Zaretskii
@ 2010-04-08 20:58                     ` Pierre Muller
  2010-04-16  8:41                       ` [PING] " Pierre Muller
                                         ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: Pierre Muller @ 2010-04-08 20:58 UTC (permalink / raw)
  To: gdb-patches; +Cc: tromey, 'Eli Zaretskii'

I added the comment from Eli about the documentation
and send this one out as a RFA.


Pierre


2010-04-08  Pierre Muller  <muller@ics.u-strasbg.fr>

	* gdbtypes.h (builtin_type): Add BUILTIN_CHAR16 and BUILTIN_CHAR32
	fields.
	* gdbtypes.c (gdbtypes_post_init): Set BUILTIN_CHAR16 and 
	BUILTIN_CHAR32 fields.
	* printcmd.c (decode_format): Set char size to '\0'
	for strings unless explicit size is given.
	(print_formatted): Correct calculation of NEXT_ADDRESS
	for 16 or 32 bit strings.
	(do_examine): Do not force byte size for strings.
	Use builtin_char16 and builtin_char32 types to display
	16 or 32 bit-wide strings. 
	(x_command): Set LAST_SIZE to 'b' for string type.

2010-04-08  Pierre Muller  <muller@ics.u-strasbg.fr>

      * gdb.texinfo (Examining memory): Update for
	change in string display with explicit size.

2010-04-08  Pierre Muller  <muller@ics.u-strasbg.fr>

	* gdb.base/charset.c (Strin16, String32): New variables.
	* gdb.base/charset.exp (gdb_test): Test correct display
	of 16 or 32 bit strings.
Index: src/gdb/gdbtypes.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtypes.c,v
retrieving revision 1.188
diff -u -p -r1.188 gdbtypes.c
--- src/gdb/gdbtypes.c	1 Mar 2010 17:19:22 -0000	1.188
+++ src/gdb/gdbtypes.c	5 Apr 2010 22:53:39 -0000
@@ -3474,6 +3474,13 @@ gdbtypes_post_init (struct gdbarch *gdba
   TYPE_NOTTEXT (builtin_type->builtin_int8) = 1;
   TYPE_NOTTEXT (builtin_type->builtin_uint8) = 1;
 
+  /* Multi-byte character types.  */
+  builtin_type->builtin_char16
+    = arch_integer_type (gdbarch, 16, 0, "char16_t");
+  builtin_type->builtin_char32
+    = arch_integer_type (gdbarch, 32, 0, "char32_t");
+	
+
   /* Default data/code pointer types.  */
   builtin_type->builtin_data_ptr
     = lookup_pointer_type (builtin_type->builtin_void);
Index: src/gdb/gdbtypes.h
===================================================================
RCS file: /cvs/src/src/gdb/gdbtypes.h,v
retrieving revision 1.125
diff -u -p -r1.125 gdbtypes.h
--- src/gdb/gdbtypes.h	15 Mar 2010 02:42:54 -0000	1.125
+++ src/gdb/gdbtypes.h	5 Apr 2010 22:53:39 -0000
@@ -1099,6 +1099,9 @@ struct builtin_type
   struct type *builtin_int128;
   struct type *builtin_uint128;
 
+  /* Multi-byte character types.  */
+  struct type *builtin_char16;
+  struct type *builtin_char32;
 
   /* Pointer types.  */
 
Index: src/gdb/printcmd.c
===================================================================
RCS file: /cvs/src/src/gdb/printcmd.c,v
retrieving revision 1.173
diff -u -p -r1.173 printcmd.c
--- src/gdb/printcmd.c	5 Mar 2010 20:18:14 -0000	1.173
+++ src/gdb/printcmd.c	5 Apr 2010 22:53:40 -0000
@@ -260,6 +260,11 @@ decode_format (char **string_ptr, int of
 	/* Characters default to one byte.  */
 	val.size = osize ? 'b' : osize;
 	break;
+      case 's':
+	/* Display strings with byte size chars unless explicitly specified.
*/
+	val.size = '\0';
+	break;
+
       default:
 	/* The default is the size most recently specified.  */
 	val.size = osize;
@@ -295,7 +300,7 @@ print_formatted (struct value *val, int 
 	    next_address = (value_address (val)
 			    + val_print_string (elttype,
 						value_address (val), -1,
-						stream, options));
+						stream, options) * len);
 	  }
 	  return;
 
@@ -802,9 +807,11 @@ do_examine (struct format_data fmt, stru
   next_gdbarch = gdbarch;
   next_address = addr;
 
-  /* String or instruction format implies fetch single bytes
-     regardless of the specified size.  */
-  if (format == 's' || format == 'i')
+  /* Instruction format implies fetch single bytes
+     regardless of the specified size.
+     The case of strings is handled n decode_format, only explicit
+     size operator are not changed to 'b'.  */
+  if (format == 'i')
     size = 'b';
 
   if (size == 'a')
@@ -831,6 +838,27 @@ do_examine (struct format_data fmt, stru
   else if (size == 'g')
     val_type = builtin_type (next_gdbarch)->builtin_int64;
 
+  if (format == 's')
+    {
+      struct type *char_type = NULL;
+      /* Search for "char16_t"  or "char32_t" types or fall back to 8-bit
char
+	 if type is not found.  */
+      if (size == 'h')
+	char_type = builtin_type (next_gdbarch)->builtin_char16;
+      else if (size == 'w')
+	char_type = builtin_type (next_gdbarch)->builtin_char32;
+      if (char_type)
+        val_type = char_type;
+      else
+        {
+	  if (size != '\0' && size != 'b')
+	    warning (_("Unable to display strings with size '%c', using 'b'
\
+instead."), size);
+	  size = 'b';
+	  val_type = builtin_type (next_gdbarch)->builtin_int8;
+        }
+    }
+
   maxelts = 8;
   if (size == 'w')
     maxelts = 4;
@@ -1412,8 +1440,11 @@ x_command (char *exp, int from_tty)
   do_examine (fmt, next_gdbarch, next_address);
 
   /* If the examine succeeds, we remember its size and format for next
-     time.  */
-  last_size = fmt.size;
+     time.  Set last_size to 'b' for strings.  */
+  if (fmt.format == 's')
+    last_size = 'b';
+  else
+    last_size = fmt.size;
   last_format = fmt.format;
 
   /* Set a couple of internal variables if appropriate. */
Index: src/gdb/doc/gdb.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.696
diff -u -p -r1.696 gdb.texinfo
--- src/gdb/doc/gdb.texinfo	5 Apr 2010 17:14:57 -0000	1.696
+++ src/gdb/doc/gdb.texinfo	5 Apr 2010 22:53:53 -0000
@@ -7236,8 +7236,16 @@ Giant words (eight bytes).
 @end table
 
 Each time you specify a unit size with @code{x}, that size becomes the
-default unit the next time you use @code{x}.  (For the @samp{s} and
-@samp{i} formats, the unit size is ignored and is normally not written.)
+default unit the next time you use @code{x}.  For the @samp{i} format,
+the unit size is ignored and is normally not written.  For the @samp{s}
format,
+the unit size defaults to @samp{b}, unless it is explicitly given.
+Use @kbd{x /hs} to display 16-bit char strings and @kbd{x /ws} to display
+32-bit strings.  The next use of @kbd{x /s} will again display 8-bit
strings.
+Note that the results depend on the programming language of the
+current compilation unit.  If the language is C, the @samp{s}
+modifier will use the UTF-16 encoding while @samp{w} will use
+UTF-32.  The encoding is set by the programming language and cannot
+be altered.
 
 @item @var{addr}, starting display address
 @var{addr} is the address where you want @value{GDBN} to begin displaying
Index: src/gdb/testsuite/gdb.base/charset.c
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/charset.c,v
retrieving revision 1.12
diff -u -p -r1.12 charset.c
--- src/gdb/testsuite/gdb.base/charset.c	1 Jan 2010 07:32:00 -0000
1.12
+++ src/gdb/testsuite/gdb.base/charset.c	5 Apr 2010 22:53:54 -0000
@@ -65,6 +65,9 @@ typedef unsigned int char32_t;
 char16_t uvar;
 char32_t Uvar;
 
+char16_t *String16;
+char32_t *String32;
+
 /* A typedef to a typedef should also work.  */
 typedef wchar_t my_wchar_t;
 my_wchar_t myvar;
Index: src/gdb/testsuite/gdb.base/charset.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/charset.exp,v
retrieving revision 1.21
diff -u -p -r1.21 charset.exp
--- src/gdb/testsuite/gdb.base/charset.exp	17 Feb 2010 22:05:58 -0000
1.21
+++ src/gdb/testsuite/gdb.base/charset.exp	5 Apr 2010 22:53:54 -0000
@@ -616,4 +616,21 @@ gdb_test "print 'a' == 'a' || 'b' == 'b'
   ".* = 1" \
   "EVAL_SKIP cleanup handling regression test"
 
+
+proc string_display { var_name set_prefix x_size x_type} {
+  gdb_test "set ${var_name} = ${set_prefix}\"Test String\\0with zeroes\""
"" "Assign ${var_name} with prefix ${set_prefix}"
+  gdb_test "x /2${x_size}s ${var_name}" ".* ${x_type}\"Test
String\"\[\r\n\]+.* ${x_type}\"with zeroes\"" "Display String ${var_name}
with x/${x_size}s"
+}
+
+string_display String16 u h u
+if {$wchar_size == 2} {
+  string_display String16 L h u
+}
+ 
+string_display String32 U w U
+if {$wchar_size == 4} {
+  string_display String32 L w U
+}
+
+
 gdb_exit 

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PING] [RFA-v3] Allow explicit 16 or 32 char in 'x /s'
  2010-04-08 20:58                     ` [RFA-v3] " Pierre Muller
@ 2010-04-16  8:41                       ` Pierre Muller
       [not found]                       ` <48335.255837492$1271407316@news.gmane.org>
  2010-06-11 17:38                       ` Ulrich Weigand
  2 siblings, 0 replies; 20+ messages in thread
From: Pierre Muller @ 2010-04-16  8:41 UTC (permalink / raw)
  To: tromey, gdb-patches; +Cc: 'Eli Zaretskii'

  Tom,
would you have some time to 
take again a look at this?

Pierre

> -----Message d'origine-----
> De : gdb-patches-owner@sourceware.org [mailto:gdb-patches-
> owner@sourceware.org] De la part de Pierre Muller
> Envoyé : Thursday, April 08, 2010 10:58 PM
> À : gdb-patches@sourceware.org
> Cc : tromey@redhat.com; 'Eli Zaretskii'
> Objet : [RFA-v3] Allow explicit 16 or 32 char in 'x /s'
> 
> I added the comment from Eli about the documentation
> and send this one out as a RFA.
> 
> 
> Pierre
> 
> 
> 2010-04-08  Pierre Muller  <muller@ics.u-strasbg.fr>
> 
> 	* gdbtypes.h (builtin_type): Add BUILTIN_CHAR16 and
> BUILTIN_CHAR32
> 	fields.
> 	* gdbtypes.c (gdbtypes_post_init): Set BUILTIN_CHAR16 and
> 	BUILTIN_CHAR32 fields.
> 	* printcmd.c (decode_format): Set char size to '\0'
> 	for strings unless explicit size is given.
> 	(print_formatted): Correct calculation of NEXT_ADDRESS
> 	for 16 or 32 bit strings.
> 	(do_examine): Do not force byte size for strings.
> 	Use builtin_char16 and builtin_char32 types to display
> 	16 or 32 bit-wide strings.
> 	(x_command): Set LAST_SIZE to 'b' for string type.
> 
> 2010-04-08  Pierre Muller  <muller@ics.u-strasbg.fr>
> 
>       * gdb.texinfo (Examining memory): Update for
> 	change in string display with explicit size.
> 
> 2010-04-08  Pierre Muller  <muller@ics.u-strasbg.fr>
> 
> 	* gdb.base/charset.c (Strin16, String32): New variables.
> 	* gdb.base/charset.exp (gdb_test): Test correct display
> 	of 16 or 32 bit strings.
> Index: src/gdb/gdbtypes.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/gdbtypes.c,v
> retrieving revision 1.188
> diff -u -p -r1.188 gdbtypes.c
> --- src/gdb/gdbtypes.c	1 Mar 2010 17:19:22 -0000	1.188
> +++ src/gdb/gdbtypes.c	5 Apr 2010 22:53:39 -0000
> @@ -3474,6 +3474,13 @@ gdbtypes_post_init (struct gdbarch *gdba
>    TYPE_NOTTEXT (builtin_type->builtin_int8) = 1;
>    TYPE_NOTTEXT (builtin_type->builtin_uint8) = 1;
> 
> +  /* Multi-byte character types.  */
> +  builtin_type->builtin_char16
> +    = arch_integer_type (gdbarch, 16, 0, "char16_t");
> +  builtin_type->builtin_char32
> +    = arch_integer_type (gdbarch, 32, 0, "char32_t");
> +
> +
>    /* Default data/code pointer types.  */
>    builtin_type->builtin_data_ptr
>      = lookup_pointer_type (builtin_type->builtin_void);
> Index: src/gdb/gdbtypes.h
> ===================================================================
> RCS file: /cvs/src/src/gdb/gdbtypes.h,v
> retrieving revision 1.125
> diff -u -p -r1.125 gdbtypes.h
> --- src/gdb/gdbtypes.h	15 Mar 2010 02:42:54 -0000	1.125
> +++ src/gdb/gdbtypes.h	5 Apr 2010 22:53:39 -0000
> @@ -1099,6 +1099,9 @@ struct builtin_type
>    struct type *builtin_int128;
>    struct type *builtin_uint128;
> 
> +  /* Multi-byte character types.  */
> +  struct type *builtin_char16;
> +  struct type *builtin_char32;
> 
>    /* Pointer types.  */
> 
> Index: src/gdb/printcmd.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/printcmd.c,v
> retrieving revision 1.173
> diff -u -p -r1.173 printcmd.c
> --- src/gdb/printcmd.c	5 Mar 2010 20:18:14 -0000	1.173
> +++ src/gdb/printcmd.c	5 Apr 2010 22:53:40 -0000
> @@ -260,6 +260,11 @@ decode_format (char **string_ptr, int of
>  	/* Characters default to one byte.  */
>  	val.size = osize ? 'b' : osize;
>  	break;
> +      case 's':
> +	/* Display strings with byte size chars unless explicitly
> specified.
> */
> +	val.size = '\0';
> +	break;
> +
>        default:
>  	/* The default is the size most recently specified.  */
>  	val.size = osize;
> @@ -295,7 +300,7 @@ print_formatted (struct value *val, int
>  	    next_address = (value_address (val)
>  			    + val_print_string (elttype,
>  						value_address (val), -1,
> -						stream, options));
> +						stream, options) * len);
>  	  }
>  	  return;
> 
> @@ -802,9 +807,11 @@ do_examine (struct format_data fmt, stru
>    next_gdbarch = gdbarch;
>    next_address = addr;
> 
> -  /* String or instruction format implies fetch single bytes
> -     regardless of the specified size.  */
> -  if (format == 's' || format == 'i')
> +  /* Instruction format implies fetch single bytes
> +     regardless of the specified size.
> +     The case of strings is handled n decode_format, only explicit
> +     size operator are not changed to 'b'.  */
> +  if (format == 'i')
>      size = 'b';
> 
>    if (size == 'a')
> @@ -831,6 +838,27 @@ do_examine (struct format_data fmt, stru
>    else if (size == 'g')
>      val_type = builtin_type (next_gdbarch)->builtin_int64;
> 
> +  if (format == 's')
> +    {
> +      struct type *char_type = NULL;
> +      /* Search for "char16_t"  or "char32_t" types or fall back to 8-
> bit
> char
> +	 if type is not found.  */
> +      if (size == 'h')
> +	char_type = builtin_type (next_gdbarch)->builtin_char16;
> +      else if (size == 'w')
> +	char_type = builtin_type (next_gdbarch)->builtin_char32;
> +      if (char_type)
> +        val_type = char_type;
> +      else
> +        {
> +	  if (size != '\0' && size != 'b')
> +	    warning (_("Unable to display strings with size '%c', using
> 'b'
> \
> +instead."), size);
> +	  size = 'b';
> +	  val_type = builtin_type (next_gdbarch)->builtin_int8;
> +        }
> +    }
> +
>    maxelts = 8;
>    if (size == 'w')
>      maxelts = 4;
> @@ -1412,8 +1440,11 @@ x_command (char *exp, int from_tty)
>    do_examine (fmt, next_gdbarch, next_address);
> 
>    /* If the examine succeeds, we remember its size and format for next
> -     time.  */
> -  last_size = fmt.size;
> +     time.  Set last_size to 'b' for strings.  */
> +  if (fmt.format == 's')
> +    last_size = 'b';
> +  else
> +    last_size = fmt.size;
>    last_format = fmt.format;
> 
>    /* Set a couple of internal variables if appropriate. */
> Index: src/gdb/doc/gdb.texinfo
> ===================================================================
> RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
> retrieving revision 1.696
> diff -u -p -r1.696 gdb.texinfo
> --- src/gdb/doc/gdb.texinfo	5 Apr 2010 17:14:57 -0000	1.696
> +++ src/gdb/doc/gdb.texinfo	5 Apr 2010 22:53:53 -0000
> @@ -7236,8 +7236,16 @@ Giant words (eight bytes).
>  @end table
> 
>  Each time you specify a unit size with @code{x}, that size becomes the
> -default unit the next time you use @code{x}.  (For the @samp{s} and
> -@samp{i} formats, the unit size is ignored and is normally not
> written.)
> +default unit the next time you use @code{x}.  For the @samp{i} format,
> +the unit size is ignored and is normally not written.  For the
> @samp{s}
> format,
> +the unit size defaults to @samp{b}, unless it is explicitly given.
> +Use @kbd{x /hs} to display 16-bit char strings and @kbd{x /ws} to
> display
> +32-bit strings.  The next use of @kbd{x /s} will again display 8-bit
> strings.
> +Note that the results depend on the programming language of the
> +current compilation unit.  If the language is C, the @samp{s}
> +modifier will use the UTF-16 encoding while @samp{w} will use
> +UTF-32.  The encoding is set by the programming language and cannot
> +be altered.
> 
>  @item @var{addr}, starting display address
>  @var{addr} is the address where you want @value{GDBN} to begin
> displaying
> Index: src/gdb/testsuite/gdb.base/charset.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/testsuite/gdb.base/charset.c,v
> retrieving revision 1.12
> diff -u -p -r1.12 charset.c
> --- src/gdb/testsuite/gdb.base/charset.c	1 Jan 2010 07:32:00 -0000
> 1.12
> +++ src/gdb/testsuite/gdb.base/charset.c	5 Apr 2010 22:53:54 -0000
> @@ -65,6 +65,9 @@ typedef unsigned int char32_t;
>  char16_t uvar;
>  char32_t Uvar;
> 
> +char16_t *String16;
> +char32_t *String32;
> +
>  /* A typedef to a typedef should also work.  */
>  typedef wchar_t my_wchar_t;
>  my_wchar_t myvar;
> Index: src/gdb/testsuite/gdb.base/charset.exp
> ===================================================================
> RCS file: /cvs/src/src/gdb/testsuite/gdb.base/charset.exp,v
> retrieving revision 1.21
> diff -u -p -r1.21 charset.exp
> --- src/gdb/testsuite/gdb.base/charset.exp	17 Feb 2010 22:05:58 -
> 0000
> 1.21
> +++ src/gdb/testsuite/gdb.base/charset.exp	5 Apr 2010 22:53:54 -
> 0000
> @@ -616,4 +616,21 @@ gdb_test "print 'a' == 'a' || 'b' == 'b'
>    ".* = 1" \
>    "EVAL_SKIP cleanup handling regression test"
> 
> +
> +proc string_display { var_name set_prefix x_size x_type} {
> +  gdb_test "set ${var_name} = ${set_prefix}\"Test String\\0with
> zeroes\""
> "" "Assign ${var_name} with prefix ${set_prefix}"
> +  gdb_test "x /2${x_size}s ${var_name}" ".* ${x_type}\"Test
> String\"\[\r\n\]+.* ${x_type}\"with zeroes\"" "Display String
> ${var_name}
> with x/${x_size}s"
> +}
> +
> +string_display String16 u h u
> +if {$wchar_size == 2} {
> +  string_display String16 L h u
> +}
> +
> +string_display String32 U w U
> +if {$wchar_size == 4} {
> +  string_display String32 L w U
> +}
> +
> +
>  gdb_exit


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PING] [RFA-v3] Allow explicit 16 or 32 char in 'x /s'
       [not found]                       ` <48335.255837492$1271407316@news.gmane.org>
@ 2010-04-21 22:49                         ` Tom Tromey
  2010-04-21 23:22                           ` Pierre Muller
  0 siblings, 1 reply; 20+ messages in thread
From: Tom Tromey @ 2010-04-21 22:49 UTC (permalink / raw)
  To: Pierre Muller; +Cc: gdb-patches, 'Eli Zaretskii'

>>>>> "Pierre" == Pierre Muller <pierre.muller@ics-cnrs.unistra.fr> writes:

Pierre>   Tom,
Pierre> would you have some time to 
Pierre> take again a look at this?

This looks pretty good.  A couple nits and it is ok.

>> +  /* Multi-byte character types.  */

I think it is more clear to describe these as "wide" character types.
I have usually seen "multi-byte" used synonymously with "variable length".

This comment appears twice.

>> +     The case of strings is handled n decode_format, only explicit

Typo, s/n/in/

Ok with those changes.  Thanks.

Tom

^ permalink raw reply	[flat|nested] 20+ messages in thread

* RE: [PING] [RFA-v3] Allow explicit 16 or 32 char in 'x /s'
  2010-04-21 22:49                         ` Tom Tromey
@ 2010-04-21 23:22                           ` Pierre Muller
  0 siblings, 0 replies; 20+ messages in thread
From: Pierre Muller @ 2010-04-21 23:22 UTC (permalink / raw)
  To: tromey; +Cc: gdb-patches



> -----Message d'origine-----
> De : gdb-patches-owner@sourceware.org [mailto:gdb-patches-
> owner@sourceware.org] De la part de Tom Tromey
> Envoyé : Thursday, April 22, 2010 12:49 AM
> À : Pierre Muller
> Cc : gdb-patches@sourceware.org; 'Eli Zaretskii'
> Objet : Re: [PING] [RFA-v3] Allow explicit 16 or 32 char in 'x /s'
> 
> >>>>> "Pierre" == Pierre Muller <pierre.muller@ics-cnrs.unistra.fr>
> writes:
> 
> Pierre>   Tom,
> Pierre> would you have some time to
> Pierre> take again a look at this?
> 
> This looks pretty good.  A couple nits and it is ok.
> 
> >> +  /* Multi-byte character types.  */
> 
> I think it is more clear to describe these as "wide" character types.
> I have usually seen "multi-byte" used synonymously with "variable
> length".
> 
> This comment appears twice.
> 
> >> +     The case of strings is handled n decode_format, only explicit
> 
> Typo, s/n/in/
> 
> Ok with those changes.  Thanks.

  Thanks for the review,
patch committed.

Pierre

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFA-v3] Allow explicit 16 or 32 char in 'x /s'
  2010-04-08 20:58                     ` [RFA-v3] " Pierre Muller
  2010-04-16  8:41                       ` [PING] " Pierre Muller
       [not found]                       ` <48335.255837492$1271407316@news.gmane.org>
@ 2010-06-11 17:38                       ` Ulrich Weigand
  2010-07-02 19:09                         ` Tom Tromey
  2 siblings, 1 reply; 20+ messages in thread
From: Ulrich Weigand @ 2010-06-11 17:38 UTC (permalink / raw)
  To: Pierre Muller; +Cc: gdb-patches, tromey, 'Eli Zaretskii'

Pierre Muller wrote:

> 2010-04-08  Pierre Muller  <muller@ics.u-strasbg.fr>
> 
> 	* gdb.base/charset.c (Strin16, String32): New variables.
> 	* gdb.base/charset.exp (gdb_test): Test correct display
> 	of 16 or 32 bit strings.

> +proc string_display { var_name set_prefix x_size x_type} {
> +  gdb_test "set ${var_name} = ${set_prefix}\"Test String\\0with zeroes\""

This test required that malloc is present in the inferior; if target
code is statically linked, we need to make sure the routine gets
pulled in (just like other testcases already do).

Tested on spu-elf, committed to mainline.

Bye,
Ulrich

ChangeLog:

	* gdb.base/charset.c (main): Make sure malloc gets linked in.

Index: gdb/testsuite/gdb.base/charset.c
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/charset.c,v
retrieving revision 1.13
diff -u -p -r1.13 charset.c
--- gdb/testsuite/gdb.base/charset.c	21 Apr 2010 23:21:04 -0000	1.13
+++ gdb/testsuite/gdb.base/charset.c	11 Jun 2010 16:43:07 -0000
@@ -120,6 +120,11 @@ int main ()
   set_debug_traps();
   breakpoint();
 #endif
+
+  /* charset.exp wants to allocate memory for constants.  So make sure malloc
+     gets linked into the program.  */
+  malloc (1);
+
   /* Initialize ascii_string.  */
   init_string (ascii_string,
                120,


-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFA-v3] Allow explicit 16 or 32 char in 'x /s'
  2010-06-11 17:38                       ` Ulrich Weigand
@ 2010-07-02 19:09                         ` Tom Tromey
  2010-07-05 10:17                           ` Ulrich Weigand
  0 siblings, 1 reply; 20+ messages in thread
From: Tom Tromey @ 2010-07-02 19:09 UTC (permalink / raw)
  To: Ulrich Weigand; +Cc: Pierre Muller, gdb-patches, 'Eli Zaretskii'

>>>>> "Ulrich" == Ulrich Weigand <uweigand@de.ibm.com> writes:

Ulrich> This test required that malloc is present in the inferior; if target
Ulrich> code is statically linked, we need to make sure the routine gets
Ulrich> pulled in (just like other testcases already do).

Ulrich> 	* gdb.base/charset.c (main): Make sure malloc gets linked in.

With this patch I now get:

Running ../../../src/gdb/testsuite/gdb.base/charset.exp ...
gdb compile failed, ../../../src/gdb/testsuite/gdb.base/charset.c: In function ‘main’:
../../../src/gdb/testsuite/gdb.base/charset.c:126: warning: incompatible implicit declaration of built-in function ‘malloc’



It isn't safe here to include <stdlib.h>, since this test intentionally
defines its own "wchar_t".

Adding:

extern void *malloc (int);

works for me, but it seems possibly problematic.

Maybe adding -fno-builtin for gcc is the thing to do?

I am not really sure what is best.  Any other ideas?

Tom

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFA-v3] Allow explicit 16 or 32 char in 'x /s'
  2010-07-02 19:09                         ` Tom Tromey
@ 2010-07-05 10:17                           ` Ulrich Weigand
  2010-07-20 20:13                             ` [patch] testsuite: regression on failed charset.exp compilation [Re: [RFA-v3] Allow explicit 16 or 32 char in 'x /s'] Jan Kratochvil
  0 siblings, 1 reply; 20+ messages in thread
From: Ulrich Weigand @ 2010-07-05 10:17 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Pierre Muller, gdb-patches, 'Eli Zaretskii'

Tom Tromey wrote:
> >>>>> "Ulrich" =3D=3D Ulrich Weigand <uweigand@de.ibm.com> writes:
> 
> Ulrich> This test required that malloc is present in the inferior; if target
> Ulrich> code is statically linked, we need to make sure the routine gets
> Ulrich> pulled in (just like other testcases already do).
> 
> Ulrich> 	* gdb.base/charset.c (main): Make sure malloc gets linked in.
> 
> With this patch I now get:
> 
> Running ../../../src/gdb/testsuite/gdb.base/charset.exp ...
> gdb compile failed, ../../../src/gdb/testsuite/gdb.base/charset.c: In function 'main':
> ../../../src/gdb/testsuite/gdb.base/charset.c:126: warning: incompatible implicit declaration of built-in function 'malloc'

Huh, sorry about that.

> It isn't safe here to include <stdlib.h>, since this test intentionally
> defines its own "wchar_t".
> 
> Adding:
> 
> extern void *malloc (int);
> 
> works for me, but it seems possibly problematic.

Yes, it really should be size_t, not int (and that may be a real issue
on some 64-bit systems).  But if you cannot include standard headers,
you don't get size_t either ...

> Maybe adding -fno-builtin for gcc is the thing to do?
> 
> I am not really sure what is best.  Any other ideas?

Can we split the testcase so that the parts that require the
non-standard wchar_t definition are separate from the parts
that construct strings in the inferior?

Bye,
Ulrich

-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [patch] testsuite: regression on failed charset.exp compilation   [Re: [RFA-v3] Allow explicit 16 or 32 char in 'x /s']
  2010-07-05 10:17                           ` Ulrich Weigand
@ 2010-07-20 20:13                             ` Jan Kratochvil
  2010-07-20 22:00                               ` Tom Tromey
  0 siblings, 1 reply; 20+ messages in thread
From: Jan Kratochvil @ 2010-07-20 20:13 UTC (permalink / raw)
  To: Ulrich Weigand
  Cc: Tom Tromey, Pierre Muller, gdb-patches, 'Eli Zaretskii'

On Mon, 05 Jul 2010 12:17:33 +0200, Ulrich Weigand wrote:
> Tom Tromey wrote:
> > >>>>> "Ulrich" =3D=3D Ulrich Weigand <uweigand@de.ibm.com> writes:
> > Ulrich> 	* gdb.base/charset.c (main): Make sure malloc gets linked in.
> > With this patch I now get:
> > Running ../../../src/gdb/testsuite/gdb.base/charset.exp ...
> > gdb compile failed, ../../../src/gdb/testsuite/gdb.base/charset.c: In function 'main':
> > ../../../src/gdb/testsuite/gdb.base/charset.c:126: warning: incompatible implicit declaration of built-in function 'malloc'
[...]
> Can we split the testcase so that the parts that require the
> non-standard wchar_t definition are separate from the parts
> that construct strings in the inferior?

Implemented.  OK to check-in?

This is a regression since gdb-7.1.

Testfile tested on x86_64-fedora13-linux-gnu.

While the malloc() result gets ignored warning gets generated only with
_FORTIFY_SOURCE level > 0 so we probably do not have to care about in the gdb
testsuite.


Thanks,
Jan


2010-07-20  Jan Kratochvil  <jan.kratochvil@redhat.com>
	    Ulrich Weigand  <uweigand@de.ibm.com>
	    Tom Tromey  <tromey@redhat.com>

	* gdb.base/charset-malloc.c: New file.
	* gdb.base/charset.c (malloc_stub): New prototype.
	(main): Call it instead of malloc itself.
	* gdb.base/charset.exp: Use only prepare_for_testing.
	(binfile): Remove the variable.

--- /dev/null
+++ b/gdb/testsuite/gdb.base/charset-malloc.c
@@ -0,0 +1,35 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2010 Free Software Foundation, Inc.
+
+   Contributed by Red Hat, originally written by Jim Blandy.
+
+   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 3 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, see <http://www.gnu.org/licenses/>.
+
+   Please email any bugs, comments, and/or additions to this file to:
+   bug-gdb@gnu.org  */
+
+/* charset.c file cannot use a system include file as it has its own wchar_t
+   definition which would be in a conflict.  Use this separate compilation
+   unit.  */
+
+#include <stdlib.h>
+
+void
+malloc_stub (void)
+{
+  /* charset.exp wants to allocate memory for constants.  So make sure malloc
+     gets linked into the program.  */
+  malloc (1);
+}
--- a/gdb/testsuite/gdb.base/charset.c
+++ b/gdb/testsuite/gdb.base/charset.c
@@ -114,6 +114,8 @@ init_utf32 ()
     utf_32_string[i] = iso_8859_1_string[i] & 0xff;
 }
 
+extern void malloc_stub (void);
+
 int main ()
 {
 #ifdef usestubs
@@ -121,9 +123,7 @@ int main ()
   breakpoint();
 #endif
 
-  /* charset.exp wants to allocate memory for constants.  So make sure malloc
-     gets linked into the program.  */
-  malloc (1);
+  malloc_stub ();
 
   /* Initialize ascii_string.  */
   init_string (ascii_string,
--- a/gdb/testsuite/gdb.base/charset.exp
+++ b/gdb/testsuite/gdb.base/charset.exp
@@ -27,18 +27,11 @@ if $tracelevel then {
 
 set testfile "charset"
 set srcfile ${testfile}.c
-set binfile ${objdir}/${subdir}/${testfile}
-if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
-    untested "couldn't compile ${srcdir}/${subdir}/${srcfile}"
+set srcmallocfile ${testfile}-malloc.c
+if { [prepare_for_testing ${testfile}.exp ${testfile} [list $srcfile $srcmallocfile]] } {
     return -1
 }
 
-# Start with a fresh gdb.
-gdb_exit
-gdb_start
-gdb_reinitialize_dir $srcdir/$subdir
-gdb_load ${binfile}
-
 # Parse the output from a `show charset' command.  Return the host
 # and target charset as a two-element list.
 proc parse_show_charset_output {testname} {

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [patch] testsuite: regression on failed charset.exp compilation   [Re: [RFA-v3] Allow explicit 16 or 32 char in 'x /s']
  2010-07-20 20:13                             ` [patch] testsuite: regression on failed charset.exp compilation [Re: [RFA-v3] Allow explicit 16 or 32 char in 'x /s'] Jan Kratochvil
@ 2010-07-20 22:00                               ` Tom Tromey
  2010-07-20 22:13                                 ` Jan Kratochvil
  0 siblings, 1 reply; 20+ messages in thread
From: Tom Tromey @ 2010-07-20 22:00 UTC (permalink / raw)
  To: Jan Kratochvil
  Cc: Ulrich Weigand, Pierre Muller, gdb-patches, 'Eli Zaretskii'

>>>>> "Jan" == Jan Kratochvil <jan.kratochvil@redhat.com> writes:

Jan> Implemented.  OK to check-in?

Yes, thanks.
Please put it on the 7.2 branch as well.

Tom

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [patch] testsuite: regression on failed charset.exp compilation   [Re: [RFA-v3] Allow explicit 16 or 32 char in 'x /s']
  2010-07-20 22:00                               ` Tom Tromey
@ 2010-07-20 22:13                                 ` Jan Kratochvil
  0 siblings, 0 replies; 20+ messages in thread
From: Jan Kratochvil @ 2010-07-20 22:13 UTC (permalink / raw)
  To: Tom Tromey
  Cc: Ulrich Weigand, Pierre Muller, gdb-patches, 'Eli Zaretskii'

On Wed, 21 Jul 2010 00:00:22 +0200, Tom Tromey wrote:
> Yes, thanks.

Checked-in:
	http://sourceware.org/ml/gdb-cvs/2010-07/msg00116.html


> Please put it on the 7.2 branch as well.

Checked-in gdb_7_2-branch:
	http://sourceware.org/ml/gdb-cvs/2010-07/msg00117.html


Thanks,
Jan

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2010-07-20 22:13 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <11484.4708740295$1268865815@news.gmane.org>
2010-03-18 22:08 ` [RFC] Allow explicit 16 or 32 char in 'x /s' Tom Tromey
2010-03-19  7:32   ` Eli Zaretskii
2010-03-22 22:54     ` Pierre Muller
     [not found]     ` <15103.6087111153$1269298497@news.gmane.org>
2010-03-30 20:33       ` Tom Tromey
2010-03-31 16:11         ` [RFC-v2] " Pierre Muller
     [not found]         ` <006101cad0ec$cb7915d0$626b4170$%muller@ics-cnrs.unistra.fr>
2010-03-31 16:17           ` Eli Zaretskii
2010-04-01  9:34             ` Pierre Muller
     [not found]             ` <000f01cad17e$7686f140$6394d3c0$%muller@ics-cnrs.unistra.fr>
2010-04-01 13:17               ` Eli Zaretskii
2010-04-05 23:01                 ` Pierre Muller
     [not found]                 ` <002701cad513$e44a7420$acdf5c60$%muller@ics-cnrs.unistra.fr>
2010-04-06 17:51                   ` Eli Zaretskii
2010-04-08 20:58                     ` [RFA-v3] " Pierre Muller
2010-04-16  8:41                       ` [PING] " Pierre Muller
     [not found]                       ` <48335.255837492$1271407316@news.gmane.org>
2010-04-21 22:49                         ` Tom Tromey
2010-04-21 23:22                           ` Pierre Muller
2010-06-11 17:38                       ` Ulrich Weigand
2010-07-02 19:09                         ` Tom Tromey
2010-07-05 10:17                           ` Ulrich Weigand
2010-07-20 20:13                             ` [patch] testsuite: regression on failed charset.exp compilation [Re: [RFA-v3] Allow explicit 16 or 32 char in 'x /s'] Jan Kratochvil
2010-07-20 22:00                               ` Tom Tromey
2010-07-20 22:13                                 ` Jan Kratochvil

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).