LLDB mainline
ModuleList.cpp
Go to the documentation of this file.
1//===-- ModuleList.cpp ----------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10#include "lldb/Core/Debugger.h"
11#include "lldb/Core/Module.h"
24#include "lldb/Target/Target.h"
29#include "lldb/Utility/Log.h"
30#include "lldb/Utility/UUID.h"
31#include "lldb/lldb-defines.h"
32#include "llvm/Support/ThreadPool.h"
33
34#if defined(_WIN32)
36#endif
37
38#include "clang/Driver/Driver.h"
39#include "llvm/ADT/StringRef.h"
40#include "llvm/Support/FileSystem.h"
41#include "llvm/Support/Threading.h"
42#include "llvm/Support/raw_ostream.h"
43
44#include <chrono>
45#include <memory>
46#include <mutex>
47#include <string>
48#include <utility>
49
50namespace lldb_private {
51class Function;
52}
53namespace lldb_private {
55}
56namespace lldb_private {
57class Stream;
58}
59namespace lldb_private {
60class SymbolFile;
61}
62namespace lldb_private {
63class Target;
64}
65
66using namespace lldb;
67using namespace lldb_private;
68
69namespace {
70
71#define LLDB_PROPERTIES_modulelist
72#include "CoreProperties.inc"
73
74enum {
75#define LLDB_PROPERTIES_modulelist
76#include "CorePropertiesEnum.inc"
77};
78
79} // namespace
80
82 m_collection_sp = std::make_shared<OptionValueProperties>("symbols");
83 m_collection_sp->Initialize(g_modulelist_properties_def);
84 m_collection_sp->SetValueChangedCallback(ePropertySymLinkPaths,
85 [this] { UpdateSymlinkMappings(); });
86
87 llvm::SmallString<128> path;
88 if (clang::driver::Driver::getDefaultModuleCachePath(path)) {
90 }
91
92 path.clear();
93 if (llvm::sys::path::cache_directory(path)) {
94 llvm::sys::path::append(path, "lldb");
95 llvm::sys::path::append(path, "IndexCache");
97 }
98}
99
101 const uint32_t idx = ePropertyEnableExternalLookup;
103 idx, g_modulelist_properties[idx].default_uint_value != 0);
104}
105
107 return SetPropertyAtIndex(ePropertyEnableExternalLookup, new_value);
108}
109
111 // Backward compatibility alias.
112 if (GetPropertyAtIndexAs<bool>(ePropertyEnableBackgroundLookup, false))
114
115 const uint32_t idx = ePropertyAutoDownload;
117 idx, static_cast<lldb::SymbolDownload>(
118 g_modulelist_properties[idx].default_uint_value));
119}
120
122 const uint32_t idx = ePropertySharedCacheBinaryLoading;
124 idx, static_cast<lldb::SymbolSharedCacheUse>(
125 g_modulelist_properties[idx].default_uint_value));
126}
127
129 const uint32_t idx = ePropertyClangModulesCachePath;
130 return GetPropertyAtIndexAs<FileSpec>(idx, {});
131}
132
134 const uint32_t idx = ePropertyClangModulesCachePath;
135 return SetPropertyAtIndex(idx, path);
136}
137
139 const uint32_t idx = ePropertyLLDBIndexCachePath;
140 return GetPropertyAtIndexAs<FileSpec>(idx, {});
141}
142
144 const uint32_t idx = ePropertyLLDBIndexCachePath;
145 return SetPropertyAtIndex(idx, path);
146}
147
149 const uint32_t idx = ePropertyEnableLLDBIndexCache;
151 idx, g_modulelist_properties[idx].default_uint_value != 0);
152}
153
155 return SetPropertyAtIndex(ePropertyEnableLLDBIndexCache, new_value);
156}
157
159 const uint32_t idx = ePropertyLLDBIndexCacheMaxByteSize;
161 idx, g_modulelist_properties[idx].default_uint_value);
162}
163
165 const uint32_t idx = ePropertyLLDBIndexCacheMaxPercent;
167 idx, g_modulelist_properties[idx].default_uint_value);
168}
169
171 const uint32_t idx = ePropertyLLDBIndexCacheExpirationDays;
173 idx, g_modulelist_properties[idx].default_uint_value);
174}
175
177 FileSpecList list =
178 GetPropertyAtIndexAs<FileSpecList>(ePropertySymLinkPaths, {});
179 llvm::sys::ScopedWriter lock(m_symlink_paths_mutex);
180 const bool notify = false;
181 m_symlink_paths.Clear(notify);
182 for (auto symlink : list) {
183 FileSpec resolved;
184 Status status = FileSystem::Instance().Readlink(symlink, resolved);
185 if (status.Success())
186 m_symlink_paths.Append(symlink.GetPath(), resolved.GetPath(), notify);
187 }
188}
189
191 llvm::sys::ScopedReader lock(m_symlink_paths_mutex);
192 return m_symlink_paths;
193}
194
196 const uint32_t idx = ePropertyLoadSymbolOnDemand;
198 idx, g_modulelist_properties[idx].default_uint_value != 0);
199}
200
202
204 std::lock_guard<std::recursive_mutex> lhs_guard(m_modules_mutex);
205 std::lock_guard<std::recursive_mutex> rhs_guard(rhs.m_modules_mutex);
206 m_modules = rhs.m_modules;
207}
208
211
213 if (this != &rhs) {
214 std::lock(m_modules_mutex, rhs.m_modules_mutex);
215 std::lock_guard<std::recursive_mutex> lhs_guard(m_modules_mutex,
216 std::adopt_lock);
217 std::lock_guard<std::recursive_mutex> rhs_guard(rhs.m_modules_mutex,
218 std::adopt_lock);
219 m_modules = rhs.m_modules;
220 }
221 return *this;
222}
223
224ModuleList::~ModuleList() = default;
225
226void ModuleList::AppendImpl(const ModuleSP &module_sp, bool use_notifier) {
227 if (!module_sp)
228 return;
229 {
230 std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
231 // We are required to keep the first element of the Module List as the
232 // executable module. So check here and if the first module is NOT an
233 // but the new one is, we insert this module at the beginning, rather than
234 // at the end.
235 // We don't need to do any of this if the list is empty:
236 if (m_modules.empty()) {
237 m_modules.push_back(module_sp);
238 } else {
239 // Since producing the ObjectFile may take some work, first check the
240 // 0th element, and only if that's NOT an executable look at the
241 // incoming ObjectFile. That way in the normal case we only look at the
242 // element 0 ObjectFile.
243 const bool elem_zero_is_executable =
244 m_modules[0]->GetObjectFile()->GetType() ==
246 lldb_private::ObjectFile *obj = module_sp->GetObjectFile();
247 if (!elem_zero_is_executable && obj &&
249 m_modules.insert(m_modules.begin(), module_sp);
250 } else {
251 m_modules.push_back(module_sp);
252 }
253 }
254 }
255 // Release the mutex before calling the notifier to avoid deadlock
256 // NotifyModuleAdded should be thread-safe
257 if (use_notifier && m_notifier)
258 m_notifier->NotifyModuleAdded(*this, module_sp);
259}
260
261void ModuleList::Append(const ModuleSP &module_sp, bool notify) {
262 AppendImpl(module_sp, notify);
263}
264
266 const ModuleSP &module_sp,
268 if (module_sp) {
269 std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
270
271 // First remove any equivalent modules. Equivalent modules are modules
272 // whose path, platform path and architecture match.
273 ModuleSpec equivalent_module_spec(module_sp->GetFileSpec(),
274 module_sp->GetArchitecture());
275 equivalent_module_spec.GetPlatformFileSpec() =
276 module_sp->GetPlatformFileSpec();
277
278 size_t idx = 0;
279 while (idx < m_modules.size()) {
280 ModuleSP test_module_sp(m_modules[idx]);
281 if (test_module_sp->MatchesModuleSpec(equivalent_module_spec)) {
282 if (old_modules)
283 old_modules->push_back(test_module_sp);
284 RemoveImpl(m_modules.begin() + idx);
285 } else {
286 ++idx;
287 }
288 }
289 // Now add the new module to the list
290 Append(module_sp);
291 }
292}
293
294bool ModuleList::AppendIfNeeded(const ModuleSP &new_module, bool notify) {
295 if (new_module) {
296 std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
297 for (const ModuleSP &module_sp : m_modules) {
298 if (module_sp.get() == new_module.get())
299 return false; // Already in the list
300 }
301 // Only push module_sp on the list if it wasn't already in there.
302 Append(new_module, notify);
303 return true;
304 }
305 return false;
306}
307
308void ModuleList::Append(const ModuleList &module_list) {
309 for (auto pos : module_list.m_modules)
310 Append(pos);
311}
312
313bool ModuleList::AppendIfNeeded(const ModuleList &module_list) {
314 bool any_in = false;
315 for (auto pos : module_list.m_modules) {
316 if (AppendIfNeeded(pos))
317 any_in = true;
318 }
319 return any_in;
320}
321
322bool ModuleList::RemoveImpl(const ModuleSP &module_sp, bool use_notifier) {
323 if (module_sp) {
324 std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
325 collection::iterator pos, end = m_modules.end();
326 for (pos = m_modules.begin(); pos != end; ++pos) {
327 if (pos->get() == module_sp.get()) {
328 m_modules.erase(pos);
329 if (use_notifier && m_notifier)
330 m_notifier->NotifyModuleRemoved(*this, module_sp);
331 return true;
332 }
333 }
334 }
335 return false;
336}
337
338ModuleList::collection::iterator
339ModuleList::RemoveImpl(ModuleList::collection::iterator pos,
340 bool use_notifier) {
341 ModuleSP module_sp(*pos);
342 collection::iterator retval = m_modules.erase(pos);
343 if (use_notifier && m_notifier)
344 m_notifier->NotifyModuleRemoved(*this, module_sp);
345 return retval;
346}
347
348bool ModuleList::Remove(const ModuleSP &module_sp, bool notify) {
349 return RemoveImpl(module_sp, notify);
350}
351
353 const lldb::ModuleSP &new_module_sp) {
354 if (!RemoveImpl(old_module_sp, false))
355 return false;
356 AppendImpl(new_module_sp, false);
357 if (m_notifier)
358 m_notifier->NotifyModuleUpdated(*this, old_module_sp, new_module_sp);
359 return true;
360}
361
363 if (auto module_sp = module_wp.lock()) {
364 std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
365 collection::iterator pos, end = m_modules.end();
366 for (pos = m_modules.begin(); pos != end; ++pos) {
367 if (pos->get() == module_sp.get()) {
368 // Since module_sp increases the refcount by 1, the use count should be
369 // the regular use count + 1.
370 constexpr long kUseCountOrphaned = kUseCountModuleListOrphaned + 1;
371 if (pos->use_count() == kUseCountOrphaned) {
372 pos = RemoveImpl(pos);
373 return true;
374 }
375 return false;
376 }
377 }
378 }
379 return false;
380}
381
382size_t ModuleList::RemoveOrphans(bool mandatory) {
383 std::unique_lock<std::recursive_mutex> lock(m_modules_mutex, std::defer_lock);
384
385 if (mandatory) {
386 lock.lock();
387 } else {
388 // Not mandatory, remove orphans if we can get the mutex
389 if (!lock.try_lock())
390 return 0;
391 }
392 size_t remove_count = 0;
393 // Modules might hold shared pointers to other modules, so removing one
394 // module might make other modules orphans. Keep removing modules until
395 // there are no further modules that can be removed.
396 bool made_progress = true;
397 while (made_progress) {
398 // Keep track if we make progress this iteration.
399 made_progress = false;
400 collection::iterator pos = m_modules.begin();
401 while (pos != m_modules.end()) {
402 if (pos->use_count() == kUseCountModuleListOrphaned) {
403 pos = RemoveImpl(pos);
404 ++remove_count;
405 // We did make progress.
406 made_progress = true;
407 } else {
408 ++pos;
409 }
410 }
411 }
412 return remove_count;
413}
414
415size_t ModuleList::Remove(ModuleList &module_list) {
416 std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
417 size_t num_removed = 0;
418 collection::iterator pos, end = module_list.m_modules.end();
419 for (pos = module_list.m_modules.begin(); pos != end; ++pos) {
420 if (Remove(*pos, false /* notify */))
421 ++num_removed;
422 }
423 if (m_notifier)
424 m_notifier->NotifyModulesRemoved(module_list);
425 return num_removed;
426}
427
429
431
432void ModuleList::ClearImpl(bool use_notifier) {
433 std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
434 if (use_notifier && m_notifier)
435 m_notifier->NotifyWillClearList(*this);
436 m_modules.clear();
437}
438
440 std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
441 if (idx < m_modules.size())
442 return m_modules[idx].get();
443 return nullptr;
444}
445
447 std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
448 return GetModuleAtIndexUnlocked(idx);
449}
450
452 ModuleSP module_sp;
453 if (idx < m_modules.size())
454 module_sp = m_modules[idx];
455 return module_sp;
456}
457
459 FunctionNameType name_type_mask,
460 const ModuleFunctionSearchOptions &options,
461 SymbolContextList &sc_list) const {
462 if (name_type_mask & eFunctionNameTypeAuto) {
463 std::vector<Module::LookupInfo> lookup_infos =
464 Module::LookupInfo::MakeLookupInfos(name, name_type_mask,
466 std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
467 for (const auto &lookup_info : lookup_infos) {
468 const size_t old_size = sc_list.GetSize();
469 for (const ModuleSP &module_sp : m_modules) {
470 module_sp->FindFunctions(lookup_info, CompilerDeclContext(), options,
471 sc_list);
472 }
473
474 const size_t new_size = sc_list.GetSize();
475 if (old_size < new_size)
476 lookup_info.Prune(sc_list, old_size);
477 }
478 } else {
479 std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
480 for (const ModuleSP &module_sp : m_modules) {
481 module_sp->FindFunctions(name, CompilerDeclContext(), name_type_mask,
482 options, sc_list);
483 }
484 }
485}
486
488 lldb::FunctionNameType name_type_mask,
489 SymbolContextList &sc_list) {
490 if (name_type_mask & eFunctionNameTypeAuto) {
491 std::vector<Module::LookupInfo> lookup_infos =
492 Module::LookupInfo::MakeLookupInfos(name, name_type_mask,
494
495 std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
496 for (const auto &lookup_info : lookup_infos) {
497 const size_t old_size = sc_list.GetSize();
498 for (const ModuleSP &module_sp : m_modules) {
499 module_sp->FindFunctionSymbols(lookup_info.GetLookupName(),
500 lookup_info.GetNameTypeMask(), sc_list);
501 }
502
503 const size_t new_size = sc_list.GetSize();
504
505 if (old_size < new_size)
506 lookup_info.Prune(sc_list, old_size);
507 }
508 } else {
509 std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
510 for (const ModuleSP &module_sp : m_modules) {
511 module_sp->FindFunctionSymbols(name, name_type_mask, sc_list);
512 }
513 }
514}
515
517 const ModuleFunctionSearchOptions &options,
518 SymbolContextList &sc_list) {
519 std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
520 for (const ModuleSP &module_sp : m_modules)
521 module_sp->FindFunctions(name, options, sc_list);
522}
523
525 SymbolContextList &sc_list) const {
526 std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
527 for (const ModuleSP &module_sp : m_modules)
528 module_sp->FindCompileUnits(path, sc_list);
529}
530
531void ModuleList::FindGlobalVariables(ConstString name, size_t max_matches,
532 VariableList &variable_list) const {
533 std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
534 for (const ModuleSP &module_sp : m_modules) {
535 module_sp->FindGlobalVariables(name, CompilerDeclContext(), max_matches,
536 variable_list);
537 }
538}
539
541 size_t max_matches,
542 VariableList &variable_list) const {
543 std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
544 for (const ModuleSP &module_sp : m_modules)
545 module_sp->FindGlobalVariables(regex, max_matches, variable_list);
546}
547
549 SymbolType symbol_type,
550 SymbolContextList &sc_list) const {
551 std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
552 for (const ModuleSP &module_sp : m_modules)
553 module_sp->FindSymbolsWithNameAndType(name, symbol_type, sc_list);
554}
555
557 const RegularExpression &regex, lldb::SymbolType symbol_type,
558 SymbolContextList &sc_list) const {
559 std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
560 for (const ModuleSP &module_sp : m_modules)
561 module_sp->FindSymbolsMatchingRegExAndType(regex, symbol_type, sc_list);
562}
563
564void ModuleList::FindModules(const ModuleSpec &module_spec,
565 ModuleList &matching_module_list) const {
566 std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
567 for (const ModuleSP &module_sp : m_modules) {
568 if (module_sp->MatchesModuleSpec(module_spec))
569 matching_module_list.Append(module_sp);
570 }
571}
572
573ModuleSP ModuleList::FindModule(const Module *module_ptr) const {
574 ModuleSP module_sp;
575
576 // Scope for "locker"
577 {
578 std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
579 collection::const_iterator pos, end = m_modules.end();
580
581 for (pos = m_modules.begin(); pos != end; ++pos) {
582 if ((*pos).get() == module_ptr) {
583 module_sp = (*pos);
584 break;
585 }
586 }
587 }
588 return module_sp;
589}
590
592 ModuleSP module_sp;
593
594 if (uuid.IsValid()) {
595 std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
596 collection::const_iterator pos, end = m_modules.end();
597
598 for (pos = m_modules.begin(); pos != end; ++pos) {
599 if ((*pos)->GetUUID() == uuid) {
600 module_sp = (*pos);
601 break;
602 }
603 }
604 }
605 return module_sp;
606}
607
609 ModuleSP module_sp;
610 ForEach([&](const ModuleSP &m) {
611 if (m->GetID() == uid) {
612 module_sp = m;
614 }
615
617 });
618
619 return module_sp;
620}
621
622void ModuleList::FindTypes(Module *search_first, const TypeQuery &query,
623 TypeResults &results) const {
624 std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
625 if (search_first) {
626 search_first->FindTypes(query, results);
627 if (results.Done(query))
628 return;
629 }
630 for (const auto &module_sp : m_modules) {
631 if (search_first != module_sp.get()) {
632 module_sp->FindTypes(query, results);
633 if (results.Done(query))
634 return;
635 }
636 }
637}
638
640 FileSpec &new_spec) const {
641 std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
642 for (const ModuleSP &module_sp : m_modules) {
643 if (module_sp->FindSourceFile(orig_spec, new_spec))
644 return true;
645 }
646 return false;
647}
648
650 const FileSpec &file, uint32_t line,
651 Function *function,
652 std::vector<Address> &output_local,
653 std::vector<Address> &output_extern) {
654 std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
655 for (const ModuleSP &module_sp : m_modules) {
656 module_sp->FindAddressesForLine(target_sp, file, line, function,
657 output_local, output_extern);
658 }
659}
660
662 ModuleSP module_sp;
663 std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
664 collection::const_iterator pos, end = m_modules.end();
665 for (pos = m_modules.begin(); pos != end; ++pos) {
666 ModuleSP module_sp(*pos);
667 if (module_sp->MatchesModuleSpec(module_spec))
668 return module_sp;
669 }
670 return module_sp;
671}
672
673size_t ModuleList::GetSize() const {
674 size_t size = 0;
675 {
676 std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
677 size = m_modules.size();
678 }
679 return size;
680}
681
682void ModuleList::Dump(Stream *s) const {
683 std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
684 for (const ModuleSP &module_sp : m_modules)
685 module_sp->Dump(s);
686}
687
688void ModuleList::LogUUIDAndPaths(Log *log, const char *prefix_cstr) {
689 if (log != nullptr) {
690 std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
691 collection::const_iterator pos, begin = m_modules.begin(),
692 end = m_modules.end();
693 for (pos = begin; pos != end; ++pos) {
694 Module *module = pos->get();
695 const FileSpec &module_file_spec = module->GetFileSpec();
696 LLDB_LOGF(log, "%s[%u] %s (%s) \"%s\"", prefix_cstr ? prefix_cstr : "",
697 (uint32_t)std::distance(begin, pos),
698 module->GetUUID().GetAsString().c_str(),
700 module_file_spec.GetPath().c_str());
701 }
702 }
703}
704
706 Address &so_addr) const {
707 std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
708 for (const ModuleSP &module_sp : m_modules) {
709 if (module_sp->ResolveFileAddress(vm_addr, so_addr))
710 return true;
711 }
712
713 return false;
714}
715
716uint32_t
718 SymbolContextItem resolve_scope,
719 SymbolContext &sc) const {
720 // The address is already section offset so it has a module
721 uint32_t resolved_flags = 0;
722 ModuleSP module_sp(so_addr.GetModule());
723 if (module_sp) {
724 resolved_flags =
725 module_sp->ResolveSymbolContextForAddress(so_addr, resolve_scope, sc);
726 } else {
727 std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
728 collection::const_iterator pos, end = m_modules.end();
729 for (pos = m_modules.begin(); pos != end; ++pos) {
730 resolved_flags =
731 (*pos)->ResolveSymbolContextForAddress(so_addr, resolve_scope, sc);
732 if (resolved_flags != 0)
733 break;
734 }
735 }
736
737 return resolved_flags;
738}
739
741 const char *file_path, uint32_t line, bool check_inlines,
742 SymbolContextItem resolve_scope, SymbolContextList &sc_list) const {
743 FileSpec file_spec(file_path);
744 return ResolveSymbolContextsForFileSpec(file_spec, line, check_inlines,
745 resolve_scope, sc_list);
746}
747
749 const FileSpec &file_spec, uint32_t line, bool check_inlines,
750 SymbolContextItem resolve_scope, SymbolContextList &sc_list) const {
751 std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
752 for (const ModuleSP &module_sp : m_modules) {
753 module_sp->ResolveSymbolContextsForFileSpec(file_spec, line, check_inlines,
754 resolve_scope, sc_list);
755 }
756
757 return sc_list.GetSize();
758}
759
760size_t ModuleList::GetIndexForModule(const Module *module) const {
761 if (module) {
762 std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
763 collection::const_iterator pos;
764 collection::const_iterator begin = m_modules.begin();
765 collection::const_iterator end = m_modules.end();
766 for (pos = begin; pos != end; ++pos) {
767 if ((*pos).get() == module)
768 return std::distance(begin, pos);
769 }
770 }
772}
773
774namespace {
775/// A wrapper around ModuleList for shared modules. Provides fast lookups for
776/// file-based ModuleSpec queries.
777class SharedModuleList {
778public:
779 /// Finds all the modules matching the module_spec, and adds them to \p
780 /// matching_module_list.
781 void FindModules(const ModuleSpec &module_spec,
782 ModuleList &matching_module_list) const {
783 std::lock_guard<std::recursive_mutex> guard(GetMutex());
784 // Try map first for performance - if found, skip expensive full list
785 // search.
786 FindModulesInMap(module_spec, matching_module_list);
787 if (!matching_module_list.IsEmpty())
788 return;
789 m_list.FindModules(module_spec, matching_module_list);
790 // Assert that modules were found in the list but not the map, it's
791 // because the module_spec has no filename or the found module has a
792 // different filename. For example, when searching by UUID and finding a
793 // module with an alias.
794 assert((matching_module_list.IsEmpty() ||
795 module_spec.GetFileSpec().GetFilename().IsEmpty() ||
796 module_spec.GetFileSpec().GetFilename() !=
797 matching_module_list.GetModuleAtIndex(0)
798 ->GetFileSpec()
799 .GetFilename()) &&
800 "Search by name not found in SharedModuleList's map");
801 }
802
803 ModuleSP FindModule(const Module &module) {
804
805 std::lock_guard<std::recursive_mutex> guard(GetMutex());
806 if (ModuleSP result = FindModuleInMap(module))
807 return result;
808 return m_list.FindModule(&module);
809 }
810
811 // UUID searches bypass map since UUIDs aren't indexed by filename.
812 ModuleSP FindModule(const UUID &uuid) const {
813 return m_list.FindModule(uuid);
814 }
815
816 void Append(const ModuleSP &module_sp, bool use_notifier) {
817 if (!module_sp)
818 return;
819 std::lock_guard<std::recursive_mutex> guard(GetMutex());
820 m_list.Append(module_sp, use_notifier);
821 AddToMap(module_sp);
822 }
823
824 size_t RemoveOrphans(bool mandatory) {
825 std::unique_lock<std::recursive_mutex> lock(GetMutex(), std::defer_lock);
826 if (mandatory) {
827 lock.lock();
828 } else {
829 if (!lock.try_lock())
830 return 0;
831 }
832 size_t total_count = 0;
833 size_t run_count;
834 do {
835 // Remove indexed orphans first, then remove non-indexed orphans. This
836 // order is important because the shared count will be different if a
837 // module is indexed or not.
838 run_count = RemoveOrphansFromMapAndList();
839 run_count += m_list.RemoveOrphans(mandatory);
840 total_count += run_count;
841 // Because removing orphans might make new orphans, remove from both
842 // containers until a fixed-point is reached.
843 } while (run_count != 0);
844
845 return total_count;
846 }
847
848 bool Remove(const ModuleSP &module_sp, bool use_notifier = true) {
849 if (!module_sp)
850 return false;
851 std::lock_guard<std::recursive_mutex> guard(GetMutex());
852 RemoveFromMap(module_sp);
853 return m_list.Remove(module_sp, use_notifier);
854 }
855
856 void ReplaceEquivalent(const ModuleSP &module_sp,
857 llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules) {
858 std::lock_guard<std::recursive_mutex> guard(GetMutex());
859 m_list.ReplaceEquivalent(module_sp, old_modules);
860 ReplaceEquivalentInMap(module_sp);
861 }
862
863 bool RemoveIfOrphaned(const ModuleWP module_wp) {
864 std::lock_guard<std::recursive_mutex> guard(GetMutex());
865 RemoveFromMap(module_wp, /*if_orphaned=*/true);
866 return m_list.RemoveIfOrphaned(module_wp);
867 }
868
869 std::recursive_mutex &GetMutex() const { return m_list.GetMutex(); }
870
871private:
872 ModuleSP FindModuleInMap(const Module &module) const {
873 if (!module.GetFileSpec().GetFilename())
874 return ModuleSP();
875 ConstString name = module.GetFileSpec().GetFilename();
876 auto it = m_name_to_modules.find(name);
877 if (it == m_name_to_modules.end())
878 return ModuleSP();
879 const llvm::SmallVectorImpl<ModuleSP> &vector = it->second;
880 for (const ModuleSP &module_sp : vector) {
881 if (module_sp.get() == &module)
882 return module_sp;
883 }
884 return ModuleSP();
885 }
886
887 void FindModulesInMap(const ModuleSpec &module_spec,
888 ModuleList &matching_module_list) const {
889 auto it = m_name_to_modules.find(module_spec.GetFileSpec().GetFilename());
890 if (it == m_name_to_modules.end())
891 return;
892 const llvm::SmallVectorImpl<ModuleSP> &vector = it->second;
893 for (const ModuleSP &module_sp : vector) {
894 if (module_sp->MatchesModuleSpec(module_spec))
895 matching_module_list.Append(module_sp);
896 }
897 }
898
899 void AddToMap(const ModuleSP &module_sp) {
900 ConstString name = module_sp->GetFileSpec().GetFilename();
901 if (name.IsEmpty())
902 return;
903 m_name_to_modules[name].push_back(module_sp);
904 }
905
906 void RemoveFromMap(const ModuleWP module_wp, bool if_orphaned = false) {
907 if (auto module_sp = module_wp.lock()) {
908 ConstString name = module_sp->GetFileSpec().GetFilename();
909 if (!m_name_to_modules.contains(name))
910 return;
911 llvm::SmallVectorImpl<ModuleSP> &vec = m_name_to_modules[name];
912 for (auto *it = vec.begin(); it != vec.end(); ++it) {
913 if (it->get() == module_sp.get()) {
914 // Since module_sp increases the refcount by 1, the use count should
915 // be the regular use count + 1.
916 constexpr long kUseCountOrphaned =
917 kUseCountSharedModuleListOrphaned + 1;
918 if (!if_orphaned || it->use_count() == kUseCountOrphaned) {
919 vec.erase(it);
920 break;
921 }
922 }
923 }
924 }
925 }
926
927 void ReplaceEquivalentInMap(const ModuleSP &module_sp) {
928 RemoveEquivalentModulesFromMap(module_sp);
929 AddToMap(module_sp);
930 }
931
932 void RemoveEquivalentModulesFromMap(const ModuleSP &module_sp) {
933 ConstString name = module_sp->GetFileSpec().GetFilename();
934 if (name.IsEmpty())
935 return;
936
937 auto it = m_name_to_modules.find(name);
938 if (it == m_name_to_modules.end())
939 return;
940
941 // First remove any equivalent modules. Equivalent modules are modules
942 // whose path, platform path and architecture match.
943 ModuleSpec equivalent_module_spec(module_sp->GetFileSpec(),
944 module_sp->GetArchitecture());
945 equivalent_module_spec.GetPlatformFileSpec() =
946 module_sp->GetPlatformFileSpec();
947
948 llvm::SmallVectorImpl<ModuleSP> &vec = it->second;
949 llvm::erase_if(vec, [&equivalent_module_spec](ModuleSP &element) {
950 return element->MatchesModuleSpec(equivalent_module_spec);
951 });
952 }
953
954 /// Remove orphans from the vector and return the removed modules.
955 ModuleList RemoveOrphansFromVector(llvm::SmallVectorImpl<ModuleSP> &vec) {
956 // remove_if moves the elements that match the condition to the end of the
957 // container, and returns an iterator to the first element that was moved.
958 auto *to_remove_start = llvm::remove_if(vec, [](const ModuleSP &module) {
959 return module.use_count() == kUseCountSharedModuleListOrphaned;
960 });
961
962 ModuleList to_remove;
963 for (ModuleSP *it = to_remove_start; it != vec.end(); ++it)
964 to_remove.Append(*it);
965
966 vec.erase(to_remove_start, vec.end());
967 return to_remove;
968 }
969
970 /// Remove orphans that exist in both the map and list. This does not remove
971 /// any orphans that exist exclusively on the list.
972 ///
973 /// The mutex must be locked by the caller.
974 int RemoveOrphansFromMapAndList() {
975 // Modules might hold shared pointers to other modules, so removing one
976 // module might orphan other modules. Keep removing modules until
977 // there are no further modules that can be removed.
978 int remove_count = 0;
979 int previous_remove_count;
980 do {
981 previous_remove_count = remove_count;
982 for (auto &[name, vec] : m_name_to_modules) {
983 if (vec.empty())
984 continue;
985 ModuleList to_remove = RemoveOrphansFromVector(vec);
986 remove_count += to_remove.GetSize();
987 m_list.Remove(to_remove);
988 }
989 // Break when fixed-point is reached.
990 } while (previous_remove_count != remove_count);
991
992 return remove_count;
993 }
994
995 ModuleList m_list;
996
997 /// A hash map from a module's filename to all the modules that share that
998 /// filename, for fast module lookups by name.
999 llvm::DenseMap<ConstString, llvm::SmallVector<ModuleSP, 1>> m_name_to_modules;
1000
1001 /// The use count of a module held only by m_list and m_name_to_modules.
1002 static constexpr long kUseCountSharedModuleListOrphaned = 2;
1003};
1004
1005struct SharedModuleListInfo {
1006 SharedModuleList module_list;
1007 ModuleListProperties module_list_properties;
1008};
1009}
1010static SharedModuleListInfo &GetSharedModuleListInfo()
1011{
1012 static SharedModuleListInfo *g_shared_module_list_info = nullptr;
1013 static llvm::once_flag g_once_flag;
1014 llvm::call_once(g_once_flag, []() {
1015 // NOTE: Intentionally leak the module list so a program doesn't have to
1016 // cleanup all modules and object files as it exits. This just wastes time
1017 // doing a bunch of cleanup that isn't required.
1018 if (g_shared_module_list_info == nullptr)
1019 g_shared_module_list_info = new SharedModuleListInfo();
1020 });
1021 return *g_shared_module_list_info;
1022}
1023
1024static SharedModuleList &GetSharedModuleList() {
1025 return GetSharedModuleListInfo().module_list;
1026}
1027
1031
1032bool ModuleList::ModuleIsInCache(const Module *module_ptr) {
1033 if (module_ptr) {
1034 SharedModuleList &shared_module_list = GetSharedModuleList();
1035 return shared_module_list.FindModule(*module_ptr).get() != nullptr;
1036 }
1037 return false;
1038}
1039
1041 ModuleList &matching_module_list) {
1042 GetSharedModuleList().FindModules(module_spec, matching_module_list);
1043}
1044
1046 return GetSharedModuleList().FindModule(uuid);
1047}
1048
1050 return GetSharedModuleList().RemoveOrphans(mandatory);
1051}
1052
1053Status
1054ModuleList::GetSharedModule(const ModuleSpec &module_spec, ModuleSP &module_sp,
1056 bool *did_create_ptr, bool invoke_locate_callback) {
1057 SharedModuleList &shared_module_list = GetSharedModuleList();
1058 std::lock_guard<std::recursive_mutex> guard(shared_module_list.GetMutex());
1059 char path[PATH_MAX];
1060
1061 Status error;
1062
1063 module_sp.reset();
1064
1065 if (did_create_ptr)
1066 *did_create_ptr = false;
1067
1068 const UUID *uuid_ptr = module_spec.GetUUIDPtr();
1069 const FileSpec &module_file_spec = module_spec.GetFileSpec();
1070 const ArchSpec &arch = module_spec.GetArchitecture();
1071
1072 // Make sure no one else can try and get or create a module while this
1073 // function is actively working on it by doing an extra lock on the global
1074 // mutex list.
1075 {
1076 ModuleList matching_module_list;
1077 shared_module_list.FindModules(module_spec, matching_module_list);
1078 const size_t num_matching_modules = matching_module_list.GetSize();
1079
1080 if (num_matching_modules > 0) {
1081 for (size_t module_idx = 0; module_idx < num_matching_modules;
1082 ++module_idx) {
1083 module_sp = matching_module_list.GetModuleAtIndex(module_idx);
1084
1085 // Make sure the file for the module hasn't been modified
1086 if (module_sp->FileHasChanged()) {
1087 if (old_modules)
1088 old_modules->push_back(module_sp);
1089
1090 Log *log = GetLog(LLDBLog::Modules);
1091 if (log != nullptr)
1092 LLDB_LOGF(
1093 log, "%p '%s' module changed: removing from global module list",
1094 static_cast<void *>(module_sp.get()),
1095 module_sp->GetFileSpec().GetFilename().GetCString());
1096
1097 shared_module_list.Remove(module_sp);
1098 module_sp.reset();
1099 } else {
1100 // The module matches and the module was not modified from when it
1101 // was last loaded.
1102 return error;
1103 }
1104 }
1105 }
1106 }
1107
1108 if (module_sp)
1109 return error;
1110
1111 // Try platform's locate module callback before second attempt.
1112 // The platform can come from either the Target (if available) or directly
1113 // from the ModuleSpec (useful when Target is not yet created, e.g., during
1114 // target creation for launch mode).
1115 if (invoke_locate_callback) {
1116 PlatformSP platform_sp;
1117 if (TargetSP target_sp = module_spec.GetTargetSP()) {
1118 if (target_sp->IsValid())
1119 platform_sp = target_sp->GetPlatform();
1120 }
1121 if (!platform_sp)
1122 platform_sp = module_spec.GetPlatformSP();
1123
1124 if (platform_sp) {
1125 FileSpec symbol_file_spec;
1126 platform_sp->CallLocateModuleCallbackIfSet(
1127 module_spec, module_sp, symbol_file_spec, did_create_ptr);
1128 if (module_sp) {
1129 // The callback found a module.
1130 return error;
1131 }
1132 }
1133 }
1134
1135 module_sp = std::make_shared<Module>(module_spec);
1136 // Make sure there are a module and an object file since we can specify a
1137 // valid file path with an architecture that might not be in that file. By
1138 // getting the object file we can guarantee that the architecture matches
1139 if (module_sp->GetObjectFile()) {
1140 // If we get in here we got the correct arch, now we just need to verify
1141 // the UUID if one was given
1142 if (uuid_ptr && *uuid_ptr != module_sp->GetUUID()) {
1143 module_sp.reset();
1144 } else {
1145 if (module_sp->GetObjectFile() &&
1146 module_sp->GetObjectFile()->GetType() ==
1148 module_sp.reset();
1149 } else {
1150 if (did_create_ptr) {
1151 *did_create_ptr = true;
1152 }
1153
1154 shared_module_list.ReplaceEquivalent(module_sp, old_modules);
1155 return error;
1156 }
1157 }
1158 } else {
1159 module_sp.reset();
1160 }
1161
1162 // Get module search paths from the target if available.
1163 lldb::TargetSP target_sp = module_spec.GetTargetSP();
1164 FileSpecList module_search_paths;
1165 if (target_sp)
1166 module_search_paths = target_sp->GetExecutableSearchPaths();
1167
1168 if (!module_search_paths.IsEmpty()) {
1169 const auto num_directories = module_search_paths.GetSize();
1170 for (size_t idx = 0; idx < num_directories; ++idx) {
1171 auto search_path_spec = module_search_paths.GetFileSpecAtIndex(idx);
1172 FileSystem::Instance().Resolve(search_path_spec);
1173 namespace fs = llvm::sys::fs;
1174 if (!FileSystem::Instance().IsDirectory(search_path_spec))
1175 continue;
1176 search_path_spec.AppendPathComponent(
1177 module_spec.GetFileSpec().GetFilename().GetStringRef());
1178 if (!FileSystem::Instance().Exists(search_path_spec))
1179 continue;
1180
1181 auto resolved_module_spec(module_spec);
1182 resolved_module_spec.GetFileSpec() = search_path_spec;
1183 module_sp = std::make_shared<Module>(resolved_module_spec);
1184 if (module_sp->GetObjectFile()) {
1185 // If we get in here we got the correct arch, now we just need to
1186 // verify the UUID if one was given
1187 if (uuid_ptr && *uuid_ptr != module_sp->GetUUID()) {
1188 module_sp.reset();
1189 } else {
1190 if (module_sp->GetObjectFile()->GetType() ==
1192 module_sp.reset();
1193 } else {
1194 if (did_create_ptr)
1195 *did_create_ptr = true;
1196
1197 shared_module_list.ReplaceEquivalent(module_sp, old_modules);
1198 return Status();
1199 }
1200 }
1201 } else {
1202 module_sp.reset();
1203 }
1204 }
1205 }
1206
1207 // Either the file didn't exist where at the path, or no path was given, so
1208 // we now have to use more extreme measures to try and find the appropriate
1209 // module.
1210
1211 // Fixup the incoming path in case the path points to a valid file, yet the
1212 // arch or UUID (if one was passed in) don't match.
1213 ModuleSpec located_binary_modulespec;
1214 StatisticsMap symbol_locator_map;
1215 located_binary_modulespec = PluginManager::LocateExecutableObjectFile(
1216 module_spec, symbol_locator_map);
1217 // Don't look for the file if it appears to be the same one we already
1218 // checked for above...
1219 if (located_binary_modulespec.GetFileSpec() != module_file_spec) {
1220 if (!FileSystem::Instance().Exists(
1221 located_binary_modulespec.GetFileSpec())) {
1222 located_binary_modulespec.GetFileSpec().GetPath(path, sizeof(path));
1223 if (path[0] == '\0')
1224 module_file_spec.GetPath(path, sizeof(path));
1225 // How can this check ever be true? This branch it is false, and we
1226 // haven't modified file_spec.
1227 if (FileSystem::Instance().Exists(
1228 located_binary_modulespec.GetFileSpec())) {
1229 std::string uuid_str;
1230 if (uuid_ptr && uuid_ptr->IsValid())
1231 uuid_str = uuid_ptr->GetAsString();
1232
1233 if (arch.IsValid()) {
1234 if (!uuid_str.empty())
1236 "'%s' does not contain the %s architecture and UUID %s", path,
1237 arch.GetArchitectureName(), uuid_str.c_str());
1238 else
1240 "'%s' does not contain the %s architecture.", path,
1241 arch.GetArchitectureName());
1242 }
1243 } else {
1244 error = Status::FromErrorStringWithFormat("'%s' does not exist", path);
1245 }
1246 if (error.Fail())
1247 module_sp.reset();
1248 return error;
1249 }
1250
1251 // Make sure no one else can try and get or create a module while this
1252 // function is actively working on it by doing an extra lock on the global
1253 // mutex list.
1254 ModuleSpec platform_module_spec(module_spec);
1255 platform_module_spec.GetFileSpec() =
1256 located_binary_modulespec.GetFileSpec();
1257 platform_module_spec.GetPlatformFileSpec() =
1258 located_binary_modulespec.GetFileSpec();
1259 platform_module_spec.GetSymbolFileSpec() =
1260 located_binary_modulespec.GetSymbolFileSpec();
1261 ModuleList matching_module_list;
1262 shared_module_list.FindModules(platform_module_spec, matching_module_list);
1263 if (!matching_module_list.IsEmpty()) {
1264 module_sp = matching_module_list.GetModuleAtIndex(0);
1265
1266 // If we didn't have a UUID in mind when looking for the object file,
1267 // then we should make sure the modification time hasn't changed!
1268 if (platform_module_spec.GetUUIDPtr() == nullptr) {
1269 auto file_spec_mod_time = FileSystem::Instance().GetModificationTime(
1270 located_binary_modulespec.GetFileSpec());
1271 if (file_spec_mod_time != llvm::sys::TimePoint<>()) {
1272 if (file_spec_mod_time != module_sp->GetModificationTime()) {
1273 if (old_modules)
1274 old_modules->push_back(module_sp);
1275 shared_module_list.Remove(module_sp);
1276 module_sp.reset();
1277 }
1278 }
1279 }
1280 }
1281
1282 if (!module_sp) {
1283 module_sp = std::make_shared<Module>(platform_module_spec);
1284 // Make sure there are a module and an object file since we can specify a
1285 // valid file path with an architecture that might not be in that file.
1286 // By getting the object file we can guarantee that the architecture
1287 // matches
1288 if (module_sp && module_sp->GetObjectFile()) {
1289 module_sp->GetSymbolLocatorStatistics().merge(symbol_locator_map);
1290 if (module_sp->GetObjectFile()->GetType() ==
1292 module_sp.reset();
1293 } else {
1294 if (did_create_ptr)
1295 *did_create_ptr = true;
1296
1297 shared_module_list.ReplaceEquivalent(module_sp, old_modules);
1298 }
1299 } else {
1300 located_binary_modulespec.GetFileSpec().GetPath(path, sizeof(path));
1301
1302 if (located_binary_modulespec.GetFileSpec()) {
1303 if (arch.IsValid())
1305 "unable to open %s architecture in '%s'",
1306 arch.GetArchitectureName(), path);
1307 else
1308 error =
1309 Status::FromErrorStringWithFormat("unable to open '%s'", path);
1310 } else {
1311 std::string uuid_str;
1312 if (uuid_ptr && uuid_ptr->IsValid())
1313 uuid_str = uuid_ptr->GetAsString();
1314
1315 if (!uuid_str.empty())
1317 "cannot locate a module for UUID '%s'", uuid_str.c_str());
1318 else
1319 error = Status::FromErrorString("cannot locate a module");
1320 }
1321 }
1322 }
1323 }
1324
1325 return error;
1326}
1327
1329 return GetSharedModuleList().Remove(module_sp);
1330}
1331
1333 return GetSharedModuleList().RemoveIfOrphaned(module_wp);
1334}
1335
1337 std::list<Status> &errors,
1338 Stream &feedback_stream,
1339 bool continue_on_error) {
1340 if (!target)
1341 return false;
1342 m_modules_mutex.lock();
1343 // Don't hold the module list mutex while loading the scripting resources,
1344 // The initializer might do any amount of work, and having that happen while
1345 // the module list is held is asking for A/B locking problems.
1346 const ModuleList tmp_module_list(*this);
1347 m_modules_mutex.unlock();
1348
1349 for (auto module : tmp_module_list.ModulesNoLocking()) {
1350 if (module) {
1351 Status error;
1352 if (!module->LoadScriptingResourceInTarget(target, error,
1353 feedback_stream)) {
1354 if (error.Fail() && error.AsCString()) {
1356 "unable to load scripting data for "
1357 "module %s - error reported was %s",
1358 module->GetFileSpec()
1359 .GetFileNameStrippingExtension()
1360 .GetCString(),
1361 error.AsCString());
1362 errors.push_back(std::move(error));
1363 if (!continue_on_error)
1364 return false;
1365 }
1366 }
1367 }
1368 }
1369 return errors.empty();
1370}
1371
1373 std::function<IterationAction(const ModuleSP &module_sp)> const &callback)
1374 const {
1375 std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
1376 for (const auto &module_sp : m_modules) {
1377 assert(module_sp != nullptr);
1378 if (callback(module_sp) == IterationAction::Stop)
1379 break;
1380 }
1381}
1382
1384 std::function<bool(lldb_private::Module &module_sp)> const &callback)
1385 const {
1386 std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
1387 for (const auto &module_sp : m_modules) {
1388 assert(module_sp != nullptr);
1389 if (callback(*module_sp))
1390 return true;
1391 }
1392
1393 return false;
1394}
1395
1396
1398 // scoped_lock locks both mutexes at once.
1399 std::scoped_lock<std::recursive_mutex, std::recursive_mutex> lock(
1401 m_modules.swap(other.m_modules);
1402}
1403
1404void ModuleList::PreloadSymbols(bool parallelize) const {
1405 std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
1406
1407 if (!parallelize) {
1408 for (const ModuleSP &module_sp : m_modules)
1409 module_sp->PreloadSymbols();
1410 return;
1411 }
1412
1413 llvm::ThreadPoolTaskGroup task_group(Debugger::GetThreadPool());
1414 for (const ModuleSP &module_sp : m_modules)
1415 task_group.async([module_sp] {
1416 if (module_sp)
1417 module_sp->PreloadSymbols();
1418 });
1419 task_group.wait();
1420}
static llvm::raw_ostream & error(Stream &strm)
#define lldbassert(x)
Definition LLDBAssert.h:16
#define LLDB_LOGF(log,...)
Definition Log.h:376
static SharedModuleListInfo & GetSharedModuleListInfo()
static SharedModuleList & GetSharedModuleList()
A section + offset based address class.
Definition Address.h:62
lldb::ModuleSP GetModule() const
Get accessor for the module for this address.
Definition Address.cpp:273
An architecture specification class.
Definition ArchSpec.h:32
bool IsValid() const
Tests if this ArchSpec is valid.
Definition ArchSpec.h:367
const char * GetArchitectureName() const
Returns a static string representing the current architecture.
Definition ArchSpec.cpp:548
Represents a generic declaration context in a program.
A uniqued constant string class.
Definition ConstString.h:40
bool IsEmpty() const
Test for empty string.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
static llvm::ThreadPoolInterface & GetThreadPool()
Shared thread pool. Use only with ThreadPoolTaskGroup.
A file collection class.
const FileSpec & GetFileSpecAtIndex(size_t idx) const
Get file at index.
size_t GetSize() const
Get the number of files in the file list.
A file utility class.
Definition FileSpec.h:57
const ConstString & GetFilename() const
Filename string const get accessor.
Definition FileSpec.h:250
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Definition FileSpec.cpp:374
llvm::sys::TimePoint GetModificationTime(const FileSpec &file_spec) const
Returns the modification time of the given file.
Status Readlink(const FileSpec &src, FileSpec &dst)
static FileSystem & Instance()
void Resolve(llvm::SmallVectorImpl< char > &path, bool force_make_absolute=false)
Resolve path to make it canonical.
A class that describes a function.
Definition Function.h:400
bool SetClangModulesCachePath(const FileSpec &path)
lldb::SymbolDownload GetSymbolAutoDownload() const
bool SetLLDBIndexCachePath(const FileSpec &path)
bool SetEnableExternalLookup(bool new_value)
PathMappingList GetSymlinkMappings() const
lldb::SymbolSharedCacheUse GetSharedCacheBinaryLoading() const
FileSpec GetClangModulesCachePath() const
llvm::sys::RWMutex m_symlink_paths_mutex
Definition ModuleList.h:95
bool SetEnableLLDBIndexCache(bool new_value)
virtual void NotifyModuleRemoved(const ModuleList &module_list, const lldb::ModuleSP &module_sp)=0
A collection class for Module objects.
Definition ModuleList.h:125
bool ReplaceModule(const lldb::ModuleSP &old_module_sp, const lldb::ModuleSP &new_module_sp)
collection m_modules
The collection of modules.
Definition ModuleList.h:555
void ClearImpl(bool use_notifier=true)
uint32_t ResolveSymbolContextsForFileSpec(const FileSpec &file_spec, uint32_t line, bool check_inlines, lldb::SymbolContextItem resolve_scope, SymbolContextList &sc_list) const
Resolve items in the symbol context for a given file and line. (const FileSpec&,...
static bool RemoveSharedModule(lldb::ModuleSP &module_sp)
void FindFunctions(ConstString name, lldb::FunctionNameType name_type_mask, const ModuleFunctionSearchOptions &options, SymbolContextList &sc_list) const
bool FindSourceFile(const FileSpec &orig_spec, FileSpec &new_spec) const
bool AnyOf(std::function< bool(lldb_private::Module &module)> const &callback) const
Returns true if 'callback' returns true for one of the modules in this ModuleList.
ModuleIterableNoLocking ModulesNoLocking() const
Definition ModuleList.h:572
static constexpr long kUseCountModuleListOrphaned
An orphaned module that lives only in the ModuleList has a count of 1.
Definition ModuleList.h:561
static bool ModuleIsInCache(const Module *module_ptr)
void FindGlobalVariables(ConstString name, size_t max_matches, VariableList &variable_list) const
Find global and static variables by name.
void Swap(ModuleList &other)
Atomically swaps the contents of this module list with other.
static Status GetSharedModule(const ModuleSpec &module_spec, lldb::ModuleSP &module_sp, llvm::SmallVectorImpl< lldb::ModuleSP > *old_modules, bool *did_create_ptr, bool invoke_locate_callback=true)
size_t GetIndexForModule(const Module *module) const
bool RemoveImpl(const lldb::ModuleSP &module_sp, bool use_notifier=true)
lldb::ModuleSP FindFirstModule(const ModuleSpec &module_spec) const
Finds the first module whose file specification matches module_spec.
void Clear()
Clear the object's state.
ModuleList()
Default constructor.
void Dump(Stream *s) const
Dump the description of each module contained in this list.
void FindTypes(Module *search_first, const TypeQuery &query, lldb_private::TypeResults &results) const
Find types using a type-matching object that contains all search parameters.
uint32_t ResolveSymbolContextForFilePath(const char *file_path, uint32_t line, bool check_inlines, lldb::SymbolContextItem resolve_scope, SymbolContextList &sc_list) const
Resolve items in the symbol context for a given file and line. (const char*,uint32_t,...
lldb::ModuleSP GetModuleAtIndexUnlocked(size_t idx) const
Get the module shared pointer for the module at index idx without acquiring the ModuleList mutex.
static bool RemoveSharedModuleIfOrphaned(const lldb::ModuleWP module_ptr)
void FindCompileUnits(const FileSpec &path, SymbolContextList &sc_list) const
Find compile units by partial or full path.
void PreloadSymbols(bool parallelize) const
For each module in this ModuleList, preload its symbols.
const ModuleList & operator=(const ModuleList &rhs)
Assignment operator.
std::recursive_mutex m_modules_mutex
Definition ModuleList.h:556
bool AppendIfNeeded(const lldb::ModuleSP &new_module, bool notify=true)
Append a module to the module list, if it is not already there.
Module * GetModulePointerAtIndex(size_t idx) const
Get the module pointer for the module at index idx.
void FindSymbolsWithNameAndType(ConstString name, lldb::SymbolType symbol_type, SymbolContextList &sc_list) const
static lldb::ModuleSP FindSharedModule(const UUID &uuid)
lldb::ModuleSP FindModule(const Module *module_ptr) const
static ModuleListProperties & GetGlobalModuleListProperties()
void FindModules(const ModuleSpec &module_spec, ModuleList &matching_module_list) const
Finds modules whose file specification matches module_spec.
void FindAddressesForLine(const lldb::TargetSP target_sp, const FileSpec &file, uint32_t line, Function *function, std::vector< Address > &output_local, std::vector< Address > &output_extern)
Find addresses by file/line.
uint32_t ResolveSymbolContextForAddress(const Address &so_addr, lldb::SymbolContextItem resolve_scope, SymbolContext &sc) const
Resolve the symbol context for the given address. (const Address&,uint32_t,SymbolContext&)
bool Remove(const lldb::ModuleSP &module_sp, bool notify=true)
Remove a module from the module list.
size_t RemoveOrphans(bool mandatory)
lldb::ModuleSP GetModuleAtIndex(size_t idx) const
Get the module shared pointer for the module at index idx.
void Append(const lldb::ModuleSP &module_sp, bool notify=true)
Append a module to the module list.
static size_t RemoveOrphanSharedModules(bool mandatory)
void Destroy()
Clear the object's state.
void AppendImpl(const lldb::ModuleSP &module_sp, bool use_notifier=true)
bool LoadScriptingResourcesInTarget(Target *target, std::list< Status > &errors, Stream &feedback_stream, bool continue_on_error=true)
void ReplaceEquivalent(const lldb::ModuleSP &module_sp, llvm::SmallVectorImpl< lldb::ModuleSP > *old_modules=nullptr)
Append a module to the module list and remove any equivalent modules.
void FindFunctionSymbols(ConstString name, lldb::FunctionNameType name_type_mask, SymbolContextList &sc_list)
static void FindSharedModules(const ModuleSpec &module_spec, ModuleList &matching_module_list)
void FindSymbolsMatchingRegExAndType(const RegularExpression &regex, lldb::SymbolType symbol_type, SymbolContextList &sc_list) const
bool ResolveFileAddress(lldb::addr_t vm_addr, Address &so_addr) const
size_t GetSize() const
Gets the size of the module list.
bool RemoveIfOrphaned(const lldb::ModuleWP module_ptr)
void LogUUIDAndPaths(Log *log, const char *prefix_cstr)
void ForEach(std::function< IterationAction(const lldb::ModuleSP &module_sp)> const &callback) const
Applies 'callback' to each module in this ModuleList.
FileSpec & GetPlatformFileSpec()
Definition ModuleSpec.h:69
FileSpec & GetFileSpec()
Definition ModuleSpec.h:57
lldb::PlatformSP GetPlatformSP() const
Definition ModuleSpec.h:143
ArchSpec & GetArchitecture()
Definition ModuleSpec.h:93
FileSpec & GetSymbolFileSpec()
Definition ModuleSpec.h:81
lldb::TargetSP GetTargetSP() const
Definition ModuleSpec.h:133
static std::vector< LookupInfo > MakeLookupInfos(ConstString name, lldb::FunctionNameType name_type_mask, lldb::LanguageType lang_type, ConstString lookup_name_override={})
Creates a vector of lookup infos for function name resolution.
Definition Module.cpp:695
A class that describes an executable image and its associated object and symbol files.
Definition Module.h:90
const lldb_private::UUID & GetUUID()
Get a reference to the UUID value contained in this object.
Definition Module.cpp:348
const ArchSpec & GetArchitecture() const
Get const accessor for the module architecture.
Definition Module.cpp:1030
const FileSpec & GetFileSpec() const
Get const accessor for the module file specification.
Definition Module.h:446
void FindTypes(const TypeQuery &query, TypeResults &results)
Find types using a type-matching object that contains all search parameters.
Definition Module.cpp:966
A plug-in interface definition class for object file parsers.
Definition ObjectFile.h:46
@ eTypeExecutable
A normal executable.
Definition ObjectFile.h:55
@ eTypeStubLibrary
A library that can be linked against but not used for execution.
Definition ObjectFile.h:65
static ModuleSpec LocateExecutableObjectFile(const ModuleSpec &module_spec, StatisticsMap &map)
lldb::OptionValuePropertiesSP m_collection_sp
T GetPropertyAtIndexAs(uint32_t idx, T default_value, const ExecutionContext *exe_ctx=nullptr) const
bool SetPropertyAtIndex(uint32_t idx, T t, const ExecutionContext *exe_ctx=nullptr) const
A class to count time for plugins.
Definition Statistics.h:94
An error handling class.
Definition Status.h:118
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Definition Status.cpp:106
static Status FromErrorString(const char *str)
Definition Status.h:141
bool Success() const
Test for success condition.
Definition Status.cpp:303
A stream class that can stream formatted output to a file.
Definition Stream.h:28
Defines a list of symbol context objects.
uint32_t GetSize() const
Get accessor for a symbol context list size.
Defines a symbol context baton that can be handed other debug core functions.
Provides public interface for all SymbolFiles.
Definition SymbolFile.h:51
A class that contains all state required for type lookups.
Definition Type.h:104
This class tracks the state and results of a TypeQuery.
Definition Type.h:344
bool Done(const TypeQuery &query) const
Check if the type matching has found all of the matches that it needs.
Definition Type.cpp:200
Represents UUID's of various sizes.
Definition UUID.h:27
std::string GetAsString(llvm::StringRef separator="-") const
Definition UUID.cpp:54
bool IsValid() const
Definition UUID.h:69
#define LLDB_INVALID_INDEX32
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:332
IterationAction
Useful for callbacks whose return type indicates whether to continue iteration or short-circuit.
std::weak_ptr< lldb_private::Module > ModuleWP
std::shared_ptr< lldb_private::Platform > PlatformSP
@ eLanguageTypeUnknown
Unknown or invalid language value.
SymbolType
Symbol types.
uint64_t user_id_t
Definition lldb-types.h:82
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::Target > TargetSP
@ eSymbolDownloadBackground
std::shared_ptr< lldb_private::Module > ModuleSP
Options used by Module::FindFunctions.
Definition Module.h:66
#define PATH_MAX