[lldb-dev] Target changes for Language Runtimes

Colin Riley colin at codeplay.com
Fri Apr 10 09:04:38 PDT 2015


Hey folks,

So I added the initial part of the RenderScript language plugin which 
went smoothly. In that review I stated it would be initialized along the 
same lines of ObjCLanguageRuntime. Now, my initial thought was along the 
lines of the attached patch - in Target::ModulesDidLoad, call a function 
to see if any modules match a renderscript pattern, if so, enable the 
languageruntime.

However, this then requires including the plugin headers within 
target.cpp, which isn't ideal. ObjC has a base class header actually in 
the target project space, so uses that. Are there any views on how to 
make this a bit more generic, to allow for other Language Runtimes to 
detect applicability on module-load?

Cheers,
Colin
-------------- next part --------------
Index: source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp
===================================================================
--- source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp	(revision 234585)
+++ source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp	(working copy)
@@ -58,6 +58,52 @@
     return g_name;
 }
 
+bool
+RenderScriptRuntime::IsRenderScriptModule(const lldb::ModuleSP &module_sp)
+{
+    if (module_sp)
+    {
+        const FileSpec &module_file_spec = module_sp->GetFileSpec();
+        static ConstString mainRSlibName ("libRS.so");
+        
+        if (module_file_spec)
+        {
+            // Is this the main renderscript lib?
+            if (module_file_spec.GetFilename() == mainRSlibName)
+                return true;
+        }
+
+        // Is this a module containing renderscript kernels?
+        const Symbol *info_sym = module_sp->FindFirstSymbolWithNameAndType(ConstString(".rs.info"), eSymbolTypeData);
+        if (info_sym)
+        {
+            return true;
+        }
+
+    }
+    return false;
+}
+
+void 
+RenderScriptRuntime::ModulesDidLoad(const lldb::ProcessSP& process_sp, const ModuleList &module_list )
+{
+    Mutex::Locker locker (module_list.GetMutex ());
+
+    size_t num_modules = module_list.GetSize();
+    for (size_t i = 0; i < num_modules; i++)
+    {
+        auto mod = module_list.GetModuleAtIndex (i);
+        if (IsRenderScriptModule (mod))
+        {
+            // Getting the runtime here ensures a LanguageRuntime for renderscript is only ever created if a module
+            // containing the rslibrary or kernels is loaded. The renderscript command only then exists in valid processes.
+            RenderScriptRuntime* runtime = (RenderScriptRuntime*)process_sp->GetLanguageRuntime(eLanguageTypeExtRenderScript);
+            runtime->LoadModule(mod);
+        }
+    }
+}
+
+
 //------------------------------------------------------------------
 // PluginInterface protocol
 //------------------------------------------------------------------
Index: source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.h
===================================================================
--- source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.h	(revision 234585)
+++ source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.h	(working copy)
@@ -93,6 +93,10 @@
 
     static lldb_private::ConstString GetPluginNameStatic();
 
+    static bool IsRenderScriptModule(const lldb::ModuleSP &module_sp);
+
+    static void ModulesDidLoad(const lldb::ProcessSP& process_sp, const ModuleList &module_list );
+
     //------------------------------------------------------------------
     // PluginInterface protocol
     //------------------------------------------------------------------
Index: source/Target/Target.cpp
===================================================================
--- source/Target/Target.cpp	(revision 234585)
+++ source/Target/Target.cpp	(working copy)
@@ -55,6 +55,8 @@
 #include "lldb/Target/Thread.h"
 #include "lldb/Target/ThreadSpec.h"
 
+#include "Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.h"
+
 using namespace lldb;
 using namespace lldb_private;
 
@@ -1277,6 +1279,8 @@
                     }
                 }
             }
+
+            RenderScriptRuntime::ModulesDidLoad(m_process_sp, module_list);
         }
         BroadcastEvent (eBroadcastBitModulesLoaded, new TargetEventData (this->shared_from_this(), module_list));
     }


More information about the lldb-dev mailing list