Add a parameter to Symbols::DownloadObjectAndSymbolFile() to control
whether we try to call an external program to load symbols unconditionally,
or if we check the user's preferences before calling it.

ProcessMachCore now sets CanJIT to false - we can't execute code in a core file.

DynamicLoaderDarwinKernel::OSKextLoadedKextSummary::LoadImageUsingMemoryModule changed
to load the kernel from an on-disk file if at all possible.
Don't load the kext binaries out of memory from the remote systems - their linkedit doesn't
seem to be in a good state and we'll error out down in SymbolVendorMacOSX if we try to use
the in-memory images.
Call Symbols::DownloadObjectAndSymbolFile to get the kext/kernel binary -- the external
program may be able to give us a file path on the local filesystem instead of reading
the binary / dSYM over a network drive every time.  Fall back to calling 
Target::GetSharedModule() like before if DownloadObjectAndSymbolFile fails.




git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@165471 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Host/macosx/Symbols.cpp b/source/Host/macosx/Symbols.cpp
index 990f3ea..a8fa1c0 100644
--- a/source/Host/macosx/Symbols.cpp
+++ b/source/Host/macosx/Symbols.cpp
@@ -643,11 +643,41 @@
 
 
 bool
-Symbols::DownloadObjectAndSymbolFile (ModuleSpec &module_spec)
+Symbols::DownloadObjectAndSymbolFile (ModuleSpec &module_spec, bool force_lookup)
 {
     bool success = false;
     const UUID *uuid_ptr = module_spec.GetUUIDPtr();
     const FileSpec *file_spec_ptr = module_spec.GetFileSpecPtr();
+
+    // It's expensive to check for the DBGShellCommands defaults setting, only do it once per
+    // lldb run and cache the result.  
+    static bool g_have_checked_for_dbgshell_command = false;
+    static const char *g_dbgshell_command = NULL;
+    if (g_have_checked_for_dbgshell_command == false)
+    {
+        g_have_checked_for_dbgshell_command = true;
+        CFTypeRef defaults_setting = CFPreferencesCopyAppValue (CFSTR ("DBGShellCommands"), CFSTR ("com.apple.DebugSymbols"));
+        if (defaults_setting && CFGetTypeID (defaults_setting) == CFStringGetTypeID())
+        { 
+            char cstr_buf[PATH_MAX];
+            if (CFStringGetCString ((CFStringRef) defaults_setting, cstr_buf, sizeof (cstr_buf), kCFStringEncodingUTF8))
+            {
+                g_dbgshell_command = strdup (cstr_buf);  // this malloc'ed memory will never be freed
+            }
+        }
+        if (defaults_setting)
+        {
+            CFRelease (defaults_setting);
+        }
+    }
+
+    // When g_dbgshell_command is NULL, the user has not enabled the use of an external program
+    // to find the symbols, don't run it for them.
+    if (force_lookup == false && g_dbgshell_command == NULL)
+    {
+        return false;
+    }
+
     if (uuid_ptr || (file_spec_ptr && file_spec_ptr->Exists()))
     {
         static bool g_located_dsym_for_uuid_exe = false;
@@ -671,9 +701,15 @@
                 if (!g_dsym_for_uuid_exe_exists)
                 {
                     dsym_for_uuid_exe_spec.SetFile("/usr/local/bin/dsymForUUID", false);
+                    g_dsym_for_uuid_exe_exists = dsym_for_uuid_exe_spec.Exists();
                 }
             }
-            
+            if (!g_dsym_for_uuid_exe_exists && g_dbgshell_command != NULL)
+            {
+                dsym_for_uuid_exe_spec.SetFile(g_dbgshell_command, true);
+                g_dsym_for_uuid_exe_exists = dsym_for_uuid_exe_spec.Exists();
+            }
+
             if (g_dsym_for_uuid_exe_exists)
                 dsym_for_uuid_exe_spec.GetPath (g_dsym_for_uuid_exe_path, sizeof(g_dsym_for_uuid_exe_path));
         }