Re: [RFC PATCH v6 1/9] tracing: Add array printing helpers

From: Dave P Martin
Date: Mon Dec 08 2014 - 11:04:11 EST


On Mon, Dec 08, 2014 at 03:42:10PM +0000, Steven Rostedt wrote:
> On Fri, 5 Dec 2014 19:04:12 +0000
> "Javi Merino" <javi.merino@xxxxxxx> wrote:

[...]

> > +
> > +DEFINE_PRINT_ARRAY(u8, unsigned int, "0x%x");
> > +DEFINE_PRINT_ARRAY(u16, unsigned int, "0x%x");
> > +DEFINE_PRINT_ARRAY(u32, unsigned int, "0x%x");
> > +DEFINE_PRINT_ARRAY(u64, unsigned long long, "0x%llx");
> > +
>
> I would really like to avoid adding a bunch of macros for each type.
> Can't we have something like this:
> ftrace_print_array(struct trace_seq *p, void *buf, int buf_len,
> int size)
> {
> char *prefix = "";
> void *ptr = buf;
>
> while (ptr < buf + buf_len) {
> switch(size) {
> case 8:
> trace_seq_printf("%s0x%x", prefix,
> *(unsigned char *)ptr);

I think this should be *(u8 *) etc.

Otherwise, I don't have a problem with this approach. It's less
ugly than my original.

> break;
> case 16:
> trace_seq_printf("%s0x%x", prefix,
> *(unsigned short *)ptr);
> break;
> case 32:
> trace_seq_printf("%s0x%x", prefix,
> *(unsigned int *)ptr);
> break;
> case 64:
> trace_seq_printf("%s0x%llx", prefix,
> *(unsigned long long *)ptr);
> break;
> default:
> BUG();
> }
> prefix = ",";
> ptr += size;
> }
>
> }
>
> We probably could even make the "BUG()" into a build bug, with a little
> work.

That sounds possible.

Javi?

Cheers
---Dave
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/