From 3cf443ddd63fa219f3681ec3ca837cc1c0dc0829 Mon Sep 17 00:00:00 2001 From: Michael Sartain Date: Wed, 17 Jul 2013 00:26:30 +0000 Subject: [PATCH] simple plugin now works with Linux fix assert in SetPluginInfo implement Linux ePathTypeLLDBSystemPlugins and ePathTypeLLDBUserPlugins implement Linux Host::Backtrace and Host::GetEnvironment add .gnu_debugdata comment Differential Revision: http://llvm-reviews.chandlerc.com/D1159 llvm-svn: 186475 --- lldb/source/Core/Debugger.cpp | 7 ++- lldb/source/Core/PluginManager.cpp | 2 +- lldb/source/Host/common/Host.cpp | 54 +++++++++++++++++++--- lldb/source/Host/linux/Host.cpp | 23 +++++++-- .../Plugins/ObjectFile/ELF/ObjectFileELF.cpp | 3 +- 5 files changed, 76 insertions(+), 13 deletions(-) diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp index 01e5ae3..f3ee4a8 100644 --- a/lldb/source/Core/Debugger.cpp +++ b/lldb/source/Core/Debugger.cpp @@ -413,6 +413,7 @@ Debugger::LoadPlugin (const FileSpec& spec, Error& error) } lldb::DebuggerSP debugger_sp(shared_from_this()); lldb::SBDebugger debugger_sb(debugger_sp); + // This calls the bool lldb::PluginInitialize(lldb::SBDebugger debugger) function. // 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) @@ -440,6 +441,7 @@ LoadPluginCallback Error error; static ConstString g_dylibext("dylib"); + static ConstString g_solibext("so"); if (!baton) return FileSpec::eEnumerateDirectoryResultQuit; @@ -457,8 +459,11 @@ LoadPluginCallback FileSpec plugin_file_spec (file_spec); plugin_file_spec.ResolvePath (); - if (plugin_file_spec.GetFileNameExtension() != g_dylibext) + if (plugin_file_spec.GetFileNameExtension() != g_dylibext && + plugin_file_spec.GetFileNameExtension() != g_solibext) + { return FileSpec::eEnumerateDirectoryResultNext; + } Error plugin_load_error; debugger->LoadPlugin (plugin_file_spec, plugin_load_error); diff --git a/lldb/source/Core/PluginManager.cpp b/lldb/source/Core/PluginManager.cpp index 7647b1b..7a2d377 100644 --- a/lldb/source/Core/PluginManager.cpp +++ b/lldb/source/Core/PluginManager.cpp @@ -75,7 +75,7 @@ SetPluginInfo (const FileSpec &plugin_file_spec, const PluginInfo &plugin_info) { Mutex::Locker locker (GetPluginMapMutex ()); PluginTerminateMap &plugin_map = GetPluginMap (); - assert (plugin_map.find (plugin_file_spec) != plugin_map.end()); + assert (plugin_map.find (plugin_file_spec) == plugin_map.end()); plugin_map[plugin_file_spec] = plugin_info; } diff --git a/lldb/source/Host/common/Host.cpp b/lldb/source/Host/common/Host.cpp index e92d824..c2f6356 100644 --- a/lldb/source/Host/common/Host.cpp +++ b/lldb/source/Host/common/Host.cpp @@ -532,13 +532,13 @@ Host::ThreadCreated (const char *thread_name) void Host::Backtrace (Stream &strm, uint32_t max_frames) { - // TODO: Is there a way to backtrace the current process on linux? Other systems? + // TODO: Is there a way to backtrace the current process on other systems? } size_t Host::GetEnvironment (StringList &env) { - // TODO: Is there a way to the host environment for this process on linux? Other systems? + // TODO: Is there a way to the host environment for this process on other systems? return 0; } @@ -880,7 +880,7 @@ Host::GetLLDBPath (PathType path_type, FileSpec &file_spec) // To get paths related to LLDB we get the path to the executable that // contains this function. On MacOSX this will be "LLDB.framework/.../LLDB", // on linux this is assumed to be the "lldb" main executable. If LLDB on - // linux is actually in a shared library (lldb.so??) then this function will + // linux is actually in a shared library (liblldb.so) then this function will // need to be modified to "do the right thing". switch (path_type) @@ -1008,12 +1008,13 @@ Host::GetLLDBPath (PathType path_type, FileSpec &file_spec) case ePathTypeLLDBSystemPlugins: // System plug-ins directory { -#if defined (__APPLE__) +#if defined (__APPLE__) || defined(__linux__) static ConstString g_lldb_system_plugin_dir; static bool g_lldb_system_plugin_dir_located = false; if (!g_lldb_system_plugin_dir_located) { g_lldb_system_plugin_dir_located = true; +#if defined (__APPLE__) FileSpec lldb_file_spec; if (GetLLDBPath (ePathTypeLLDBShlibDir, lldb_file_spec)) { @@ -1031,6 +1032,13 @@ Host::GetLLDBPath (PathType path_type, FileSpec &file_spec) } return false; } +#elif defined (__linux__) + FileSpec lldb_file_spec("/usr/lib/lldb", true); + if (lldb_file_spec.Exists()) + { + g_lldb_system_plugin_dir.SetCString(lldb_file_spec.GetPath().c_str()); + } +#endif // __APPLE__ || __linux__ } if (g_lldb_system_plugin_dir) @@ -1038,9 +1046,10 @@ Host::GetLLDBPath (PathType path_type, FileSpec &file_spec) file_spec.GetDirectory() = g_lldb_system_plugin_dir; return true; } -#endif - // TODO: where would system LLDB plug-ins be located on linux? Other systems? +#else + // TODO: where would system LLDB plug-ins be located on other systems? return false; +#endif } break; @@ -1060,8 +1069,39 @@ Host::GetLLDBPath (PathType path_type, FileSpec &file_spec) } file_spec.GetDirectory() = g_lldb_user_plugin_dir; return file_spec.GetDirectory(); +#elif defined (__linux__) + static ConstString g_lldb_user_plugin_dir; + if (!g_lldb_user_plugin_dir) + { + // XDG Base Directory Specification + // http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html + // If XDG_DATA_HOME exists, use that, otherwise use ~/.local/share/lldb. + FileSpec lldb_file_spec; + const char *xdg_data_home = getenv("XDG_DATA_HOME"); + if (xdg_data_home && xdg_data_home[0]) + { + std::string user_plugin_dir (xdg_data_home); + user_plugin_dir += "/lldb"; + lldb_file_spec.SetFile (user_plugin_dir.c_str(), true); + } + else + { + const char *home_dir = getenv("HOME"); + if (home_dir && home_dir[0]) + { + std::string user_plugin_dir (home_dir); + user_plugin_dir += "/.local/share/lldb"; + lldb_file_spec.SetFile (user_plugin_dir.c_str(), true); + } + } + + if (lldb_file_spec.Exists()) + g_lldb_user_plugin_dir.SetCString(lldb_file_spec.GetPath().c_str()); + } + file_spec.GetDirectory() = g_lldb_user_plugin_dir; + return file_spec.GetDirectory(); #endif - // TODO: where would user LLDB plug-ins be located on linux? Other systems? + // TODO: where would user LLDB plug-ins be located on other systems? return false; } } diff --git a/lldb/source/Host/linux/Host.cpp b/lldb/source/Host/linux/Host.cpp index ef3c9fb..a756a47 100644 --- a/lldb/source/Host/linux/Host.cpp +++ b/lldb/source/Host/linux/Host.cpp @@ -14,6 +14,7 @@ #include #include #include +#include // C++ Includes // Other libraries and framework includes @@ -509,12 +510,28 @@ Host::GetThreadName (lldb::pid_t pid, lldb::tid_t tid) void Host::Backtrace (Stream &strm, uint32_t max_frames) { - // TODO: Is there a way to backtrace the current process on linux? + if (max_frames > 0) + { + std::vector frame_buffer (max_frames, NULL); + int num_frames = ::backtrace (&frame_buffer[0], frame_buffer.size()); + char** strs = ::backtrace_symbols (&frame_buffer[0], num_frames); + if (strs) + { + // Start at 1 to skip the "Host::Backtrace" frame + for (int i = 1; i < num_frames; ++i) + strm.Printf("%s\n", strs[i]); + ::free (strs); + } + } } size_t Host::GetEnvironment (StringList &env) { - // TODO: Is there a way to the host environment for this process on linux? - return 0; + char **host_env = environ; + char *env_entry; + size_t i; + for (i=0; (env_entry = host_env[i]) != NULL; ++i) + env.AppendString(env_entry); + return i; } diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp index 251b8f9..2e9f690 100644 --- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp +++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp @@ -911,7 +911,8 @@ ObjectFileELF::CreateSections(SectionList &unified_section_list) // .debug_pubtypes – Lookup table for mapping type names to compilation units // .debug_ranges – Address ranges used in DW_AT_ranges attributes // .debug_str – String table used in .debug_info - // MISSING? .debug-index http://src.chromium.org/viewvc/chrome/trunk/src/build/gdb-add-index?pathrev=144644 + // MISSING? .gnu_debugdata - "mini debuginfo / MiniDebugInfo" section, http://sourceware.org/gdb/onlinedocs/gdb/MiniDebugInfo.html + // MISSING? .debug-index - http://src.chromium.org/viewvc/chrome/trunk/src/build/gdb-add-index?pathrev=144644 // MISSING? .debug_types - Type descriptions from DWARF 4? See http://gcc.gnu.org/wiki/DwarfSeparateTypeInfo else if (name == g_sect_name_dwarf_debug_abbrev) sect_type = eSectionTypeDWARFDebugAbbrev; else if (name == g_sect_name_dwarf_debug_aranges) sect_type = eSectionTypeDWARFDebugAranges; -- 2.7.4