Lines Matching defs:BTF

9 // BTFParser reads/interprets .BTF and .BTF.ext ELF sections.
14 #include "llvm/DebugInfo/BTF/BTFParser.h"
26 const char BTFSectionName[] = ".BTF";
27 const char BTFExtSectionName[] = ".BTF.ext";
103 Error BTFParser::parseBTF(ParseContext &Ctx, SectionRef BTF) {
104 Expected<DataExtractor> MaybeExtractor = Ctx.makeExtractor(BTF);
112 return Err(".BTF", C);
113 if (Magic != BTF::MAGIC)
114 return Err("invalid .BTF magic: ").write_hex(Magic);
117 return Err(".BTF", C);
119 return Err("unsupported .BTF version: ") << (unsigned)Version;
123 return Err(".BTF", C);
125 return Err("unexpected .BTF header length: ") << HdrLen;
136 return Err(".BTF", C);
138 return Err("invalid .BTF section size, expecting at-least ")
152 // Compute record size for each BTF::CommonType sub-type
154 static size_t byteSize(BTF::CommonType *Type) {
155 size_t Size = sizeof(BTF::CommonType);
157 case BTF::BTF_KIND_INT:
160 case BTF::BTF_KIND_ARRAY:
161 Size += sizeof(BTF::BTFArray);
163 case BTF::BTF_KIND_VAR:
166 case BTF::BTF_KIND_DECL_TAG:
169 case BTF::BTF_KIND_STRUCT:
170 case BTF::BTF_KIND_UNION:
171 Size += sizeof(BTF::BTFMember) * Type->getVlen();
173 case BTF::BTF_KIND_ENUM:
174 Size += sizeof(BTF::BTFEnum) * Type->getVlen();
176 case BTF::BTF_KIND_ENUM64:
177 Size += sizeof(BTF::BTFEnum64) * Type->getVlen();
179 case BTF::BTF_KIND_FUNC_PROTO:
180 Size += sizeof(BTF::BTFParam) * Type->getVlen();
182 case BTF::BTF_KIND_DATASEC:
183 Size += sizeof(BTF::BTFDataSec) * Type->getVlen();
191 const BTF::CommonType VoidTypeInst = {0, BTF::BTF_KIND_UNKN << 24, {0}};
197 // according to BTF spec all buffer elements are structures comprised
224 BTF::CommonType *Type = (BTF::CommonType *)&TypesBuffer[Pos];
226 return Err("incomplete type definition in .BTF section:")
231 return Err("incomplete type definition in .BTF section:")
236 llvm::dbgs() << "Adding BTF type:\n"
258 return Err(".BTF.ext", C);
259 if (Magic != BTF::MAGIC)
260 return Err("invalid .BTF.ext magic: ").write_hex(Magic);
263 return Err(".BTF", C);
265 return Err("unsupported .BTF.ext version: ") << (unsigned)Version;
269 return Err(".BTF.ext", C);
271 return Err("unexpected .BTF.ext header length: ") << HdrLen;
279 return Err(".BTF.ext", C);
303 return Err(".BTF.ext", C);
305 return Err("unexpected .BTF.ext line info record length: ") << RecSize;
313 return Err(".BTF.ext", C);
316 << "' while parsing .BTF.ext line info";
325 return Err(".BTF.ext", C);
330 [](const BTF::BPFLineInfo &L, const BTF::BPFLineInfo &R) {
335 return Err(".BTF.ext", C);
346 return Err(".BTF.ext", C);
348 return Err("unexpected .BTF.ext field reloc info record length: ")
363 return Err(".BTF.ext", C);
368 Relocs, [](const BTF::BPFFieldReloc &L, const BTF::BPFFieldReloc &R) {
373 return Err(".BTF.ext", C);
386 std::optional<SectionRef> BTF;
394 BTF = Sec;
398 if (!BTF)
399 return Err("can't find .BTF section");
401 return Err("can't find .BTF.ext section");
402 if (Error E = parseBTF(Ctx, *BTF))
448 const BTF::BPFLineInfo *
453 const BTF::BPFFieldReloc *
458 const BTF::CommonType *BTFParser::findType(uint32_t Id) const {
471 static RelocKindGroup relocKindGroup(const BTF::BPFFieldReloc *Reloc) {
473 case BTF::FIELD_BYTE_OFFSET:
474 case BTF::FIELD_BYTE_SIZE:
475 case BTF::FIELD_EXISTENCE:
476 case BTF::FIELD_SIGNEDNESS:
477 case BTF::FIELD_LSHIFT_U64:
478 case BTF::FIELD_RSHIFT_U64:
480 case BTF::BTF_TYPE_ID_LOCAL:
481 case BTF::BTF_TYPE_ID_REMOTE:
482 case BTF::TYPE_EXISTENCE:
483 case BTF::TYPE_MATCH:
484 case BTF::TYPE_SIZE:
486 case BTF::ENUM_VALUE_EXISTENCE:
487 case BTF::ENUM_VALUE:
494 static bool isMod(const BTF::CommonType *Type) {
496 case BTF::BTF_KIND_VOLATILE:
497 case BTF::BTF_KIND_CONST:
498 case BTF::BTF_KIND_RESTRICT:
499 case BTF::BTF_KIND_TYPE_TAG:
506 static bool printMod(const BTFParser &BTF, const BTF::CommonType *Type,
509 case BTF::BTF_KIND_CONST:
512 case BTF::BTF_KIND_VOLATILE:
515 case BTF::BTF_KIND_RESTRICT:
518 case BTF::BTF_KIND_TYPE_TAG:
519 Stream << " type_tag(\"" << BTF.findString(Type->NameOff) << "\")";
527 static const BTF::CommonType *skipModsAndTypedefs(const BTFParser &BTF,
528 const BTF::CommonType *Type) {
529 while (isMod(Type) || Type->getKind() == BTF::BTF_KIND_TYPEDEF) {
530 auto *Base = BTF.findType(Type->Type);
540 const BTFParser &BTF;
546 StringRef Str = S.BTF.findString(S.Offset);
561 case BTF::FIELD_BYTE_OFFSET:
564 case BTF::FIELD_BYTE_SIZE:
567 case BTF::FIELD_EXISTENCE:
570 case BTF::FIELD_SIGNEDNESS:
573 case BTF::FIELD_LSHIFT_U64:
576 case BTF::FIELD_RSHIFT_U64:
579 case BTF::BTF_TYPE_ID_LOCAL:
582 case BTF::BTF_TYPE_ID_REMOTE:
585 case BTF::TYPE_EXISTENCE:
588 case BTF::TYPE_MATCH:
591 case BTF::TYPE_SIZE:
594 case BTF::ENUM_VALUE_EXISTENCE:
597 case BTF::ENUM_VALUE:
610 // - BTF type ID;
654 // llvm/unittests/DebugInfo/BTF/BTFParserTest.cpp.
657 void BTFParser::symbolize(const BTF::BPFFieldReloc *Reloc,
690 const BTF::CommonType *Type = findType(CurId);
697 // would refer to BTF type of kind BTF_KIND_CONST.
704 const BTF::CommonType *NextType = findType(CurId);
714 case BTF::BTF_KIND_TYPEDEF:
717 case BTF::BTF_KIND_STRUCT:
720 case BTF::BTF_KIND_UNION:
723 case BTF::BTF_KIND_ENUM:
726 case BTF::BTF_KIND_ENUM64:
729 case BTF::BTF_KIND_FWD:
730 if (Type->Info & BTF::FWD_UNION_FLAG)
756 // - kind: BTF::ENUM_VALUE
757 // - BTF id: id for `E`
768 if (auto *T = dyn_cast<BTF::EnumType>(Type)) {
771 const BTF::BTFEnum &E = T->values()[Idx];
774 } else if (auto *T = dyn_cast<BTF::Enum64Type>(Type)) {
777 const BTF::BTFEnum64 &E = T->values()[Idx];
786 if (Type->Info & BTF::ENUM_SIGNED_FLAG)
825 if (auto *T = dyn_cast<BTF::StructType>(Type)) {
831 const BTF::BTFMember &Member = T->members()[Idx];
839 } else if (auto *T = dyn_cast<BTF::ArrayType>(Type)) {