Don't link against the DebugSymbols private framework; try to dlopen
+ dlsym the two functions we need from there at runtime.

I'm not maintaining a negative cache if DebugSymbols is absent, so
we'll try to dlopen() it on every call to
LocateMacOSXFilesUsingDebugSymbols but this file is only built on
mac and iOS type systems, so there's a slight perf impact running
lldb on an iOS type system.

I store the function pointer results in two global variables without
any locking; two threads calling into LocateMacOSXFilesUsingDebugSymbols
for the first time will both try to set these fptrs, but they'll be
setting them to the same value, so I'm not too worried.

I didn't see where in the cmake build configurations we link against
DebugSymbols, but I removed the dependency from the xcode project
file.

<rdar://problem/49458356> 

llvm-svn: 364243
diff --git a/lldb/lldb.xcodeproj/project.pbxproj b/lldb/lldb.xcodeproj/project.pbxproj
index b7bbe19e..4c7eaeb 100644
--- a/lldb/lldb.xcodeproj/project.pbxproj
+++ b/lldb/lldb.xcodeproj/project.pbxproj
@@ -1824,7 +1824,6 @@
 		6D0F613C1C80AA8900A4ECEE /* DebugMacros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DebugMacros.h; path = include/lldb/Symbol/DebugMacros.h; sourceTree = "<group>"; };
 		AF116BED20CF234B0071093F /* DebugNamesDWARFIndex.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DebugNamesDWARFIndex.cpp; sourceTree = "<group>"; };
 		AF116BEE20CF234B0071093F /* DebugNamesDWARFIndex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DebugNamesDWARFIndex.h; sourceTree = "<group>"; };
-		265ABF6210F42EE900531910 /* DebugSymbols.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = DebugSymbols.framework; path = /System/Library/PrivateFrameworks/DebugSymbols.framework; sourceTree = "<absolute>"; };
 		263664921140A4930075843B /* Debugger.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = Debugger.cpp; path = source/Core/Debugger.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
 		263664941140A4C10075843B /* Debugger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = Debugger.h; path = include/lldb/Core/Debugger.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
 		49B01A2D15F67B1700666829 /* DeclVendor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = DeclVendor.h; path = include/lldb/Symbol/DeclVendor.h; sourceTree = "<group>"; };
@@ -6056,7 +6055,6 @@
 			isa = PBXGroup;
 			children = (
 				26F5C39010F3FA26009D5894 /* CoreFoundation.framework */,
-				265ABF6210F42EE900531910 /* DebugSymbols.framework */,
 				260C876910F538E700BB2B04 /* Foundation.framework */,
 				26709E311964A34000B94724 /* LaunchServices.framework */,
 				26F5C32A10F3DFDD009D5894 /* libedit.dylib */,
@@ -9173,8 +9171,6 @@
 					"-framework",
 					Foundation,
 					"-framework",
-					DebugSymbols,
-					"-framework",
 					Security,
 					"-framework",
 					CoreServices,
@@ -9213,8 +9209,6 @@
 					"-framework",
 					Foundation,
 					"-framework",
-					DebugSymbols,
-					"-framework",
 					Security,
 					"-framework",
 					CoreServices,
@@ -9253,8 +9247,6 @@
 					"-framework",
 					Foundation,
 					"-framework",
-					DebugSymbols,
-					"-framework",
 					Security,
 					"-framework",
 					CoreServices,
@@ -9293,8 +9285,6 @@
 					"-framework",
 					Foundation,
 					"-framework",
-					DebugSymbols,
-					"-framework",
 					Security,
 					"-framework",
 					CoreServices,
@@ -9333,8 +9323,6 @@
 					"-framework",
 					Foundation,
 					"-framework",
-					DebugSymbols,
-					"-framework",
 					Security,
 					"-framework",
 					CoreServices,
@@ -9374,8 +9362,6 @@
 					"-framework",
 					Foundation,
 					"-framework",
-					DebugSymbols,
-					"-framework",
 					Security,
 					"-framework",
 					CoreServices,
@@ -9415,8 +9401,6 @@
 					"-framework",
 					Foundation,
 					"-framework",
-					DebugSymbols,
-					"-framework",
 					Security,
 					"-framework",
 					CoreServices,
@@ -9456,8 +9440,6 @@
 					"-framework",
 					Foundation,
 					"-framework",
-					DebugSymbols,
-					"-framework",
 					Security,
 					"-framework",
 					CoreServices,
@@ -9557,8 +9539,6 @@
 					"-framework",
 					Foundation,
 					"-framework",
-					DebugSymbols,
-					"-framework",
 					Security,
 					"-framework",
 					CoreServices,
@@ -9625,8 +9605,6 @@
 					"-framework",
 					Foundation,
 					"-framework",
-					DebugSymbols,
-					"-framework",
 					Security,
 					"-framework",
 					CoreServices,
@@ -10256,8 +10234,6 @@
 					"-framework",
 					Foundation,
 					"-framework",
-					DebugSymbols,
-					"-framework",
 					Security,
 					"-framework",
 					CoreServices,
@@ -10523,8 +10499,6 @@
 					"-lobjc",
 					"-lpython",
 					"-framework",
-					DebugSymbols,
-					"-framework",
 					Carbon,
 					"-framework",
 					Foundation,
@@ -10556,8 +10530,6 @@
 					"-lpython2.7",
 					"-lxml2",
 					"-framework",
-					DebugSymbols,
-					"-framework",
 					Foundation,
 					"-framework",
 					Carbon,
@@ -10594,8 +10566,6 @@
 					"-lobjc",
 					"-lpython",
 					"-framework",
-					DebugSymbols,
-					"-framework",
 					Carbon,
 					"-framework",
 					Foundation,
@@ -10627,8 +10597,6 @@
 					"-lpython2.7",
 					"-lxml2",
 					"-framework",
-					DebugSymbols,
-					"-framework",
 					Foundation,
 					"-framework",
 					Carbon,
@@ -10664,8 +10632,6 @@
 					"-lobjc",
 					"-lpython",
 					"-framework",
-					DebugSymbols,
-					"-framework",
 					Carbon,
 					"-framework",
 					Foundation,
@@ -10698,8 +10664,6 @@
 					"-lpython2.7",
 					"-lxml2",
 					"-framework",
-					DebugSymbols,
-					"-framework",
 					Foundation,
 					"-framework",
 					Carbon,
@@ -10998,8 +10962,6 @@
 					"-framework",
 					Foundation,
 					"-framework",
-					DebugSymbols,
-					"-framework",
 					Security,
 					"-framework",
 					CoreServices,
@@ -11102,8 +11064,6 @@
 					"-lobjc",
 					"-lpython",
 					"-framework",
-					DebugSymbols,
-					"-framework",
 					Carbon,
 					"-framework",
 					Foundation,
@@ -11135,8 +11095,6 @@
 					"-lpython2.7",
 					"-lxml2",
 					"-framework",
-					DebugSymbols,
-					"-framework",
 					Foundation,
 					"-framework",
 					Carbon,
@@ -11224,8 +11182,6 @@
 					"-lpython2.7",
 					"-lxml2",
 					"-framework",
-					DebugSymbols,
-					"-framework",
 					Foundation,
 					"-framework",
 					Carbon,
@@ -11290,8 +11246,6 @@
 					"-lpython2.7",
 					"-lxml2",
 					"-framework",
-					DebugSymbols,
-					"-framework",
 					Foundation,
 					"-framework",
 					Carbon,
@@ -11353,8 +11307,6 @@
 					"-lpython2.7",
 					"-lxml2",
 					"-framework",
-					DebugSymbols,
-					"-framework",
 					Foundation,
 					"-framework",
 					Carbon,
@@ -11418,8 +11370,6 @@
 					"-lpython2.7",
 					"-lxml2",
 					"-framework",
-					DebugSymbols,
-					"-framework",
 					Foundation,
 					"-framework",
 					Carbon,
diff --git a/lldb/source/Symbol/LocateSymbolFileMacOSX.cpp b/lldb/source/Symbol/LocateSymbolFileMacOSX.cpp
index 8c65e67..4e16382 100644
--- a/lldb/source/Symbol/LocateSymbolFileMacOSX.cpp
+++ b/lldb/source/Symbol/LocateSymbolFileMacOSX.cpp
@@ -9,6 +9,7 @@
 #include "lldb/Symbol/LocateSymbolFile.h"
 
 #include <dirent.h>
+#include <dlfcn.h>
 #include <pwd.h>
 
 #include <CoreFoundation/CoreFoundation.h>
@@ -37,14 +38,8 @@
 using namespace lldb;
 using namespace lldb_private;
 
-#if !defined(__arm__) && !defined(__arm64__) &&                                \
-    !defined(__aarch64__) // No DebugSymbols on the iOS devices
-extern "C" {
-
-CFURLRef DBGCopyFullDSYMURLForUUID(CFUUIDRef uuid, CFURLRef exec_url);
-CFDictionaryRef DBGCopyDSYMPropertyLists(CFURLRef dsym_url);
-}
-#endif
+static CFURLRef (*g_dlsym_DBGCopyFullDSYMURLForUUID)(CFUUIDRef uuid, CFURLRef exec_url) = nullptr;
+static CFDictionaryRef (*g_dlsym_DBGCopyDSYMPropertyLists)(CFURLRef dsym_url) = nullptr;
 
 int LocateMacOSXFilesUsingDebugSymbols(const ModuleSpec &module_spec,
                                        ModuleSpec &return_module_spec) {
@@ -61,8 +56,19 @@
 
   int items_found = 0;
 
-#if !defined(__arm__) && !defined(__arm64__) &&                                \
-    !defined(__aarch64__) // No DebugSymbols on the iOS devices
+  if (g_dlsym_DBGCopyFullDSYMURLForUUID == nullptr ||
+      g_dlsym_DBGCopyDSYMPropertyLists == nullptr) {
+    void *handle = dlopen ("/System/Library/PrivateFrameworks/DebugSymbols.framework/DebugSymbols", RTLD_LAZY | RTLD_LOCAL);
+    if (handle) {
+      g_dlsym_DBGCopyFullDSYMURLForUUID = (CFURLRef (*)(CFUUIDRef, CFURLRef)) dlsym (handle, "DBGCopyFullDSYMURLForUUID");
+      g_dlsym_DBGCopyDSYMPropertyLists = (CFDictionaryRef (*)(CFURLRef)) dlsym (handle, "DBGCopyDSYMPropertyLists");
+    }
+  }
+
+  if (g_dlsym_DBGCopyFullDSYMURLForUUID == nullptr ||
+      g_dlsym_DBGCopyDSYMPropertyLists == nullptr) {
+    return items_found;
+  }
 
   const UUID *uuid = module_spec.GetUUIDPtr();
   const ArchSpec *arch = module_spec.GetArchitecturePtr();
@@ -89,7 +95,7 @@
         }
 
         CFCReleaser<CFURLRef> dsym_url(
-            ::DBGCopyFullDSYMURLForUUID(module_uuid_ref.get(), exec_url.get()));
+            g_dlsym_DBGCopyFullDSYMURLForUUID(module_uuid_ref.get(), exec_url.get()));
         char path[PATH_MAX];
 
         if (dsym_url.get()) {
@@ -125,7 +131,7 @@
           }
 
           CFCReleaser<CFDictionaryRef> dict(
-              ::DBGCopyDSYMPropertyLists(dsym_url.get()));
+              g_dlsym_DBGCopyDSYMPropertyLists(dsym_url.get()));
           CFDictionaryRef uuid_dict = NULL;
           if (dict.get()) {
             CFCString uuid_cfstr(uuid->GetAsString().c_str());
@@ -236,8 +242,6 @@
       }
     }
   }
-#endif // #if !defined (__arm__) && !defined (__arm64__) && !defined
-       // (__aarch64__)
 
   return items_found;
 }