diff options
-rw-r--r-- | lldb/include/lldb/Core/PluginManager.h | 17 | ||||
-rw-r--r-- | lldb/include/lldb/lldb-forward.h | 1 | ||||
-rw-r--r-- | lldb/include/lldb/lldb-private-interfaces.h | 1 | ||||
-rw-r--r-- | lldb/source/Core/PluginManager.cpp | 122 |
4 files changed, 141 insertions, 0 deletions
diff --git a/lldb/include/lldb/Core/PluginManager.h b/lldb/include/lldb/Core/PluginManager.h index 1671bb96647..d147cab3471 100644 --- a/lldb/include/lldb/Core/PluginManager.h +++ b/lldb/include/lldb/Core/PluginManager.h @@ -73,6 +73,23 @@ public: //------------------------------------------------------------------ + // EmulateInstruction + //------------------------------------------------------------------ + static bool + RegisterPlugin (const char *name, + const char *description, + EmulateInstructionCreateInstance create_callback); + + static bool + UnregisterPlugin (EmulateInstructionCreateInstance create_callback); + + static EmulateInstructionCreateInstance + GetEmulateInstructionCreateCallbackAtIndex (uint32_t idx); + + static EmulateInstructionCreateInstance + GetEmulateInstructionCreateCallbackForPluginName (const char *name); + + //------------------------------------------------------------------ // LanguageRuntime //------------------------------------------------------------------ static bool diff --git a/lldb/include/lldb/lldb-forward.h b/lldb/include/lldb/lldb-forward.h index 85457597bca..f7f3092e15b 100644 --- a/lldb/include/lldb/lldb-forward.h +++ b/lldb/include/lldb/lldb-forward.h @@ -69,6 +69,7 @@ class Debugger; class Declaration; class Disassembler; class DynamicLoader; +class EmulateInstruction; class Error; class Event; class EventData; diff --git a/lldb/include/lldb/lldb-private-interfaces.h b/lldb/include/lldb/lldb-private-interfaces.h index f450618443b..6c190adffde 100644 --- a/lldb/include/lldb/lldb-private-interfaces.h +++ b/lldb/include/lldb/lldb-private-interfaces.h @@ -22,6 +22,7 @@ namespace lldb_private typedef ObjectContainer* (*ObjectContainerCreateInstance) (Module* module, lldb::DataBufferSP& dataSP, const FileSpec *file, lldb::addr_t offset, lldb::addr_t length); typedef ObjectFile* (*ObjectFileCreateInstance) (Module* module, lldb::DataBufferSP& dataSP, const FileSpec* file, lldb::addr_t offset, lldb::addr_t length); typedef LogChannel* (*LogChannelCreateInstance) (); + typedef EmulateInstruction * (*EmulateInstructionCreateInstance) (const ConstString &triple); typedef LanguageRuntime *(*LanguageRuntimeCreateInstance) (Process *process, lldb::LanguageType language); typedef Process* (*ProcessCreateInstance) (Target &target, Listener &listener); typedef SymbolFile* (*SymbolFileCreateInstance) (ObjectFile* obj_file); diff --git a/lldb/source/Core/PluginManager.cpp b/lldb/source/Core/PluginManager.cpp index e68bafea838..198beae191a 100644 --- a/lldb/source/Core/PluginManager.cpp +++ b/lldb/source/Core/PluginManager.cpp @@ -391,6 +391,128 @@ PluginManager::GetDynamicLoaderCreateCallbackForPluginName (const char *name) return NULL; } +#pragma mark EmulateInstruction + + +struct EmulateInstructionInstance +{ + EmulateInstructionInstance() : + name(), + description(), + create_callback(NULL) + { + } + + std::string name; + std::string description; + EmulateInstructionCreateInstance create_callback; +}; + +typedef std::vector<EmulateInstructionInstance> EmulateInstructionInstances; + +static bool +AccessEmulateInstructionInstances (PluginAction action, EmulateInstructionInstance &instance, uint32_t index) +{ + static EmulateInstructionInstances g_plugin_instances; + + switch (action) + { + case ePluginRegisterInstance: + if (instance.create_callback) + { + g_plugin_instances.push_back (instance); + return true; + } + break; + + case ePluginUnregisterInstance: + if (instance.create_callback) + { + EmulateInstructionInstances::iterator pos, end = g_plugin_instances.end(); + for (pos = g_plugin_instances.begin(); pos != end; ++ pos) + { + if (pos->create_callback == instance.create_callback) + { + g_plugin_instances.erase(pos); + return true; + } + } + } + break; + + case ePluginGetInstanceAtIndex: + if (index < g_plugin_instances.size()) + { + instance = g_plugin_instances[index]; + return true; + } + break; + + default: + break; + } + return false; +} + + +bool +PluginManager::RegisterPlugin +( + const char *name, + const char *description, + EmulateInstructionCreateInstance create_callback + ) +{ + if (create_callback) + { + EmulateInstructionInstance instance; + assert (name && name[0]); + instance.name = name; + if (description && description[0]) + instance.description = description; + instance.create_callback = create_callback; + return AccessEmulateInstructionInstances (ePluginRegisterInstance, instance, 0); + } + return false; +} + +bool +PluginManager::UnregisterPlugin (EmulateInstructionCreateInstance create_callback) +{ + if (create_callback) + { + EmulateInstructionInstance instance; + instance.create_callback = create_callback; + return AccessEmulateInstructionInstances (ePluginUnregisterInstance, instance, 0); + } + return false; +} + +EmulateInstructionCreateInstance +PluginManager::GetEmulateInstructionCreateCallbackAtIndex (uint32_t idx) +{ + EmulateInstructionInstance instance; + if (AccessEmulateInstructionInstances (ePluginGetInstanceAtIndex, instance, idx)) + return instance.create_callback; + return NULL; +} + +EmulateInstructionCreateInstance +PluginManager::GetEmulateInstructionCreateCallbackForPluginName (const char *name) +{ + if (name && name[0]) + { + EmulateInstructionInstance instance; + std::string ss_name(name); + for (uint32_t idx = 0; AccessEmulateInstructionInstances (ePluginGetInstanceAtIndex, instance, idx); ++idx) + { + if (instance.name == ss_name) + return instance.create_callback; + } + } + return NULL; +} + #pragma mark LanguageRuntime |