xref: /freebsd/contrib/llvm-project/lldb/source/Symbol/SymbolLocator.cpp (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
15f757f3fSDimitry Andric //===-- symbolLocator.cpp -------------------------------------------------===//
25f757f3fSDimitry Andric //
35f757f3fSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45f757f3fSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
55f757f3fSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65f757f3fSDimitry Andric //
75f757f3fSDimitry Andric //===----------------------------------------------------------------------===//
85f757f3fSDimitry Andric 
95f757f3fSDimitry Andric #include "lldb/Symbol/SymbolLocator.h"
105f757f3fSDimitry Andric 
115f757f3fSDimitry Andric #include "lldb/Core/Debugger.h"
125f757f3fSDimitry Andric #include "lldb/Core/PluginManager.h"
13*0fca6ea1SDimitry Andric #include "lldb/Host/Host.h"
145f757f3fSDimitry Andric 
155f757f3fSDimitry Andric #include "llvm/ADT/SmallSet.h"
165f757f3fSDimitry Andric #include "llvm/Support/ThreadPool.h"
175f757f3fSDimitry Andric 
185f757f3fSDimitry Andric using namespace lldb;
195f757f3fSDimitry Andric using namespace lldb_private;
205f757f3fSDimitry Andric 
DownloadSymbolFileAsync(const UUID & uuid)215f757f3fSDimitry Andric void SymbolLocator::DownloadSymbolFileAsync(const UUID &uuid) {
225f757f3fSDimitry Andric   static llvm::SmallSet<UUID, 8> g_seen_uuids;
235f757f3fSDimitry Andric   static std::mutex g_mutex;
24*0fca6ea1SDimitry Andric 
25*0fca6ea1SDimitry Andric   auto lookup = [=]() {
265f757f3fSDimitry Andric     {
275f757f3fSDimitry Andric       std::lock_guard<std::mutex> guard(g_mutex);
285f757f3fSDimitry Andric       if (g_seen_uuids.count(uuid))
295f757f3fSDimitry Andric         return;
305f757f3fSDimitry Andric       g_seen_uuids.insert(uuid);
315f757f3fSDimitry Andric     }
325f757f3fSDimitry Andric 
335f757f3fSDimitry Andric     Status error;
345f757f3fSDimitry Andric     ModuleSpec module_spec;
355f757f3fSDimitry Andric     module_spec.GetUUID() = uuid;
365f757f3fSDimitry Andric     if (!PluginManager::DownloadObjectAndSymbolFile(module_spec, error,
375f757f3fSDimitry Andric                                                     /*force_lookup=*/true,
38*0fca6ea1SDimitry Andric                                                     /*copy_executable=*/true))
395f757f3fSDimitry Andric       return;
405f757f3fSDimitry Andric 
415f757f3fSDimitry Andric     if (error.Fail())
425f757f3fSDimitry Andric       return;
435f757f3fSDimitry Andric 
445f757f3fSDimitry Andric     Debugger::ReportSymbolChange(module_spec);
45*0fca6ea1SDimitry Andric   };
46*0fca6ea1SDimitry Andric 
47*0fca6ea1SDimitry Andric   switch (ModuleList::GetGlobalModuleListProperties().GetSymbolAutoDownload()) {
48*0fca6ea1SDimitry Andric   case eSymbolDownloadOff:
49*0fca6ea1SDimitry Andric     break;
50*0fca6ea1SDimitry Andric   case eSymbolDownloadBackground:
51*0fca6ea1SDimitry Andric     Debugger::GetThreadPool().async(lookup);
52*0fca6ea1SDimitry Andric     break;
53*0fca6ea1SDimitry Andric   case eSymbolDownloadForeground:
54*0fca6ea1SDimitry Andric     lookup();
55*0fca6ea1SDimitry Andric     break;
56*0fca6ea1SDimitry Andric   };
575f757f3fSDimitry Andric }
58