1 //===-- ObjDumper.h ---------------------------------------------*- 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_TOOLS_LLVM_READOBJ_OBJDUMPER_H 10 #define LLVM_TOOLS_LLVM_READOBJ_OBJDUMPER_H 11 12 #include <memory> 13 #include <system_error> 14 15 #include "llvm/ADT/StringRef.h" 16 #include "llvm/Object/ObjectFile.h" 17 #include "llvm/Support/CommandLine.h" 18 19 namespace llvm { 20 namespace object { 21 class COFFImportFile; 22 class ObjectFile; 23 } 24 namespace codeview { 25 class GlobalTypeTableBuilder; 26 class MergingTypeTableBuilder; 27 } // namespace codeview 28 29 class ScopedPrinter; 30 31 class ObjDumper { 32 public: 33 ObjDumper(ScopedPrinter &Writer); 34 virtual ~ObjDumper(); 35 36 virtual void printFileHeaders() = 0; 37 virtual void printSectionHeaders() = 0; 38 virtual void printRelocations() = 0; 39 virtual void printSymbols(bool PrintSymbols, bool PrintDynamicSymbols) { 40 if (PrintSymbols) 41 printSymbols(); 42 if (PrintDynamicSymbols) 43 printDynamicSymbols(); 44 } 45 virtual void printProgramHeaders(bool PrintProgramHeaders, 46 cl::boolOrDefault PrintSectionMapping) { 47 if (PrintProgramHeaders) 48 printProgramHeaders(); 49 if (PrintSectionMapping == cl::BOU_TRUE) 50 printSectionMapping(); 51 } 52 53 virtual void printUnwindInfo() = 0; 54 55 // Only implemented for ELF at this time. 56 virtual void printDynamicRelocations() { } 57 virtual void printDynamicTable() { } 58 virtual void printNeededLibraries() { } 59 virtual void printSectionAsHex(StringRef SectionName) {} 60 virtual void printHashTable() { } 61 virtual void printGnuHashTable() { } 62 virtual void printHashSymbols() {} 63 virtual void printLoadName() {} 64 virtual void printVersionInfo() {} 65 virtual void printGroupSections() {} 66 virtual void printHashHistogram() {} 67 virtual void printCGProfile() {} 68 virtual void printAddrsig() {} 69 virtual void printNotes() {} 70 virtual void printELFLinkerOptions() {} 71 72 // Only implemented for ARM ELF at this time. 73 virtual void printAttributes() { } 74 75 // Only implemented for MIPS ELF at this time. 76 virtual void printMipsPLTGOT() { } 77 virtual void printMipsABIFlags() { } 78 virtual void printMipsReginfo() { } 79 virtual void printMipsOptions() { } 80 81 // Only implemented for PE/COFF. 82 virtual void printCOFFImports() { } 83 virtual void printCOFFExports() { } 84 virtual void printCOFFDirectives() { } 85 virtual void printCOFFBaseReloc() { } 86 virtual void printCOFFDebugDirectory() { } 87 virtual void printCOFFResources() {} 88 virtual void printCOFFLoadConfig() { } 89 virtual void printCodeViewDebugInfo() { } 90 virtual void 91 mergeCodeViewTypes(llvm::codeview::MergingTypeTableBuilder &CVIDs, 92 llvm::codeview::MergingTypeTableBuilder &CVTypes, 93 llvm::codeview::GlobalTypeTableBuilder &GlobalCVIDs, 94 llvm::codeview::GlobalTypeTableBuilder &GlobalCVTypes, 95 bool GHash) {} 96 97 // Only implemented for MachO. 98 virtual void printMachODataInCode() { } 99 virtual void printMachOVersionMin() { } 100 virtual void printMachODysymtab() { } 101 virtual void printMachOSegment() { } 102 virtual void printMachOIndirectSymbols() { } 103 virtual void printMachOLinkerOptions() { } 104 105 virtual void printStackMap() const = 0; 106 107 void printSectionsAsString(const object::ObjectFile *Obj, 108 ArrayRef<std::string> Sections); 109 void printSectionsAsHex(const object::ObjectFile *Obj, 110 ArrayRef<std::string> Sections); 111 112 protected: 113 ScopedPrinter &W; 114 115 private: 116 virtual void printSymbols() {} 117 virtual void printDynamicSymbols() {} 118 virtual void printProgramHeaders() {} 119 virtual void printSectionMapping() {} 120 }; 121 122 std::error_code createCOFFDumper(const object::ObjectFile *Obj, 123 ScopedPrinter &Writer, 124 std::unique_ptr<ObjDumper> &Result); 125 126 std::error_code createELFDumper(const object::ObjectFile *Obj, 127 ScopedPrinter &Writer, 128 std::unique_ptr<ObjDumper> &Result); 129 130 std::error_code createMachODumper(const object::ObjectFile *Obj, 131 ScopedPrinter &Writer, 132 std::unique_ptr<ObjDumper> &Result); 133 134 std::error_code createWasmDumper(const object::ObjectFile *Obj, 135 ScopedPrinter &Writer, 136 std::unique_ptr<ObjDumper> &Result); 137 138 std::error_code createXCOFFDumper(const object::ObjectFile *Obj, 139 ScopedPrinter &Writer, 140 std::unique_ptr<ObjDumper> &Result); 141 142 void dumpCOFFImportFile(const object::COFFImportFile *File, 143 ScopedPrinter &Writer); 144 145 void dumpCodeViewMergedTypes(ScopedPrinter &Writer, 146 ArrayRef<ArrayRef<uint8_t>> IpiRecords, 147 ArrayRef<ArrayRef<uint8_t>> TpiRecords); 148 149 } // namespace llvm 150 151 #endif 152