Utility library for parsing BPF Type Format data
This project permits parsing the BTF data generated by LLVM and "pahole" and returning it as C++ types.
Run cmake -S . -B build
to configure the project, then run cmake --build build
to build the project.
Linux
build/test/tests -d yes
Windows
build/test/Debug/tests.exe -d yes
- Add reference to your cmake project
Include(FetchContent)
FetchContent_Declare(
libbtf
GIT_REPOSITORY https://github.com/Alan-Jowett/libbtf.git
GIT_TAG 0.0.1 # or a later release
)
FetchContent_MakeAvailable(libbtf)
include_directories(${libbtf_SOURCE_DIR})
target_link_libraries(<your project> PRIVATE libbtf)
- Obtain pointer to vector of BTF data.
auto reader = ELFIO::elfio();
if (!reader.load(argv[1])) {
std::cerr << "Failed to load " << argv[1] << "\n";
return 1;
}
auto btf = reader.sections[".BTF"];
- Parse the BTF data.
libbtf::btf_type_data btf_data = std::vector<std::byte>(
{reinterpret_cast<const std::byte *>(btf->get_data()),
reinterpret_cast<const std::byte *>(btf->get_data() + btf->get_size())});
- Use the BTF data.
std::ostringstream json;
btf_data.to_json(json);
std::cout << libbtf::pretty_print_json(json.str()) << "\n";