Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error message for args in mixed probes #3047

Merged
merged 1 commit into from
Mar 25, 2024

Conversation

viktormalik
Copy link
Contributor

@viktormalik viktormalik commented Mar 12, 2024

It is not possible to use the args builtin in probes with mixed probe types (e.g. tracepoints and kfuncs). When trying that, bpftrace correctly fails but the error message is not very clear:

# bpftrace -e 'tracepoint:syscalls:sys_enter_read,kfunc:vfs_read { print(args.count); }'
stdin:1:53-63: ERROR: The args builtin can only be used with tracepoint/kfunc/uprobeprobes (invalid used here)
tracepoint:syscalls:sys_enter_read,kfunc:vfs_read { print(args.count); }
                                                    ~~~~~~~~~~

Improve the error message:

# bpftrace -e 'tracepoint:syscalls:sys_enter_read,kfunc:vfs_read { print(args.count); }'
stdin:1:53-63: ERROR: The args builtin must be used in probes with a single probe type
tracepoint:syscalls:sys_enter_read,kfunc:vfs_read { print(args.count); }
                                                    ~~~~~~~~~~
Checklist
  • Language changes are updated in man/adoc/bpftrace.adoc
  • User-visible and non-trivial changes updated in CHANGELOG.md
  • The new behaviour is covered by tests

@ajor
Copy link
Member

ajor commented Mar 12, 2024

Could we get a test for this error message? A la:

test_error("BEGIN { @x = 0; @x[1]; }", R"(
stdin:1:17-22: ERROR: Argument mismatch for @x: trying to access with arguments: [unsigned int64] when map expects arguments: []
BEGIN { @x = 0; @x[1]; }
~~~~~
)");

Errors messages are one of the main outputs of SemanticAnalyser, so I'd like to eventually have all of them tested.

@viktormalik
Copy link
Contributor Author

Could we get a test for this error message? A la:

test_error("BEGIN { @x = 0; @x[1]; }", R"(
stdin:1:17-22: ERROR: Argument mismatch for @x: trying to access with arguments: [unsigned int64] when map expects arguments: []
BEGIN { @x = 0; @x[1]; }
~~~~~
)");

Errors messages are one of the main outputs of SemanticAnalyser, so I'd like to eventually have all of them tested.

Done. I had to add it into semantic_analyser_btf tests to be able to mix kfunc and tracepoint and get the expected error message.

Copy link
Contributor

@jordalgo jordalgo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The most rigorously reviewed change to an error message ever! Thanks @viktormalik!

It is not possible to use the `args` builtin in probes with mixed probe
types (e.g. tracepoints and kfuncs). When trying that, bpftrace
correctly fails but the error message is not very clear:

    # bpftrace -e 'tracepoint:syscalls:sys_enter_read,kfunc:vfs_read { print(args.count); }'
    stdin:1:53-63: ERROR: The args builtin can only be used with tracepoint/kfunc/uprobeprobes (invalid used here)
    tracepoint:syscalls:sys_enter_read,kfunc:vfs_read { print(args.count); }
                                                        ~~~~~~~~~~

Improve the error message:

    # bpftrace -e 'tracepoint:syscalls:sys_enter_read,kfunc:vfs_read { print(args.count); }'
    stdin:1:53-63: ERROR: The args builtin can only be used within the context of a single probe type, e.g. "probe1 {args}" is valid while "probe1,probe2 {args}" is not.
    tracepoint:syscalls:sys_enter_read,kfunc:vfs_read { print(args.count); }
                                                        ~~~~~~~~~~
@viktormalik viktormalik merged commit 118e829 into bpftrace:master Mar 25, 2024
18 checks passed
@viktormalik viktormalik deleted the mixed-args-errmsg branch March 25, 2024 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants