blob: 13de563469abd51a3fe03998aff0949f5a9e8400 [file] [log] [blame]
Rafael Espindolaed3c5432015-07-21 13:42:38 +00001//===-- ObjDumper.h ---------------------------------------------*- C++ -*-===//
Eric Christopher76e70f32013-04-03 18:31:38 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Benjamin Kramer00e08fc2014-08-13 16:26:38 +000010#ifndef LLVM_TOOLS_LLVM_READOBJ_OBJDUMPER_H
11#define LLVM_TOOLS_LLVM_READOBJ_OBJDUMPER_H
Eric Christopher76e70f32013-04-03 18:31:38 +000012
Ahmed Charlesf4ccd112014-03-06 05:51:42 +000013#include <memory>
Rafael Espindolad5132f92014-06-12 17:38:55 +000014#include <system_error>
Ahmed Charlesf4ccd112014-03-06 05:51:42 +000015
Paul Semel064db432018-06-15 14:15:02 +000016#include "llvm/ADT/StringRef.h"
Paul Semel9f006d32018-07-18 18:00:41 +000017#include "llvm/Object/ObjectFile.h"
Paul Semel064db432018-06-15 14:15:02 +000018
Eric Christopher76e70f32013-04-03 18:31:38 +000019namespace llvm {
Eric Christopher76e70f32013-04-03 18:31:38 +000020namespace object {
Rui Ueyamac2aa1792015-08-28 10:27:50 +000021class COFFImportFile;
22class ObjectFile;
Eric Christopher76e70f32013-04-03 18:31:38 +000023}
Reid Klecknerfed38e22016-05-14 00:02:53 +000024namespace codeview {
Zachary Turner47856b22017-11-30 18:39:50 +000025class MergingTypeTableBuilder;
Michael Kupersteine7eda982016-05-16 23:09:32 +000026}
Eric Christopher76e70f32013-04-03 18:31:38 +000027
Zachary Turner2448e9f2016-05-03 00:28:04 +000028class ScopedPrinter;
Eric Christopher76e70f32013-04-03 18:31:38 +000029
30class ObjDumper {
31public:
Zachary Turner2448e9f2016-05-03 00:28:04 +000032 ObjDumper(ScopedPrinter &Writer);
Eric Christopher76e70f32013-04-03 18:31:38 +000033 virtual ~ObjDumper();
34
35 virtual void printFileHeaders() = 0;
Jordan Rupprecht6856bcc2018-11-12 18:02:38 +000036 virtual void printSectionHeaders() = 0;
Eric Christopher76e70f32013-04-03 18:31:38 +000037 virtual void printRelocations() = 0;
38 virtual void printSymbols() = 0;
39 virtual void printDynamicSymbols() = 0;
40 virtual void printUnwindInfo() = 0;
41
42 // Only implemented for ELF at this time.
Michael J. Spencer4cbb2db2015-06-25 21:47:32 +000043 virtual void printDynamicRelocations() { }
Eric Christopher76e70f32013-04-03 18:31:38 +000044 virtual void printDynamicTable() { }
45 virtual void printNeededLibraries() { }
Nico Rieckcf3b55a2013-04-12 04:07:39 +000046 virtual void printProgramHeaders() { }
Paul Semel94b09402018-07-11 10:00:29 +000047 virtual void printSectionAsHex(StringRef SectionName) {}
Michael J. Spencer81097632015-07-09 22:32:24 +000048 virtual void printHashTable() { }
Igor Kudrin45981542015-10-14 12:11:50 +000049 virtual void printGnuHashTable() { }
Rafael Espindola71e35252015-07-21 13:48:41 +000050 virtual void printLoadName() {}
Davide Italianoc813f4c2015-10-16 23:19:01 +000051 virtual void printVersionInfo() {}
Hemant Kulkarni8822b472016-01-26 19:46:39 +000052 virtual void printGroupSections() {}
Hemant Kulkarni14dddbf2016-04-11 17:15:30 +000053 virtual void printHashHistogram() {}
Michael J. Spencer56500c72018-06-02 16:33:01 +000054 virtual void printCGProfile() {}
Peter Collingbournea29ff2e2018-07-17 22:17:18 +000055 virtual void printAddrsig() {}
Saleem Abdulrasoolb899d192016-08-30 18:52:02 +000056 virtual void printNotes() {}
Saleem Abdulrasoole7676fe2018-01-30 16:29:29 +000057 virtual void printELFLinkerOptions() {}
Eric Christopher76e70f32013-04-03 18:31:38 +000058
Saleem Abdulrasool459c9492014-01-30 04:46:33 +000059 // Only implemented for ARM ELF at this time.
60 virtual void printAttributes() { }
61
Simon Atanasyan42469f62014-06-18 08:47:09 +000062 // Only implemented for MIPS ELF at this time.
63 virtual void printMipsPLTGOT() { }
Simon Atanasyanef7c2562015-05-07 15:40:35 +000064 virtual void printMipsABIFlags() { }
Simon Atanasyan3bcfd462015-06-16 21:47:43 +000065 virtual void printMipsReginfo() { }
Simon Atanasyan125d6462016-05-04 05:58:57 +000066 virtual void printMipsOptions() { }
Simon Atanasyan42469f62014-06-18 08:47:09 +000067
Rui Ueyamaf3cd10b2014-10-02 17:02:18 +000068 // Only implemented for PE/COFF.
69 virtual void printCOFFImports() { }
Saleem Abdulrasoolb19a4852015-01-03 21:35:09 +000070 virtual void printCOFFExports() { }
Saleem Abdulrasooldb02fa52014-10-07 19:37:52 +000071 virtual void printCOFFDirectives() { }
Rui Ueyama6272b8c2014-11-19 00:18:07 +000072 virtual void printCOFFBaseReloc() { }
Reid Klecknerfb1a9112016-06-02 17:10:43 +000073 virtual void printCOFFDebugDirectory() { }
Zachary Turner224acd22017-04-27 19:38:38 +000074 virtual void printCOFFResources() {}
Reid Kleckner367f21d2017-06-22 01:10:29 +000075 virtual void printCOFFLoadConfig() { }
Reid Klecknerc81f0002015-12-16 18:28:12 +000076 virtual void printCodeViewDebugInfo() { }
Zachary Turner47856b22017-11-30 18:39:50 +000077 virtual void
78 mergeCodeViewTypes(llvm::codeview::MergingTypeTableBuilder &CVIDs,
79 llvm::codeview::MergingTypeTableBuilder &CVTypes) {}
Rui Ueyamaf3cd10b2014-10-02 17:02:18 +000080
Davide Italiano241f7162015-08-21 20:28:30 +000081 // Only implemented for MachO.
82 virtual void printMachODataInCode() { }
Davide Italiano7dbe74f2015-08-27 15:11:32 +000083 virtual void printMachOVersionMin() { }
Davide Italiano19c43a62015-08-31 19:32:31 +000084 virtual void printMachODysymtab() { }
Davide Italiano885eb982015-09-02 16:24:24 +000085 virtual void printMachOSegment() { }
Davide Italiano7ab20092015-09-03 18:10:28 +000086 virtual void printMachOIndirectSymbols() { }
Davide Italiano793616c2015-09-09 00:21:18 +000087 virtual void printMachOLinkerOptions() { }
Davide Italiano241f7162015-08-21 20:28:30 +000088
Lang Hames63f40542015-06-26 23:56:53 +000089 virtual void printStackMap() const = 0;
90
Paul Semel9f006d32018-07-18 18:00:41 +000091 void printSectionAsString(const object::ObjectFile *Obj, StringRef SecName);
Paul Semelcac968e2018-07-25 10:04:37 +000092 void printSectionAsHex(const object::ObjectFile *Obj, StringRef SecName);
Paul Semel9f006d32018-07-18 18:00:41 +000093
Eric Christopher76e70f32013-04-03 18:31:38 +000094protected:
Zachary Turner2448e9f2016-05-03 00:28:04 +000095 ScopedPrinter &W;
Eric Christopher76e70f32013-04-03 18:31:38 +000096};
97
Rafael Espindolaa20bcb92014-06-13 01:25:41 +000098std::error_code createCOFFDumper(const object::ObjectFile *Obj,
Zachary Turner2448e9f2016-05-03 00:28:04 +000099 ScopedPrinter &Writer,
Rafael Espindolaa20bcb92014-06-13 01:25:41 +0000100 std::unique_ptr<ObjDumper> &Result);
Eric Christopher76e70f32013-04-03 18:31:38 +0000101
Rafael Espindolaa20bcb92014-06-13 01:25:41 +0000102std::error_code createELFDumper(const object::ObjectFile *Obj,
Zachary Turner2448e9f2016-05-03 00:28:04 +0000103 ScopedPrinter &Writer,
Rafael Espindolaa20bcb92014-06-13 01:25:41 +0000104 std::unique_ptr<ObjDumper> &Result);
Eric Christopher76e70f32013-04-03 18:31:38 +0000105
Rafael Espindolaa20bcb92014-06-13 01:25:41 +0000106std::error_code createMachODumper(const object::ObjectFile *Obj,
Zachary Turner2448e9f2016-05-03 00:28:04 +0000107 ScopedPrinter &Writer,
Rafael Espindolaa20bcb92014-06-13 01:25:41 +0000108 std::unique_ptr<ObjDumper> &Result);
Eric Christopher76e70f32013-04-03 18:31:38 +0000109
Derek Schuffc20099f2017-01-30 23:30:52 +0000110std::error_code createWasmDumper(const object::ObjectFile *Obj,
111 ScopedPrinter &Writer,
112 std::unique_ptr<ObjDumper> &Result);
113
Sam Clegg52483262018-01-10 00:14:19 +0000114void dumpCOFFImportFile(const object::COFFImportFile *File,
115 ScopedPrinter &Writer);
Rui Ueyamac2aa1792015-08-28 10:27:50 +0000116
Zachary Turner47856b22017-11-30 18:39:50 +0000117void dumpCodeViewMergedTypes(
118 ScopedPrinter &Writer, llvm::codeview::MergingTypeTableBuilder &IDTable,
119 llvm::codeview::MergingTypeTableBuilder &TypeTable);
Reid Klecknerfed38e22016-05-14 00:02:53 +0000120
Eric Christopher76e70f32013-04-03 18:31:38 +0000121} // namespace llvm
122
123#endif