{"id":18894096,"url":"https://github.com/trailofbits/btfparse","last_synced_at":"2025-04-15T00:31:53.980Z","repository":{"id":39964360,"uuid":"402123938","full_name":"trailofbits/btfparse","owner":"trailofbits","description":"A C++ library that parses debug information encoded in BTF format","archived":false,"fork":false,"pushed_at":"2023-04-11T18:03:22.000Z","size":118,"stargazers_count":25,"open_issues_count":1,"forks_count":6,"subscribers_count":20,"default_branch":"main","last_synced_at":"2025-03-28T12:51:14.670Z","etag":null,"topics":["bpf","btf","ebpf","tracing"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/trailofbits.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-09-01T16:10:34.000Z","updated_at":"2024-10-07T13:13:42.000Z","dependencies_parsed_at":"2024-06-21T16:41:27.878Z","dependency_job_id":"46d4f142-db0e-4f2d-bb2e-c16bd823e04b","html_url":"https://github.com/trailofbits/btfparse","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trailofbits%2Fbtfparse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trailofbits%2Fbtfparse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trailofbits%2Fbtfparse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trailofbits%2Fbtfparse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/trailofbits","download_url":"https://codeload.github.com/trailofbits/btfparse/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248984386,"owners_count":21193737,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bpf","btf","ebpf","tracing"],"created_at":"2024-11-08T08:17:49.447Z","updated_at":"2025-04-15T00:31:53.423Z","avatar_url":"https://github.com/trailofbits.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# btfparse\n\nbtfparse is a C++ library that parses kernel debug symbols in BTF format.\n\n# CI\n\n[![Linux](https://github.com/trailofbits/btfparse/actions/workflows/main.yml/badge.svg)](https://github.com/trailofbits/btfparse/actions/workflows/main.yml)\n\n# Building\n\n## Prerequisites\n\n * A recent C++ compiler, supporting C++17\n * CMake \u003e= 3.16.4\n\n## Steps to build\n\n**Clone the repository**\n\n```bash\ngit clone https://github.com/trailofbits/btfparse\ncd btfparse\ngit submodule update --init\n```\n\n**Configure the project**\n\n```bash\nmkdir build\ncd build\ncmake .. \\\n  -DCMAKE_BUILD_TYPE=RelWithDebInfo \\\n  -DBTFPARSE_ENABLE_TOOLS=true \\\n  -DBTFPARSE_ENABLE_TESTS=true\n```\n\n**Build the project**\n\n```bash\ncmake \\\n  --build . \\\n  -j $(nproc)\n```\n\n**Running the tests**\n\nThe tests require `bpftool` which can be installed in Ubuntu via the `linux-tools-generic` package:\n\n```bash\nsudo apt-get install linux-tools-generic\n```\n\nThen, tests can be run:\n\n```bash\ncmake \\\n  --build . \\\n  --target test\n```\n\n# Importing btfparse in your project\n\nThis library is meant to be used as a git submodule:\n\n1. Enter your project folder\n2. Create the submodule: `git submodule add https://github.com/trailofbits/btfparse`\n3. Import the library from your CMakeLists.txt file: `add_subdirectory(\"btfparse\")`\n4. Link the btfparse library against your target: `target_link_libraries(your_target PRIVATE btfparse)`\n\n# Examples\n\n## Tool example: dump-btf\n\nThe library comes with a **dump-btf** tool that is output-compatible with **bpftool**. In order to build it, make sure to pass `-DBTFPARSE_ENABLE_TOOLS=true` at configure time.\n\n```bash\nalessandro@ubuntu2110:~/btfparse-build$ ./tools/dump-btf/dump-btf /sys/kernel/btf/vmlinux | head\n[1] INT 'long unsigned int' size=8 bits_offset=0 nr_bits=64 encoding=(none)\n[2] CONST '(anon)' type_id=1\n[3] ARRAY '(anon)' type_id=1 index_type_id=18 nr_elems=2\n[4] PTR '(anon)' type_id=6\n[5] INT 'char' size=1 bits_offset=0 nr_bits=8 encoding=(none)\n[6] CONST '(anon)' type_id=5\n[7] INT 'unsigned int' size=4 bits_offset=0 nr_bits=32 encoding=(none)\n[8] CONST '(anon)' type_id=7\n[9] INT 'signed char' size=1 bits_offset=0 nr_bits=8 encoding=(none)\n[10] TYPEDEF '__u8' type_id=11\n```\n\n## Code example\n\n```c++\n#include \u003cbtfparse/ibtf.h\u003e\n\nbool parseTypes() {\n  static const std::vector\u003cstd::filesystem::path\u003e kPathList{\n      \"/sys/kernel/btf/vmlinux\"};\n\n  auto btf_res = btfparse::IBTF::createFromPathList(kPathList);\n  if (btf_res.failed()) {\n    std::cerr \u003c\u003c \"Failed to open the BTF file: \" \u003c\u003c btf_res.takeError() \u003c\u003c \"\\n\";\n    return false;\n  }\n\n  auto btf = btf_res.takeValue();\n  if (btf-\u003ecount() == 0) {\n    std::cout \u003c\u003c \"No types were found!\\n\";\n    return false;\n  }\n\n  for (const auto \u0026btf_type_map_p : btf-\u003egetAll()) {\n    const auto \u0026id = btf_type_map_p.first;\n    const auto \u0026btf_type = btf_type_map_p.second;\n\n    auto type_kind = btfparse::IBTF::getBTFTypeKind(btf_type);\n    if (type_kind != btfparse::BTFKind::Struct) {\n      continue;\n    }\n\n    const auto \u0026btf_struct = std::get\u003cbtfparse::StructBTFType\u003e(btf_type);\n\n    std::cout \u003c\u003c std::to_string(id) \u003c\u003c \": \";\n    if (btf_struct.opt_name.has_value()) {\n      std::cout \u003c\u003c btf_struct.opt_name.value() \u003c\u003c \"\\n\";\n\n    } else {\n      std::cout \u003c\u003c \"unnamed\\n\";\n    }\n  }\n\n  return true;\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrailofbits%2Fbtfparse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrailofbits%2Fbtfparse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrailofbits%2Fbtfparse/lists"}