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