lkml.org 
[lkml]   [2019]   [Oct]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] tools/lib/traceevent, perf tools: Handle %pU format correctly
On Wed, 16 Oct 2019 14:39:20 +0800
Qu Wenruo <wqu@suse.com> wrote:

> +static void print_uuid_arg(struct trace_seq *s, void *data, int size,
> + struct tep_event *event, struct tep_print_arg *arg)
> +{
> + const char *fmt;
> + unsigned char *buf;
> +
> + fmt = "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x";
> + if (arg->type != TEP_PRINT_FIELD) {
> + trace_seq_printf(s, "ARG TYPE NOT FIELID but %d", arg->type);
> + return;
> + }
> +
> + if (!arg->field.field) {
> + arg->field.field = tep_find_any_field(event, arg->field.name);
> + if (!arg->field.field) {
> + do_warning("%s: field %s not found",
> + __func__, arg->field.name);
> + return;
> + }
> + }
> + buf = data + arg->field.field->offset;

You also need to make sure the data field is not smaller than 16 bytes.

if (arg->field.field->size < 16) {
trace_seq_puts(s, "INVALIDUUID");
return;
}

> +
> + trace_seq_printf(s, fmt, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5],
> + buf[6], buf[7], buf[8], buf[9], buf[10], buf[11], buf[12],
> + buf[13], buf[14], buf[15]);
> +}
> +

Hmm, I know print_mac_addr() does something similar as this, but this
is getting a bit extreme (too many arguments!). What about doing:

for (i = 0; i < 4; i++)
trace_seq_printf(s, "%02x", buf++);

for (i = 0; i < 3; i++)
trace_seq_printf(s, "-%02x%02x", buf[i * 2], buf[i * 2 + 1]);

buf += 6;

trace_seq_putc(s, '-');

for (i = 0; i < 6; i++)
trace_seq_printf(s, "%02x", buf++);



Hmm, not sure the above is better, but having that many arguments just
looks ugly to me.

-- Steve

\
 
 \ /
  Last update: 2019-10-16 16:56    [W:0.059 / U:1.504 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site