bulbazord created this revision.
bulbazord added reviewers: JDevlieghere, labath, clayborg, mib, jingham.
Herald added subscribers: pmatos, asb, sbc100, emaste.
Herald added a project: All.
bulbazord requested review of this revision.
Herald added subscribers: lldb-commits, MaskRay, aheejin.
Herald added a project: LLDB.
The high level goal is the title. The way this is accomplished is by adding a
new callback ObjectFileCreateInstanceWithDelegate where the intention is
to be able to create ObjectFile instances that are backed by a delegate
(like the way ObjectFileJIT works now with IRExecutionUnit as its
delegate).
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D147009
Files:
lldb/include/lldb/Core/Module.h
lldb/include/lldb/Core/PluginManager.h
lldb/include/lldb/Expression/IRExecutionUnit.h
lldb/include/lldb/Symbol/ObjectFile.h
lldb/include/lldb/lldb-forward.h
lldb/include/lldb/lldb-private-interfaces.h
lldb/source/Core/Module.cpp
lldb/source/Core/PluginManager.cpp
lldb/source/Expression/CMakeLists.txt
lldb/source/Expression/FunctionCaller.cpp
lldb/source/Expression/IRExecutionUnit.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp
lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.cpp
lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.h
lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp
lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.h
lldb/source/Plugins/ObjectFile/JSON/ObjectFileJSON.cpp
lldb/source/Plugins/ObjectFile/JSON/ObjectFileJSON.h
lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp
lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.h
lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp
lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.h
lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp
lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.h
lldb/source/Symbol/ObjectFile.cpp
Index: lldb/source/Symbol/ObjectFile.cpp
===================================================================
--- lldb/source/Symbol/ObjectFile.cpp
+++ lldb/source/Symbol/ObjectFile.cpp
@@ -184,6 +184,28 @@
return object_file_sp;
}
+ObjectFileSP
+ObjectFile::FindPlugin(const lldb::ModuleSP &module_sp,
+ const lldb::ObjectFileDelegateSP &delegate_sp) {
+ if (!module_sp)
+ return ObjectFileSP();
+
+ ObjectFileSP object_file_sp;
+ ObjectFileCreateInstanceWithDelegate create_callback;
+ for (uint32_t idx = 0;
+ (create_callback =
+ PluginManager::GetObjectFileCreateWithDelegateCallbackAtIndex(
+ idx)) != nullptr;
+ idx++) {
+ object_file_sp.reset(create_callback(module_sp, delegate_sp));
+ if (object_file_sp)
+ return object_file_sp;
+ }
+
+ object_file_sp.reset();
+ return object_file_sp;
+}
+
size_t ObjectFile::GetModuleSpecifications(const FileSpec &file,
lldb::offset_t file_offset,
lldb::offset_t file_size,
Index: lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.h
===================================================================
--- lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.h
+++ lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.h
@@ -40,6 +40,10 @@
const lldb::ProcessSP &process_sp,
lldb::addr_t header_addr);
+ static ObjectFile *
+ CreateInstanceWithDelegate(const lldb::ModuleSP &module_sp,
+ const lldb::ObjectFileDelegateSP &delegate_sp);
+
static size_t GetModuleSpecifications(const FileSpec &file,
lldb::DataBufferSP &data_sp,
lldb::offset_t data_offset,
Index: lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp
===================================================================
--- lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp
+++ lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp
@@ -79,9 +79,11 @@
char ObjectFileWasm::ID;
void ObjectFileWasm::Initialize() {
- PluginManager::RegisterPlugin(GetPluginNameStatic(),
- GetPluginDescriptionStatic(), CreateInstance,
- CreateMemoryInstance, GetModuleSpecifications);
+ PluginManager::RegisterPlugin(
+ GetPluginNameStatic(), GetPluginDescriptionStatic(), CreateInstance,
+ CreateMemoryInstance,
+ /* ObjectFileCreateInstanceWithDelegate = */ nullptr,
+ GetModuleSpecifications);
}
void ObjectFileWasm::Terminate() {
@@ -156,6 +158,11 @@
return nullptr;
}
+ObjectFile *ObjectFileWasm::CreateInstanceWithDelegate(
+ const ModuleSP &module_sp, const ObjectFileDelegateSP &delegate_sp) {
+ return nullptr;
+}
+
bool ObjectFileWasm::DecodeNextSection(lldb::offset_t *offset_ptr) {
// Buffer sufficient to read a section header and find the pointer to the next
// section.
Index: lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
===================================================================
--- lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
+++ lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
@@ -73,6 +73,10 @@
const lldb::ModuleSP &module_sp, lldb::WritableDataBufferSP data_sp,
const lldb::ProcessSP &process_sp, lldb::addr_t header_addr);
+ static lldb_private::ObjectFile *
+ CreateInstanceWithDelegate(const lldb::ModuleSP &module_sp,
+ const lldb::ObjectFileDelegateSP &delegate_sp);
+
static size_t GetModuleSpecifications(const lldb_private::FileSpec &file,
lldb::DataBufferSP &data_sp,
lldb::offset_t data_offset,
Index: lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
===================================================================
--- lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
+++ lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
@@ -178,10 +178,10 @@
char ObjectFilePECOFF::ID;
void ObjectFilePECOFF::Initialize() {
- PluginManager::RegisterPlugin(GetPluginNameStatic(),
- GetPluginDescriptionStatic(), CreateInstance,
- CreateMemoryInstance, GetModuleSpecifications,
- SaveCore, DebuggerInitialize);
+ PluginManager::RegisterPlugin(
+ GetPluginNameStatic(), GetPluginDescriptionStatic(), CreateInstance,
+ CreateMemoryInstance, CreateInstanceWithDelegate, GetModuleSpecifications,
+ SaveCore, DebuggerInitialize);
}
void ObjectFilePECOFF::DebuggerInitialize(Debugger &debugger) {
@@ -250,6 +250,12 @@
return nullptr;
}
+ObjectFile *ObjectFilePECOFF::CreateInstanceWithDelegate(
+ const lldb::ModuleSP &module_sp,
+ const lldb::ObjectFileDelegateSP &delegate_sp) {
+ return nullptr;
+}
+
size_t ObjectFilePECOFF::GetModuleSpecifications(
const lldb_private::FileSpec &file, lldb::DataBufferSP &data_sp,
lldb::offset_t data_offset, lldb::offset_t file_offset,
Index: lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.h
===================================================================
--- lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.h
+++ lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.h
@@ -40,6 +40,10 @@
const lldb::ProcessSP &process_sp,
lldb::addr_t header_addr);
+ static ObjectFile *
+ CreateInstanceWithDelegate(const lldb::ModuleSP &module_sp,
+ const lldb::ObjectFileDelegateSP &delegate_sp);
+
static size_t GetModuleSpecifications(const FileSpec &file,
lldb::DataBufferSP &data_sp,
lldb::offset_t data_offset,
Index: lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp
===================================================================
--- lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp
+++ lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp
@@ -37,9 +37,10 @@
char ObjectFilePDB::ID;
void ObjectFilePDB::Initialize() {
- PluginManager::RegisterPlugin(GetPluginNameStatic(),
- GetPluginDescriptionStatic(), CreateInstance,
- CreateMemoryInstance, GetModuleSpecifications);
+ PluginManager::RegisterPlugin(
+ GetPluginNameStatic(), GetPluginDescriptionStatic(), CreateInstance,
+ CreateMemoryInstance, CreateInstanceWithDelegate,
+ GetModuleSpecifications);
}
void ObjectFilePDB::Terminate() {
@@ -104,6 +105,11 @@
return nullptr;
}
+ObjectFile *ObjectFilePDB::CreateInstanceWithDelegate(
+ const ModuleSP &module_sp, const ObjectFileDelegateSP &delegate_sp) {
+ return nullptr;
+}
+
size_t ObjectFilePDB::GetModuleSpecifications(
const FileSpec &file, DataBufferSP &data_sp, offset_t data_offset,
offset_t file_offset, offset_t length, ModuleSpecList &specs) {
Index: lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.h
===================================================================
--- lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.h
+++ lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.h
@@ -46,6 +46,10 @@
const lldb::ModuleSP &module_sp, lldb::WritableDataBufferSP data_sp,
const lldb::ProcessSP &process_sp, lldb::addr_t header_addr);
+ static lldb_private::ObjectFile *
+ CreateInstanceWithDelegate(const lldb::ModuleSP &module_sp,
+ const lldb::ObjectFileDelegateSP &delegate_sp);
+
static size_t GetModuleSpecifications(const lldb_private::FileSpec &file,
lldb::DataBufferSP &data_sp,
lldb::offset_t data_offset,
Index: lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp
===================================================================
--- lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp
+++ lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp
@@ -25,7 +25,8 @@
void ObjectFileMinidump::Initialize() {
PluginManager::RegisterPlugin(
GetPluginNameStatic(), GetPluginDescriptionStatic(), CreateInstance,
- CreateMemoryInstance, GetModuleSpecifications, SaveCore);
+ CreateMemoryInstance, CreateInstanceWithDelegate, GetModuleSpecifications,
+ SaveCore);
}
void ObjectFileMinidump::Terminate() {
@@ -45,6 +46,12 @@
return nullptr;
}
+ObjectFile *ObjectFileMinidump::CreateInstanceWithDelegate(
+ const lldb::ModuleSP &module_sp,
+ const lldb::ObjectFileDelegateSP &delegate_sp) {
+ return nullptr;
+}
+
size_t ObjectFileMinidump::GetModuleSpecifications(
const lldb_private::FileSpec &file, lldb::DataBufferSP &data_sp,
lldb::offset_t data_offset, lldb::offset_t file_offset,
Index: lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
===================================================================
--- lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
+++ lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
@@ -54,6 +54,10 @@
const lldb::ModuleSP &module_sp, lldb::WritableDataBufferSP data_sp,
const lldb::ProcessSP &process_sp, lldb::addr_t header_addr);
+ static lldb_private::ObjectFile *
+ CreateInstanceWithDelegate(const lldb::ModuleSP &module_sp,
+ const lldb::ObjectFileDelegateSP &delegate_sp);
+
static size_t GetModuleSpecifications(const lldb_private::FileSpec &file,
lldb::DataBufferSP &data_sp,
lldb::offset_t data_offset,
Index: lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
===================================================================
--- lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -815,7 +815,8 @@
void ObjectFileMachO::Initialize() {
PluginManager::RegisterPlugin(
GetPluginNameStatic(), GetPluginDescriptionStatic(), CreateInstance,
- CreateMemoryInstance, GetModuleSpecifications, SaveCore);
+ CreateMemoryInstance, CreateInstanceWithDelegate, GetModuleSpecifications,
+ SaveCore);
}
void ObjectFileMachO::Terminate() {
@@ -865,6 +866,12 @@
return nullptr;
}
+ObjectFile *ObjectFileMachO::CreateInstanceWithDelegate(
+ const lldb::ModuleSP &module_sp,
+ const lldb::ObjectFileDelegateSP &delegate_sp) {
+ return nullptr;
+}
+
size_t ObjectFileMachO::GetModuleSpecifications(
const lldb_private::FileSpec &file, lldb::DataBufferSP &data_sp,
lldb::offset_t data_offset, lldb::offset_t file_offset,
Index: lldb/source/Plugins/ObjectFile/JSON/ObjectFileJSON.h
===================================================================
--- lldb/source/Plugins/ObjectFile/JSON/ObjectFileJSON.h
+++ lldb/source/Plugins/ObjectFile/JSON/ObjectFileJSON.h
@@ -36,6 +36,10 @@
const lldb::ProcessSP &process_sp,
lldb::addr_t header_addr);
+ static ObjectFile *
+ CreateInstanceWithDelegate(const lldb::ModuleSP &module_sp,
+ const lldb::ObjectFileDelegateSP &delegate_sp);
+
static size_t GetModuleSpecifications(const FileSpec &file,
lldb::DataBufferSP &data_sp,
lldb::offset_t data_offset,
Index: lldb/source/Plugins/ObjectFile/JSON/ObjectFileJSON.cpp
===================================================================
--- lldb/source/Plugins/ObjectFile/JSON/ObjectFileJSON.cpp
+++ lldb/source/Plugins/ObjectFile/JSON/ObjectFileJSON.cpp
@@ -26,9 +26,10 @@
char ObjectFileJSON::ID;
void ObjectFileJSON::Initialize() {
- PluginManager::RegisterPlugin(GetPluginNameStatic(),
- GetPluginDescriptionStatic(), CreateInstance,
- CreateMemoryInstance, GetModuleSpecifications);
+ PluginManager::RegisterPlugin(
+ GetPluginNameStatic(), GetPluginDescriptionStatic(), CreateInstance,
+ CreateMemoryInstance, CreateInstanceWithDelegate,
+ GetModuleSpecifications);
}
void ObjectFileJSON::Terminate() {
@@ -89,6 +90,12 @@
return nullptr;
}
+ObjectFile *ObjectFileJSON::CreateInstanceWithDelegate(
+ const lldb::ModuleSP &module_sp,
+ const lldb::ObjectFileDelegateSP &delegate_sp) {
+ return nullptr;
+}
+
size_t ObjectFileJSON::GetModuleSpecifications(
const FileSpec &file, DataBufferSP &data_sp, offset_t data_offset,
offset_t file_offset, offset_t length, ModuleSpecList &specs) {
Index: lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.h
===================================================================
--- lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.h
+++ lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.h
@@ -17,7 +17,7 @@
class ObjectFileJIT : public lldb_private::ObjectFile {
public:
ObjectFileJIT(const lldb::ModuleSP &module_sp,
- const lldb::ObjectFileJITDelegateSP &delegate_sp);
+ const lldb::ObjectFileDelegateSP &delegate_sp);
~ObjectFileJIT() override;
@@ -41,6 +41,10 @@
const lldb::ModuleSP &module_sp, lldb::WritableDataBufferSP data_sp,
const lldb::ProcessSP &process_sp, lldb::addr_t header_addr);
+ static lldb_private::ObjectFile *
+ CreateInstanceWithDelegate(const lldb::ModuleSP &module_sp,
+ const lldb::ObjectFileDelegateSP &delegate_sp);
+
static size_t GetModuleSpecifications(const lldb_private::FileSpec &file,
lldb::DataBufferSP &data_sp,
lldb::offset_t data_offset,
@@ -101,7 +105,7 @@
llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
protected:
- lldb::ObjectFileJITDelegateWP m_delegate_wp;
+ lldb::ObjectFileDelegateWP m_delegate_wp;
};
#endif // LLDB_SOURCE_PLUGINS_OBJECTFILE_JIT_OBJECTFILEJIT_H
Index: lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp
===================================================================
--- lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp
+++ lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp
@@ -44,9 +44,10 @@
char ObjectFileJIT::ID;
void ObjectFileJIT::Initialize() {
- PluginManager::RegisterPlugin(GetPluginNameStatic(),
- GetPluginDescriptionStatic(), CreateInstance,
- CreateMemoryInstance, GetModuleSpecifications);
+ PluginManager::RegisterPlugin(
+ GetPluginNameStatic(), GetPluginDescriptionStatic(), CreateInstance,
+ CreateMemoryInstance, CreateInstanceWithDelegate,
+ GetModuleSpecifications);
}
void ObjectFileJIT::Terminate() {
@@ -59,7 +60,7 @@
const FileSpec *file,
lldb::offset_t file_offset,
lldb::offset_t length) {
- // JIT'ed object file is backed by the ObjectFileJITDelegate, never read from
+ // JIT'ed object file is backed by the ObjectFileDelegate, never read from
// a file
return nullptr;
}
@@ -68,11 +69,24 @@
WritableDataBufferSP data_sp,
const ProcessSP &process_sp,
lldb::addr_t header_addr) {
- // JIT'ed object file is backed by the ObjectFileJITDelegate, never read from
+ // JIT'ed object file is backed by the ObjectFileDelegate, never read from
// memory
return nullptr;
}
+ObjectFile *ObjectFileJIT::CreateInstanceWithDelegate(
+ const lldb::ModuleSP &module_sp,
+ const lldb::ObjectFileDelegateSP &delegate_sp) {
+ if (!module_sp || !delegate_sp)
+ return nullptr;
+
+ auto objfile_jit_up = std::make_unique<ObjectFileJIT>(module_sp, delegate_sp);
+ if (!objfile_jit_up)
+ return nullptr;
+
+ return objfile_jit_up.release();
+}
+
size_t ObjectFileJIT::GetModuleSpecifications(
const lldb_private::FileSpec &file, lldb::DataBufferSP &data_sp,
lldb::offset_t data_offset, lldb::offset_t file_offset,
@@ -82,7 +96,7 @@
}
ObjectFileJIT::ObjectFileJIT(const lldb::ModuleSP &module_sp,
- const ObjectFileJITDelegateSP &delegate_sp)
+ const ObjectFileDelegateSP &delegate_sp)
: ObjectFile(module_sp, nullptr, 0, 0, DataBufferSP(), 0), m_delegate_wp() {
if (delegate_sp) {
m_delegate_wp = delegate_sp;
@@ -107,7 +121,7 @@
}
void ObjectFileJIT::ParseSymtab(Symtab &symtab) {
- ObjectFileJITDelegateSP delegate_sp(m_delegate_wp.lock());
+ ObjectFileDelegateSP delegate_sp(m_delegate_wp.lock());
if (delegate_sp)
delegate_sp->PopulateSymtab(this, symtab);
}
@@ -119,7 +133,7 @@
void ObjectFileJIT::CreateSections(SectionList &unified_section_list) {
if (!m_sections_up) {
m_sections_up = std::make_unique<SectionList>();
- ObjectFileJITDelegateSP delegate_sp(m_delegate_wp.lock());
+ ObjectFileDelegateSP delegate_sp(m_delegate_wp.lock());
if (delegate_sp) {
delegate_sp->PopulateSectionList(this, *m_sections_up);
unified_section_list = *m_sections_up;
@@ -173,7 +187,7 @@
ObjectFile::Strata ObjectFileJIT::CalculateStrata() { return eStrataJIT; }
ArchSpec ObjectFileJIT::GetArchitecture() {
- if (ObjectFileJITDelegateSP delegate_sp = m_delegate_wp.lock())
+ if (ObjectFileDelegateSP delegate_sp = m_delegate_wp.lock())
return delegate_sp->GetArchitecture();
return ArchSpec();
}
Index: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
===================================================================
--- lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
+++ lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
@@ -77,6 +77,10 @@
const lldb::ModuleSP &module_sp, lldb::WritableDataBufferSP data_sp,
const lldb::ProcessSP &process_sp, lldb::addr_t header_addr);
+ static lldb_private::ObjectFile *
+ CreateInstanceWithDelegate(const lldb::ModuleSP &module_sp,
+ const lldb::ObjectFileDelegateSP &delegate_sp);
+
static size_t GetModuleSpecifications(const lldb_private::FileSpec &file,
lldb::DataBufferSP &data_sp,
lldb::offset_t data_offset,
Index: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
===================================================================
--- lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -353,9 +353,10 @@
// Static methods.
void ObjectFileELF::Initialize() {
- PluginManager::RegisterPlugin(GetPluginNameStatic(),
- GetPluginDescriptionStatic(), CreateInstance,
- CreateMemoryInstance, GetModuleSpecifications);
+ PluginManager::RegisterPlugin(
+ GetPluginNameStatic(), GetPluginDescriptionStatic(), CreateInstance,
+ CreateMemoryInstance, CreateInstanceWithDelegate,
+ GetModuleSpecifications);
}
void ObjectFileELF::Terminate() {
@@ -435,6 +436,12 @@
return nullptr;
}
+ObjectFile *ObjectFileELF::CreateInstanceWithDelegate(
+ const lldb::ModuleSP &module_sp,
+ const lldb::ObjectFileDelegateSP &delegate_sp) {
+ return nullptr;
+}
+
bool ObjectFileELF::MagicBytesMatch(DataBufferSP &data_sp,
lldb::addr_t data_offset,
lldb::addr_t data_length) {
Index: lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.h
===================================================================
--- lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.h
+++ lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.h
@@ -36,6 +36,10 @@
const lldb::ProcessSP &process_sp,
lldb::addr_t header_addr);
+ static ObjectFile *
+ CreateInstanceWithDelegate(const lldb::ModuleSP &module_sp,
+ const lldb::ObjectFileDelegateSP &delegate_sp);
+
static size_t GetModuleSpecifications(const FileSpec &file,
lldb::DataBufferSP &data_sp,
lldb::offset_t data_offset,
Index: lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.cpp
===================================================================
--- lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.cpp
+++ lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.cpp
@@ -48,9 +48,10 @@
char ObjectFileBreakpad::ID;
void ObjectFileBreakpad::Initialize() {
- PluginManager::RegisterPlugin(GetPluginNameStatic(),
- GetPluginDescriptionStatic(), CreateInstance,
- CreateMemoryInstance, GetModuleSpecifications);
+ PluginManager::RegisterPlugin(
+ GetPluginNameStatic(), GetPluginDescriptionStatic(), CreateInstance,
+ CreateMemoryInstance, CreateInstanceWithDelegate,
+ GetModuleSpecifications);
}
void ObjectFileBreakpad::Terminate() {
@@ -90,6 +91,12 @@
return nullptr;
}
+ObjectFile *ObjectFileBreakpad::CreateInstanceWithDelegate(
+ const lldb::ModuleSP &module_sp,
+ const lldb::ObjectFileDelegateSP &delegate_sp) {
+ return nullptr;
+}
+
size_t ObjectFileBreakpad::GetModuleSpecifications(
const FileSpec &file, DataBufferSP &data_sp, offset_t data_offset,
offset_t file_offset, offset_t length, ModuleSpecList &specs) {
Index: lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp
===================================================================
--- lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp
@@ -145,13 +145,10 @@
if (m_jit_start_addr != LLDB_INVALID_ADDRESS) {
m_jit_process_wp = process->shared_from_this();
if (parser.GetGenerateDebugInfo()) {
- lldb::ModuleSP jit_module_sp(m_execution_unit_sp->GetJITModule());
-
- if (jit_module_sp) {
- ConstString const_func_name(FunctionName());
- FileSpec jit_file;
- jit_file.SetFilename(const_func_name);
- jit_module_sp->SetFileSpecAndObjectName(jit_file, ConstString());
+ ConstString const_func_name(FunctionName());
+ FileSpec jit_file;
+ jit_file.SetFilename(const_func_name);
+ if (auto jit_module_sp = m_execution_unit_sp->CreateJITModule(jit_file)) {
m_jit_module_wp = jit_module_sp;
target->GetImages().Append(jit_module_sp);
}
Index: lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
===================================================================
--- lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
@@ -748,13 +748,11 @@
}
if (generate_debug_info) {
- lldb::ModuleSP jit_module_sp(m_execution_unit_sp->GetJITModule());
+ ConstString const_func_name(FunctionName());
+ FileSpec jit_file;
+ jit_file.SetFilename(const_func_name);
- if (jit_module_sp) {
- ConstString const_func_name(FunctionName());
- FileSpec jit_file;
- jit_file.SetFilename(const_func_name);
- jit_module_sp->SetFileSpecAndObjectName(jit_file, ConstString());
+ if (auto jit_module_sp = m_execution_unit_sp->CreateJITModule(jit_file)) {
m_jit_module_wp = jit_module_sp;
target->GetImages().Append(jit_module_sp);
}
Index: lldb/source/Expression/IRExecutionUnit.cpp
===================================================================
--- lldb/source/Expression/IRExecutionUnit.cpp
+++ lldb/source/Expression/IRExecutionUnit.cpp
@@ -36,7 +36,6 @@
#include "lldb/Utility/LLDBLog.h"
#include "lldb/Utility/Log.h"
-#include "lldb/../../source/Plugins/ObjectFile/JIT/ObjectFileJIT.h"
#include <optional>
using namespace lldb_private;
@@ -1185,21 +1184,28 @@
return ArchSpec();
}
-lldb::ModuleSP IRExecutionUnit::GetJITModule() {
+lldb::ModuleSP IRExecutionUnit::CreateJITModule(const FileSpec &file_spec) {
ExecutionContext exe_ctx(GetBestExecutionContextScope());
Target *target = exe_ctx.GetTargetPtr();
if (!target)
- return nullptr;
+ return lldb::ModuleSP();
- auto Delegate = std::static_pointer_cast<lldb_private::ObjectFileJITDelegate>(
- shared_from_this());
+ // If we are unable to get the architecture, we consider the creation a
+ // failure.
+ auto arch = GetArchitecture();
+ if (!arch)
+ return lldb::ModuleSP();
- lldb::ModuleSP jit_module_sp =
- lldb_private::Module::CreateModuleFromObjectFile<ObjectFileJIT>(Delegate);
- if (!jit_module_sp)
- return nullptr;
+ auto module_sp = std::make_shared<Module>(file_spec, arch);
+ if (!module_sp)
+ return lldb::ModuleSP();
+
+ auto objfile = module_sp->GetObjectFileWithDelegate(shared_from_this());
+ if (!objfile)
+ return lldb::ModuleSP();
bool changed = false;
- jit_module_sp->SetLoadAddress(*target, 0, true, changed);
- return jit_module_sp;
+ module_sp->SetLoadAddress(*target, /*value = */ 0,
+ /*value_is_offset = */ true, changed);
+ return module_sp;
}
Index: lldb/source/Expression/FunctionCaller.cpp
===================================================================
--- lldb/source/Expression/FunctionCaller.cpp
+++ lldb/source/Expression/FunctionCaller.cpp
@@ -108,16 +108,12 @@
}
if (m_parser->GetGenerateDebugInfo()) {
- lldb::ModuleSP jit_module_sp(m_execution_unit_sp->GetJITModule());
-
- if (jit_module_sp) {
- ConstString const_func_name(FunctionName());
- FileSpec jit_file;
- jit_file.SetFilename(const_func_name);
- jit_module_sp->SetFileSpecAndObjectName(jit_file, ConstString());
+ ConstString const_func_name(FunctionName());
+ FileSpec jit_file;
+ jit_file.SetFilename(const_func_name);
+ if (auto jit_module_sp = m_execution_unit_sp->CreateJITModule(jit_file)) {
m_jit_module_wp = jit_module_sp;
- process->GetTarget().GetImages().Append(jit_module_sp,
- true /* notify */);
+ process->GetTarget().GetImages().Append(jit_module_sp);
}
}
if (process && m_jit_start_addr)
Index: lldb/source/Expression/CMakeLists.txt
===================================================================
--- lldb/source/Expression/CMakeLists.txt
+++ lldb/source/Expression/CMakeLists.txt
@@ -1,5 +1,4 @@
-# TODO: Add property `NO_PLUGIN_DEPENDENCIES` to lldbExpression
-add_lldb_library(lldbExpression
+add_lldb_library(lldbExpression NO_PLUGIN_DEPENDENCIES
DiagnosticManager.cpp
DWARFExpression.cpp
DWARFExpressionList.cpp
@@ -25,7 +24,6 @@
lldbSymbol
lldbTarget
lldbUtility
- lldbPluginObjectFileJIT
LINK_COMPONENTS
Core
Index: lldb/source/Core/PluginManager.cpp
===================================================================
--- lldb/source/Core/PluginManager.cpp
+++ lldb/source/Core/PluginManager.cpp
@@ -620,16 +620,19 @@
llvm::StringRef name, llvm::StringRef description,
CallbackType create_callback,
ObjectFileCreateMemoryInstance create_memory_callback,
+ ObjectFileCreateInstanceWithDelegate create_delegate_callback,
ObjectFileGetModuleSpecifications get_module_specifications,
ObjectFileSaveCore save_core,
DebuggerInitializeCallback debugger_init_callback)
: PluginInstance<ObjectFileCreateInstance>(
name, description, create_callback, debugger_init_callback),
create_memory_callback(create_memory_callback),
+ create_delegate_callback(create_delegate_callback),
get_module_specifications(get_module_specifications),
save_core(save_core) {}
ObjectFileCreateMemoryInstance create_memory_callback;
+ ObjectFileCreateInstanceWithDelegate create_delegate_callback;
ObjectFileGetModuleSpecifications get_module_specifications;
ObjectFileSaveCore save_core;
};
@@ -644,12 +647,14 @@
llvm::StringRef name, llvm::StringRef description,
ObjectFileCreateInstance create_callback,
ObjectFileCreateMemoryInstance create_memory_callback,
+ ObjectFileCreateInstanceWithDelegate create_delegate_callback,
ObjectFileGetModuleSpecifications get_module_specifications,
ObjectFileSaveCore save_core,
DebuggerInitializeCallback debugger_init_callback) {
return GetObjectFileInstances().RegisterPlugin(
name, description, create_callback, create_memory_callback,
- get_module_specifications, save_core, debugger_init_callback);
+ create_delegate_callback, get_module_specifications, save_core,
+ debugger_init_callback);
}
bool PluginManager::UnregisterPlugin(ObjectFileCreateInstance create_callback) {
@@ -689,6 +694,14 @@
return nullptr;
}
+ObjectFileCreateInstanceWithDelegate
+PluginManager::GetObjectFileCreateWithDelegateCallbackAtIndex(uint32_t idx) {
+ const auto &instances = GetObjectFileInstances().GetInstances();
+ if (idx < instances.size())
+ return instances[idx].create_delegate_callback;
+ return nullptr;
+}
+
Status PluginManager::SaveCore(const lldb::ProcessSP &process_sp,
const FileSpec &outfile,
lldb::SaveCoreStyle &core_style,
Index: lldb/source/Core/Module.cpp
===================================================================
--- lldb/source/Core/Module.cpp
+++ lldb/source/Core/Module.cpp
@@ -340,6 +340,21 @@
return m_objfile_sp.get();
}
+ObjectFile *Module::GetObjectFileWithDelegate(
+ const lldb::ObjectFileDelegateSP &delegate_sp) {
+ if (m_objfile_sp)
+ return m_objfile_sp.get();
+
+ {
+ std::lock_guard<std::recursive_mutex> guard(m_mutex);
+ m_did_load_objfile.store(true, std::memory_order_relaxed);
+ m_objfile_sp = ObjectFile::FindPlugin(shared_from_this(), delegate_sp);
+ if (m_objfile_sp)
+ m_arch = m_objfile_sp->GetArchitecture();
+ }
+ return m_objfile_sp.get();
+}
+
const lldb_private::UUID &Module::GetUUID() {
if (!m_did_set_uuid.load()) {
std::lock_guard<std::recursive_mutex> guard(m_mutex);
Index: lldb/include/lldb/lldb-private-interfaces.h
===================================================================
--- lldb/include/lldb/lldb-private-interfaces.h
+++ lldb/include/lldb/lldb-private-interfaces.h
@@ -56,6 +56,9 @@
typedef ObjectFile *(*ObjectFileCreateMemoryInstance)(
const lldb::ModuleSP &module_sp, lldb::WritableDataBufferSP data_sp,
const lldb::ProcessSP &process_sp, lldb::addr_t offset);
+typedef ObjectFile *(*ObjectFileCreateInstanceWithDelegate)(
+ const lldb::ModuleSP &module_sp,
+ const lldb::ObjectFileDelegateSP &delegate_sp);
typedef bool (*ObjectFileSaveCore)(const lldb::ProcessSP &process_sp,
const FileSpec &outfile,
lldb::SaveCoreStyle &core_style,
Index: lldb/include/lldb/lldb-forward.h
===================================================================
--- lldb/include/lldb/lldb-forward.h
+++ lldb/include/lldb/lldb-forward.h
@@ -130,7 +130,7 @@
class ModuleSpecList;
class ObjectContainer;
class ObjectFile;
-class ObjectFileJITDelegate;
+class ObjectFileDelegate;
class OperatingSystem;
class OptionGroup;
class OptionGroupOptions;
@@ -355,10 +355,10 @@
typedef std::weak_ptr<lldb_private::Module> ModuleWP;
typedef std::shared_ptr<lldb_private::ObjectFile> ObjectFileSP;
typedef std::shared_ptr<lldb_private::ObjectContainer> ObjectContainerSP;
-typedef std::shared_ptr<lldb_private::ObjectFileJITDelegate>
- ObjectFileJITDelegateSP;
-typedef std::weak_ptr<lldb_private::ObjectFileJITDelegate>
- ObjectFileJITDelegateWP;
+typedef std::shared_ptr<lldb_private::ObjectFileDelegate>
+ ObjectFileDelegateSP;
+typedef std::weak_ptr<lldb_private::ObjectFileDelegate>
+ ObjectFileDelegateWP;
typedef std::unique_ptr<lldb_private::OperatingSystem> OperatingSystemUP;
typedef std::shared_ptr<lldb_private::OptionValue> OptionValueSP;
typedef std::weak_ptr<lldb_private::OptionValue> OptionValueWP;
Index: lldb/include/lldb/Symbol/ObjectFile.h
===================================================================
--- lldb/include/lldb/Symbol/ObjectFile.h
+++ lldb/include/lldb/Symbol/ObjectFile.h
@@ -25,11 +25,11 @@
namespace lldb_private {
-class ObjectFileJITDelegate {
+class ObjectFileDelegate {
public:
- ObjectFileJITDelegate() = default;
+ ObjectFileDelegate() = default;
- virtual ~ObjectFileJITDelegate() = default;
+ virtual ~ObjectFileDelegate() = default;
virtual lldb::ByteOrder GetByteOrder() const = 0;
@@ -185,6 +185,21 @@
lldb::addr_t header_addr,
lldb::WritableDataBufferSP file_data_sp);
+ /// Find an ObjectFile plugin that can be backed by a delegate.
+ ///
+ /// Scans all loaded plugin interfaces that implement versions of the
+ /// ObjectFile plugin interface and returns the first instance that can be
+ /// backed by the given delegate.
+ ///
+ /// \param[in] module_sp
+ /// The parent module that owns this object file.
+ ///
+ /// \param[in] delegate_sp
+ /// The delegate that will back the object file.
+ static lldb::ObjectFileSP
+ FindPlugin(const lldb::ModuleSP &module_sp,
+ const lldb::ObjectFileDelegateSP &delegate_sp);
+
static size_t
GetModuleSpecifications(const FileSpec &file, lldb::offset_t file_offset,
lldb::offset_t file_size, ModuleSpecList &specs,
Index: lldb/include/lldb/Expression/IRExecutionUnit.h
===================================================================
--- lldb/include/lldb/Expression/IRExecutionUnit.h
+++ lldb/include/lldb/Expression/IRExecutionUnit.h
@@ -21,6 +21,7 @@
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Symbol/SymbolContext.h"
#include "lldb/Utility/DataBufferHeap.h"
+#include "lldb/Utility/FileSpec.h"
#include "lldb/lldb-forward.h"
#include "lldb/lldb-private.h"
@@ -55,7 +56,7 @@
/// code into the target process.
class IRExecutionUnit : public std::enable_shared_from_this<IRExecutionUnit>,
public IRMemoryMap,
- public ObjectFileJITDelegate {
+ public ObjectFileDelegate {
public:
/// Constructor
IRExecutionUnit(std::unique_ptr<llvm::LLVMContext> &context_up,
@@ -86,7 +87,7 @@
void FreeNow(lldb::addr_t allocation);
- /// ObjectFileJITDelegate overrides
+ /// ObjectFileDelegate overrides
lldb::ByteOrder GetByteOrder() const override;
uint32_t GetAddressByteSize() const override;
@@ -99,7 +100,7 @@
ArchSpec GetArchitecture() override;
- lldb::ModuleSP GetJITModule();
+ lldb::ModuleSP CreateJITModule(const FileSpec &file_spec);
lldb::addr_t FindSymbol(ConstString name, bool &missing_weak);
Index: lldb/include/lldb/Core/PluginManager.h
===================================================================
--- lldb/include/lldb/Core/PluginManager.h
+++ lldb/include/lldb/Core/PluginManager.h
@@ -169,13 +169,14 @@
GetSystemRuntimeCreateCallbackAtIndex(uint32_t idx);
// ObjectFile
- static bool
- RegisterPlugin(llvm::StringRef name, llvm::StringRef description,
- ObjectFileCreateInstance create_callback,
- ObjectFileCreateMemoryInstance create_memory_callback,
- ObjectFileGetModuleSpecifications get_module_specifications,
- ObjectFileSaveCore save_core = nullptr,
- DebuggerInitializeCallback debugger_init_callback = nullptr);
+ static bool RegisterPlugin(
+ llvm::StringRef name, llvm::StringRef description,
+ ObjectFileCreateInstance create_callback,
+ ObjectFileCreateMemoryInstance create_memory_callback,
+ ObjectFileCreateInstanceWithDelegate create_with_delegate_callback,
+ ObjectFileGetModuleSpecifications get_module_specifications,
+ ObjectFileSaveCore save_core = nullptr,
+ DebuggerInitializeCallback debugger_init_callback = nullptr);
static bool UnregisterPlugin(ObjectFileCreateInstance create_callback);
@@ -191,6 +192,9 @@
static ObjectFileCreateMemoryInstance
GetObjectFileCreateMemoryCallbackForPluginName(llvm::StringRef name);
+ static ObjectFileCreateInstanceWithDelegate
+ GetObjectFileCreateWithDelegateCallbackAtIndex(uint32_t idx);
+
static Status SaveCore(const lldb::ProcessSP &process_sp,
const FileSpec &outfile,
lldb::SaveCoreStyle &core_style,
Index: lldb/include/lldb/Core/Module.h
===================================================================
--- lldb/include/lldb/Core/Module.h
+++ lldb/include/lldb/Core/Module.h
@@ -642,6 +642,17 @@
lldb::addr_t header_addr, Status &error,
size_t size_to_read = 512);
+ /// Load an object file backed by an ObjectFileDelegate
+ ///
+ /// If the object file has not been created yet, this function
+ /// will find the best ObjectFile plugin with the given delegate.
+ ///
+ /// \return
+ /// The object file backed by the delegate or nullptr if the operation
+ /// failed.
+ ObjectFile *
+ GetObjectFileWithDelegate(const lldb::ObjectFileDelegateSP &delegate_sp);
+
/// Get the module's symbol file
///
/// If the symbol file has already been loaded, this function returns it. All
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits