xref: /freebsd-src/contrib/llvm-project/lldb/include/lldb/Expression/ObjectFileJIT.h (revision 06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e)
1*06c3fb27SDimitry Andric //===-- ObjectFileJIT.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_EXPRESSION_OBJECTFILEJIT_H
10*06c3fb27SDimitry Andric #define LLDB_EXPRESSION_OBJECTFILEJIT_H
11*06c3fb27SDimitry Andric 
12*06c3fb27SDimitry Andric #include "lldb/Core/Address.h"
13*06c3fb27SDimitry Andric #include "lldb/Core/Section.h"
14*06c3fb27SDimitry Andric #include "lldb/Symbol/ObjectFile.h"
15*06c3fb27SDimitry Andric #include "lldb/Symbol/Symtab.h"
16*06c3fb27SDimitry Andric #include "lldb/Utility/ArchSpec.h"
17*06c3fb27SDimitry Andric 
18*06c3fb27SDimitry Andric namespace lldb_private {
19*06c3fb27SDimitry Andric 
20*06c3fb27SDimitry Andric class ObjectFileJITDelegate {
21*06c3fb27SDimitry Andric public:
22*06c3fb27SDimitry Andric   ObjectFileJITDelegate() = default;
23*06c3fb27SDimitry Andric   virtual ~ObjectFileJITDelegate() = default;
24*06c3fb27SDimitry Andric   virtual lldb::ByteOrder GetByteOrder() const = 0;
25*06c3fb27SDimitry Andric   virtual uint32_t GetAddressByteSize() const = 0;
26*06c3fb27SDimitry Andric   virtual void PopulateSymtab(lldb_private::ObjectFile *obj_file,
27*06c3fb27SDimitry Andric                               lldb_private::Symtab &symtab) = 0;
28*06c3fb27SDimitry Andric   virtual void PopulateSectionList(lldb_private::ObjectFile *obj_file,
29*06c3fb27SDimitry Andric                                    lldb_private::SectionList &section_list) = 0;
30*06c3fb27SDimitry Andric   virtual ArchSpec GetArchitecture() = 0;
31*06c3fb27SDimitry Andric };
32*06c3fb27SDimitry Andric 
33*06c3fb27SDimitry Andric class ObjectFileJIT : public ObjectFile {
34*06c3fb27SDimitry Andric public:
35*06c3fb27SDimitry Andric   ObjectFileJIT(const lldb::ModuleSP &module_sp,
36*06c3fb27SDimitry Andric                 const lldb::ObjectFileJITDelegateSP &delegate_sp);
37*06c3fb27SDimitry Andric 
38*06c3fb27SDimitry Andric   ~ObjectFileJIT() override;
39*06c3fb27SDimitry Andric 
40*06c3fb27SDimitry Andric   // Static Functions
41*06c3fb27SDimitry Andric   static void Initialize();
42*06c3fb27SDimitry Andric 
43*06c3fb27SDimitry Andric   static void Terminate();
44*06c3fb27SDimitry Andric 
GetPluginNameStatic()45*06c3fb27SDimitry Andric   static llvm::StringRef GetPluginNameStatic() { return "jit"; }
46*06c3fb27SDimitry Andric 
GetPluginDescriptionStatic()47*06c3fb27SDimitry Andric   static llvm::StringRef GetPluginDescriptionStatic() {
48*06c3fb27SDimitry Andric     return "JIT code object file";
49*06c3fb27SDimitry Andric   }
50*06c3fb27SDimitry Andric 
51*06c3fb27SDimitry Andric   static lldb_private::ObjectFile *
52*06c3fb27SDimitry Andric   CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP data_sp,
53*06c3fb27SDimitry Andric                  lldb::offset_t data_offset, const lldb_private::FileSpec *file,
54*06c3fb27SDimitry Andric                  lldb::offset_t file_offset, lldb::offset_t length);
55*06c3fb27SDimitry Andric 
56*06c3fb27SDimitry Andric   static lldb_private::ObjectFile *CreateMemoryInstance(
57*06c3fb27SDimitry Andric       const lldb::ModuleSP &module_sp, lldb::WritableDataBufferSP data_sp,
58*06c3fb27SDimitry Andric       const lldb::ProcessSP &process_sp, lldb::addr_t header_addr);
59*06c3fb27SDimitry Andric 
60*06c3fb27SDimitry Andric   static size_t GetModuleSpecifications(const lldb_private::FileSpec &file,
61*06c3fb27SDimitry Andric                                         lldb::DataBufferSP &data_sp,
62*06c3fb27SDimitry Andric                                         lldb::offset_t data_offset,
63*06c3fb27SDimitry Andric                                         lldb::offset_t file_offset,
64*06c3fb27SDimitry Andric                                         lldb::offset_t length,
65*06c3fb27SDimitry Andric                                         lldb_private::ModuleSpecList &specs);
66*06c3fb27SDimitry Andric 
67*06c3fb27SDimitry Andric   // LLVM RTTI support
68*06c3fb27SDimitry Andric   static char ID;
isA(const void * ClassID)69*06c3fb27SDimitry Andric   bool isA(const void *ClassID) const override {
70*06c3fb27SDimitry Andric     return ClassID == &ID || ObjectFile::isA(ClassID);
71*06c3fb27SDimitry Andric   }
classof(const ObjectFile * obj)72*06c3fb27SDimitry Andric   static bool classof(const ObjectFile *obj) { return obj->isA(&ID); }
73*06c3fb27SDimitry Andric 
74*06c3fb27SDimitry Andric   // Member Functions
75*06c3fb27SDimitry Andric   bool ParseHeader() override;
76*06c3fb27SDimitry Andric 
77*06c3fb27SDimitry Andric   bool SetLoadAddress(lldb_private::Target &target, lldb::addr_t value,
78*06c3fb27SDimitry Andric                       bool value_is_offset) override;
79*06c3fb27SDimitry Andric 
80*06c3fb27SDimitry Andric   lldb::ByteOrder GetByteOrder() const override;
81*06c3fb27SDimitry Andric 
82*06c3fb27SDimitry Andric   bool IsExecutable() const override;
83*06c3fb27SDimitry Andric 
84*06c3fb27SDimitry Andric   uint32_t GetAddressByteSize() const override;
85*06c3fb27SDimitry Andric 
86*06c3fb27SDimitry Andric   void ParseSymtab(lldb_private::Symtab &symtab) override;
87*06c3fb27SDimitry Andric 
88*06c3fb27SDimitry Andric   bool IsStripped() override;
89*06c3fb27SDimitry Andric 
90*06c3fb27SDimitry Andric   void CreateSections(lldb_private::SectionList &unified_section_list) override;
91*06c3fb27SDimitry Andric 
92*06c3fb27SDimitry Andric   void Dump(lldb_private::Stream *s) override;
93*06c3fb27SDimitry Andric 
94*06c3fb27SDimitry Andric   lldb_private::ArchSpec GetArchitecture() override;
95*06c3fb27SDimitry Andric 
96*06c3fb27SDimitry Andric   lldb_private::UUID GetUUID() override;
97*06c3fb27SDimitry Andric 
98*06c3fb27SDimitry Andric   uint32_t GetDependentModules(lldb_private::FileSpecList &files) override;
99*06c3fb27SDimitry Andric 
100*06c3fb27SDimitry Andric   size_t ReadSectionData(lldb_private::Section *section,
101*06c3fb27SDimitry Andric                          lldb::offset_t section_offset, void *dst,
102*06c3fb27SDimitry Andric                          size_t dst_len) override;
103*06c3fb27SDimitry Andric 
104*06c3fb27SDimitry Andric   size_t ReadSectionData(lldb_private::Section *section,
105*06c3fb27SDimitry Andric                          lldb_private::DataExtractor &section_data) override;
106*06c3fb27SDimitry Andric 
107*06c3fb27SDimitry Andric   lldb_private::Address GetEntryPointAddress() override;
108*06c3fb27SDimitry Andric 
109*06c3fb27SDimitry Andric   lldb_private::Address GetBaseAddress() override;
110*06c3fb27SDimitry Andric 
111*06c3fb27SDimitry Andric   ObjectFile::Type CalculateType() override;
112*06c3fb27SDimitry Andric 
113*06c3fb27SDimitry Andric   ObjectFile::Strata CalculateStrata() override;
114*06c3fb27SDimitry Andric 
115*06c3fb27SDimitry Andric   // PluginInterface protocol
GetPluginName()116*06c3fb27SDimitry Andric   llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
117*06c3fb27SDimitry Andric 
118*06c3fb27SDimitry Andric protected:
119*06c3fb27SDimitry Andric   lldb::ObjectFileJITDelegateWP m_delegate_wp;
120*06c3fb27SDimitry Andric };
121*06c3fb27SDimitry Andric } // namespace lldb_private
122*06c3fb27SDimitry Andric 
123*06c3fb27SDimitry Andric #endif // LLDB_EXPRESSION_OBJECTFILEJIT_H
124