brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.1 KiB · bac8589 Raw
155 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_TOOLS_LLVM_OBJDUMP_LLVM_OBJDUMP_H10#define LLVM_TOOLS_LLVM_OBJDUMP_LLVM_OBJDUMP_H11 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/FormattedStream.h"19#include <functional>20#include <memory>21 22namespace llvm {23class StringRef;24class Twine;25 26namespace opt {27class Arg;28} // namespace opt29 30namespace object {31class RelocationRef;32struct VersionEntry;33 34class COFFObjectFile;35class ELFObjectFileBase;36class MachOObjectFile;37class WasmObjectFile;38class XCOFFObjectFile;39class DXContainer;40} // namespace object41 42namespace objdump {43 44enum DebugFormat { DFASCII, DFDisabled, DFInvalid, DFLimitsOnly, DFUnicode };45 46extern bool ArchiveHeaders;47extern int DbgIndent;48extern DebugFormat DbgVariables;49extern DebugFormat DbgInlinedFunctions;50extern bool Demangle;51extern bool Disassemble;52extern bool DisassembleAll;53extern std::vector<std::string> DisassemblerOptions;54extern DIDumpType DwarfDumpType;55extern std::vector<std::string> FilterSections;56extern bool LeadingAddr;57extern std::vector<std::string> MAttrs;58extern std::string MCPU;59extern std::string Prefix;60extern uint32_t PrefixStrip;61extern bool PrintImmHex;62extern bool PrintLines;63extern bool PrintSource;64extern bool PrivateHeaders;65extern bool Relocations;66extern bool SectionHeaders;67extern bool SectionContents;68extern bool ShowRawInsn;69extern bool SymbolDescription;70extern bool TracebackTable;71extern bool SymbolTable;72extern std::string TripleName;73extern bool UnwindInfo;74 75extern StringSet<> FoundSectionSet;76 77class Dumper {78  const object::ObjectFile &O;79  StringSet<> Warnings;80 81protected:82  llvm::raw_ostream &OS;83  std::function<Error(const Twine &Msg)> WarningHandler;84 85public:86  Dumper(const object::ObjectFile &O);87  virtual ~Dumper() = default;88 89  void reportUniqueWarning(Error Err);90  void reportUniqueWarning(const Twine &Msg);91 92  virtual void printPrivateHeaders();93  virtual void printDynamicRelocations() {}94  void printSymbolTable(StringRef ArchiveName,95                        StringRef ArchitectureName = StringRef(),96                        bool DumpDynamic = false);97  void printSymbol(const object::SymbolRef &Symbol,98                   ArrayRef<object::VersionEntry> SymbolVersions,99                   StringRef FileName, StringRef ArchiveName,100                   StringRef ArchitectureName, bool DumpDynamic);101  void printRelocations();102};103 104std::unique_ptr<Dumper> createCOFFDumper(const object::COFFObjectFile &Obj);105std::unique_ptr<Dumper> createELFDumper(const object::ELFObjectFileBase &Obj);106std::unique_ptr<Dumper> createMachODumper(const object::MachOObjectFile &Obj);107std::unique_ptr<Dumper> createWasmDumper(const object::WasmObjectFile &Obj);108std::unique_ptr<Dumper> createXCOFFDumper(const object::XCOFFObjectFile &Obj);109std::unique_ptr<Dumper>110createDXContainerDumper(const object::DXContainerObjectFile &Obj);111 112// Various helper functions.113 114/// Creates a SectionFilter with a standard predicate that conditionally skips115/// sections when the --section objdump flag is provided.116///117/// Idx is an optional output parameter that keeps track of which section index118/// this is. This may be different than the actual section number, as some119/// sections may be filtered (e.g. symbol tables).120object::SectionFilter ToolSectionFilter(const llvm::object::ObjectFile &O,121                                        uint64_t *Idx = nullptr);122 123bool isRelocAddressLess(object::RelocationRef A, object::RelocationRef B);124void printSectionHeaders(object::ObjectFile &O);125void printSectionContents(const object::ObjectFile *O);126[[noreturn]] void reportError(StringRef File, const Twine &Message);127[[noreturn]] void reportError(Error E, StringRef FileName,128                              StringRef ArchiveName = "",129                              StringRef ArchitectureName = "");130void reportWarning(const Twine &Message, StringRef File);131 132template <typename T, typename... Ts>133T unwrapOrError(Expected<T> EO, Ts &&...Args) {134  if (EO)135    return std::move(*EO);136  reportError(EO.takeError(), std::forward<Ts>(Args)...);137}138 139void invalidArgValue(const opt::Arg *A);140 141std::string getFileNameForError(const object::Archive::Child &C,142                                unsigned Index);143SymbolInfoTy createSymbolInfo(const object::ObjectFile &Obj,144                              const object::SymbolRef &Symbol,145                              bool IsMappingSymbol = false);146unsigned getInstStartColumn(const MCSubtargetInfo &STI);147void printRawData(llvm::ArrayRef<uint8_t> Bytes, uint64_t Address,148                  llvm::formatted_raw_ostream &OS,149                  llvm::MCSubtargetInfo const &STI);150 151} // namespace objdump152} // end namespace llvm153 154#endif155