libtraceveent: Add printable characters
PATCH 1/1 libtraceveent: Add printable characters
From: Steven Rostedt <[email protected]>
If an array of characters are all printable, print the string it represents.
Signed-off-by Steven Rostedt <[email protected]>
--- src/event-parse.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)
src/event-parse.c +28 -1
@@ -5416,6 +5416,7 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,case TEP_PRINT_INT_ARRAY : {void *num;int el_size; +int is_print =0 ; len =0 ;
@@ -5450,7 +5451,20 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,trace_seq_putc (s,',' );if (el_size ==1 ) { -trace_seq_printf (s,"0x%x" , *(uint8_t *)num); +int ch = *(uint8_t *)num; + +trace_seq_printf (s,"0x%x" , ch); + +if (!is_print) + is_print =1 ; + +/* +* Only print string if all characters are +* printable +*/ +if (is_print && !isprint (ch) && !isspace (ch)) + is_print =-1 ; + }else if (el_size ==2 ) {trace_seq_printf (s,"0x%x" , *(uint16_t *)num); }else if (el_size ==4 ) {
@@ -5466,6 +5480,19 @@ static void print_str_arg(struct trace_seq *s, void *data, int size, num += el_size; }trace_seq_putc (s,'}' ); + +if (is_print ==1 ) { +char *p = data + offset; + +trace_seq_puts (s," \"" ); +for (i =0 ; i < len; i++) { +if (p[i] =='\n' ) +trace_seq_puts (s,"\\n" ); +else +trace_seq_putc (s, p[i]); + } +trace_seq_putc (s,'"' ); + }break ; }case TEP_PRINT_TYPE :
Signature · 1 line
2.51.0