[obj2yaml] - Fix a comment. NFC.
[llvm-complete.git] / tools / llvm-readobj / ObjDumper.h
blob2ba441342499c06b2aa2a7c02b84eac45eccfc04
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 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_TOOLS_LLVM_READOBJ_OBJDUMPER_H
10 #define LLVM_TOOLS_LLVM_READOBJ_OBJDUMPER_H
12 #include <memory>
13 #include <system_error>
15 #include "llvm/ADT/StringRef.h"
16 #include "llvm/Object/ObjectFile.h"
17 #include "llvm/Support/CommandLine.h"
19 namespace llvm {
20 namespace object {
21 class COFFImportFile;
22 class ObjectFile;
24 namespace codeview {
25 class GlobalTypeTableBuilder;
26 class MergingTypeTableBuilder;
27 } // namespace codeview
29 class ScopedPrinter;
31 class ObjDumper {
32 public:
33 ObjDumper(ScopedPrinter &Writer);
34 virtual ~ObjDumper();
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();
45 virtual void printProgramHeaders(bool PrintProgramHeaders,
46 cl::boolOrDefault PrintSectionMapping) {
47 if (PrintProgramHeaders)
48 printProgramHeaders();
49 if (PrintSectionMapping == cl::BOU_TRUE)
50 printSectionMapping();
53 virtual void printUnwindInfo() = 0;
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 virtual void printStackSizes() {}
72 virtual void printArchSpecificInfo() { }
74 // Only implemented for PE/COFF.
75 virtual void printCOFFImports() { }
76 virtual void printCOFFExports() { }
77 virtual void printCOFFDirectives() { }
78 virtual void printCOFFBaseReloc() { }
79 virtual void printCOFFDebugDirectory() { }
80 virtual void printCOFFResources() {}
81 virtual void printCOFFLoadConfig() { }
82 virtual void printCodeViewDebugInfo() { }
83 virtual void
84 mergeCodeViewTypes(llvm::codeview::MergingTypeTableBuilder &CVIDs,
85 llvm::codeview::MergingTypeTableBuilder &CVTypes,
86 llvm::codeview::GlobalTypeTableBuilder &GlobalCVIDs,
87 llvm::codeview::GlobalTypeTableBuilder &GlobalCVTypes,
88 bool GHash) {}
90 // Only implemented for MachO.
91 virtual void printMachODataInCode() { }
92 virtual void printMachOVersionMin() { }
93 virtual void printMachODysymtab() { }
94 virtual void printMachOSegment() { }
95 virtual void printMachOIndirectSymbols() { }
96 virtual void printMachOLinkerOptions() { }
98 virtual void printStackMap() const = 0;
100 void printSectionsAsString(const object::ObjectFile *Obj,
101 ArrayRef<std::string> Sections);
102 void printSectionsAsHex(const object::ObjectFile *Obj,
103 ArrayRef<std::string> Sections);
105 protected:
106 ScopedPrinter &W;
108 private:
109 virtual void printSymbols() {}
110 virtual void printDynamicSymbols() {}
111 virtual void printProgramHeaders() {}
112 virtual void printSectionMapping() {}
115 std::error_code createCOFFDumper(const object::ObjectFile *Obj,
116 ScopedPrinter &Writer,
117 std::unique_ptr<ObjDumper> &Result);
119 std::error_code createELFDumper(const object::ObjectFile *Obj,
120 ScopedPrinter &Writer,
121 std::unique_ptr<ObjDumper> &Result);
123 std::error_code createMachODumper(const object::ObjectFile *Obj,
124 ScopedPrinter &Writer,
125 std::unique_ptr<ObjDumper> &Result);
127 std::error_code createWasmDumper(const object::ObjectFile *Obj,
128 ScopedPrinter &Writer,
129 std::unique_ptr<ObjDumper> &Result);
131 std::error_code createXCOFFDumper(const object::ObjectFile *Obj,
132 ScopedPrinter &Writer,
133 std::unique_ptr<ObjDumper> &Result);
135 void dumpCOFFImportFile(const object::COFFImportFile *File,
136 ScopedPrinter &Writer);
138 void dumpCodeViewMergedTypes(ScopedPrinter &Writer,
139 ArrayRef<ArrayRef<uint8_t>> IpiRecords,
140 ArrayRef<ArrayRef<uint8_t>> TpiRecords);
142 } // namespace llvm
144 #endif