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