blob: 8c3a7bec73be4c210c984c7c490c0dfcea6c4703 [file] [log] [blame]
Rafael Espindolafbb86b22015-07-21 13:42:38 +00001//===-- ObjDumper.h ---------------------------------------------*- C++ -*-===//
Eric Christopher9cad53c2013-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 Kramera7c40ef2014-08-13 16:26:38 +000010#ifndef LLVM_TOOLS_LLVM_READOBJ_OBJDUMPER_H
11#define LLVM_TOOLS_LLVM_READOBJ_OBJDUMPER_H
Eric Christopher9cad53c2013-04-03 18:31:38 +000012
Ahmed Charles56440fd2014-03-06 05:51:42 +000013#include <memory>
Rafael Espindolaa6e9c3e2014-06-12 17:38:55 +000014#include <system_error>
Ahmed Charles56440fd2014-03-06 05:51:42 +000015
Paul Semelfa5597b2018-06-15 14:15:02 +000016#include "llvm/ADT/StringRef.h"
Paul Semel6e137902018-07-18 18:00:41 +000017#include "llvm/Object/ObjectFile.h"
Paul Semelfa5597b2018-06-15 14:15:02 +000018
Eric Christopher9cad53c2013-04-03 18:31:38 +000019namespace llvm {
Eric Christopher9cad53c2013-04-03 18:31:38 +000020namespace object {
Rui Ueyama93210892015-08-28 10:27:50 +000021class COFFImportFile;
22class ObjectFile;
Eric Christopher9cad53c2013-04-03 18:31:38 +000023}
Reid Kleckner0b269742016-05-14 00:02:53 +000024namespace codeview {
Zachary Turnerca6dbf12017-11-30 18:39:50 +000025class MergingTypeTableBuilder;
Michael Kupersteina5560502016-05-16 23:09:32 +000026}
Eric Christopher9cad53c2013-04-03 18:31:38 +000027
Zachary Turner88bb1632016-05-03 00:28:04 +000028class ScopedPrinter;
Eric Christopher9cad53c2013-04-03 18:31:38 +000029
30class ObjDumper {
31public:
Zachary Turner88bb1632016-05-03 00:28:04 +000032 ObjDumper(ScopedPrinter &Writer);
Eric Christopher9cad53c2013-04-03 18:31:38 +000033 virtual ~ObjDumper();
34
35 virtual void printFileHeaders() = 0;
36 virtual void printSections() = 0;
37 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. Spencer594c0282015-06-25 21:47:32 +000043 virtual void printDynamicRelocations() { }
Eric Christopher9cad53c2013-04-03 18:31:38 +000044 virtual void printDynamicTable() { }
45 virtual void printNeededLibraries() { }
Nico Rieckd6df0542013-04-12 04:07:39 +000046 virtual void printProgramHeaders() { }
Paul Semelb98f5042018-07-11 10:00:29 +000047 virtual void printSectionAsHex(StringRef SectionName) {}
Michael J. Spencer20546ff2015-07-09 22:32:24 +000048 virtual void printHashTable() { }
Igor Kudrin496fb2f2015-10-14 12:11:50 +000049 virtual void printGnuHashTable() { }
Rafael Espindola33e746f22015-07-21 13:48:41 +000050 virtual void printLoadName() {}
Davide Italiano4f05f322015-10-16 23:19:01 +000051 virtual void printVersionInfo() {}
Hemant Kulkarniab4a46f2016-01-26 19:46:39 +000052 virtual void printGroupSections() {}
Hemant Kulkarni9b1b7f02016-04-11 17:15:30 +000053 virtual void printHashHistogram() {}
Michael J. Spencerae6eeae2018-06-02 16:33:01 +000054 virtual void printCGProfile() {}
Peter Collingbourne3e227332018-07-17 22:17:18 +000055 virtual void printAddrsig() {}
Saleem Abdulrasool6a405442016-08-30 18:52:02 +000056 virtual void printNotes() {}
Saleem Abdulrasoolb36fbbc2018-01-30 16:29:29 +000057 virtual void printELFLinkerOptions() {}
Eric Christopher9cad53c2013-04-03 18:31:38 +000058
Saleem Abdulrasool15d16d82014-01-30 04:46:33 +000059 // Only implemented for ARM ELF at this time.
60 virtual void printAttributes() { }
61
Simon Atanasyan80433902014-06-18 08:47:09 +000062 // Only implemented for MIPS ELF at this time.
63 virtual void printMipsPLTGOT() { }
Simon Atanasyanc914de22015-05-07 15:40:35 +000064 virtual void printMipsABIFlags() { }
Simon Atanasyan6e07e932015-06-16 21:47:43 +000065 virtual void printMipsReginfo() { }
Simon Atanasyan8a71b532016-05-04 05:58:57 +000066 virtual void printMipsOptions() { }
Simon Atanasyan80433902014-06-18 08:47:09 +000067
Rui Ueyama1e152d52014-10-02 17:02:18 +000068 // Only implemented for PE/COFF.
69 virtual void printCOFFImports() { }
Saleem Abdulrasoolddd92642015-01-03 21:35:09 +000070 virtual void printCOFFExports() { }
Saleem Abdulrasoolf9578632014-10-07 19:37:52 +000071 virtual void printCOFFDirectives() { }
Rui Ueyama74e85132014-11-19 00:18:07 +000072 virtual void printCOFFBaseReloc() { }
Reid Kleckner2da433e2016-06-02 17:10:43 +000073 virtual void printCOFFDebugDirectory() { }
Zachary Turner8d6396d2017-04-27 19:38:38 +000074 virtual void printCOFFResources() {}
Reid Klecknerb7d716c2017-06-22 01:10:29 +000075 virtual void printCOFFLoadConfig() { }
Reid Kleckner83ebad32015-12-16 18:28:12 +000076 virtual void printCodeViewDebugInfo() { }
Zachary Turnerca6dbf12017-11-30 18:39:50 +000077 virtual void
78 mergeCodeViewTypes(llvm::codeview::MergingTypeTableBuilder &CVIDs,
79 llvm::codeview::MergingTypeTableBuilder &CVTypes) {}
Rui Ueyama1e152d52014-10-02 17:02:18 +000080
Davide Italiano07e7acb2015-08-21 20:28:30 +000081 // Only implemented for MachO.
82 virtual void printMachODataInCode() { }
Davide Italiano976f4da2015-08-27 15:11:32 +000083 virtual void printMachOVersionMin() { }
Davide Italiano35eebe12015-08-31 19:32:31 +000084 virtual void printMachODysymtab() { }
Davide Italianod1f09962015-09-02 16:24:24 +000085 virtual void printMachOSegment() { }
Davide Italiano4410b222015-09-03 18:10:28 +000086 virtual void printMachOIndirectSymbols() { }
Davide Italiano9a429b72015-09-09 00:21:18 +000087 virtual void printMachOLinkerOptions() { }
Davide Italiano07e7acb2015-08-21 20:28:30 +000088
Lang Hames0000afd2015-06-26 23:56:53 +000089 virtual void printStackMap() const = 0;
90
Paul Semel6e137902018-07-18 18:00:41 +000091 void printSectionAsString(const object::ObjectFile *Obj, StringRef SecName);
Paul Semel5ce8f152018-07-25 10:04:37 +000092 void printSectionAsHex(const object::ObjectFile *Obj, StringRef SecName);
Paul Semel6e137902018-07-18 18:00:41 +000093
Eric Christopher9cad53c2013-04-03 18:31:38 +000094protected:
Zachary Turner88bb1632016-05-03 00:28:04 +000095 ScopedPrinter &W;
Eric Christopher9cad53c2013-04-03 18:31:38 +000096};
97
Rafael Espindolabff5d0d2014-06-13 01:25:41 +000098std::error_code createCOFFDumper(const object::ObjectFile *Obj,
Zachary Turner88bb1632016-05-03 00:28:04 +000099 ScopedPrinter &Writer,
Rafael Espindolabff5d0d2014-06-13 01:25:41 +0000100 std::unique_ptr<ObjDumper> &Result);
Eric Christopher9cad53c2013-04-03 18:31:38 +0000101
Rafael Espindolabff5d0d2014-06-13 01:25:41 +0000102std::error_code createELFDumper(const object::ObjectFile *Obj,
Zachary Turner88bb1632016-05-03 00:28:04 +0000103 ScopedPrinter &Writer,
Rafael Espindolabff5d0d2014-06-13 01:25:41 +0000104 std::unique_ptr<ObjDumper> &Result);
Eric Christopher9cad53c2013-04-03 18:31:38 +0000105
Rafael Espindolabff5d0d2014-06-13 01:25:41 +0000106std::error_code createMachODumper(const object::ObjectFile *Obj,
Zachary Turner88bb1632016-05-03 00:28:04 +0000107 ScopedPrinter &Writer,
Rafael Espindolabff5d0d2014-06-13 01:25:41 +0000108 std::unique_ptr<ObjDumper> &Result);
Eric Christopher9cad53c2013-04-03 18:31:38 +0000109
Derek Schuff6d76b7b2017-01-30 23:30:52 +0000110std::error_code createWasmDumper(const object::ObjectFile *Obj,
111 ScopedPrinter &Writer,
112 std::unique_ptr<ObjDumper> &Result);
113
Sam Clegg88e9a152018-01-10 00:14:19 +0000114void dumpCOFFImportFile(const object::COFFImportFile *File,
115 ScopedPrinter &Writer);
Rui Ueyama93210892015-08-28 10:27:50 +0000116
Zachary Turnerca6dbf12017-11-30 18:39:50 +0000117void dumpCodeViewMergedTypes(
118 ScopedPrinter &Writer, llvm::codeview::MergingTypeTableBuilder &IDTable,
119 llvm::codeview::MergingTypeTableBuilder &TypeTable);
Reid Kleckner0b269742016-05-14 00:02:53 +0000120
Eric Christopher9cad53c2013-04-03 18:31:38 +0000121} // namespace llvm
122
123#endif