Modified the LocateMacOSXFilesUsingDebugSymbols(...) function to locate
an executable file if it is right next to a dSYM file that is found using
DebugSymbols. The code also looks into a bundle if the dSYM file is right
next to a bundle.

Modified the MacOSX kernel dynamic loader plug-in to correctly set the load
address for kext sections. This is a tad tricky because of how LLDB chooses
to treat mach-o segments with no name. Also modified the loader to properly
handle the older version 1 kext summary info.

Fixed a crasher in the Mach-o object file parser when it is trying to set
the section size correctly for dSYM sections.

Added packet dumpers to the CommunicationKDP class. We now also properly 
detect address byte sizes based on the cpu type and subtype that is provided.
Added a read memory and read register support to CommunicationKDP. Added a
ThreadKDP class that now uses subclasses of the RegisterContextDarwin_XXX for
arm, i386 and x86_64. 

Fixed some register numbering issues in the RegisterContextDarwin_arm class
and added ARM GDB numbers to the ARM_GCC_Registers.h file.

Change the RegisterContextMach_XXX classes over to subclassing their
RegisterContextDarwin_XXX counterparts so we can share the mach register 
contexts between the user and kernel plug-ins.




git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@135466 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Host/macosx/Symbols.cpp b/source/Host/macosx/Symbols.cpp
index c6d2f08..aadb93c 100644
--- a/source/Host/macosx/Symbols.cpp
+++ b/source/Host/macosx/Symbols.cpp
@@ -29,6 +29,9 @@
 #include "Host/macosx/cfcpp/CFCString.h"
 #include "mach/machine.h"
 
+#include "CFCBundle.h"
+
+
 using namespace lldb;
 using namespace lldb_private;
 using namespace llvm::MachO;
@@ -291,7 +294,7 @@
         const UInt8 *module_uuid = (const UInt8 *)uuid->GetBytes();
         if (module_uuid != NULL)
         {
-            CFCReleaser<CFUUIDRef> module_uuid_ref(::CFUUIDCreateWithBytes ( NULL,
+            CFCReleaser<CFUUIDRef> module_uuid_ref(::CFUUIDCreateWithBytes (NULL,
                                                                             module_uuid[0],
                                                                             module_uuid[1],
                                                                             module_uuid[2],
@@ -366,6 +369,57 @@
                                 }
                             }
                         }
+                        else
+                        {
+                            // No dictionary, check near the dSYM bundle for an executable that matches...
+                            if (::CFURLGetFileSystemRepresentation (dsym_url.get(), true, (UInt8*)path, sizeof(path)-1))
+                            {
+                                char *dsym_extension_pos = ::strstr (path, ".dSYM");
+                                if (dsym_extension_pos)
+                                {
+                                    *dsym_extension_pos = '\0';
+                                    FileSpec file_spec (path, true);
+                                    switch (file_spec.GetFileType())
+                                    {
+                                        case FileSpec::eFileTypeDirectory:  // Bundle directory?
+                                            {
+                                                CFCBundle bundle (path);
+                                                CFCReleaser<CFURLRef> bundle_exe_url (bundle.CopyExecutableURL ());
+                                                if (bundle_exe_url.get())
+                                                {
+                                                    if (::CFURLGetFileSystemRepresentation (bundle_exe_url.get(), true, (UInt8*)path, sizeof(path)-1))
+                                                    {
+                                                        FileSpec bundle_exe_file_spec (path, true);
+                                                        
+                                                        if (FileAtPathContainsArchAndUUID (bundle_exe_file_spec, arch, uuid))
+                                                        {
+                                                            ++items_found;
+                                                            *out_exec_fspec = bundle_exe_file_spec;
+                                                        }
+                                                    }
+                                                }
+                                            }
+                                            break;
+                                            
+                                        case FileSpec::eFileTypePipe:       // Forget pipes
+                                        case FileSpec::eFileTypeSocket:     // We can't process socket files
+                                        case FileSpec::eFileTypeInvalid:    // File doesn't exist...
+                                            break;
+
+                                        case FileSpec::eFileTypeUnknown:
+                                        case FileSpec::eFileTypeRegular:
+                                        case FileSpec::eFileTypeSymbolicLink:
+                                        case FileSpec::eFileTypeOther:
+                                            if (FileAtPathContainsArchAndUUID (file_spec, arch, uuid))
+                                            {
+                                                ++items_found;
+                                                *out_exec_fspec = file_spec;
+                                            }
+                                            break;
+                                    }
+                                }
+                            }
+                        }
                     }
                 }
             }