[Lldb-commits] [lldb] r162332 - in /lldb/trunk: source/Commands/CommandObjectTarget.cpp source/Host/macosx/Symbols.cpp source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp test/warnings/uuid/TestAddDsymCommand.py

Johnny Chen johnny.chen at apple.com
Tue Aug 21 17:18:43 PDT 2012


Author: johnny
Date: Tue Aug 21 19:18:43 2012
New Revision: 162332

URL: http://llvm.org/viewvc/llvm-project?rev=162332&view=rev
Log:
rdar://problem/11324515

'add-dsym' (aka 'target symbols add') should display error messages when dsym file is not found
or the dsym uuid does not match any existing modules. Add TestAddDsymCommand.py test file.

Added:
    lldb/trunk/test/warnings/uuid/TestAddDsymCommand.py
Modified:
    lldb/trunk/source/Commands/CommandObjectTarget.cpp
    lldb/trunk/source/Host/macosx/Symbols.cpp
    lldb/trunk/source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp

Modified: lldb/trunk/source/Commands/CommandObjectTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectTarget.cpp?rev=162332&r1=162331&r2=162332&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectTarget.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectTarget.cpp Tue Aug 21 19:18:43 2012
@@ -4047,6 +4047,10 @@
                         if (symfile_spec.Exists())
                         {
                             ModuleSP symfile_module_sp (new Module (symfile_spec, target->GetArchitecture()));
+                            const UUID &symfile_uuid = symfile_module_sp->GetUUID();
+                            StreamString ss_symfile_uuid;
+                            symfile_module_sp->GetUUID().Dump(&ss_symfile_uuid);
+
                             if (symfile_module_sp)
                             {
                                 // We now have a module that represents a symbol file
@@ -4054,7 +4058,7 @@
                                 // current target, so we need to find that module in the
                                 // target
                                 
-                                ModuleSP old_module_sp (target->GetImages().FindModule (symfile_module_sp->GetUUID()));
+                                ModuleSP old_module_sp (target->GetImages().FindModule (symfile_uuid));
                                 if (old_module_sp)
                                 {
                                     // The module has not yet created its symbol vendor, we can just
@@ -4062,6 +4066,12 @@
                                     // when it decides to create it!
                                     old_module_sp->SetSymbolFileFileSpec (symfile_module_sp->GetFileSpec());
 
+                                    // Provide feedback that the symfile has been successfully added.
+                                    const FileSpec &module_fs = old_module_sp->GetFileSpec();
+                                    result.AppendMessageWithFormat("symbol file '%s' with UUID %s has been successfully added to the '%s/%s' module\n",
+                                                                   symfile_path, ss_symfile_uuid.GetData(),
+                                                                   module_fs.GetDirectory().AsCString(), module_fs.GetFilename().AsCString());
+
                                     // Let clients know something changed in the module
                                     // if it is currently loaded
                                     ModuleList module_list;
@@ -4069,6 +4079,15 @@
                                     target->ModulesDidLoad (module_list);
                                     flush = true;
                                 }
+                                else
+                                {
+                                    result.AppendErrorWithFormat ("symbol file '%s' with UUID %s does not match any existing module%s\n",
+                                                                  symfile_path, ss_symfile_uuid.GetData(),
+                                                                  (symfile_spec.GetFileType() != FileSpec::eFileTypeRegular)
+                                                                      ? "\n       please specify the full path to the symbol file"
+                                                                      : "");
+                                    break;
+                                }
                             }
                             else
                             {

Modified: lldb/trunk/source/Host/macosx/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/macosx/Symbols.cpp?rev=162332&r1=162331&r2=162332&view=diff
==============================================================================
--- lldb/trunk/source/Host/macosx/Symbols.cpp (original)
+++ lldb/trunk/source/Host/macosx/Symbols.cpp Tue Aug 21 19:18:43 2012
@@ -22,6 +22,7 @@
 #include "lldb/Core/DataBuffer.h"
 #include "lldb/Core/DataExtractor.h"
 #include "lldb/Core/Module.h"
+#include "lldb/Core/StreamString.h"
 #include "lldb/Core/Timer.h"
 #include "lldb/Core/UUID.h"
 #include "lldb/Host/Endian.h"
@@ -126,9 +127,12 @@
             path_buf[0] = '\0';
             const char *path = file_spec.GetPath(path_buf, PATH_MAX) ? path_buf
                                                                      : file_spec.GetFilename().AsCString();
+            StreamString ss_m_uuid, ss_o_uuid;
+            uuid->Dump(&ss_m_uuid);
+            file_uuid.Dump(&ss_o_uuid);
             Host::SystemLog (Host::eSystemLogWarning, 
-                             "warning: UUID mismatch detected between binary and:\n\t'%s'\n", 
-                             path);
+                             "warning: UUID mismatch detected between binary (%s) and:\n\t'%s' (%s)\n", 
+                             ss_m_uuid.GetData(), path, ss_o_uuid.GetData());
             return false;
         }
         data_offset = cmd_offset + cmd_size;

Modified: lldb/trunk/source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp?rev=162332&r1=162331&r2=162332&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolVendor/MacOSX/SymbolVendorMacOSX.cpp Tue Aug 21 19:18:43 2012
@@ -18,7 +18,9 @@
 #include "lldb/Core/Module.h"
 #include "lldb/Core/PluginManager.h"
 #include "lldb/Core/Section.h"
+#include "lldb/Core/StreamString.h"
 #include "lldb/Core/Timer.h"
+#include "lldb/Host/Host.h"
 #include "lldb/Host/Symbols.h"
 #include "lldb/Symbol/ObjectFile.h"
 
@@ -50,6 +52,20 @@
         lldb_private::UUID dsym_uuid;
         if (ofile->GetUUID(&dsym_uuid))
             return dsym_uuid == module->GetUUID();
+
+        // Emit some warning messages since the UUIDs do not match!
+        const FileSpec &m_file_spec = module->GetFileSpec();
+        const FileSpec &o_file_spec = ofile->GetFileSpec();
+        StreamString ss_m_path, ss_o_path;
+        m_file_spec.Dump(&ss_m_path);
+        o_file_spec.Dump(&ss_o_path);
+
+        StreamString ss_m_uuid, ss_o_uuid;
+        module->GetUUID().Dump(&ss_m_uuid);
+        dsym_uuid.Dump(&ss_o_uuid);
+        Host::SystemLog (Host::eSystemLogWarning, 
+                         "warning: UUID mismatch detected between module '%s' (%s) and:\n\t'%s' (%s)\n", 
+                         ss_m_path.GetData(), ss_m_uuid.GetData(), ss_o_path.GetData(), ss_o_uuid.GetData());
     }
     return false;
 }

Added: lldb/trunk/test/warnings/uuid/TestAddDsymCommand.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/warnings/uuid/TestAddDsymCommand.py?rev=162332&view=auto
==============================================================================
--- lldb/trunk/test/warnings/uuid/TestAddDsymCommand.py (added)
+++ lldb/trunk/test/warnings/uuid/TestAddDsymCommand.py Tue Aug 21 19:18:43 2012
@@ -0,0 +1,91 @@
+"""Test that the 'add-dsym', aka 'target symbols add', command informs the user about success or failure."""
+
+import os, time
+import unittest2
+import lldb
+import pexpect
+from lldbtest import *
+
+ at unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+class AddDsymCommandCase(TestBase):
+
+    mydir = os.path.join("warnings", "uuid")
+
+    def setUp(self):
+        TestBase.setUp(self)
+        self.template = 'main.cpp.template'
+        self.source = 'main.cpp'
+        self.teardown_hook_added = False
+
+    def test_add_dsym_command_with_error(self):
+        """Test that the 'add-dsym' command informs the user about failures."""
+
+        # Call the program generator to produce main.cpp, version 1.
+        self.generate_main_cpp(version=1)
+        self.buildDsym(clean=True)
+
+        # Insert some delay and then call the program generator to produce main.cpp, version 2.
+        time.sleep(5)
+        self.generate_main_cpp(version=101)
+        # Now call make again, but this time don't generate the dSYM.
+        self.buildDwarf(clean=False)
+
+        self.exe_name = 'a.out'
+        self.do_add_dsym_with_error(self.exe_name)
+
+    def test_add_dsym_command_with_success(self):
+        """Test that the 'add-dsym' command informs the user about success."""
+
+        # Call the program generator to produce main.cpp, version 1.
+        self.generate_main_cpp(version=1)
+        self.buildDsym(clean=True)
+
+        self.exe_name = 'a.out'
+        self.do_add_dsym_with_success(self.exe_name)
+
+    def generate_main_cpp(self, version=0):
+        """Generate main.cpp from main.cpp.template."""
+        temp = os.path.join(os.getcwd(), self.template)
+        with open(temp, 'r') as f:
+            content = f.read()
+
+        new_content = content.replace('%ADD_EXTRA_CODE%',
+                                      'printf("This is version %d\\n");' % version)
+        src = os.path.join(os.getcwd(), self.source)
+        with open(src, 'w') as f:
+            f.write(new_content)
+
+        # The main.cpp has been generated, add a teardown hook to remove it.
+        if not self.teardown_hook_added:
+            self.addTearDownHook(lambda: os.remove(src))
+            self.teardown_hook_added = True
+
+    def do_add_dsym_with_error(self, exe_name):
+        """Test that the 'add-dsym' command informs the user about failures."""
+        self.runCmd("file " + exe_name, CURRENT_EXECUTABLE_SET)
+
+        wrong_path = "%s.dSYM" % exe_name
+        self.expect("add-dsym " + wrong_path, error=True,
+            substrs = ['symbol file', 'with UUID', 'does not match',
+                       'please specify the full path to the symbol file'])
+
+        right_path = os.path.join(wrong_path, "Contents", "Resources", "DWARF", exe_name)
+        self.expect("add-dsym " + right_path, error=True,
+            substrs = ['symbol file', 'with UUID', 'does not match'])
+
+    def do_add_dsym_with_success(self, exe_name):
+        """Test that the 'add-dsym' command informs the user about success."""
+        self.runCmd("file " + exe_name, CURRENT_EXECUTABLE_SET)
+
+        # This time, the UUID should match and we expect some feedback from lldb.
+        right_path = os.path.join("%s.dSYM" % exe_name, "Contents", "Resources", "DWARF", exe_name)
+        self.expect("add-dsym " + right_path,
+            substrs = ['symbol file', 'with UUID', 'has been successfully added to the',
+                       'module'])
+
+
+if __name__ == '__main__':
+    import atexit
+    lldb.SBDebugger.Initialize()
+    atexit.register(lambda: lldb.SBDebugger.Terminate())
+    unittest2.main()





More information about the lldb-commits mailing list