forked from bpftrace/bpftrace
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Since bpftrace PR [1] support offsetof() function. As previously discussed [2], the current offsetof() does not support sub-fields, and this PR implements offsetof(struct foo, a.b.c). Example: struct Foo { struct e { int a; int b; struct c { int a, b, c; } c; } e; } struct offsetof { struct { int comm; int ustack; } kstack; } BEGIN { printf("struct Foo e.b offset %ld\n", offsetof(struct Foo, e.b)); printf("struct Foo e.c offset %ld\n", offsetof(struct Foo, e.c)); printf("struct Foo e.c.b offset %ld\n", offsetof(struct Foo, e.c.b)); printf("struct offsetof kstack.ustack offset %ld\n", offsetof(struct offsetof, kstack.ustack)); exit(); } Link: bpftrace#2579 [1] merged Link: bpftrace#2216 [2] Signed-off-by: Rong Tao <rongtao@cestc.cn>
- Loading branch information
Showing
4 changed files
with
103 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!./src/bpftrace | ||
|
||
struct Foo { | ||
int a; | ||
long b; | ||
char c; | ||
struct { | ||
int d; | ||
}; | ||
struct e { | ||
int a; | ||
int b; | ||
struct c { | ||
int a, b, c; | ||
} c; | ||
} e; | ||
} | ||
struct offsetof { | ||
int bswap; | ||
int comm; | ||
int kstack; | ||
int ustack; | ||
int pid; | ||
int ctx; | ||
int arg; | ||
} | ||
|
||
union Bar { | ||
int a; | ||
}; | ||
|
||
BEGIN { | ||
printf("%ld\n", offsetof(struct Foo, c)); | ||
|
||
printf("%ld\n", offsetof(struct Foo, d)); | ||
// printf("%ld\n", offsetof(struct Foo_1, d)); | ||
|
||
printf("e.a %ld\n", offsetof(struct Foo, e.a)); | ||
printf("e.b %ld\n", offsetof(struct Foo, e.b)); | ||
printf("e.c %ld\n", offsetof(struct Foo, e.c)); | ||
printf("e.c.a %ld\n", offsetof(struct Foo, e.c.a)); | ||
printf("e.c.b %ld\n", offsetof(struct Foo, e.c.b)); | ||
|
||
printf("%ld union\n", offsetof(union Bar, a)); | ||
|
||
printf("%ld\n", offsetof(struct offsetof, bswap)); | ||
|
||
printf("%ld\n", offsetof(struct task_struct, comm)); | ||
printf("%ld\n", offsetof(*curtask, comm)); | ||
|
||
printf("%ld\n", offsetof(*(struct task_struct *)0, comm)); | ||
|
||
exit(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters