xref: /openbsd-src/gnu/llvm/lldb/source/Symbol/LocateSymbolFile.cpp (revision f6aab3d83b51b91c24247ad2c2573574de475a82)
1dda28197Spatrick //===-- LocateSymbolFile.cpp ----------------------------------------------===//
2061da546Spatrick //
3061da546Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4061da546Spatrick // See https://llvm.org/LICENSE.txt for license information.
5061da546Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6061da546Spatrick //
7061da546Spatrick //===----------------------------------------------------------------------===//
8061da546Spatrick 
9061da546Spatrick #include "lldb/Symbol/LocateSymbolFile.h"
10061da546Spatrick 
11*f6aab3d8Srobert #include "lldb/Core/Debugger.h"
12*f6aab3d8Srobert #include "lldb/Core/Module.h"
13061da546Spatrick #include "lldb/Core/ModuleList.h"
14061da546Spatrick #include "lldb/Core/ModuleSpec.h"
15*f6aab3d8Srobert #include "lldb/Core/Progress.h"
16061da546Spatrick #include "lldb/Host/FileSystem.h"
17061da546Spatrick #include "lldb/Symbol/ObjectFile.h"
18061da546Spatrick #include "lldb/Utility/ArchSpec.h"
19061da546Spatrick #include "lldb/Utility/DataBuffer.h"
20061da546Spatrick #include "lldb/Utility/DataExtractor.h"
21*f6aab3d8Srobert #include "lldb/Utility/LLDBLog.h"
22061da546Spatrick #include "lldb/Utility/Log.h"
23061da546Spatrick #include "lldb/Utility/StreamString.h"
24061da546Spatrick #include "lldb/Utility/Timer.h"
25061da546Spatrick #include "lldb/Utility/UUID.h"
26061da546Spatrick 
27*f6aab3d8Srobert #include "llvm/ADT/SmallSet.h"
28061da546Spatrick #include "llvm/Support/FileSystem.h"
29*f6aab3d8Srobert #include "llvm/Support/ThreadPool.h"
30061da546Spatrick 
31061da546Spatrick // From MacOSX system header "mach/machine.h"
32061da546Spatrick typedef int cpu_type_t;
33061da546Spatrick typedef int cpu_subtype_t;
34061da546Spatrick 
35061da546Spatrick using namespace lldb;
36061da546Spatrick using namespace lldb_private;
37061da546Spatrick 
38061da546Spatrick #if defined(__APPLE__)
39061da546Spatrick 
40061da546Spatrick // Forward declaration of method defined in source/Host/macosx/Symbols.cpp
41061da546Spatrick int LocateMacOSXFilesUsingDebugSymbols(const ModuleSpec &module_spec,
42061da546Spatrick                                        ModuleSpec &return_module_spec);
43061da546Spatrick 
44061da546Spatrick #else
45061da546Spatrick 
LocateMacOSXFilesUsingDebugSymbols(const ModuleSpec & module_spec,ModuleSpec & return_module_spec)46061da546Spatrick int LocateMacOSXFilesUsingDebugSymbols(const ModuleSpec &module_spec,
47061da546Spatrick                                        ModuleSpec &return_module_spec) {
48061da546Spatrick   // Cannot find MacOSX files using debug symbols on non MacOSX.
49061da546Spatrick   return 0;
50061da546Spatrick }
51061da546Spatrick 
52061da546Spatrick #endif
53061da546Spatrick 
FileAtPathContainsArchAndUUID(const FileSpec & file_fspec,const ArchSpec * arch,const lldb_private::UUID * uuid)54061da546Spatrick static bool FileAtPathContainsArchAndUUID(const FileSpec &file_fspec,
55061da546Spatrick                                           const ArchSpec *arch,
56061da546Spatrick                                           const lldb_private::UUID *uuid) {
57061da546Spatrick   ModuleSpecList module_specs;
58061da546Spatrick   if (ObjectFile::GetModuleSpecifications(file_fspec, 0, 0, module_specs)) {
59061da546Spatrick     ModuleSpec spec;
60061da546Spatrick     for (size_t i = 0; i < module_specs.GetSize(); ++i) {
61061da546Spatrick       bool got_spec = module_specs.GetModuleSpecAtIndex(i, spec);
62061da546Spatrick       UNUSED_IF_ASSERT_DISABLED(got_spec);
63061da546Spatrick       assert(got_spec);
64061da546Spatrick       if ((uuid == nullptr || (spec.GetUUIDPtr() && spec.GetUUID() == *uuid)) &&
65061da546Spatrick           (arch == nullptr ||
66061da546Spatrick            (spec.GetArchitecturePtr() &&
67061da546Spatrick             spec.GetArchitecture().IsCompatibleMatch(*arch)))) {
68061da546Spatrick         return true;
69061da546Spatrick       }
70061da546Spatrick     }
71061da546Spatrick   }
72061da546Spatrick   return false;
73061da546Spatrick }
74061da546Spatrick 
75061da546Spatrick // Given a binary exec_fspec, and a ModuleSpec with an architecture/uuid,
76061da546Spatrick // return true if there is a matching dSYM bundle next to the exec_fspec,
77061da546Spatrick // and return that value in dsym_fspec.
78061da546Spatrick // If there is a .dSYM.yaa compressed archive next to the exec_fspec,
79061da546Spatrick // call through Symbols::DownloadObjectAndSymbolFile to download the
80061da546Spatrick // expanded/uncompressed dSYM and return that filepath in dsym_fspec.
81061da546Spatrick 
LookForDsymNextToExecutablePath(const ModuleSpec & mod_spec,const FileSpec & exec_fspec,FileSpec & dsym_fspec)82061da546Spatrick static bool LookForDsymNextToExecutablePath(const ModuleSpec &mod_spec,
83061da546Spatrick                                             const FileSpec &exec_fspec,
84061da546Spatrick                                             FileSpec &dsym_fspec) {
85061da546Spatrick   ConstString filename = exec_fspec.GetFilename();
86061da546Spatrick   FileSpec dsym_directory = exec_fspec;
87061da546Spatrick   dsym_directory.RemoveLastPathComponent();
88061da546Spatrick 
89061da546Spatrick   std::string dsym_filename = filename.AsCString();
90061da546Spatrick   dsym_filename += ".dSYM";
91061da546Spatrick   dsym_directory.AppendPathComponent(dsym_filename);
92061da546Spatrick   dsym_directory.AppendPathComponent("Contents");
93061da546Spatrick   dsym_directory.AppendPathComponent("Resources");
94061da546Spatrick   dsym_directory.AppendPathComponent("DWARF");
95061da546Spatrick 
96061da546Spatrick   if (FileSystem::Instance().Exists(dsym_directory)) {
97061da546Spatrick 
98061da546Spatrick     // See if the binary name exists in the dSYM DWARF
99061da546Spatrick     // subdir.
100061da546Spatrick     dsym_fspec = dsym_directory;
101061da546Spatrick     dsym_fspec.AppendPathComponent(filename.AsCString());
102061da546Spatrick     if (FileSystem::Instance().Exists(dsym_fspec) &&
103061da546Spatrick         FileAtPathContainsArchAndUUID(dsym_fspec, mod_spec.GetArchitecturePtr(),
104061da546Spatrick                                       mod_spec.GetUUIDPtr())) {
105061da546Spatrick       return true;
106061da546Spatrick     }
107061da546Spatrick 
108061da546Spatrick     // See if we have "../CF.framework" - so we'll look for
109061da546Spatrick     // CF.framework.dSYM/Contents/Resources/DWARF/CF
110061da546Spatrick     // We need to drop the last suffix after '.' to match
111061da546Spatrick     // 'CF' in the DWARF subdir.
112061da546Spatrick     std::string binary_name(filename.AsCString());
113061da546Spatrick     auto last_dot = binary_name.find_last_of('.');
114061da546Spatrick     if (last_dot != std::string::npos) {
115061da546Spatrick       binary_name.erase(last_dot);
116061da546Spatrick       dsym_fspec = dsym_directory;
117061da546Spatrick       dsym_fspec.AppendPathComponent(binary_name);
118061da546Spatrick       if (FileSystem::Instance().Exists(dsym_fspec) &&
119061da546Spatrick           FileAtPathContainsArchAndUUID(dsym_fspec,
120061da546Spatrick                                         mod_spec.GetArchitecturePtr(),
121061da546Spatrick                                         mod_spec.GetUUIDPtr())) {
122061da546Spatrick         return true;
123061da546Spatrick       }
124061da546Spatrick     }
125061da546Spatrick   }
126061da546Spatrick 
127061da546Spatrick   // See if we have a .dSYM.yaa next to this executable path.
128061da546Spatrick   FileSpec dsym_yaa_fspec = exec_fspec;
129061da546Spatrick   dsym_yaa_fspec.RemoveLastPathComponent();
130061da546Spatrick   std::string dsym_yaa_filename = filename.AsCString();
131061da546Spatrick   dsym_yaa_filename += ".dSYM.yaa";
132061da546Spatrick   dsym_yaa_fspec.AppendPathComponent(dsym_yaa_filename);
133061da546Spatrick 
134061da546Spatrick   if (FileSystem::Instance().Exists(dsym_yaa_fspec)) {
135061da546Spatrick     ModuleSpec mutable_mod_spec = mod_spec;
136*f6aab3d8Srobert     Status error;
137*f6aab3d8Srobert     if (Symbols::DownloadObjectAndSymbolFile(mutable_mod_spec, error, true) &&
138061da546Spatrick         FileSystem::Instance().Exists(mutable_mod_spec.GetSymbolFileSpec())) {
139061da546Spatrick       dsym_fspec = mutable_mod_spec.GetSymbolFileSpec();
140061da546Spatrick       return true;
141061da546Spatrick     }
142061da546Spatrick   }
143061da546Spatrick 
144061da546Spatrick   return false;
145061da546Spatrick }
146061da546Spatrick 
147061da546Spatrick // Given a ModuleSpec with a FileSpec and optionally uuid/architecture
148061da546Spatrick // filled in, look for a .dSYM bundle next to that binary.  Returns true
149061da546Spatrick // if a .dSYM bundle is found, and that path is returned in the dsym_fspec
150061da546Spatrick // FileSpec.
151061da546Spatrick //
152061da546Spatrick // This routine looks a few directory layers above the given exec_path -
153061da546Spatrick // exec_path might be /System/Library/Frameworks/CF.framework/CF and the
154061da546Spatrick // dSYM might be /System/Library/Frameworks/CF.framework.dSYM.
155061da546Spatrick //
156061da546Spatrick // If there is a .dSYM.yaa compressed archive found next to the binary,
157061da546Spatrick // we'll call DownloadObjectAndSymbolFile to expand it into a plain .dSYM
158061da546Spatrick 
LocateDSYMInVincinityOfExecutable(const ModuleSpec & module_spec,FileSpec & dsym_fspec)159061da546Spatrick static bool LocateDSYMInVincinityOfExecutable(const ModuleSpec &module_spec,
160061da546Spatrick                                               FileSpec &dsym_fspec) {
161*f6aab3d8Srobert   Log *log = GetLog(LLDBLog::Host);
162061da546Spatrick   const FileSpec &exec_fspec = module_spec.GetFileSpec();
163061da546Spatrick   if (exec_fspec) {
164061da546Spatrick     if (::LookForDsymNextToExecutablePath(module_spec, exec_fspec,
165061da546Spatrick                                           dsym_fspec)) {
166061da546Spatrick       if (log) {
167061da546Spatrick         LLDB_LOGF(log, "dSYM with matching UUID & arch found at %s",
168061da546Spatrick                   dsym_fspec.GetPath().c_str());
169061da546Spatrick       }
170061da546Spatrick       return true;
171061da546Spatrick     } else {
172061da546Spatrick       FileSpec parent_dirs = exec_fspec;
173061da546Spatrick 
174061da546Spatrick       // Remove the binary name from the FileSpec
175061da546Spatrick       parent_dirs.RemoveLastPathComponent();
176061da546Spatrick 
177061da546Spatrick       // Add a ".dSYM" name to each directory component of the path,
178061da546Spatrick       // stripping off components.  e.g. we may have a binary like
179061da546Spatrick       // /S/L/F/Foundation.framework/Versions/A/Foundation and
180061da546Spatrick       // /S/L/F/Foundation.framework.dSYM
181061da546Spatrick       //
182061da546Spatrick       // so we'll need to start with
183061da546Spatrick       // /S/L/F/Foundation.framework/Versions/A, add the .dSYM part to the
184061da546Spatrick       // "A", and if that doesn't exist, strip off the "A" and try it again
185061da546Spatrick       // with "Versions", etc., until we find a dSYM bundle or we've
186061da546Spatrick       // stripped off enough path components that there's no need to
187061da546Spatrick       // continue.
188061da546Spatrick 
189061da546Spatrick       for (int i = 0; i < 4; i++) {
190061da546Spatrick         // Does this part of the path have a "." character - could it be a
191061da546Spatrick         // bundle's top level directory?
192061da546Spatrick         const char *fn = parent_dirs.GetFilename().AsCString();
193061da546Spatrick         if (fn == nullptr)
194061da546Spatrick           break;
195061da546Spatrick         if (::strchr(fn, '.') != nullptr) {
196061da546Spatrick           if (::LookForDsymNextToExecutablePath(module_spec, parent_dirs,
197061da546Spatrick                                                 dsym_fspec)) {
198061da546Spatrick             if (log) {
199061da546Spatrick               LLDB_LOGF(log, "dSYM with matching UUID & arch found at %s",
200061da546Spatrick                         dsym_fspec.GetPath().c_str());
201061da546Spatrick             }
202061da546Spatrick             return true;
203061da546Spatrick           }
204061da546Spatrick         }
205061da546Spatrick         parent_dirs.RemoveLastPathComponent();
206061da546Spatrick       }
207061da546Spatrick     }
208061da546Spatrick   }
209061da546Spatrick   dsym_fspec.Clear();
210061da546Spatrick   return false;
211061da546Spatrick }
212061da546Spatrick 
LocateExecutableSymbolFileDsym(const ModuleSpec & module_spec)213061da546Spatrick static FileSpec LocateExecutableSymbolFileDsym(const ModuleSpec &module_spec) {
214061da546Spatrick   const FileSpec *exec_fspec = module_spec.GetFileSpecPtr();
215061da546Spatrick   const ArchSpec *arch = module_spec.GetArchitecturePtr();
216061da546Spatrick   const UUID *uuid = module_spec.GetUUIDPtr();
217061da546Spatrick 
218be691f3bSpatrick   LLDB_SCOPED_TIMERF(
219061da546Spatrick       "LocateExecutableSymbolFileDsym (file = %s, arch = %s, uuid = %p)",
220061da546Spatrick       exec_fspec ? exec_fspec->GetFilename().AsCString("<NULL>") : "<NULL>",
221061da546Spatrick       arch ? arch->GetArchitectureName() : "<NULL>", (const void *)uuid);
222061da546Spatrick 
223061da546Spatrick   FileSpec symbol_fspec;
224061da546Spatrick   ModuleSpec dsym_module_spec;
225061da546Spatrick   // First try and find the dSYM in the same directory as the executable or in
226061da546Spatrick   // an appropriate parent directory
227061da546Spatrick   if (!LocateDSYMInVincinityOfExecutable(module_spec, symbol_fspec)) {
228061da546Spatrick     // We failed to easily find the dSYM above, so use DebugSymbols
229061da546Spatrick     LocateMacOSXFilesUsingDebugSymbols(module_spec, dsym_module_spec);
230061da546Spatrick   } else {
231061da546Spatrick     dsym_module_spec.GetSymbolFileSpec() = symbol_fspec;
232061da546Spatrick   }
233be691f3bSpatrick 
234061da546Spatrick   return dsym_module_spec.GetSymbolFileSpec();
235061da546Spatrick }
236061da546Spatrick 
LocateExecutableObjectFile(const ModuleSpec & module_spec)237061da546Spatrick ModuleSpec Symbols::LocateExecutableObjectFile(const ModuleSpec &module_spec) {
238061da546Spatrick   ModuleSpec result;
239061da546Spatrick   const FileSpec &exec_fspec = module_spec.GetFileSpec();
240061da546Spatrick   const ArchSpec *arch = module_spec.GetArchitecturePtr();
241061da546Spatrick   const UUID *uuid = module_spec.GetUUIDPtr();
242be691f3bSpatrick   LLDB_SCOPED_TIMERF(
243be691f3bSpatrick       "LocateExecutableObjectFile (file = %s, arch = %s, uuid = %p)",
244061da546Spatrick       exec_fspec ? exec_fspec.GetFilename().AsCString("<NULL>") : "<NULL>",
245061da546Spatrick       arch ? arch->GetArchitectureName() : "<NULL>", (const void *)uuid);
246061da546Spatrick 
247061da546Spatrick   ModuleSpecList module_specs;
248061da546Spatrick   ModuleSpec matched_module_spec;
249061da546Spatrick   if (exec_fspec &&
250061da546Spatrick       ObjectFile::GetModuleSpecifications(exec_fspec, 0, 0, module_specs) &&
251061da546Spatrick       module_specs.FindMatchingModuleSpec(module_spec, matched_module_spec)) {
252061da546Spatrick     result.GetFileSpec() = exec_fspec;
253061da546Spatrick   } else {
254061da546Spatrick     LocateMacOSXFilesUsingDebugSymbols(module_spec, result);
255061da546Spatrick   }
256be691f3bSpatrick 
257061da546Spatrick   return result;
258061da546Spatrick }
259061da546Spatrick 
260061da546Spatrick // Keep "symbols.enable-external-lookup" description in sync with this function.
261061da546Spatrick 
262061da546Spatrick FileSpec
LocateExecutableSymbolFile(const ModuleSpec & module_spec,const FileSpecList & default_search_paths)263061da546Spatrick Symbols::LocateExecutableSymbolFile(const ModuleSpec &module_spec,
264061da546Spatrick                                     const FileSpecList &default_search_paths) {
265061da546Spatrick   FileSpec symbol_file_spec = module_spec.GetSymbolFileSpec();
266061da546Spatrick   if (symbol_file_spec.IsAbsolute() &&
267061da546Spatrick       FileSystem::Instance().Exists(symbol_file_spec))
268061da546Spatrick     return symbol_file_spec;
269061da546Spatrick 
270*f6aab3d8Srobert   Progress progress(llvm::formatv(
271*f6aab3d8Srobert       "Locating external symbol file for {0}",
272*f6aab3d8Srobert       module_spec.GetFileSpec().GetFilename().AsCString("<Unknown>")));
273*f6aab3d8Srobert 
274061da546Spatrick   FileSpecList debug_file_search_paths = default_search_paths;
275061da546Spatrick 
276061da546Spatrick   // Add module directory.
277061da546Spatrick   FileSpec module_file_spec = module_spec.GetFileSpec();
278061da546Spatrick   // We keep the unresolved pathname if it fails.
279061da546Spatrick   FileSystem::Instance().ResolveSymbolicLink(module_file_spec,
280061da546Spatrick                                              module_file_spec);
281061da546Spatrick 
282061da546Spatrick   ConstString file_dir = module_file_spec.GetDirectory();
283061da546Spatrick   {
284061da546Spatrick     FileSpec file_spec(file_dir.AsCString("."));
285061da546Spatrick     FileSystem::Instance().Resolve(file_spec);
286061da546Spatrick     debug_file_search_paths.AppendIfUnique(file_spec);
287061da546Spatrick   }
288061da546Spatrick 
289061da546Spatrick   if (ModuleList::GetGlobalModuleListProperties().GetEnableExternalLookup()) {
290061da546Spatrick 
291061da546Spatrick     // Add current working directory.
292061da546Spatrick     {
293061da546Spatrick       FileSpec file_spec(".");
294061da546Spatrick       FileSystem::Instance().Resolve(file_spec);
295061da546Spatrick       debug_file_search_paths.AppendIfUnique(file_spec);
296061da546Spatrick     }
297061da546Spatrick 
298061da546Spatrick #ifndef _WIN32
299061da546Spatrick #if defined(__NetBSD__)
300061da546Spatrick     // Add /usr/libdata/debug directory.
301061da546Spatrick     {
302061da546Spatrick       FileSpec file_spec("/usr/libdata/debug");
303061da546Spatrick       FileSystem::Instance().Resolve(file_spec);
304061da546Spatrick       debug_file_search_paths.AppendIfUnique(file_spec);
305061da546Spatrick     }
306061da546Spatrick #else
307061da546Spatrick     // Add /usr/lib/debug directory.
308061da546Spatrick     {
309061da546Spatrick       FileSpec file_spec("/usr/lib/debug");
310061da546Spatrick       FileSystem::Instance().Resolve(file_spec);
311061da546Spatrick       debug_file_search_paths.AppendIfUnique(file_spec);
312061da546Spatrick     }
313061da546Spatrick #endif
314061da546Spatrick #endif // _WIN32
315061da546Spatrick   }
316061da546Spatrick 
317061da546Spatrick   std::string uuid_str;
318061da546Spatrick   const UUID &module_uuid = module_spec.GetUUID();
319061da546Spatrick   if (module_uuid.IsValid()) {
320061da546Spatrick     // Some debug files are stored in the .build-id directory like this:
321061da546Spatrick     //   /usr/lib/debug/.build-id/ff/e7fe727889ad82bb153de2ad065b2189693315.debug
322061da546Spatrick     uuid_str = module_uuid.GetAsString("");
323061da546Spatrick     std::transform(uuid_str.begin(), uuid_str.end(), uuid_str.begin(),
324061da546Spatrick                    ::tolower);
325061da546Spatrick     uuid_str.insert(2, 1, '/');
326061da546Spatrick     uuid_str = uuid_str + ".debug";
327061da546Spatrick   }
328061da546Spatrick 
329061da546Spatrick   size_t num_directories = debug_file_search_paths.GetSize();
330061da546Spatrick   for (size_t idx = 0; idx < num_directories; ++idx) {
331061da546Spatrick     FileSpec dirspec = debug_file_search_paths.GetFileSpecAtIndex(idx);
332061da546Spatrick     FileSystem::Instance().Resolve(dirspec);
333061da546Spatrick     if (!FileSystem::Instance().IsDirectory(dirspec))
334061da546Spatrick       continue;
335061da546Spatrick 
336061da546Spatrick     std::vector<std::string> files;
337061da546Spatrick     std::string dirname = dirspec.GetPath();
338061da546Spatrick 
339061da546Spatrick     if (!uuid_str.empty())
340061da546Spatrick       files.push_back(dirname + "/.build-id/" + uuid_str);
341061da546Spatrick     if (symbol_file_spec.GetFilename()) {
342061da546Spatrick       files.push_back(dirname + "/" +
343061da546Spatrick                       symbol_file_spec.GetFilename().GetCString());
344061da546Spatrick       files.push_back(dirname + "/.debug/" +
345061da546Spatrick                       symbol_file_spec.GetFilename().GetCString());
346061da546Spatrick 
347061da546Spatrick       // Some debug files may stored in the module directory like this:
348061da546Spatrick       //   /usr/lib/debug/usr/lib/library.so.debug
349061da546Spatrick       if (!file_dir.IsEmpty())
350061da546Spatrick         files.push_back(dirname + file_dir.AsCString() + "/" +
351061da546Spatrick                         symbol_file_spec.GetFilename().GetCString());
352061da546Spatrick     }
353061da546Spatrick 
354061da546Spatrick     const uint32_t num_files = files.size();
355061da546Spatrick     for (size_t idx_file = 0; idx_file < num_files; ++idx_file) {
356061da546Spatrick       const std::string &filename = files[idx_file];
357061da546Spatrick       FileSpec file_spec(filename);
358061da546Spatrick       FileSystem::Instance().Resolve(file_spec);
359061da546Spatrick 
360061da546Spatrick       if (llvm::sys::fs::equivalent(file_spec.GetPath(),
361061da546Spatrick                                     module_file_spec.GetPath()))
362061da546Spatrick         continue;
363061da546Spatrick 
364061da546Spatrick       if (FileSystem::Instance().Exists(file_spec)) {
365061da546Spatrick         lldb_private::ModuleSpecList specs;
366061da546Spatrick         const size_t num_specs =
367061da546Spatrick             ObjectFile::GetModuleSpecifications(file_spec, 0, 0, specs);
368*f6aab3d8Srobert         ModuleSpec mspec;
369*f6aab3d8Srobert         bool valid_mspec = false;
370*f6aab3d8Srobert         if (num_specs == 2) {
371*f6aab3d8Srobert           // Special case to handle both i386 and i686 from ObjectFilePECOFF
372*f6aab3d8Srobert           ModuleSpec mspec2;
373*f6aab3d8Srobert           if (specs.GetModuleSpecAtIndex(0, mspec) &&
374*f6aab3d8Srobert               specs.GetModuleSpecAtIndex(1, mspec2) &&
375*f6aab3d8Srobert               mspec.GetArchitecture().GetTriple().isCompatibleWith(
376*f6aab3d8Srobert                   mspec2.GetArchitecture().GetTriple())) {
377*f6aab3d8Srobert             valid_mspec = true;
378*f6aab3d8Srobert           }
379*f6aab3d8Srobert         }
380*f6aab3d8Srobert         if (!valid_mspec) {
381061da546Spatrick           assert(num_specs <= 1 &&
382061da546Spatrick                  "Symbol Vendor supports only a single architecture");
383061da546Spatrick           if (num_specs == 1) {
384061da546Spatrick             if (specs.GetModuleSpecAtIndex(0, mspec)) {
385*f6aab3d8Srobert               valid_mspec = true;
386*f6aab3d8Srobert             }
387*f6aab3d8Srobert           }
388*f6aab3d8Srobert         }
389*f6aab3d8Srobert         if (valid_mspec) {
390061da546Spatrick           // Skip the uuids check if module_uuid is invalid. For example,
391061da546Spatrick           // this happens for *.dwp files since at the moment llvm-dwp
392061da546Spatrick           // doesn't output build ids, nor does binutils dwp.
393061da546Spatrick           if (!module_uuid.IsValid() || module_uuid == mspec.GetUUID())
394061da546Spatrick             return file_spec;
395061da546Spatrick         }
396061da546Spatrick       }
397061da546Spatrick     }
398061da546Spatrick   }
399061da546Spatrick 
400061da546Spatrick   return LocateExecutableSymbolFileDsym(module_spec);
401061da546Spatrick }
402061da546Spatrick 
DownloadSymbolFileAsync(const UUID & uuid)403*f6aab3d8Srobert void Symbols::DownloadSymbolFileAsync(const UUID &uuid) {
404*f6aab3d8Srobert   if (!ModuleList::GetGlobalModuleListProperties().GetEnableBackgroundLookup())
405*f6aab3d8Srobert     return;
406*f6aab3d8Srobert 
407*f6aab3d8Srobert   static llvm::SmallSet<UUID, 8> g_seen_uuids;
408*f6aab3d8Srobert   static std::mutex g_mutex;
409*f6aab3d8Srobert   Debugger::GetThreadPool().async([=]() {
410*f6aab3d8Srobert     {
411*f6aab3d8Srobert       std::lock_guard<std::mutex> guard(g_mutex);
412*f6aab3d8Srobert       if (g_seen_uuids.count(uuid))
413*f6aab3d8Srobert         return;
414*f6aab3d8Srobert       g_seen_uuids.insert(uuid);
415*f6aab3d8Srobert     }
416*f6aab3d8Srobert 
417*f6aab3d8Srobert     Status error;
418*f6aab3d8Srobert     ModuleSpec module_spec;
419*f6aab3d8Srobert     module_spec.GetUUID() = uuid;
420*f6aab3d8Srobert     if (!Symbols::DownloadObjectAndSymbolFile(module_spec, error,
421*f6aab3d8Srobert                                               /*force_lookup=*/true,
422*f6aab3d8Srobert                                               /*copy_executable=*/false))
423*f6aab3d8Srobert       return;
424*f6aab3d8Srobert 
425*f6aab3d8Srobert     if (error.Fail())
426*f6aab3d8Srobert       return;
427*f6aab3d8Srobert 
428*f6aab3d8Srobert     Debugger::ReportSymbolChange(module_spec);
429*f6aab3d8Srobert   });
430*f6aab3d8Srobert }
431*f6aab3d8Srobert 
432061da546Spatrick #if !defined(__APPLE__)
433061da546Spatrick 
FindSymbolFileInBundle(const FileSpec & symfile_bundle,const lldb_private::UUID * uuid,const ArchSpec * arch)434061da546Spatrick FileSpec Symbols::FindSymbolFileInBundle(const FileSpec &symfile_bundle,
435061da546Spatrick                                          const lldb_private::UUID *uuid,
436061da546Spatrick                                          const ArchSpec *arch) {
437061da546Spatrick   // FIXME
438061da546Spatrick   return FileSpec();
439061da546Spatrick }
440061da546Spatrick 
DownloadObjectAndSymbolFile(ModuleSpec & module_spec,Status & error,bool force_lookup,bool copy_executable)441061da546Spatrick bool Symbols::DownloadObjectAndSymbolFile(ModuleSpec &module_spec,
442*f6aab3d8Srobert                                           Status &error, bool force_lookup,
443*f6aab3d8Srobert                                           bool copy_executable) {
444061da546Spatrick   // Fill in the module_spec.GetFileSpec() for the object file and/or the
445061da546Spatrick   // module_spec.GetSymbolFileSpec() for the debug symbols file.
446061da546Spatrick   return false;
447061da546Spatrick }
448061da546Spatrick 
449061da546Spatrick #endif
450