Skip to content

Commit

Permalink
Add support for new common fields
Browse files Browse the repository at this point in the history
Current parser covers common fields with:
  u64 __do_not_use__
so the new common fields are not accounted for.

Keeping the 'u64 __do_not_use__' field for backward compatibility
(who knows who's actualy using it) and adding new fields, like:
  char __do_not_use__X

for each byte of extra common fields, where X is the offset of the
field.

With this fix the bcc-tools correctly parses tracepoints on RT kernel
and it's usable again.

Signed-off-by: Jiri Olsa <[email protected]>
  • Loading branch information
olsajiri authored and yonghong-song committed Mar 15, 2020
1 parent b8423e6 commit 0a9d6db
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/cc/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ std::string parse_tracepoint(std::istream &input, std::string const& category,
std::string const& event) {
std::string tp_struct = "struct tracepoint__" + category + "__" + event + " {\n";
tp_struct += "\tu64 __do_not_use__;\n";
int last_offset = 0;
int last_offset = 0, common_offset = 8;
for (std::string line; getline(input, line); ) {
std::string field_type, field_name;
field_kind_t kind;
Expand All @@ -175,7 +175,12 @@ std::string parse_tracepoint(std::istream &input, std::string const& category,

switch (kind) {
case field_kind_t::invalid:
continue;
case field_kind_t::common:
for (;common_offset < last_offset; common_offset++)
{
tp_struct += "\tchar __do_not_use__" + std::to_string(common_offset) + ";\n";
}
continue;
case field_kind_t::data_loc:
tp_struct += "\tint data_loc_" + field_name + ";\n";
Expand Down
34 changes: 34 additions & 0 deletions tests/cc/test_parse_tracepoint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,38 @@ TEST_CASE("test tracepoint parser", "[TracepointParser]") {
std::string result = ebpf::parse_tracepoint(input, "signal", "signal_deliver");
REQUIRE(expected == result);
}

format =
" field:unsigned short common_type; offset:0; size:2; signed:0;\n"
" field:unsigned char common_flags; offset:2; size:1; signed:0;\n"
" field:unsigned char common_preempt_count; offset:3; size:1; signed:0;\n"
" field:int common_pid; offset:4; size:4; signed:1;\n"
" field:unsigned char common_migrate_disable; offset:8; size:1; signed:0;\n"
" field:unsigned char common_preempt_lazy_count; offset:9; size:1; signed:0;\n"

" field:char comm[16]; offset:12; size:16; signed:1;\n"
" field:pid_t pid; offset:28; size:4; signed:1;\n"
" field:int prio; offset:32; size:4; signed:1;\n"
" field:int success; offset:36; size:4; signed:1;\n"
" field:int target_cpu; offset:40; size:4; signed:1;\n";

expected =
"struct tracepoint__sched__sched_wakeup {\n"
"\tu64 __do_not_use__;\n"
"\tchar __do_not_use__8;\n"
"\tchar __do_not_use__9;\n"
"\tchar __pad_10;\n"
"\tchar __pad_11;\n"
"\tchar comm[16];\n"
"\tpid_t pid;\n"
"\tint prio;\n"
"\tint success;\n"
"\tint target_cpu;\n"
"};\n";

{
std::istringstream input(format);
std::string result = ebpf::parse_tracepoint(input, "sched", "sched_wakeup");
REQUIRE(expected == result);
}
}

0 comments on commit 0a9d6db

Please sign in to comment.