[UpdateCCTestChecks] Detect function mangled name on separate line
[llvm-core.git] / tools / llvm-objdump / llvm-objdump.h
blobd36c4fdc00e28f3a7da772ed4316e2c84e728d3d
1 //
2 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3 // See https://llvm.org/LICENSE.txt for license information.
4 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5 //
6 //===----------------------------------------------------------------------===//
8 #ifndef LLVM_TOOLS_LLVM_OBJDUMP_LLVM_OBJDUMP_H
9 #define LLVM_TOOLS_LLVM_OBJDUMP_LLVM_OBJDUMP_H
11 #include "llvm/DebugInfo/DIContext.h"
12 #include "llvm/Support/CommandLine.h"
13 #include "llvm/Support/Compiler.h"
14 #include "llvm/Support/DataTypes.h"
15 #include "llvm/Object/Archive.h"
17 namespace llvm {
18 class StringRef;
20 namespace object {
21 class COFFObjectFile;
22 class COFFImportFile;
23 class ELFObjectFileBase;
24 class ELFSectionRef;
25 class MachOObjectFile;
26 class MachOUniversalBinary;
27 class RelocationRef;
30 extern cl::opt<bool> Demangle;
32 typedef std::function<bool(llvm::object::SectionRef const &)> FilterPredicate;
34 class SectionFilterIterator {
35 public:
36 SectionFilterIterator(FilterPredicate P,
37 llvm::object::section_iterator const &I,
38 llvm::object::section_iterator const &E)
39 : Predicate(std::move(P)), Iterator(I), End(E) {
40 ScanPredicate();
42 const llvm::object::SectionRef &operator*() const { return *Iterator; }
43 SectionFilterIterator &operator++() {
44 ++Iterator;
45 ScanPredicate();
46 return *this;
48 bool operator!=(SectionFilterIterator const &Other) const {
49 return Iterator != Other.Iterator;
52 private:
53 void ScanPredicate() {
54 while (Iterator != End && !Predicate(*Iterator)) {
55 ++Iterator;
58 FilterPredicate Predicate;
59 llvm::object::section_iterator Iterator;
60 llvm::object::section_iterator End;
63 class SectionFilter {
64 public:
65 SectionFilter(FilterPredicate P, llvm::object::ObjectFile const &O)
66 : Predicate(std::move(P)), Object(O) {}
67 SectionFilterIterator begin() {
68 return SectionFilterIterator(Predicate, Object.section_begin(),
69 Object.section_end());
71 SectionFilterIterator end() {
72 return SectionFilterIterator(Predicate, Object.section_end(),
73 Object.section_end());
76 private:
77 FilterPredicate Predicate;
78 llvm::object::ObjectFile const &Object;
81 // Various helper functions.
82 SectionFilter ToolSectionFilter(llvm::object::ObjectFile const &O);
84 Error getELFRelocationValueString(const object::ELFObjectFileBase *Obj,
85 const object::RelocationRef &Rel,
86 llvm::SmallVectorImpl<char> &Result);
87 Error getCOFFRelocationValueString(const object::COFFObjectFile *Obj,
88 const object::RelocationRef &Rel,
89 llvm::SmallVectorImpl<char> &Result);
90 Error getWasmRelocationValueString(const object::WasmObjectFile *Obj,
91 const object::RelocationRef &RelRef,
92 llvm::SmallVectorImpl<char> &Result);
93 Error getMachORelocationValueString(const object::MachOObjectFile *Obj,
94 const object::RelocationRef &RelRef,
95 llvm::SmallVectorImpl<char> &Result);
97 uint64_t getELFSectionLMA(const object::ELFSectionRef& Sec);
99 bool isRelocAddressLess(object::RelocationRef A, object::RelocationRef B);
100 void parseInputMachO(StringRef Filename);
101 void parseInputMachO(object::MachOUniversalBinary *UB);
102 void printCOFFUnwindInfo(const object::COFFObjectFile *O);
103 void printMachOUnwindInfo(const object::MachOObjectFile *O);
104 void printMachOExportsTrie(const object::MachOObjectFile *O);
105 void printMachORebaseTable(object::MachOObjectFile *O);
106 void printMachOBindTable(object::MachOObjectFile *O);
107 void printMachOLazyBindTable(object::MachOObjectFile *O);
108 void printMachOWeakBindTable(object::MachOObjectFile *O);
109 void printELFFileHeader(const object::ObjectFile *O);
110 void printELFDynamicSection(const object::ObjectFile *Obj);
111 void printELFSymbolVersionInfo(const object::ObjectFile *Obj);
112 void printCOFFFileHeader(const object::ObjectFile *O);
113 void printCOFFSymbolTable(const object::COFFImportFile *I);
114 void printCOFFSymbolTable(const object::COFFObjectFile *O);
115 void printMachOFileHeader(const object::ObjectFile *O);
116 void printMachOLoadCommands(const object::ObjectFile *O);
117 void printWasmFileHeader(const object::ObjectFile *O);
118 void printExportsTrie(const object::ObjectFile *O);
119 void printRebaseTable(object::ObjectFile *O);
120 void printBindTable(object::ObjectFile *O);
121 void printLazyBindTable(object::ObjectFile *O);
122 void printWeakBindTable(object::ObjectFile *O);
123 void printRawClangAST(const object::ObjectFile *O);
124 void printRelocations(const object::ObjectFile *O);
125 void printDynamicRelocations(const object::ObjectFile *O);
126 void printSectionHeaders(const object::ObjectFile *O);
127 void printSectionContents(const object::ObjectFile *O);
128 void printSymbolTable(const object::ObjectFile *O, StringRef ArchiveName,
129 StringRef ArchitectureName = StringRef());
130 LLVM_ATTRIBUTE_NORETURN void reportError(StringRef File, Twine Message);
131 LLVM_ATTRIBUTE_NORETURN void reportError(Error E, StringRef FileName,
132 StringRef ArchiveName = "",
133 StringRef ArchitectureName = "");
134 void reportWarning(Twine Message, StringRef File);
136 template <typename T, typename... Ts>
137 T unwrapOrError(Expected<T> EO, Ts &&... Args) {
138 if (EO)
139 return std::move(*EO);
140 reportError(EO.takeError(), std::forward<Ts>(Args)...);
143 std::string getFileNameForError(const object::Archive::Child &C,
144 unsigned Index);
146 } // end namespace llvm
148 #endif