1 | //===-- ObjectFileCOFF.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 LLDB_SOURCE_PLUGINS_OBJECTFILE_COFF_OBJECTFILECOFF_H |
10 | #define LLDB_SOURCE_PLUGINS_OBJECTFILE_COFF_OBJECTFILECOFF_H |
11 | |
12 | #include "lldb/Symbol/ObjectFile.h" |
13 | |
14 | #include "llvm/Object/COFF.h" |
15 | |
16 | /// \class ObjectFileELF |
17 | /// Generic COFF object file reader. |
18 | /// |
19 | /// This class provides a generic COFF reader plugin implementing the ObjectFile |
20 | /// protocol. Assumes that the COFF object format is a Microsoft style COFF |
21 | /// rather than the full generality afforded by it. |
22 | class ObjectFileCOFF : public lldb_private::ObjectFile { |
23 | std::unique_ptr<llvm::object::COFFObjectFile> m_object; |
24 | lldb_private::UUID m_uuid; |
25 | |
26 | ObjectFileCOFF(std::unique_ptr<llvm::object::COFFObjectFile> object, |
27 | const lldb::ModuleSP &module_sp, lldb::DataBufferSP data_sp, |
28 | lldb::offset_t data_offset, const lldb_private::FileSpec *file, |
29 | lldb::offset_t file_offset, lldb::offset_t length) |
30 | : ObjectFile(module_sp, file, file_offset, length, data_sp, data_offset), |
31 | m_object(std::move(object)) {} |
32 | |
33 | public: |
34 | ~ObjectFileCOFF() override; |
35 | |
36 | static void Initialize(); |
37 | static void Terminate(); |
38 | |
39 | static llvm::StringRef GetPluginNameStatic() { return "COFF" ; } |
40 | static llvm::StringRef GetPluginDescriptionStatic() { |
41 | return "COFF Object File Reader" ; |
42 | } |
43 | |
44 | static lldb_private::ObjectFile * |
45 | CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP data_sp, |
46 | lldb::offset_t data_offset, const lldb_private::FileSpec *file, |
47 | lldb::offset_t file_offset, lldb::offset_t length); |
48 | |
49 | static lldb_private::ObjectFile * |
50 | CreateMemoryInstance(const lldb::ModuleSP &module_sp, |
51 | lldb::WritableDataBufferSP data_sp, |
52 | const lldb::ProcessSP &process_sp, lldb::addr_t ); |
53 | |
54 | static size_t GetModuleSpecifications(const lldb_private::FileSpec &file, |
55 | lldb::DataBufferSP &data_sp, |
56 | lldb::offset_t data_offset, |
57 | lldb::offset_t file_offset, |
58 | lldb::offset_t length, |
59 | lldb_private::ModuleSpecList &specs); |
60 | |
61 | // LLVM RTTI support |
62 | static char ID; |
63 | bool isA(const void *ClassID) const override { |
64 | return ClassID == &ID || ObjectFile::isA(ClassID); |
65 | } |
66 | static bool classof(const ObjectFile *obj) { return obj->isA(ClassID: &ID); } |
67 | |
68 | // PluginInterface protocol |
69 | llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); } |
70 | |
71 | // ObjectFile protocol |
72 | void Dump(lldb_private::Stream *stream) override; |
73 | |
74 | uint32_t GetAddressByteSize() const override; |
75 | |
76 | uint32_t GetDependentModules(lldb_private::FileSpecList &specs) override { |
77 | return 0; |
78 | } |
79 | |
80 | bool IsExecutable() const override { |
81 | // COFF is an object file format only, it cannot host an executable. |
82 | return false; |
83 | } |
84 | |
85 | lldb_private::ArchSpec GetArchitecture() override; |
86 | |
87 | void CreateSections(lldb_private::SectionList &) override; |
88 | |
89 | void ParseSymtab(lldb_private::Symtab &) override; |
90 | |
91 | bool IsStripped() override { |
92 | // FIXME see if there is a good way to identify a /Z7 v /Zi or /ZI build. |
93 | return false; |
94 | } |
95 | |
96 | lldb_private::UUID GetUUID() override { return m_uuid; } |
97 | |
98 | lldb::ByteOrder GetByteOrder() const override { |
99 | // Microsoft always uses little endian. |
100 | return lldb::ByteOrder::eByteOrderLittle; |
101 | } |
102 | |
103 | bool () override; |
104 | |
105 | lldb_private::ObjectFile::Type CalculateType() override { |
106 | // COFF is an object file format only, it cannot host an executable. |
107 | return lldb_private::ObjectFile::eTypeObjectFile; |
108 | } |
109 | |
110 | lldb_private::ObjectFile::Strata CalculateStrata() override { |
111 | // FIXME the object file may correspond to a kernel image. |
112 | return lldb_private::ObjectFile::eStrataUser; |
113 | } |
114 | }; |
115 | |
116 | #endif |
117 | |