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