1 //===--- llvm-objdump.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_OBJDUMP_LLVM_OBJDUMP_H 10 #define LLVM_TOOLS_LLVM_OBJDUMP_LLVM_OBJDUMP_H 11 12 #include "llvm/ADT/StringSet.h" 13 #include "llvm/DebugInfo/DIContext.h" 14 #include "llvm/MC/MCDisassembler/MCDisassembler.h" 15 #include "llvm/MC/MCSubtargetInfo.h" 16 #include "llvm/Object/Archive.h" 17 #include "llvm/Object/ObjectFile.h" 18 #include "llvm/Support/Compiler.h" 19 #include "llvm/Support/DataTypes.h" 20 #include "llvm/Support/FormattedStream.h" 21 22 namespace llvm { 23 class StringRef; 24 class Twine; 25 26 namespace opt { 27 class Arg; 28 } // namespace opt 29 30 namespace object { 31 class RelocationRef; 32 struct VersionEntry; 33 } // namespace object 34 35 namespace objdump { 36 37 enum DebugVarsFormat { DVDisabled, DVUnicode, DVASCII, DVInvalid }; 38 39 extern bool ArchiveHeaders; 40 extern int DbgIndent; 41 extern DebugVarsFormat DbgVariables; 42 extern bool Demangle; 43 extern bool Disassemble; 44 extern bool DisassembleAll; 45 extern DIDumpType DwarfDumpType; 46 extern std::vector<std::string> FilterSections; 47 extern bool LeadingAddr; 48 extern std::vector<std::string> MAttrs; 49 extern std::string MCPU; 50 extern std::string Prefix; 51 extern uint32_t PrefixStrip; 52 extern bool PrintImmHex; 53 extern bool PrintLines; 54 extern bool PrintSource; 55 extern bool PrivateHeaders; 56 extern bool Relocations; 57 extern bool SectionHeaders; 58 extern bool SectionContents; 59 extern bool ShowRawInsn; 60 extern bool SymbolDescription; 61 extern bool TracebackTable; 62 extern bool SymbolTable; 63 extern std::string TripleName; 64 extern bool UnwindInfo; 65 66 extern StringSet<> FoundSectionSet; 67 68 class Dumper { 69 const object::ObjectFile &O; 70 StringSet<> Warnings; 71 72 public: 73 Dumper(const object::ObjectFile &O) : O(O) {} 74 75 void reportUniqueWarning(Error Err); 76 void reportUniqueWarning(const Twine &Msg); 77 78 void printSymbolTable(StringRef ArchiveName, 79 StringRef ArchitectureName = StringRef(), 80 bool DumpDynamic = false); 81 void printSymbol(const object::SymbolRef &Symbol, 82 ArrayRef<object::VersionEntry> SymbolVersions, 83 StringRef FileName, StringRef ArchiveName, 84 StringRef ArchitectureName, bool DumpDynamic); 85 void printRelocations(); 86 }; 87 88 // Various helper functions. 89 90 /// Creates a SectionFilter with a standard predicate that conditionally skips 91 /// sections when the --section objdump flag is provided. 92 /// 93 /// Idx is an optional output parameter that keeps track of which section index 94 /// this is. This may be different than the actual section number, as some 95 /// sections may be filtered (e.g. symbol tables). 96 object::SectionFilter ToolSectionFilter(const llvm::object::ObjectFile &O, 97 uint64_t *Idx = nullptr); 98 99 bool isRelocAddressLess(object::RelocationRef A, object::RelocationRef B); 100 void printDynamicRelocations(const object::ObjectFile *O); 101 void printSectionHeaders(object::ObjectFile &O); 102 void printSectionContents(const object::ObjectFile *O); 103 [[noreturn]] void reportError(StringRef File, const Twine &Message); 104 [[noreturn]] void reportError(Error E, StringRef FileName, 105 StringRef ArchiveName = "", 106 StringRef ArchitectureName = ""); 107 void reportWarning(const Twine &Message, StringRef File); 108 109 template <typename T, typename... Ts> 110 T unwrapOrError(Expected<T> EO, Ts &&... Args) { 111 if (EO) 112 return std::move(*EO); 113 reportError(EO.takeError(), std::forward<Ts>(Args)...); 114 } 115 116 void invalidArgValue(const opt::Arg *A); 117 118 std::string getFileNameForError(const object::Archive::Child &C, 119 unsigned Index); 120 SymbolInfoTy createSymbolInfo(const object::ObjectFile &Obj, 121 const object::SymbolRef &Symbol); 122 unsigned getInstStartColumn(const MCSubtargetInfo &STI); 123 void printRawData(llvm::ArrayRef<uint8_t> Bytes, uint64_t Address, 124 llvm::formatted_raw_ostream &OS, 125 llvm::MCSubtargetInfo const &STI); 126 127 } // namespace objdump 128 } // end namespace llvm 129 130 #endif 131