ObjDumper.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. //===----------------------------------------------------------------------===//
  8. #ifndef LLVM_TOOLS_LLVM_READOBJ_OBJDUMPER_H
  9. #define LLVM_TOOLS_LLVM_READOBJ_OBJDUMPER_H
  10. #include <memory>
  11. #include <system_error>
  12. #include "llvm/ADT/StringRef.h"
  13. #include "llvm/Object/ObjectFile.h"
  14. #include "llvm/Support/CommandLine.h"
  15. #include <unordered_set>
  16. namespace llvm {
  17. namespace object {
  18. class COFFImportFile;
  19. class ObjectFile;
  20. class XCOFFObjectFile;
  21. class ELFObjectFileBase;
  22. }
  23. namespace codeview {
  24. class GlobalTypeTableBuilder;
  25. class MergingTypeTableBuilder;
  26. } // namespace codeview
  27. class ScopedPrinter;
  28. class ObjDumper {
  29. public:
  30. ObjDumper(ScopedPrinter &Writer, StringRef ObjName);
  31. virtual ~ObjDumper();
  32. virtual bool canDumpContent() { return true; }
  33. virtual void printFileHeaders() = 0;
  34. virtual void printSectionHeaders() = 0;
  35. virtual void printRelocations() = 0;
  36. virtual void printSymbols(bool PrintSymbols, bool PrintDynamicSymbols) {
  37. if (PrintSymbols)
  38. printSymbols();
  39. if (PrintDynamicSymbols)
  40. printDynamicSymbols();
  41. }
  42. virtual void printProgramHeaders(bool PrintProgramHeaders,
  43. cl::boolOrDefault PrintSectionMapping) {
  44. if (PrintProgramHeaders)
  45. printProgramHeaders();
  46. if (PrintSectionMapping == cl::BOU_TRUE)
  47. printSectionMapping();
  48. }
  49. virtual void printUnwindInfo() = 0;
  50. // Only implemented for ELF at this time.
  51. virtual void printDependentLibs() {}
  52. virtual void printDynamicRelocations() { }
  53. virtual void printDynamicTable() { }
  54. virtual void printNeededLibraries() { }
  55. virtual void printSectionAsHex(StringRef SectionName) {}
  56. virtual void printHashTable() { }
  57. virtual void printGnuHashTable() {}
  58. virtual void printHashSymbols() {}
  59. virtual void printLoadName() {}
  60. virtual void printVersionInfo() {}
  61. virtual void printGroupSections() {}
  62. virtual void printHashHistograms() {}
  63. virtual void printCGProfile() {}
  64. virtual void printAddrsig() {}
  65. virtual void printNotes() {}
  66. virtual void printELFLinkerOptions() {}
  67. virtual void printStackSizes() {}
  68. virtual void printSectionDetails() {}
  69. virtual void printArchSpecificInfo() {}
  70. // Only implemented for PE/COFF.
  71. virtual void printCOFFImports() { }
  72. virtual void printCOFFExports() { }
  73. virtual void printCOFFDirectives() { }
  74. virtual void printCOFFBaseReloc() { }
  75. virtual void printCOFFDebugDirectory() { }
  76. virtual void printCOFFTLSDirectory() {}
  77. virtual void printCOFFResources() {}
  78. virtual void printCOFFLoadConfig() { }
  79. virtual void printCodeViewDebugInfo() { }
  80. virtual void
  81. mergeCodeViewTypes(llvm::codeview::MergingTypeTableBuilder &CVIDs,
  82. llvm::codeview::MergingTypeTableBuilder &CVTypes,
  83. llvm::codeview::GlobalTypeTableBuilder &GlobalCVIDs,
  84. llvm::codeview::GlobalTypeTableBuilder &GlobalCVTypes,
  85. bool GHash) {}
  86. // Only implemented for MachO.
  87. virtual void printMachODataInCode() { }
  88. virtual void printMachOVersionMin() { }
  89. virtual void printMachODysymtab() { }
  90. virtual void printMachOSegment() { }
  91. virtual void printMachOIndirectSymbols() { }
  92. virtual void printMachOLinkerOptions() { }
  93. virtual void printStackMap() const = 0;
  94. void printSectionsAsString(const object::ObjectFile &Obj,
  95. ArrayRef<std::string> Sections);
  96. void printSectionsAsHex(const object::ObjectFile &Obj,
  97. ArrayRef<std::string> Sections);
  98. std::function<Error(const Twine &Msg)> WarningHandler;
  99. void reportUniqueWarning(Error Err) const;
  100. void reportUniqueWarning(const Twine &Msg) const;
  101. protected:
  102. ScopedPrinter &W;
  103. private:
  104. virtual void printSymbols() {}
  105. virtual void printDynamicSymbols() {}
  106. virtual void printProgramHeaders() {}
  107. virtual void printSectionMapping() {}
  108. std::unordered_set<std::string> Warnings;
  109. };
  110. std::unique_ptr<ObjDumper> createCOFFDumper(const object::COFFObjectFile &Obj,
  111. ScopedPrinter &Writer);
  112. std::unique_ptr<ObjDumper> createELFDumper(const object::ELFObjectFileBase &Obj,
  113. ScopedPrinter &Writer);
  114. std::unique_ptr<ObjDumper> createMachODumper(const object::MachOObjectFile &Obj,
  115. ScopedPrinter &Writer);
  116. std::unique_ptr<ObjDumper> createWasmDumper(const object::WasmObjectFile &Obj,
  117. ScopedPrinter &Writer);
  118. std::unique_ptr<ObjDumper> createXCOFFDumper(const object::XCOFFObjectFile &Obj,
  119. ScopedPrinter &Writer);
  120. void dumpCOFFImportFile(const object::COFFImportFile *File,
  121. ScopedPrinter &Writer);
  122. void dumpCodeViewMergedTypes(ScopedPrinter &Writer,
  123. ArrayRef<ArrayRef<uint8_t>> IpiRecords,
  124. ArrayRef<ArrayRef<uint8_t>> TpiRecords);
  125. } // namespace llvm
  126. #endif