xref: /freebsd/contrib/llvm-project/lldb/source/Symbol/SymbolLocator.cpp (revision 5f757f3ff9144b609b3c433dfd370cc6bdc191ad)
1*5f757f3fSDimitry Andric //===-- symbolLocator.cpp -------------------------------------------------===//
2*5f757f3fSDimitry Andric //
3*5f757f3fSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*5f757f3fSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*5f757f3fSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*5f757f3fSDimitry Andric //
7*5f757f3fSDimitry Andric //===----------------------------------------------------------------------===//
8*5f757f3fSDimitry Andric 
9*5f757f3fSDimitry Andric #include "lldb/Symbol/SymbolLocator.h"
10*5f757f3fSDimitry Andric 
11*5f757f3fSDimitry Andric #include "lldb/Core/Debugger.h"
12*5f757f3fSDimitry Andric #include "lldb/Core/PluginManager.h"
13*5f757f3fSDimitry Andric 
14*5f757f3fSDimitry Andric #include "llvm/ADT/SmallSet.h"
15*5f757f3fSDimitry Andric #include "llvm/Support/ThreadPool.h"
16*5f757f3fSDimitry Andric 
17*5f757f3fSDimitry Andric using namespace lldb;
18*5f757f3fSDimitry Andric using namespace lldb_private;
19*5f757f3fSDimitry Andric 
20*5f757f3fSDimitry Andric void SymbolLocator::DownloadSymbolFileAsync(const UUID &uuid) {
21*5f757f3fSDimitry Andric   if (!ModuleList::GetGlobalModuleListProperties().GetEnableBackgroundLookup())
22*5f757f3fSDimitry Andric     return;
23*5f757f3fSDimitry Andric 
24*5f757f3fSDimitry Andric   static llvm::SmallSet<UUID, 8> g_seen_uuids;
25*5f757f3fSDimitry Andric   static std::mutex g_mutex;
26*5f757f3fSDimitry Andric   Debugger::GetThreadPool().async([=]() {
27*5f757f3fSDimitry Andric     {
28*5f757f3fSDimitry Andric       std::lock_guard<std::mutex> guard(g_mutex);
29*5f757f3fSDimitry Andric       if (g_seen_uuids.count(uuid))
30*5f757f3fSDimitry Andric         return;
31*5f757f3fSDimitry Andric       g_seen_uuids.insert(uuid);
32*5f757f3fSDimitry Andric     }
33*5f757f3fSDimitry Andric 
34*5f757f3fSDimitry Andric     Status error;
35*5f757f3fSDimitry Andric     ModuleSpec module_spec;
36*5f757f3fSDimitry Andric     module_spec.GetUUID() = uuid;
37*5f757f3fSDimitry Andric     if (!PluginManager::DownloadObjectAndSymbolFile(module_spec, error,
38*5f757f3fSDimitry Andric                                                     /*force_lookup=*/true,
39*5f757f3fSDimitry Andric                                                     /*copy_executable=*/false))
40*5f757f3fSDimitry Andric       return;
41*5f757f3fSDimitry Andric 
42*5f757f3fSDimitry Andric     if (error.Fail())
43*5f757f3fSDimitry Andric       return;
44*5f757f3fSDimitry Andric 
45*5f757f3fSDimitry Andric     Debugger::ReportSymbolChange(module_spec);
46*5f757f3fSDimitry Andric   });
47*5f757f3fSDimitry Andric }
48