1 //===-- TypeDumpVisitor.h - CodeView type info dumper -----------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLVM_DEBUGINFO_CODEVIEW_TYPEDUMPVISITOR_H 10 #define LLVM_DEBUGINFO_CODEVIEW_TYPEDUMPVISITOR_H 11 12 #include "llvm/ADT/StringRef.h" 13 #include "llvm/DebugInfo/CodeView/CVRecord.h" 14 #include "llvm/DebugInfo/CodeView/CodeView.h" 15 #include "llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h" 16 #include "llvm/Support/Compiler.h" 17 18 namespace llvm { 19 class ScopedPrinter; 20 21 namespace codeview { 22 class TypeIndex; 23 struct CVMemberRecord; 24 struct MemberAttributes; 25 26 class TypeCollection; 27 28 /// Dumper for CodeView type streams found in COFF object files and PDB files. 29 class LLVM_ABI TypeDumpVisitor : public TypeVisitorCallbacks { 30 public: TypeDumpVisitor(TypeCollection & TpiTypes,ScopedPrinter * W,bool PrintRecordBytes)31 TypeDumpVisitor(TypeCollection &TpiTypes, ScopedPrinter *W, 32 bool PrintRecordBytes) 33 : W(W), PrintRecordBytes(PrintRecordBytes), TpiTypes(TpiTypes) {} 34 35 /// When dumping types from an IPI stream in a PDB, a type index may refer to 36 /// a type or an item ID. The dumper will lookup the "name" of the index in 37 /// the item database if appropriate. If ItemDB is null, it will use TypeDB, 38 /// which is correct when dumping types from an object file (/Z7). setIpiTypes(TypeCollection & Types)39 void setIpiTypes(TypeCollection &Types) { IpiTypes = &Types; } 40 41 void printTypeIndex(StringRef FieldName, TypeIndex TI) const; 42 43 void printItemIndex(StringRef FieldName, TypeIndex TI) const; 44 45 /// Action to take on unknown types. By default, they are ignored. 46 Error visitUnknownType(CVType &Record) override; 47 Error visitUnknownMember(CVMemberRecord &Record) override; 48 49 /// Paired begin/end actions for all types. Receives all record data, 50 /// including the fixed-length record prefix. 51 Error visitTypeBegin(CVType &Record) override; 52 Error visitTypeBegin(CVType &Record, TypeIndex Index) override; 53 Error visitTypeEnd(CVType &Record) override; 54 Error visitMemberBegin(CVMemberRecord &Record) override; 55 Error visitMemberEnd(CVMemberRecord &Record) override; 56 57 #define TYPE_RECORD(EnumName, EnumVal, Name) \ 58 Error visitKnownRecord(CVType &CVR, Name##Record &Record) override; 59 #define MEMBER_RECORD(EnumName, EnumVal, Name) \ 60 Error visitKnownMember(CVMemberRecord &CVR, Name##Record &Record) override; 61 #define TYPE_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName) 62 #define MEMBER_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName) 63 #include "llvm/DebugInfo/CodeView/CodeViewTypes.def" 64 65 private: 66 void printMemberAttributes(MemberAttributes Attrs); 67 void printMemberAttributes(MemberAccess Access, MethodKind Kind, 68 MethodOptions Options); 69 70 /// Get the database of indices for the stream that we are dumping. If ItemDB 71 /// is set, then we must be dumping an item (IPI) stream. This will also 72 /// always get the appropriate DB for printing item names. getSourceTypes()73 TypeCollection &getSourceTypes() const { 74 return IpiTypes ? *IpiTypes : TpiTypes; 75 } 76 77 ScopedPrinter *W; 78 79 bool PrintRecordBytes = false; 80 81 TypeCollection &TpiTypes; 82 TypeCollection *IpiTypes = nullptr; 83 }; 84 85 } // end namespace codeview 86 } // end namespace llvm 87 88 #endif 89