Re: [PATCH RESEND] libtraceevent: Pretty print function parameters of enum-type

Donglin Peng <[email protected]> Sun, 8 Feb 2026 20:02:55 +0800
Newsgroups org.kernel.vger.linux-trace-devel
Message-ID <CAErzpmuGSUJVogLgY3gu+e5=1qJohoga49t0w4hkkgRVoV7yHQ@mail.gmail.com>
On Sat, Feb 7, 2026 at 10:16=E2=80=AFPM Steven Rostedt <[email protected]=
> wrote:
>
> On Sat, 7 Feb 2026 13:04:02 +0800
> Donglin Peng <[email protected]> wrote:
>
> > > > +#define for_each_enum(i, enum_type, member)                  \
> > > > +     for (i =3D 0, member =3D btf_enum(enum_type);               \
> > > > +          i < BTF_INFO_VLEN(enum_type->info);                \
> > > > +          i++, member++)
> > >
> > >
> > > You can make the above into:
> > >
> > >  #define for_each_enum(enum_type, member)                       \
> > >         for (int __i =3D 0, member =3D btf_enum(enum_type);         \
> > >              __i < BTF_INFO_VLEN((enum_type)->info);            \
> > >              __i++, member++)
> > >
> > > Then you don't need to pass in the counter "i".
> >
> > Sorry, I found that the previous change causes a build failure.
> >
> > The error occurs in trace-btf.c:36:
> > warning: initialization of 'int' from 'struct btf_enum *' makes
> > integer from pointer without a cast [-Wint-conversion]
> >    36 |         for (int __i =3D 0, member =3D btf_enum(enum_type); \
> >
> > This is due to the member variable being redefined as an int type,
> > conflicting with its assignment of a struct btf_enum *pointer from
> > btf_enum(enum_type).
>
> Ah, I had that issue before. But this should work:
>
>  #define for_each_enum(enum_type, member)                               \
>         member =3D btf_enum(enum_type);                                  =
 \
>         for (int __i =3D 0; __i < BTF_INFO_VLEN((enum_type)->info);      =
 \
>              __i++, member++)
>
> Just can't use it as a single line for if statements.
>
>         if (x)
>                 for_each_enum() {
>                 }
>
> But we shouldn't be doing that anyway.

Thanks. I will do it in v2.

>
> -- Steve