[Lldb-commits] [lldb] r180218 - <rdar://problem/13209140>

Enrico Granata egranata at apple.com
Wed Apr 24 14:29:08 PDT 2013


Author: enrico
Date: Wed Apr 24 16:29:08 2013
New Revision: 180218

URL: http://llvm.org/viewvc/llvm-project?rev=180218&view=rev
Log:
<rdar://problem/13209140>

“plugin load” tries to be more helpful when it fails to load a plugin

Modified:
    lldb/trunk/include/lldb/Core/Debugger.h
    lldb/trunk/include/lldb/Host/DynamicLibrary.h
    lldb/trunk/source/Commands/CommandObjectPlugin.cpp
    lldb/trunk/source/Core/Debugger.cpp
    lldb/trunk/source/Host/common/DynamicLibrary.cpp

Modified: lldb/trunk/include/lldb/Core/Debugger.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Debugger.h?rev=180218&r1=180217&r2=180218&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Debugger.h (original)
+++ lldb/trunk/include/lldb/Core/Debugger.h Wed Apr 24 16:29:08 2013
@@ -330,7 +330,7 @@ public:
     typedef bool (*LLDBCommandPluginInit) (lldb::SBDebugger& debugger);
     
     bool
-    LoadPlugin (const FileSpec& spec);
+    LoadPlugin (const FileSpec& spec, Error& error);
 
 protected:
 

Modified: lldb/trunk/include/lldb/Host/DynamicLibrary.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/DynamicLibrary.h?rev=180218&r1=180217&r2=180218&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/DynamicLibrary.h (original)
+++ lldb/trunk/include/lldb/Host/DynamicLibrary.h Wed Apr 24 16:29:08 2013
@@ -36,6 +36,9 @@ public:
         return (T)symbol;
     }
     
+    bool
+    IsValid ();
+    
 private:
     lldb_private::FileSpec m_filespec;
     void* m_handle;

Modified: lldb/trunk/source/Commands/CommandObjectPlugin.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectPlugin.cpp?rev=180218&r1=180217&r2=180218&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectPlugin.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectPlugin.cpp Wed Apr 24 16:29:08 2013
@@ -96,10 +96,13 @@ protected:
         
         FileSpec dylib_fspec(path,true);
         
-        if (m_interpreter.GetDebugger().LoadPlugin(dylib_fspec))
+        if (m_interpreter.GetDebugger().LoadPlugin(dylib_fspec, error))
             result.SetStatus(eReturnStatusSuccessFinishResult);
         else
+        {
+            result.AppendError(error.AsCString());
             result.SetStatus(eReturnStatusFailed);
+        }
         
         return result.Succeeded();
     }

Modified: lldb/trunk/source/Core/Debugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Debugger.cpp?rev=180218&r1=180217&r2=180218&view=diff
==============================================================================
--- lldb/trunk/source/Core/Debugger.cpp (original)
+++ lldb/trunk/source/Core/Debugger.cpp Wed Apr 24 16:29:08 2013
@@ -344,20 +344,32 @@ Debugger::SettingsTerminate ()
 }
 
 bool
-Debugger::LoadPlugin (const FileSpec& spec)
+Debugger::LoadPlugin (const FileSpec& spec, Error& error)
 {
     lldb::DynamicLibrarySP dynlib_sp(new lldb_private::DynamicLibrary(spec));
+    if (!dynlib_sp || dynlib_sp->IsValid() == false)
+    {
+        if (spec.Exists())
+            error.SetErrorString("this file does not represent a loadable dylib");
+        else
+            error.SetErrorString("no such file");
+        return false;
+    }
     lldb::DebuggerSP debugger_sp(shared_from_this());
     lldb::SBDebugger debugger_sb(debugger_sp);
     // TODO: mangle this differently for your system - on OSX, the first underscore needs to be removed and the second one stays
     LLDBCommandPluginInit init_func = dynlib_sp->GetSymbol<LLDBCommandPluginInit>("_ZN4lldb16PluginInitializeENS_10SBDebuggerE");
     if (!init_func)
+    {
+        error.SetErrorString("cannot find the initialization function lldb::PluginInitialize(lldb::SBDebugger)");
         return false;
+    }
     if (init_func(debugger_sb))
     {
         m_loaded_plugins.push_back(dynlib_sp);
         return true;
     }
+    error.SetErrorString("dylib refused to be loaded");
     return false;
 }
 
@@ -392,7 +404,8 @@ LoadPluginCallback
         if (plugin_file_spec.GetFileNameExtension() != g_dylibext)
             return FileSpec::eEnumerateDirectoryResultNext;
 
-        debugger->LoadPlugin (plugin_file_spec);
+        Error plugin_load_error;
+        debugger->LoadPlugin (plugin_file_spec, plugin_load_error);
         
         return FileSpec::eEnumerateDirectoryResultNext;
     }

Modified: lldb/trunk/source/Host/common/DynamicLibrary.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/DynamicLibrary.cpp?rev=180218&r1=180217&r2=180218&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/DynamicLibrary.cpp (original)
+++ lldb/trunk/source/Host/common/DynamicLibrary.cpp Wed Apr 24 16:29:08 2013
@@ -20,6 +20,12 @@ DynamicLibrary::DynamicLibrary (const Fi
         m_handle = NULL;
 }
 
+bool
+DynamicLibrary::IsValid ()
+{
+    return m_handle != NULL;
+}
+
 DynamicLibrary::~DynamicLibrary ()
 {
     if (m_handle)





More information about the lldb-commits mailing list