1 //===-- ObjDumper.h ---------------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef LLVM_TOOLS_LLVM_READOBJ_OBJDUMPER_H 11 #define LLVM_TOOLS_LLVM_READOBJ_OBJDUMPER_H 12 13 #include <memory> 14 #include <system_error> 15 16 #include "llvm/ADT/StringRef.h" 17 #include "llvm/Object/ObjectFile.h" 18 19 namespace llvm { 20 namespace object { 21 class COFFImportFile; 22 class ObjectFile; 23 } 24 namespace codeview { 25 class MergingTypeTableBuilder; 26 } 27 28 class ScopedPrinter; 29 30 class ObjDumper { 31 public: 32 ObjDumper(ScopedPrinter &Writer); 33 virtual ~ObjDumper(); 34 35 virtual void printFileHeaders() = 0; 36 virtual void printSections() = 0; 37 virtual void printRelocations() = 0; 38 virtual void printSymbols() = 0; 39 virtual void printDynamicSymbols() = 0; 40 virtual void printUnwindInfo() = 0; 41 42 // Only implemented for ELF at this time. printDynamicRelocations()43 virtual void printDynamicRelocations() { } printDynamicTable()44 virtual void printDynamicTable() { } printNeededLibraries()45 virtual void printNeededLibraries() { } printProgramHeaders()46 virtual void printProgramHeaders() { } printSectionAsHex(StringRef SectionName)47 virtual void printSectionAsHex(StringRef SectionName) {} printHashTable()48 virtual void printHashTable() { } printGnuHashTable()49 virtual void printGnuHashTable() { } printLoadName()50 virtual void printLoadName() {} printVersionInfo()51 virtual void printVersionInfo() {} printGroupSections()52 virtual void printGroupSections() {} printHashHistogram()53 virtual void printHashHistogram() {} printCGProfile()54 virtual void printCGProfile() {} printAddrsig()55 virtual void printAddrsig() {} printNotes()56 virtual void printNotes() {} printELFLinkerOptions()57 virtual void printELFLinkerOptions() {} 58 59 // Only implemented for ARM ELF at this time. printAttributes()60 virtual void printAttributes() { } 61 62 // Only implemented for MIPS ELF at this time. printMipsPLTGOT()63 virtual void printMipsPLTGOT() { } printMipsABIFlags()64 virtual void printMipsABIFlags() { } printMipsReginfo()65 virtual void printMipsReginfo() { } printMipsOptions()66 virtual void printMipsOptions() { } 67 68 // Only implemented for PE/COFF. printCOFFImports()69 virtual void printCOFFImports() { } printCOFFExports()70 virtual void printCOFFExports() { } printCOFFDirectives()71 virtual void printCOFFDirectives() { } printCOFFBaseReloc()72 virtual void printCOFFBaseReloc() { } printCOFFDebugDirectory()73 virtual void printCOFFDebugDirectory() { } printCOFFResources()74 virtual void printCOFFResources() {} printCOFFLoadConfig()75 virtual void printCOFFLoadConfig() { } printCodeViewDebugInfo()76 virtual void printCodeViewDebugInfo() { } 77 virtual void mergeCodeViewTypes(llvm::codeview::MergingTypeTableBuilder & CVIDs,llvm::codeview::MergingTypeTableBuilder & CVTypes)78 mergeCodeViewTypes(llvm::codeview::MergingTypeTableBuilder &CVIDs, 79 llvm::codeview::MergingTypeTableBuilder &CVTypes) {} 80 81 // Only implemented for MachO. printMachODataInCode()82 virtual void printMachODataInCode() { } printMachOVersionMin()83 virtual void printMachOVersionMin() { } printMachODysymtab()84 virtual void printMachODysymtab() { } printMachOSegment()85 virtual void printMachOSegment() { } printMachOIndirectSymbols()86 virtual void printMachOIndirectSymbols() { } printMachOLinkerOptions()87 virtual void printMachOLinkerOptions() { } 88 89 virtual void printStackMap() const = 0; 90 91 void printSectionAsString(const object::ObjectFile *Obj, StringRef SecName); 92 void printSectionAsHex(const object::ObjectFile *Obj, StringRef SecName); 93 94 protected: 95 ScopedPrinter &W; 96 }; 97 98 std::error_code createCOFFDumper(const object::ObjectFile *Obj, 99 ScopedPrinter &Writer, 100 std::unique_ptr<ObjDumper> &Result); 101 102 std::error_code createELFDumper(const object::ObjectFile *Obj, 103 ScopedPrinter &Writer, 104 std::unique_ptr<ObjDumper> &Result); 105 106 std::error_code createMachODumper(const object::ObjectFile *Obj, 107 ScopedPrinter &Writer, 108 std::unique_ptr<ObjDumper> &Result); 109 110 std::error_code createWasmDumper(const object::ObjectFile *Obj, 111 ScopedPrinter &Writer, 112 std::unique_ptr<ObjDumper> &Result); 113 114 void dumpCOFFImportFile(const object::COFFImportFile *File, 115 ScopedPrinter &Writer); 116 117 void dumpCodeViewMergedTypes( 118 ScopedPrinter &Writer, llvm::codeview::MergingTypeTableBuilder &IDTable, 119 llvm::codeview::MergingTypeTableBuilder &TypeTable); 120 121 } // namespace llvm 122 123 #endif 124