diff mbox series

[bpf] traceevent: ignore __attribute__ in fields format

Message ID 20200115180645.53331-1-john.koepi@gmail.com (mailing list archive)
State Handled Elsewhere
Headers show
Series [bpf] traceevent: ignore __attribute__ in fields format | expand

Commit Message

John Koepi Jan. 15, 2020, 6:06 p.m. UTC
To support kernel (e.g. Arch linux) tracing that
have events fields with C attributes (__attribute__((xxx))),
traceevent must ignore __attribute__ parts when
parsing fields types.

An example from Arch linux kernel 4.2:

  $ cat /sys/kernel/.../sys_enter_io_submit/format
  ...
  field:struct iocb __attribute__((user)) * ...
                    ^^^

This fix adds support for fields types C attributes
parsing to event_read_fields function. When it sees
__attribute__ ((attribute-list)) expression it skips
it.

Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=205857
Base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf.git/
Signed-off-by: Ivan Prisyazhnyy <john.koepi@gmail.com>
---
 tools/lib/traceevent/event-parse.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

Comments

John Koepi Jan. 15, 2020, 6:47 p.m. UTC | #1
I am not sure this is the right mailing list (I was not sure about
@netdev). If it is not - I am sorry, I can resend it. The test for
this change is at https://github.com/sitano/traceevent_attribute.

On Wed, Jan 15, 2020 at 8:06 PM Ivan Prisyazhnyy <john.koepi@gmail.com> wrote:
>
> To support kernel (e.g. Arch linux) tracing that
> have events fields with C attributes (__attribute__((xxx))),
> traceevent must ignore __attribute__ parts when
> parsing fields types.
>
> An example from Arch linux kernel 4.2:
>
>   $ cat /sys/kernel/.../sys_enter_io_submit/format
>   ...
>   field:struct iocb __attribute__((user)) * ...
>                     ^^^
>
> This fix adds support for fields types C attributes
> parsing to event_read_fields function. When it sees
> __attribute__ ((attribute-list)) expression it skips
> it.
>
> Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=205857
> Base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf.git/
> Signed-off-by: Ivan Prisyazhnyy <john.koepi@gmail.com>
> ---
>  tools/lib/traceevent/event-parse.c | 22 ++++++++++++++++++++++
>  1 file changed, 22 insertions(+)
>
> diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
> index beaa8b8c08ff..fbc1ea536742 100644
> --- a/tools/lib/traceevent/event-parse.c
> +++ b/tools/lib/traceevent/event-parse.c
> @@ -1486,6 +1486,28 @@ static int event_read_fields(struct tep_event *event, struct tep_format_field **
>                             (event->flags & TEP_EVENT_FL_ISFTRACE &&
>                              type == TEP_EVENT_OP && strcmp(token, ".") == 0)) {
>
> +                               /* ignore C attributes: __attribute__((expr)) */
> +                               if (strcmp(token, "__attribute__") == 0) {
> +                                       free(token);
> +                                       for (int i = 0; i < 2; i++) {
> +                                               if (read_expected_item(TEP_EVENT_DELIM, "(") < 0) {
> +                                                       goto fail_expect;
> +                                               }
> +                                       }
> +                                       for (int brackets = 2; brackets > 0;) {
> +                                               if (read_token(&token) == TEP_EVENT_NONE) {
> +                                                       do_warning_event(event, "%s: __attribute__ not full", __func__);
> +                                                       goto fail_expect;
> +                                               }
> +                                               if (strcmp(token, "(") == 0)
> +                                                       brackets++;
> +                                               else if (strcmp(token, ")") == 0)
> +                                                       brackets--;
> +                                               free(token);
> +                                       }
> +                                       continue;
> +                               }
> +
>                                 if (strcmp(token, "*") == 0)
>                                         field->flags |= TEP_FIELD_IS_POINTER;
>
> --
> 2.24.1
>
Steven Rostedt Jan. 15, 2020, 7:31 p.m. UTC | #2
On Wed, 15 Jan 2020 20:47:47 +0200
John Koepi <john.koepi@gmail.com> wrote:

> I am not sure this is the right mailing list (I was not sure about
> @netdev). If it is not - I am sorry, I can resend it. The test for
> this change is at https://github.com/sitano/traceevent_attribute.
> 

It's fine to send it here. It's in my queue to look at.

Thanks!

-- Steve
diff mbox series

Patch

diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index beaa8b8c08ff..fbc1ea536742 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -1486,6 +1486,28 @@  static int event_read_fields(struct tep_event *event, struct tep_format_field **
 			    (event->flags & TEP_EVENT_FL_ISFTRACE &&
 			     type == TEP_EVENT_OP && strcmp(token, ".") == 0)) {
 
+				/* ignore C attributes: __attribute__((expr)) */
+				if (strcmp(token, "__attribute__") == 0) {
+					free(token);
+					for (int i = 0; i < 2; i++) {
+						if (read_expected_item(TEP_EVENT_DELIM, "(") < 0) {
+							goto fail_expect;
+						}
+					}
+					for (int brackets = 2; brackets > 0;) {
+						if (read_token(&token) == TEP_EVENT_NONE) {
+							do_warning_event(event, "%s: __attribute__ not full", __func__);
+							goto fail_expect;
+						}
+						if (strcmp(token, "(") == 0)
+							brackets++;
+						else if (strcmp(token, ")") == 0)
+							brackets--;
+						free(token);
+					}
+					continue;
+				}
+
 				if (strcmp(token, "*") == 0)
 					field->flags |= TEP_FIELD_IS_POINTER;