lkml.org 
[lkml]   [2019]   [Oct]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH] tools/lib/traceevent, perf tools: Handle %pU format correctly
From
Date


On 2019/10/16 下午10:54, Steven Rostedt wrote:
> 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;
> }
>

Oh, forgot that sanity check.

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

Indeed, I'll update the patchset to make it more sane.

Thanks,
Qu
>
> -- Steve
>

[unhandled content-type:application/pgp-signature]
\
 
 \ /
  Last update: 2019-10-17 01:47    [W:0.085 / U:0.528 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site