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