diff --git a/lldb/include/lldb/Core/Debugger.h b/lldb/include/lldb/Core/Debugger.h index 4f80430163ce995ac0f502b01eda4262be64d915..34e939dec6467af08629a52a1169d1968ebd4c63 100644 --- a/lldb/include/lldb/Core/Debugger.h +++ b/lldb/include/lldb/Core/Debugger.h @@ -330,7 +330,7 @@ public: typedef bool (*LLDBCommandPluginInit) (lldb::SBDebugger& debugger); bool - LoadPlugin (const FileSpec& spec); + LoadPlugin (const FileSpec& spec, Error& error); protected: diff --git a/lldb/include/lldb/Host/DynamicLibrary.h b/lldb/include/lldb/Host/DynamicLibrary.h index 3a360b04f51cf853fc8d2bcaf8c5fe92799ed281..1fcc7d1883cfe0f902e3d47d423c394e918bcc8f 100644 --- a/lldb/include/lldb/Host/DynamicLibrary.h +++ b/lldb/include/lldb/Host/DynamicLibrary.h @@ -36,6 +36,9 @@ public: return (T)symbol; } + bool + IsValid (); + private: lldb_private::FileSpec m_filespec; void* m_handle; diff --git a/lldb/source/Commands/CommandObjectPlugin.cpp b/lldb/source/Commands/CommandObjectPlugin.cpp index 395dad752190ede9d9bef687dadd35ba7efa731d..1bc7632e2985b550d0bc4a6bfc04f9259ad92fd3 100644 --- a/lldb/source/Commands/CommandObjectPlugin.cpp +++ b/lldb/source/Commands/CommandObjectPlugin.cpp @@ -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(); } diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp index f442aa6073dc6dc76d3e030af722f8dd63b7017f..42a1540986e1df0afbab9d13a16f612c67b7587b 100644 --- a/lldb/source/Core/Debugger.cpp +++ b/lldb/source/Core/Debugger.cpp @@ -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("_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; } diff --git a/lldb/source/Host/common/DynamicLibrary.cpp b/lldb/source/Host/common/DynamicLibrary.cpp index e1ac3666829178638b48aa7c5c28c823fc422853..315a675895ff6dc8ca196ea20ecddf4c02f0971e 100644 --- a/lldb/source/Host/common/DynamicLibrary.cpp +++ b/lldb/source/Host/common/DynamicLibrary.cpp @@ -20,6 +20,12 @@ DynamicLibrary::DynamicLibrary (const FileSpec& spec, uint32_t options) : m_file m_handle = NULL; } +bool +DynamicLibrary::IsValid () +{ + return m_handle != NULL; +} + DynamicLibrary::~DynamicLibrary () { if (m_handle)