public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix display of tabulation character for mingw hosts.
@ 2014-05-05  9:29 Yao Qi
  2014-05-05  9:40 ` Yao Qi
  2014-05-13  9:22 ` ping: " Yao Qi
  0 siblings, 2 replies; 5+ messages in thread
From: Yao Qi @ 2014-05-05  9:29 UTC (permalink / raw)
  To: gdb-patches

Pierre proposed this patch
https://sourceware.org/ml/gdb-patches/2013-10/msg00011.html and
Tom gave a suggestion that it's better to do check \t in print_wchar
<https://sourceware.org/ml/gdb-patches/2013-11/msg00148.html>
However, I don't see the follow-up to this discussion.

We encounter two fails in printcmds.exp on mingw host, and Pierre's
patch fixes them.  I pick it up, update a little per Tom's
comments, and post it here for review.  This patch fixes these fails
below on mingw32 host.

FAIL: gdb.base/charset.exp: print string in ASCII
FAIL: gdb.base/charset.exp: try printing '\t' in ASCII
FAIL: gdb.base/charset.exp: print string in ISO-8859-1
FAIL: gdb.base/charset.exp: try printing '\t' in ISO-8859-1
FAIL: gdb.base/charset.exp: print string in UTF-32
FAIL: gdb.base/charset.exp: try printing '\t' in UTF-32
FAIL: gdb.base/printcmds.exp: p ctable1[9]
FAIL: gdb.base/printcmds.exp: p &ctable1[1*8]

Also regression tested on x86_64-linux.  Is it OK?

gdb:

2014-05-05  Pierre Muller  <muller@sourceware.org>
	    Yao Qi  <yao@codesourcery.com>

	* valprint.c (print_wchar): Move the code on checking whether
	W is a printable wide char to the default branch of switch
	statement below.  Call wchar_printable instead of gdb_iswprint.
---
 gdb/valprint.c | 122 +++++++++++++++++++++++++++++----------------------------
 1 file changed, 63 insertions(+), 59 deletions(-)

diff --git a/gdb/valprint.c b/gdb/valprint.c
index fe23530..f55b5db 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -1949,73 +1949,77 @@ print_wchar (gdb_wint_t w, const gdb_byte *orig,
   int need_escape = *need_escapep;
 
   *need_escapep = 0;
-  if (gdb_iswprint (w) && (!need_escape || (!gdb_iswdigit (w)
-					    && w != LCST ('8')
-					    && w != LCST ('9'))))
-    {
-      gdb_wchar_t wchar = w;
 
-      if (w == gdb_btowc (quoter) || w == LCST ('\\'))
-	obstack_grow_wstr (output, LCST ("\\"));
-      obstack_grow (output, &wchar, sizeof (gdb_wchar_t));
-    }
-  else
+  /* iswprint implementation on Windows returns 1 for tab character.
+     In order to avoid different printout on this host, we explicitly
+     use wchar_printable function.  */
+  switch (w)
     {
-      switch (w)
+      case LCST ('\a'):
+	obstack_grow_wstr (output, LCST ("\\a"));
+	break;
+      case LCST ('\b'):
+	obstack_grow_wstr (output, LCST ("\\b"));
+	break;
+      case LCST ('\f'):
+	obstack_grow_wstr (output, LCST ("\\f"));
+	break;
+      case LCST ('\n'):
+	obstack_grow_wstr (output, LCST ("\\n"));
+	break;
+      case LCST ('\r'):
+	obstack_grow_wstr (output, LCST ("\\r"));
+	break;
+      case LCST ('\t'):
+	obstack_grow_wstr (output, LCST ("\\t"));
+	break;
+      case LCST ('\v'):
+	obstack_grow_wstr (output, LCST ("\\v"));
+	break;
+      default:
 	{
-	case LCST ('\a'):
-	  obstack_grow_wstr (output, LCST ("\\a"));
-	  break;
-	case LCST ('\b'):
-	  obstack_grow_wstr (output, LCST ("\\b"));
-	  break;
-	case LCST ('\f'):
-	  obstack_grow_wstr (output, LCST ("\\f"));
-	  break;
-	case LCST ('\n'):
-	  obstack_grow_wstr (output, LCST ("\\n"));
-	  break;
-	case LCST ('\r'):
-	  obstack_grow_wstr (output, LCST ("\\r"));
-	  break;
-	case LCST ('\t'):
-	  obstack_grow_wstr (output, LCST ("\\t"));
-	  break;
-	case LCST ('\v'):
-	  obstack_grow_wstr (output, LCST ("\\v"));
-	  break;
-	default:
-	  {
-	    int i;
+	  if (wchar_printable (w) && (!need_escape || (!gdb_iswdigit (w)
+						       && w != LCST ('8')
+						       && w != LCST ('9'))))
+	    {
+	      gdb_wchar_t wchar = w;
 
-	    for (i = 0; i + width <= orig_len; i += width)
-	      {
-		char octal[30];
-		ULONGEST value;
+	      if (w == gdb_btowc (quoter) || w == LCST ('\\'))
+		obstack_grow_wstr (output, LCST ("\\"));
+	      obstack_grow (output, &wchar, sizeof (gdb_wchar_t));
+	    }
+	  else
+	    {
+	      int i;
+
+	      for (i = 0; i + width <= orig_len; i += width)
+		{
+		  char octal[30];
+		  ULONGEST value;
 
-		value = extract_unsigned_integer (&orig[i], width,
+		  value = extract_unsigned_integer (&orig[i], width,
 						  byte_order);
-		/* If the value fits in 3 octal digits, print it that
-		   way.  Otherwise, print it as a hex escape.  */
-		if (value <= 0777)
-		  xsnprintf (octal, sizeof (octal), "\\%.3o",
-			     (int) (value & 0777));
-		else
-		  xsnprintf (octal, sizeof (octal), "\\x%lx", (long) value);
-		append_string_as_wide (octal, output);
-	      }
-	    /* If we somehow have extra bytes, print them now.  */
-	    while (i < orig_len)
-	      {
-		char octal[5];
+		  /* If the value fits in 3 octal digits, print it that
+		     way.  Otherwise, print it as a hex escape.  */
+		  if (value <= 0777)
+		    xsnprintf (octal, sizeof (octal), "\\%.3o",
+			       (int) (value & 0777));
+		  else
+		    xsnprintf (octal, sizeof (octal), "\\x%lx", (long) value);
+		  append_string_as_wide (octal, output);
+		}
+	      /* If we somehow have extra bytes, print them now.  */
+	      while (i < orig_len)
+		{
+		  char octal[5];
 
-		xsnprintf (octal, sizeof (octal), "\\%.3o", orig[i] & 0xff);
-		append_string_as_wide (octal, output);
-		++i;
-	      }
+		  xsnprintf (octal, sizeof (octal), "\\%.3o", orig[i] & 0xff);
+		  append_string_as_wide (octal, output);
+		  ++i;
+		}
 
-	    *need_escapep = 1;
-	  }
+	      *need_escapep = 1;
+	    }
 	  break;
 	}
     }
-- 
1.9.0

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

* Re: [PATCH] Fix display of tabulation character for mingw hosts.
  2014-05-05  9:29 [PATCH] Fix display of tabulation character for mingw hosts Yao Qi
@ 2014-05-05  9:40 ` Yao Qi
  2014-05-13  9:22 ` ping: " Yao Qi
  1 sibling, 0 replies; 5+ messages in thread
From: Yao Qi @ 2014-05-05  9:40 UTC (permalink / raw)
  To: gdb-patches

To make the patch more readable, here is the diff generated with
'git diff -b'.

-- 
Yao (齐尧)

diff --git a/gdb/valprint.c b/gdb/valprint.c
index fe23530..f55b5db 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -1949,18 +1949,10 @@ print_wchar (gdb_wint_t w, const gdb_byte *orig,
   int need_escape = *need_escapep;
 
   *need_escapep = 0;
-  if (gdb_iswprint (w) && (!need_escape || (!gdb_iswdigit (w)
-					    && w != LCST ('8')
-					    && w != LCST ('9'))))
-    {
-      gdb_wchar_t wchar = w;
 
-      if (w == gdb_btowc (quoter) || w == LCST ('\\'))
-	obstack_grow_wstr (output, LCST ("\\"));
-      obstack_grow (output, &wchar, sizeof (gdb_wchar_t));
-    }
-  else
-    {
+  /* iswprint implementation on Windows returns 1 for tab character.
+     In order to avoid different printout on this host, we explicitly
+     use wchar_printable function.  */
   switch (w)
     {
       case LCST ('\a'):
@@ -1986,6 +1978,18 @@ print_wchar (gdb_wint_t w, const gdb_byte *orig,
 	break;
       default:
 	{
+	  if (wchar_printable (w) && (!need_escape || (!gdb_iswdigit (w)
+						       && w != LCST ('8')
+						       && w != LCST ('9'))))
+	    {
+	      gdb_wchar_t wchar = w;
+
+	      if (w == gdb_btowc (quoter) || w == LCST ('\\'))
+		obstack_grow_wstr (output, LCST ("\\"));
+	      obstack_grow (output, &wchar, sizeof (gdb_wchar_t));
+	    }
+	  else
+	    {
 	      int i;
 
 	      for (i = 0; i + width <= orig_len; i += width)

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

* ping: [PATCH] Fix display of tabulation character for mingw hosts.
  2014-05-05  9:29 [PATCH] Fix display of tabulation character for mingw hosts Yao Qi
  2014-05-05  9:40 ` Yao Qi
@ 2014-05-13  9:22 ` Yao Qi
  2014-05-15 17:31   ` Tom Tromey
  1 sibling, 1 reply; 5+ messages in thread
From: Yao Qi @ 2014-05-13  9:22 UTC (permalink / raw)
  To: gdb-patches

On 05/05/2014 05:26 PM, Yao Qi wrote:
> Pierre proposed this patch
> https://sourceware.org/ml/gdb-patches/2013-10/msg00011.html and
> Tom gave a suggestion that it's better to do check \t in print_wchar
> <https://sourceware.org/ml/gdb-patches/2013-11/msg00148.html>
> However, I don't see the follow-up to this discussion.
> 
> We encounter two fails in printcmds.exp on mingw host, and Pierre's
> patch fixes them.  I pick it up, update a little per Tom's
> comments, and post it here for review.  This patch fixes these fails
> below on mingw32 host.
> 
> FAIL: gdb.base/charset.exp: print string in ASCII
> FAIL: gdb.base/charset.exp: try printing '\t' in ASCII
> FAIL: gdb.base/charset.exp: print string in ISO-8859-1
> FAIL: gdb.base/charset.exp: try printing '\t' in ISO-8859-1
> FAIL: gdb.base/charset.exp: print string in UTF-32
> FAIL: gdb.base/charset.exp: try printing '\t' in UTF-32
> FAIL: gdb.base/printcmds.exp: p ctable1[9]
> FAIL: gdb.base/printcmds.exp: p &ctable1[1*8]
> 
> Also regression tested on x86_64-linux.  Is it OK?
> 
> gdb:
> 
> 2014-05-05  Pierre Muller  <muller@sourceware.org>
> 	    Yao Qi  <yao@codesourcery.com>
> 
> 	* valprint.c (print_wchar): Move the code on checking whether
> 	W is a printable wide char to the default branch of switch
> 	statement below.  Call wchar_printable instead of gdb_iswprint.

Ping.  https://sourceware.org/ml/gdb-patches/2014-05/msg00034.html

-- 
Yao (齐尧)

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

* Re: ping: [PATCH] Fix display of tabulation character for mingw hosts.
  2014-05-13  9:22 ` ping: " Yao Qi
@ 2014-05-15 17:31   ` Tom Tromey
  2014-05-16 12:22     ` Yao Qi
  0 siblings, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2014-05-15 17:31 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

>> 2014-05-05  Pierre Muller  <muller@sourceware.org>
>> Yao Qi  <yao@codesourcery.com>
>> 
>> * valprint.c (print_wchar): Move the code on checking whether
>> W is a printable wide char to the default branch of switch
>> statement below.  Call wchar_printable instead of gdb_iswprint.

Yao> Ping.  https://sourceware.org/ml/gdb-patches/2014-05/msg00034.html

Thanks, this is ok.

Tom

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

* Re: ping: [PATCH] Fix display of tabulation character for mingw hosts.
  2014-05-15 17:31   ` Tom Tromey
@ 2014-05-16 12:22     ` Yao Qi
  0 siblings, 0 replies; 5+ messages in thread
From: Yao Qi @ 2014-05-16 12:22 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

On 05/16/2014 01:31 AM, Tom Tromey wrote:
>>> 2014-05-05  Pierre Muller  <muller@sourceware.org>
>>> Yao Qi  <yao@codesourcery.com>
>>>
>>> * valprint.c (print_wchar): Move the code on checking whether
>>> W is a printable wide char to the default branch of switch
>>> statement below.  Call wchar_printable instead of gdb_iswprint.
> 
> Yao> Ping.  https://sourceware.org/ml/gdb-patches/2014-05/msg00034.html
> 
> Thanks, this is ok.
> 

Thanks for the review.  Patch is pushed in.

-- 
Yao (齐尧)

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

end of thread, other threads:[~2014-05-16 12:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-05  9:29 [PATCH] Fix display of tabulation character for mingw hosts Yao Qi
2014-05-05  9:40 ` Yao Qi
2014-05-13  9:22 ` ping: " Yao Qi
2014-05-15 17:31   ` Tom Tromey
2014-05-16 12:22     ` Yao Qi

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).