[Lldb-commits] [lldb] r124644 - in /lldb/trunk: include/lldb/Core/PluginManager.h include/lldb/lldb-forward.h include/lldb/lldb-private-interfaces.h source/Core/PluginManager.cpp
Greg Clayton
gclayton at apple.com
Mon Jan 31 17:37:45 PST 2011
Author: gclayton
Date: Mon Jan 31 19:37:45 2011
New Revision: 124644
URL: http://llvm.org/viewvc/llvm-project?rev=124644&view=rev
Log:
Added EmulateIntruction plug-in manager support.
Modified:
lldb/trunk/include/lldb/Core/PluginManager.h
lldb/trunk/include/lldb/lldb-forward.h
lldb/trunk/include/lldb/lldb-private-interfaces.h
lldb/trunk/source/Core/PluginManager.cpp
Modified: lldb/trunk/include/lldb/Core/PluginManager.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/PluginManager.h?rev=124644&r1=124643&r2=124644&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/PluginManager.h (original)
+++ lldb/trunk/include/lldb/Core/PluginManager.h Mon Jan 31 19:37:45 2011
@@ -73,6 +73,23 @@
//------------------------------------------------------------------
+ // 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
Modified: lldb/trunk/include/lldb/lldb-forward.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-forward.h?rev=124644&r1=124643&r2=124644&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-forward.h (original)
+++ lldb/trunk/include/lldb/lldb-forward.h Mon Jan 31 19:37:45 2011
@@ -69,6 +69,7 @@
class Declaration;
class Disassembler;
class DynamicLoader;
+class EmulateInstruction;
class Error;
class Event;
class EventData;
Modified: lldb/trunk/include/lldb/lldb-private-interfaces.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-private-interfaces.h?rev=124644&r1=124643&r2=124644&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-private-interfaces.h (original)
+++ lldb/trunk/include/lldb/lldb-private-interfaces.h Mon Jan 31 19:37:45 2011
@@ -22,6 +22,7 @@
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);
Modified: lldb/trunk/source/Core/PluginManager.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/PluginManager.cpp?rev=124644&r1=124643&r2=124644&view=diff
==============================================================================
--- lldb/trunk/source/Core/PluginManager.cpp (original)
+++ lldb/trunk/source/Core/PluginManager.cpp Mon Jan 31 19:37:45 2011
@@ -391,6 +391,128 @@
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
More information about the lldb-commits
mailing list