diff mbox

Escape non-printable chars in dumped strings.

Message ID 5e9b02e8-9bf7-5429-fda7-2b6efbcbef0a@suse.cz
State New
Headers show

Commit Message

Martin Liška Dec. 8, 2016, 1:37 p.m. UTC
Hello.

Following patch changes behavior in pretty_print_string, where all non-printable
characters are encoded as \x%x. Currently, when some non-printable characters are directly
printed to a dump file stream. That makes it complicated to read a dump file for instance
via a Python script.

Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.

Ready to be installed?
Martin

Comments

Richard Biener Dec. 9, 2016, 10 a.m. UTC | #1
On Thu, Dec 8, 2016 at 2:37 PM, Martin Liška <mliska@suse.cz> wrote:
> Hello.

>

> Following patch changes behavior in pretty_print_string, where all non-printable

> characters are encoded as \x%x. Currently, when some non-printable characters are directly

> printed to a dump file stream. That makes it complicated to read a dump file for instance

> via a Python script.

>

> Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.

>

> Ready to be installed?


Ok.  Does ISPRINT ('\') yield true or false?  That is, I suppose we
want to escape that?

> Martin
Martin Liška Dec. 9, 2016, 10:05 a.m. UTC | #2
On 12/09/2016 11:00 AM, Richard Biener wrote:
> On Thu, Dec 8, 2016 at 2:37 PM, Martin Liška <mliska@suse.cz> wrote:

>> Hello.

>>

>> Following patch changes behavior in pretty_print_string, where all non-printable

>> characters are encoded as \x%x. Currently, when some non-printable characters are directly

>> printed to a dump file stream. That makes it complicated to read a dump file for instance

>> via a Python script.

>>

>> Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.

>>

>> Ready to be installed?

> 

> Ok.  Does ISPRINT ('\') yield true or false?  That is, I suppose we

> want to escape that?


You mean '\\', which is already covered by a case:

	case '\\':
	  pp_string (pp, "\\\\");
	  break;

I'm going to install the patch.

Martin


> 

>> Martin
Richard Biener Dec. 9, 2016, 10:13 a.m. UTC | #3
On Fri, Dec 9, 2016 at 11:05 AM, Martin Liška <mliska@suse.cz> wrote:
> On 12/09/2016 11:00 AM, Richard Biener wrote:

>> On Thu, Dec 8, 2016 at 2:37 PM, Martin Liška <mliska@suse.cz> wrote:

>>> Hello.

>>>

>>> Following patch changes behavior in pretty_print_string, where all non-printable

>>> characters are encoded as \x%x. Currently, when some non-printable characters are directly

>>> printed to a dump file stream. That makes it complicated to read a dump file for instance

>>> via a Python script.

>>>

>>> Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.

>>>

>>> Ready to be installed?

>>

>> Ok.  Does ISPRINT ('\') yield true or false?  That is, I suppose we

>> want to escape that?

>

> You mean '\\', which is already covered by a case:

>

>         case '\\':

>           pp_string (pp, "\\\\");

>           break;


Ah, I see.

> I'm going to install the patch.


Thanks.

> Martin

>

>

>>

>>> Martin

>
diff mbox

Patch

From 0241ee4a366d3c4912def45770945b17c528f920 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Thu, 8 Dec 2016 11:22:44 +0100
Subject: [PATCH] Escape non-printable chars in strings.

gcc/ChangeLog:

2016-12-08  Martin Liska  <mliska@suse.cz>

	* tree-pretty-print.c (pretty_print_string): Escape non-printable
	chars in strings.
---
 gcc/tree-pretty-print.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/gcc/tree-pretty-print.c b/gcc/tree-pretty-print.c
index 95db710..5b3e23e 100644
--- a/gcc/tree-pretty-print.c
+++ b/gcc/tree-pretty-print.c
@@ -3869,7 +3869,14 @@  pretty_print_string (pretty_printer *pp, const char *str)
 	  break;
 
 	default:
-	  pp_character (pp, str[0]);
+	  if (!ISPRINT (str[0]))
+	    {
+	      char buf[5];
+	      sprintf (buf, "\\x%x", (unsigned char)str[0]);
+	      pp_string (pp, buf);
+	    }
+	  else
+	    pp_character (pp, str[0]);
 	  break;
 	}
       str++;
-- 
2.10.2