2009-10-14 19:48:51

by Steven Rostedt

[permalink] [raw]
Subject: [PATCH 02/13] [PATCH 02/13] perf tools: fix backslash processing on trace print formats

From: Steven Rostedt <[email protected]>

The handling of backslashes was broken. It would stop parsing when
accountering one. Also, '\n', '\t', '\r' and '\\' were not converted.

Signed-off-by: Steven Rostedt <[email protected]>
---
tools/perf/util/trace-event-parse.c | 27 +++++++++++++++++++++++++--
1 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/trace-event-parse.c b/tools/perf/util/trace-event-parse.c
index 2fee75f..cae88de 100644
--- a/tools/perf/util/trace-event-parse.c
+++ b/tools/perf/util/trace-event-parse.c
@@ -522,7 +522,10 @@ static enum event_type __read_token(char **tok)
last_ch = ch;
ch = __read_char();
buf[i++] = ch;
- } while (ch != quote_ch && last_ch != '\\');
+ /* the '\' '\' will cancel itself */
+ if (ch == '\\' && last_ch == '\\')
+ last_ch = 0;
+ } while (ch != quote_ch || last_ch == '\\');
/* remove the last quote */
i--;
goto out;
@@ -2325,7 +2328,27 @@ static void pretty_print(void *data, int size, struct event *event)

for (; *ptr; ptr++) {
ls = 0;
- if (*ptr == '%') {
+ if (*ptr == '\\') {
+ ptr++;
+ switch (*ptr) {
+ case 'n':
+ printf("\n");
+ break;
+ case 't':
+ printf("\t");
+ break;
+ case 'r':
+ printf("\r");
+ break;
+ case '\\':
+ printf("\\");
+ break;
+ default:
+ printf("%c", *ptr);
+ break;
+ }
+
+ } else if (*ptr == '%') {
saveptr = ptr;
show_func = 0;
cont_process:
--
1.6.3.3


2009-10-15 08:49:39

by Steven Rostedt

[permalink] [raw]
Subject: [tip:perf/core] perf tools: Fix backslash processing on trace print formats

Commit-ID: 91ff2bc191827f0d3f5ad0a433ff7df7d2dd9aee
Gitweb: http://git.kernel.org/tip/91ff2bc191827f0d3f5ad0a433ff7df7d2dd9aee
Author: Steven Rostedt <[email protected]>
AuthorDate: Wed, 14 Oct 2009 15:43:33 -0400
Committer: Ingo Molnar <[email protected]>
CommitDate: Thu, 15 Oct 2009 10:42:35 +0200

perf tools: Fix backslash processing on trace print formats

The handling of backslashes was broken. It would stop parsing
when encountering one. Also, '\n', '\t', '\r' and '\\' were not
converted.

Signed-off-by: Steven Rostedt <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
LKML-Reference: <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
---
tools/perf/util/trace-event-parse.c | 27 +++++++++++++++++++++++++--
1 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/trace-event-parse.c b/tools/perf/util/trace-event-parse.c
index a05c714..2b75ec2 100644
--- a/tools/perf/util/trace-event-parse.c
+++ b/tools/perf/util/trace-event-parse.c
@@ -522,7 +522,10 @@ static enum event_type __read_token(char **tok)
last_ch = ch;
ch = __read_char();
buf[i++] = ch;
- } while (ch != quote_ch && last_ch != '\\');
+ /* the '\' '\' will cancel itself */
+ if (ch == '\\' && last_ch == '\\')
+ last_ch = 0;
+ } while (ch != quote_ch || last_ch == '\\');
/* remove the last quote */
i--;
goto out;
@@ -2325,7 +2328,27 @@ static void pretty_print(void *data, int size, struct event *event)

for (; *ptr; ptr++) {
ls = 0;
- if (*ptr == '%') {
+ if (*ptr == '\\') {
+ ptr++;
+ switch (*ptr) {
+ case 'n':
+ printf("\n");
+ break;
+ case 't':
+ printf("\t");
+ break;
+ case 'r':
+ printf("\r");
+ break;
+ case '\\':
+ printf("\\");
+ break;
+ default:
+ printf("%c", *ptr);
+ break;
+ }
+
+ } else if (*ptr == '%') {
saveptr = ptr;
show_func = 0;
cont_process: