[Lldb-commits] [lldb] r243580 - Make DWARF at_comp_dir symbolic links configurable via plugin.symbol-file.dwarf.comp-dir-symlink-paths setting.

Oleksiy Vyalov ovyalov at google.com
Wed Jul 29 15:18:16 PDT 2015


Author: ovyalov
Date: Wed Jul 29 17:18:16 2015
New Revision: 243580

URL: http://llvm.org/viewvc/llvm-project?rev=243580&view=rev
Log:
Make DWARF at_comp_dir symbolic links configurable via plugin.symbol-file.dwarf.comp-dir-symlink-paths setting.

http://reviews.llvm.org/D11586


Added:
    lldb/trunk/test/functionalities/breakpoint/comp_dir_symlink/
    lldb/trunk/test/functionalities/breakpoint/comp_dir_symlink/Makefile
    lldb/trunk/test/functionalities/breakpoint/comp_dir_symlink/TestCompDirSymLink.py
    lldb/trunk/test/functionalities/breakpoint/comp_dir_symlink/main.cpp
Modified:
    lldb/trunk/include/lldb/Core/PluginManager.h
    lldb/trunk/source/Core/PluginManager.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
    lldb/trunk/test/lldbtest.py

Modified: lldb/trunk/include/lldb/Core/PluginManager.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/PluginManager.h?rev=243580&r1=243579&r2=243580&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/PluginManager.h (original)
+++ lldb/trunk/include/lldb/Core/PluginManager.h Wed Jul 29 17:18:16 2015
@@ -301,7 +301,8 @@ public:
     static bool
     RegisterPlugin (const ConstString &name,
                     const char *description,
-                    SymbolFileCreateInstance create_callback);
+                    SymbolFileCreateInstance create_callback,
+                    DebuggerInitializeCallback debugger_init_callback = nullptr);
 
     static bool
     UnregisterPlugin (SymbolFileCreateInstance create_callback);
@@ -419,13 +420,22 @@ public:
     static lldb::OptionValuePropertiesSP
     GetSettingForProcessPlugin (Debugger &debugger,
                                 const ConstString &setting_name);
-    
+
     static bool
     CreateSettingForProcessPlugin (Debugger &debugger,
                                    const lldb::OptionValuePropertiesSP &properties_sp,
                                    const ConstString &description,
                                    bool is_global_property);
 
+    static lldb::OptionValuePropertiesSP
+    GetSettingForSymbolFilePlugin (Debugger &debugger,
+                                   const ConstString &setting_name);
+
+    static bool
+    CreateSettingForSymbolFilePlugin (Debugger &debugger,
+                                      const lldb::OptionValuePropertiesSP &properties_sp,
+                                      const ConstString &description,
+                                      bool is_global_property);
 };
 
 

Modified: lldb/trunk/source/Core/PluginManager.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/PluginManager.cpp?rev=243580&r1=243579&r2=243580&view=diff
==============================================================================
--- lldb/trunk/source/Core/PluginManager.cpp (original)
+++ lldb/trunk/source/Core/PluginManager.cpp Wed Jul 29 17:18:16 2015
@@ -1771,13 +1771,15 @@ struct SymbolFileInstance
     SymbolFileInstance() :
         name(),
         description(),
-        create_callback(NULL)
+        create_callback(nullptr),
+        debugger_init_callback(nullptr)
     {
     }
 
     ConstString name;
     std::string description;
     SymbolFileCreateInstance create_callback;
+    DebuggerInitializeCallback debugger_init_callback;
 };
 
 typedef std::vector<SymbolFileInstance> SymbolFileInstances;
@@ -1802,7 +1804,8 @@ PluginManager::RegisterPlugin
 (
     const ConstString &name,
     const char *description,
-    SymbolFileCreateInstance create_callback
+    SymbolFileCreateInstance create_callback,
+    DebuggerInitializeCallback debugger_init_callback
 )
 {
     if (create_callback)
@@ -1813,6 +1816,7 @@ PluginManager::RegisterPlugin
         if (description && description[0])
             instance.description = description;
         instance.create_callback = create_callback;
+        instance.debugger_init_callback = debugger_init_callback;
         Mutex::Locker locker (GetSymbolFileMutex ());
         GetSymbolFileInstances ().push_back (instance);
     }
@@ -2343,7 +2347,7 @@ PluginManager::DebuggerInitialize (Debug
                 pos->debugger_init_callback (debugger);
         }
     }
-    
+
     // Initialize the Process plugins
     {
         Mutex::Locker locker (GetProcessMutex());
@@ -2357,6 +2361,15 @@ PluginManager::DebuggerInitialize (Debug
         }
     }
 
+    // Initialize the SymbolFile plugins
+    {
+        Mutex::Locker locker (GetSymbolFileMutex());
+        for (auto& sym_file: GetSymbolFileInstances())
+        {
+            if (sym_file.debugger_init_callback)
+                sym_file.debugger_init_callback (debugger);
+        }
+    }
 }
 
 // This is the preferred new way to register plugin specific settings.  e.g.
@@ -2553,3 +2566,43 @@ PluginManager::CreateSettingForProcessPl
     return false;
 }
 
+
+static const char* kSymbolFilePluginName("symbol-file");
+
+lldb::OptionValuePropertiesSP
+PluginManager::GetSettingForSymbolFilePlugin (Debugger &debugger,
+                                              const ConstString &setting_name)
+{
+    lldb::OptionValuePropertiesSP properties_sp;
+    lldb::OptionValuePropertiesSP plugin_type_properties_sp (GetDebuggerPropertyForPlugins (debugger,
+                                                                                            ConstString(kSymbolFilePluginName),
+                                                                                            ConstString(), // not creating to so we don't need the description
+                                                                                            false));
+    if (plugin_type_properties_sp)
+        properties_sp = plugin_type_properties_sp->GetSubProperty (nullptr, setting_name);
+    return properties_sp;
+}
+
+bool
+PluginManager::CreateSettingForSymbolFilePlugin (Debugger &debugger,
+                                                 const lldb::OptionValuePropertiesSP &properties_sp,
+                                                 const ConstString &description,
+                                                 bool is_global_property)
+{
+    if (properties_sp)
+    {
+        lldb::OptionValuePropertiesSP plugin_type_properties_sp (GetDebuggerPropertyForPlugins (debugger,
+                                                                                                ConstString(kSymbolFilePluginName),
+                                                                                                ConstString("Settings for symbol file plug-ins"),
+                                                                                                true));
+        if (plugin_type_properties_sp)
+        {
+            plugin_type_properties_sp->AppendProperty (properties_sp->GetName(),
+                                                       description,
+                                                       is_global_property,
+                                                       properties_sp);
+            return true;
+        }
+    }
+    return false;
+}

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp?rev=243580&r1=243579&r2=243580&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Wed Jul 29 17:18:16 2015
@@ -44,6 +44,9 @@
 #include "lldb/Host/FileSystem.h"
 #include "lldb/Host/Host.h"
 
+#include "lldb/Interpreter/OptionValueFileSpecList.h"
+#include "lldb/Interpreter/OptionValueProperties.h"
+
 #include "lldb/Symbol/Block.h"
 #include "lldb/Symbol/ClangExternalASTSourceCallbacks.h"
 #include "lldb/Symbol/CompileUnit.h"
@@ -106,6 +109,59 @@ using namespace lldb_private;
 //    return false;
 //}
 //
+
+namespace {
+
+    PropertyDefinition
+    g_properties[] =
+    {
+        { "comp-dir-symlink-paths" , OptionValue::eTypeFileSpecList, true,  0 ,   nullptr, nullptr, "If the DW_AT_comp_dir matches any of these paths the symbolic links will be resolved at DWARF parse time." },
+        {  nullptr                 , OptionValue::eTypeInvalid     , false, 0,    nullptr, nullptr, nullptr }
+    };
+
+    enum
+    {
+        ePropertySymLinkPaths
+    };
+
+
+    class PluginProperties : public Properties
+    {
+    public:
+        static ConstString
+        GetSettingName()
+        {
+            return SymbolFileDWARF::GetPluginNameStatic();
+        }
+
+        PluginProperties()
+        {
+            m_collection_sp.reset (new OptionValueProperties(GetSettingName()));
+            m_collection_sp->Initialize(g_properties);
+        }
+
+        FileSpecList&
+        GetSymLinkPaths()
+        {
+            OptionValueFileSpecList *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList(nullptr, true, ePropertySymLinkPaths);
+            assert(option_value);
+            return option_value->GetCurrentValue();
+        }
+
+    };
+
+    typedef std::shared_ptr<PluginProperties> SymbolFileDWARFPropertiesSP;
+
+    static const SymbolFileDWARFPropertiesSP&
+    GetGlobalPluginProperties()
+    {
+        static const auto g_settings_sp(std::make_shared<PluginProperties>());
+        return g_settings_sp;
+    }
+
+}  // anonymous namespace end
+
+
 static AccessType
 DW_ACCESS_to_AccessType (uint32_t dwarf_accessibility)
 {
@@ -153,11 +209,6 @@ removeHostnameFromPathname(const char* p
     return colon_pos + 1;
 }
 
-// DW_AT_comp_dir can be overridden by setting compiler's PWD environment
-// variable - for example, set to "/proc/self/cwd" in order to cope with
-// distributed builds.
-static const char* comp_dir_symlinks[] = {"/proc/self/cwd"};
-
 static const char*
 resolveCompDir(const char* path_from_dwarf)
 {
@@ -171,13 +222,14 @@ resolveCompDir(const char* path_from_dwa
         return nullptr;
 
     bool is_symlink = false;
-    for (unsigned long i = 0; i < sizeof(comp_dir_symlinks)/sizeof(comp_dir_symlinks[0]) && !is_symlink; ++i)
-        is_symlink = !strcmp(comp_dir_symlinks[i], local_path);
+    FileSpec local_path_spec(local_path, false);
+    const auto& file_specs = GetGlobalPluginProperties()->GetSymLinkPaths();
+    for (size_t i = 0; i < file_specs.GetSize() && !is_symlink; ++i)
+        is_symlink = FileSpec::Equal(file_specs.GetFileSpecAtIndex(i), local_path_spec, true);
 
     if (!is_symlink)
         return local_path;
 
-    const FileSpec local_path_spec(local_path, true);
     if (!local_path_spec.IsSymbolicLink())
         return local_path;
 
@@ -276,7 +328,21 @@ SymbolFileDWARF::Initialize()
     LogChannelDWARF::Initialize();
     PluginManager::RegisterPlugin (GetPluginNameStatic(),
                                    GetPluginDescriptionStatic(),
-                                   CreateInstance);
+                                   CreateInstance,
+                                   DebuggerInitialize);
+}
+
+void
+SymbolFileDWARF::DebuggerInitialize(Debugger &debugger)
+{
+    if (!PluginManager::GetSettingForSymbolFilePlugin(debugger, PluginProperties::GetSettingName()))
+    {
+        const bool is_global_setting = true;
+        PluginManager::CreateSettingForSymbolFilePlugin(debugger,
+                                                        GetGlobalPluginProperties()->GetValueProperties(),
+                                                        ConstString ("Properties for the dwarf symbol-file plug-in."),
+                                                        is_global_setting);
+    }
 }
 
 void

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h?rev=243580&r1=243579&r2=243580&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h Wed Jul 29 17:18:16 2015
@@ -76,6 +76,9 @@ public:
     static void
     Terminate();
 
+    static void
+    DebuggerInitialize(lldb_private::Debugger &debugger);
+
     static lldb_private::ConstString
     GetPluginNameStatic();
 

Added: lldb/trunk/test/functionalities/breakpoint/comp_dir_symlink/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/breakpoint/comp_dir_symlink/Makefile?rev=243580&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/breakpoint/comp_dir_symlink/Makefile (added)
+++ lldb/trunk/test/functionalities/breakpoint/comp_dir_symlink/Makefile Wed Jul 29 17:18:16 2015
@@ -0,0 +1,7 @@
+LEVEL = ../../../make
+
+CXX_SOURCES := main.cpp
+
+EXE := CompDirSymLink
+
+include $(LEVEL)/Makefile.rules

Added: lldb/trunk/test/functionalities/breakpoint/comp_dir_symlink/TestCompDirSymLink.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/breakpoint/comp_dir_symlink/TestCompDirSymLink.py?rev=243580&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/breakpoint/comp_dir_symlink/TestCompDirSymLink.py (added)
+++ lldb/trunk/test/functionalities/breakpoint/comp_dir_symlink/TestCompDirSymLink.py Wed Jul 29 17:18:16 2015
@@ -0,0 +1,68 @@
+"""
+Test breakpoint command with AT_comp_dir set to symbolic link.
+"""
+import os
+import unittest2
+import lldb
+from lldbtest import *
+import lldbutil
+import shutil
+
+
+_EXE_NAME = 'CompDirSymLink'  # Must match Makefile
+_SRC_FILE = 'main.cpp'
+_COMP_DIR_SYM_LINK_PROP = 'plugin.symbol-file.dwarf.comp-dir-symlink-paths'
+
+class CompDirSymLinkTestCase(TestBase):
+
+    mydir = TestBase.compute_mydir(__file__)
+
+    def setUp(self):
+        # Call super's setUp().
+        TestBase.setUp(self)
+        # Find the line number to break inside main().
+        self.line = line_number(_SRC_FILE, '// Set break point at this line.')
+        self.src_path = os.path.join(os.getcwd(), _SRC_FILE)
+
+    @dwarf_test
+    @skipIfHostWindows
+    def test_symlink_paths_set(self):
+        pwd_symlink = self.create_src_symlink()
+        self.build(pwd_symlink)
+        self.runCmd("settings set %s %s" % (_COMP_DIR_SYM_LINK_PROP, pwd_symlink))
+        lldbutil.run_break_set_by_file_and_line(self, self.src_path, self.line)
+
+    @dwarf_test
+    @skipUnlessHostLinux
+    def test_symlink_paths_set_procselfcwd(self):
+        pwd_symlink = '/proc/self/cwd'
+        self.build(pwd_symlink)
+        self.runCmd("settings set %s %s" % (_COMP_DIR_SYM_LINK_PROP, pwd_symlink))
+        lldbutil.run_break_set_by_file_and_line(self, self.src_path, self.line)
+
+    @dwarf_test
+    @skipIfHostWindows
+    def test_symlink_paths_unset(self):
+        pwd_symlink = self.create_src_symlink()
+        self.build(pwd_symlink)
+        self.runCmd('settings clear ' + _COMP_DIR_SYM_LINK_PROP)
+        self.assertRaises(AssertionError, lldbutil.run_break_set_by_file_and_line, self, self.src_path, self.line)
+
+    def create_src_symlink(self):
+        pwd_symlink = os.path.join(os.getcwd(), 'pwd_symlink')
+        os.symlink(os.getcwd(), pwd_symlink)
+        self.addTearDownHook(lambda: os.remove(pwd_symlink))
+        return pwd_symlink
+
+    def build(self, pwd_symlink):
+        self.buildDwarf(None, None, {'PWD': pwd_symlink}, True)
+
+        exe = os.path.join(os.getcwd(), _EXE_NAME)
+        self.runCmd('file ' + exe, CURRENT_EXECUTABLE_SET)
+
+
+if __name__ == '__main__':
+    import atexit
+    lldb.SBDebugger.Initialize()
+    atexit.register(lambda: lldb.SBDebugger.Terminate())
+    unittest2.main()

Added: lldb/trunk/test/functionalities/breakpoint/comp_dir_symlink/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/breakpoint/comp_dir_symlink/main.cpp?rev=243580&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/breakpoint/comp_dir_symlink/main.cpp (added)
+++ lldb/trunk/test/functionalities/breakpoint/comp_dir_symlink/main.cpp Wed Jul 29 17:18:16 2015
@@ -0,0 +1,13 @@
+//===-- main.cpp ------------------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+int main (int argc, char const *argv[])
+{
+    return 0; // Set break point at this line.
+}

Modified: lldb/trunk/test/lldbtest.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbtest.py?rev=243580&r1=243579&r2=243580&view=diff
==============================================================================
--- lldb/trunk/test/lldbtest.py (original)
+++ lldb/trunk/test/lldbtest.py Wed Jul 29 17:18:16 2015
@@ -869,6 +869,10 @@ def skipIfLinux(func):
     """Decorate the item to skip tests that should be skipped on Linux."""
     return skipIfPlatform(["linux"])(func)
 
+def skipUnlessHostLinux(func):
+    """Decorate the item to skip tests that should be skipped on any non Linux host."""
+    return skipUnlessHostPlatform(["linux"])(func)
+
 def skipIfWindows(func):
     """Decorate the item to skip tests that should be skipped on Windows."""
     return skipIfPlatform(["windows"])(func)





More information about the lldb-commits mailing list