Skip to content
New issue

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

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

Already on GitHub? # to your account

Implement sizeof() function #1269

Merged
merged 5 commits into from
Apr 17, 2020
Merged

Implement sizeof() function #1269

merged 5 commits into from
Apr 17, 2020

Conversation

danobi
Copy link
Member

@danobi danobi commented Apr 16, 2020

It's often useful to know the size of a struct. As a bonus, this
implementation also works with all other known types and
expressions. eg:

struct Foo
{
    int x;
}

BEGIN
{
    printf("%d\n", sizeof(struct Foo));
    printf("%d\n", sizeof(1 == 1));
    printf("%d\n", sizeof(((struct Foo)0).x));
}

This closes #73 .

@@ -9,6 +9,7 @@
import re

BPF_PATH = environ["BPFTRACE_RUNTIME_TEST_EXECUTABLE"]
ENV_PATH = environ["PATH"]
Copy link
Member Author

Choose a reason for hiding this comment

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

This is stolen from #1268 . Whichever PR goes in second I'll take it out from.

@danobi
Copy link
Member Author

danobi commented Apr 16, 2020

cc @olsajiri for the BTF fix

danobi added 4 commits April 16, 2020 11:30
It's often useful to know the size of a struct. As a bonus, this
implementation also works with expressions. eg:

    struct Foo
    {
        int x;
    }

    BEGIN
    {
        printf("%d\n", sizeof(struct Foo));
        printf("%d\n", sizeof(1 == 1));
        printf("%d\n", sizeof(((struct Foo)0).x));
    }
Before, identifiers weren't being pulled in. eg if you used an enum like
this:

    printf("%d\n", SOME_KERNEL_ENUM);

This commit correctly pulls in the identifier. So sizeof can work
correctly.
@danobi danobi merged commit 5ff22c8 into bpftrace:master Apr 17, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

support sizeof
2 participants