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

WIP: Index anonymous structs #2874

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/dwarf_parser.cpp
Expand Up @@ -17,7 +17,7 @@ struct FuncInfo
};

Dwarf::Dwarf(BPFtrace *bpftrace, const std::string &file_path)
: bpftrace_(bpftrace), file_path_(file_path)
: bpftrace_(bpftrace), file_path_(file_path), anon_idx(1)
{
callbacks.find_debuginfo = dwfl_standard_find_debuginfo;
callbacks.section_address = dwfl_offline_section_address;
Expand Down Expand Up @@ -181,7 +181,9 @@ SizedType Dwarf::get_stype(Dwarf_Die &type_die, bool resolve_structs) const
}
case DW_TAG_structure_type:
case DW_TAG_union_type: {
std::string name = dwarf_diename(&type_die);
std::string name = dwarf_hasattr_integrate(&type_die, DW_AT_name)
? dwarf_diename(&type_die)
: "__anon_" + std::to_string(anon_idx++);
name = (tag == DW_TAG_structure_type ? "struct " : "union ") + name;
auto result = CreateRecord(
name, bpftrace_->structs.LookupOrAdd(name, bit_size / 8));
Expand Down
1 change: 1 addition & 0 deletions src/dwarf_parser.h
Expand Up @@ -60,6 +60,7 @@ class Dwarf

BPFtrace *bpftrace_;
std::string file_path_;
mutable int anon_idx;
};

} // namespace bpftrace
Expand Down
5 changes: 5 additions & 0 deletions tests/data/data_source.c
Expand Up @@ -41,6 +41,11 @@ struct Foo3 *func_3(int a, int *b, struct Foo1 *foo1)
return 0;
}

void *func_4(const struct Foo2 *p)
{
return 0;
}

struct task_struct
{
int pid;
Expand Down
6 changes: 6 additions & 0 deletions tests/field_analyser.cpp
Expand Up @@ -225,6 +225,12 @@ TEST_F(field_analyser_dwarf, uprobe_args)
test(uprobe + ":func_2, " + uprobe + ":func_3 { }", 0);
test(uprobe + ":func_2, " + uprobe + ":func_3 { $x = args.a; }", 0);

// func_1 has a parameter that contains an anonymous struct
// test(uprobe + ":func_1 { $x = args.foo2->a; }", 0);
// test(uprobe + ":func_1 { $x = args.foo2->g; }", 0);
// func_4 has a parameter with a const qualifier
test(uprobe + ":func_4 { $x = args.p->a; }", 0);

// Probes with wildcards (need non-mock BPFtrace)
BPFtrace bpftrace;
// func_* have different args, but none of them
Expand Down