<rdar://problem/11374963>

Partial fix for the above radar where we now resolve dsym mach-o files within the dSYM bundle when using "add-dsym" through the platform.



git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@163676 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/lldb/Host/Symbols.h b/include/lldb/Host/Symbols.h
index 57f168e..7e997cc 100644
--- a/include/lldb/Host/Symbols.h
+++ b/include/lldb/Host/Symbols.h
@@ -29,6 +29,11 @@
 
     static FileSpec
     LocateExecutableSymbolFile (const ModuleSpec &module_spec);
+    
+    static FileSpec
+    FindSymbolFileInBundle (const FileSpec& dsym_bundle_fspec,
+                            const lldb_private::UUID *uuid,
+                            const ArchSpec *arch);
 };
 
 } // namespace lldb_private
diff --git a/include/lldb/Target/Platform.h b/include/lldb/Target/Platform.h
index d72d162..89f6441 100644
--- a/include/lldb/Target/Platform.h
+++ b/include/lldb/Target/Platform.h
@@ -118,6 +118,59 @@
                            lldb::ModuleSP &module_sp,
                            const FileSpecList *module_search_paths_ptr);
 
+        
+        //------------------------------------------------------------------
+        /// Find a symbol file given a symbol file module specification.
+        ///
+        /// Each platform might have tricks to find symbol files for an
+        /// executable given information in a symbol file ModuleSpec. Some
+        /// platforms might also support symbol files that are bundles and
+        /// know how to extract the right symbol file given a bundle.
+        ///
+        /// @param[in] target
+        ///     The target in which we are trying to resolve the symbol file.
+        ///     The target has a list of modules that we might be able to
+        ///     use in order to help find the right symbol file. If the
+        ///     "m_file" or "m_platform_file" entries in the \a sym_spec
+        ///     are filled in, then we might be able to locate a module in
+        ///     the target, extract its UUID and locate a symbol file.
+        ///     If just the "m_uuid" is specified, then we might be able
+        ///     to find the module in the target that matches that UUID
+        ///     and pair the symbol file along with it. If just "m_symbol_file"
+        ///     is specified, we can use a variety of tricks to locate the
+        ///     symbols in an SDK, PDK, or other development kit location.
+        ///
+        /// @param[in] sym_spec
+        ///     A module spec that describes some information about the
+        ///     symbol file we are trying to resolve. The ModuleSpec might
+        ///     contain the following:
+        ///     m_file - A full or partial path to an executable from the
+        ///              target (might be empty).
+        ///     m_platform_file - Another executable hint that contains
+        ///                       the path to the file as known on the
+        ///                       local/remote platform.
+        ///     m_symbol_file - A full or partial path to a symbol file
+        ///                     or symbol bundle that should be used when
+        ///                     trying to resolve the symbol file.
+        ///     m_arch - The architecture we are looking for when resolving
+        ///              the symbol file.
+        ///     m_uuid - The UUID of the executable and symbol file. This
+        ///              can often be used to match up an exectuable with
+        ///              a symbol file, or resolve an symbol file in a
+        ///              symbol file bundle.
+        ///
+        /// @param[out] sym_file
+        ///     The resolved symbol file spec if the returned error
+        ///     indicates succes.
+        ///
+        /// @return
+        ///     Returns an error that describes success or failure.
+        //------------------------------------------------------------------
+        virtual Error
+        ResolveSymbolFile (Target &target,
+                           const ModuleSpec &sym_spec,
+                           FileSpec &sym_file);
+
         //------------------------------------------------------------------
         /// Resolves the FileSpec to a (possibly) remote path. Remote
         /// platforms must override this to resolve to a path on the remote
diff --git a/source/Commands/CommandObjectTarget.cpp b/source/Commands/CommandObjectTarget.cpp
index 90ac761..d29c8a1 100644
--- a/source/Commands/CommandObjectTarget.cpp
+++ b/source/Commands/CommandObjectTarget.cpp
@@ -4040,12 +4040,21 @@
             }
             else
             {
+                PlatformSP platform_sp (target->GetPlatform());
+
                 for (size_t i=0; i<argc; ++i)
                 {
                     const char *symfile_path = args.GetArgumentAtIndex(i);
                     if (symfile_path)
                     {
-                        FileSpec symfile_spec(symfile_path, true);
+                        ModuleSpec sym_spec;
+                        FileSpec symfile_spec;
+                        sym_spec.GetSymbolFileSpec().SetFile(symfile_path, true);
+                        if (platform_sp)
+                            platform_sp->ResolveSymbolFile(*target, sym_spec, symfile_spec);
+                        else
+                            symfile_spec.SetFile(symfile_path, true);
+                        
                         ArchSpec arch;
                         if (symfile_spec.Exists())
                         {
diff --git a/source/Host/common/Symbols.cpp b/source/Host/common/Symbols.cpp
index a4e5703..464c2fc 100644
--- a/source/Host/common/Symbols.cpp
+++ b/source/Host/common/Symbols.cpp
@@ -28,4 +28,13 @@
     return FileSpec();
 }
 
+FileSpec
+Symbols::FindSymbolFileInBundle (const FileSpec& symfile_bundle,
+                                 const lldb_private::UUID *uuid,
+                                 const ArchSpec *arch)
+{
+    return FileSpec();
+}
+
+
 #endif
diff --git a/source/Host/macosx/Symbols.cpp b/source/Host/macosx/Symbols.cpp
index eb7341d..c49592e 100644
--- a/source/Host/macosx/Symbols.cpp
+++ b/source/Host/macosx/Symbols.cpp
@@ -244,12 +244,10 @@
     return false;
 }
 
-static FileSpec
-LocateDSYMMachFileInDSYMBundle
-(
-    const FileSpec& dsym_bundle_fspec,
-    const lldb_private::UUID *uuid,
-    const ArchSpec *arch)
+FileSpec
+Symbols::FindSymbolFileInBundle (const FileSpec& dsym_bundle_fspec,
+                                 const lldb_private::UUID *uuid,
+                                 const ArchSpec *arch)
 {
     char path[PATH_MAX];
 
@@ -361,7 +359,7 @@
 
                             if (out_dsym_fspec->GetFileType () == FileSpec::eFileTypeDirectory)
                             {
-                                *out_dsym_fspec = LocateDSYMMachFileInDSYMBundle (*out_dsym_fspec, uuid, arch);
+                                *out_dsym_fspec = Symbols::FindSymbolFileInBundle (*out_dsym_fspec, uuid, arch);
                                 if (*out_dsym_fspec)
                                     ++items_found;
                             }
diff --git a/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
index dc5658b..4d5c722 100644
--- a/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ b/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -19,6 +19,7 @@
 #include "lldb/Core/Module.h"
 #include "lldb/Core/ModuleSpec.h"
 #include "lldb/Host/Host.h"
+#include "lldb/Host/Symbols.h"
 #include "lldb/Symbol/ObjectFile.h"
 #include "lldb/Target/Target.h"
 
@@ -170,6 +171,33 @@
     return error;
 }
 
+Error
+PlatformDarwin::ResolveSymbolFile (Target &target,
+                                   const ModuleSpec &sym_spec,
+                                   FileSpec &sym_file)
+{
+    Error error;
+    sym_file = sym_spec.GetSymbolFileSpec();
+    if (sym_file.Exists())
+    {
+        if (sym_file.GetFileType() == FileSpec::eFileTypeDirectory)
+        {
+            sym_file = Symbols::FindSymbolFileInBundle (sym_file,
+                                                        sym_spec.GetUUIDPtr(),
+                                                        sym_spec.GetArchitecturePtr());
+        }
+    }
+    else
+    {
+        if (sym_spec.GetUUID().IsValid())
+        {
+            
+        }
+    }
+    return error;
+    
+}
+
 
 
 Error
diff --git a/source/Plugins/Platform/MacOSX/PlatformDarwin.h b/source/Plugins/Platform/MacOSX/PlatformDarwin.h
index 3c27d43..9376a66 100644
--- a/source/Plugins/Platform/MacOSX/PlatformDarwin.h
+++ b/source/Plugins/Platform/MacOSX/PlatformDarwin.h
@@ -34,6 +34,11 @@
                        const lldb_private::FileSpecList *module_search_paths_ptr);
 
     virtual lldb_private::Error
+    ResolveSymbolFile (lldb_private::Target &target,
+                       const lldb_private::ModuleSpec &sym_spec,
+                       lldb_private::FileSpec &sym_file);
+
+    virtual lldb_private::Error
     GetSharedModule (const lldb_private::ModuleSpec &module_spec,
                      lldb::ModuleSP &module_sp,
                      const lldb_private::FileSpecList *module_search_paths_ptr,
diff --git a/source/Target/Platform.cpp b/source/Target/Platform.cpp
index 666daaa..6772abf 100644
--- a/source/Target/Platform.cpp
+++ b/source/Target/Platform.cpp
@@ -466,6 +466,22 @@
     return error;
 }
 
+Error
+Platform::ResolveSymbolFile (Target &target,
+                             const ModuleSpec &sym_spec,
+                             FileSpec &sym_file)
+{
+    Error error;
+    if (sym_spec.GetSymbolFileSpec().Exists())
+        sym_file = sym_spec.GetSymbolFileSpec();
+    else
+        error.SetErrorString("unable to resolve symbol file");
+    return error;
+    
+}
+
+
+
 bool
 Platform::ResolveRemotePath (const FileSpec &platform_path,
                              FileSpec &resolved_platform_path)