LLDB mainline
Module.cpp
Go to the documentation of this file.
1//===-- Module.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
9#include "lldb/Core/Module.h"
10
14#include "lldb/Core/Debugger.h"
15#include "lldb/Core/Mangled.h"
17#include "lldb/Core/Progress.h"
19#include "lldb/Core/Section.h"
21#include "lldb/Host/Host.h"
22#include "lldb/Host/HostInfo.h"
28#include "lldb/Symbol/Symbol.h"
33#include "lldb/Symbol/Symtab.h"
34#include "lldb/Symbol/Type.h"
36#include "lldb/Symbol/TypeMap.h"
39#include "lldb/Target/Process.h"
40#include "lldb/Target/Target.h"
45#include "lldb/Utility/Log.h"
47#include "lldb/Utility/Status.h"
48#include "lldb/Utility/Stream.h"
50#include "lldb/Utility/Timer.h"
51
52#if defined(_WIN32)
54#endif
55
56#include "llvm/ADT/STLExtras.h"
57#include "llvm/Support/Compiler.h"
58#include "llvm/Support/DJB.h"
59#include "llvm/Support/FileSystem.h"
60#include "llvm/Support/FormatVariadic.h"
61#include "llvm/Support/JSON.h"
62#include "llvm/Support/MemoryBuffer.h"
63#include "llvm/Support/Signals.h"
64#include "llvm/Support/VirtualFileSystem.h"
65#include "llvm/Support/raw_ostream.h"
66
67#include <cassert>
68#include <cinttypes>
69#include <cstdarg>
70#include <cstdint>
71#include <cstring>
72#include <map>
73#include <optional>
74#include <type_traits>
75#include <utility>
76
77namespace lldb_private {
79}
80namespace lldb_private {
81class VariableList;
82}
83
84using namespace lldb;
85using namespace lldb_private;
86
87// Shared pointers to modules track module lifetimes in targets and in the
88// global module, but this collection will track all module objects that are
89// still alive
90typedef std::vector<Module *> ModuleCollection;
91
93 // This module collection needs to live past any module, so we could either
94 // make it a shared pointer in each module or just leak is. Since it is only
95 // an empty vector by the time all the modules have gone away, we just leak
96 // it for now. If we decide this is a big problem we can introduce a
97 // Finalize method that will tear everything down in a predictable order.
98
99 static ModuleCollection *g_module_collection = nullptr;
100 if (g_module_collection == nullptr)
101 g_module_collection = new ModuleCollection();
102
103 return *g_module_collection;
104}
105
107 // NOTE: The mutex below must be leaked since the global module list in
108 // the ModuleList class will get torn at some point, and we can't know if it
109 // will tear itself down before the "g_module_collection_mutex" below will.
110 // So we leak a Mutex object below to safeguard against that
111
112 static std::recursive_mutex *g_module_collection_mutex = nullptr;
113 if (g_module_collection_mutex == nullptr)
114 g_module_collection_mutex = new std::recursive_mutex; // NOTE: known leak
115 return *g_module_collection_mutex;
116}
117
119 std::lock_guard<std::recursive_mutex> guard(
121 return GetModuleCollection().size();
122}
123
125 std::lock_guard<std::recursive_mutex> guard(
128 if (idx < modules.size())
129 return modules[idx];
130 return nullptr;
131}
132
133static std::atomic<lldb::user_id_t> g_unique_id = 1;
134
135Module::Module(const ModuleSpec &module_spec)
138 // Scope for locker below...
139 {
140 std::lock_guard<std::recursive_mutex> guard(
142 GetModuleCollection().push_back(this);
143 }
144
146 LLDB_LOGF(log, "%p Module::Module((%s) '%s%s%s%s')",
147 static_cast<void *>(this),
148 module_spec.GetArchitecture().GetArchitectureName(),
149 module_spec.GetFileSpec().GetPath().c_str(),
150 module_spec.GetObjectName().IsEmpty() ? "" : "(",
151 module_spec.GetObjectName().AsCString(""),
152 module_spec.GetObjectName().IsEmpty() ? "" : ")");
153
154 auto extractor_sp = module_spec.GetExtractor();
155 lldb::offset_t file_size = 0;
156 if (extractor_sp)
157 file_size = extractor_sp->GetByteSize();
158
159 // First extract all module specifications from the file using the local file
160 // path. If there are no specifications, then don't fill anything in
162 module_spec.GetFileSpec(), 0, file_size, extractor_sp);
163 if (modules_specs.GetSize() == 0)
164 return;
165
166 // Now make sure that one of the module specifications matches what we just
167 // extract. We might have a module specification that specifies a file
168 // "/usr/lib/dyld" with UUID XXX, but we might have a local version of
169 // "/usr/lib/dyld" that has
170 // UUID YYY and we don't want those to match. If they don't match, just don't
171 // fill any ivars in so we don't accidentally grab the wrong file later since
172 // they don't match...
173 ModuleSpec matching_module_spec;
174 if (!modules_specs.FindMatchingModuleSpec(module_spec,
175 matching_module_spec)) {
176 LLDB_LOGF(log, "Found local object file but the specs didn't match");
177 return;
178 }
179
180 // Set m_extractor_sp if it was initially provided in the ModuleSpec. Note
181 // that we cannot use the extractor_sp variable here, because it will have
182 // been modified by GetModuleSpecifications().
183 if (auto module_spec_extractor_sp = module_spec.GetExtractor()) {
184 m_extractor_sp = module_spec_extractor_sp;
185 m_mod_time = {};
186 } else {
187 if (module_spec.GetFileSpec())
188 m_mod_time =
190 else if (matching_module_spec.GetFileSpec())
192 matching_module_spec.GetFileSpec());
193 }
194
195 // Copy the architecture from the actual spec if we got one back, else use
196 // the one that was specified
197 if (matching_module_spec.GetArchitecture().IsValid())
198 m_arch = matching_module_spec.GetArchitecture();
199 else if (module_spec.GetArchitecture().IsValid())
200 m_arch = module_spec.GetArchitecture();
201
202 // Copy the file spec over and use the specified one (if there was one) so we
203 // don't use a path that might have gotten resolved a path in
204 // 'matching_module_spec'
205 if (module_spec.GetFileSpec())
206 m_file = module_spec.GetFileSpec();
207 else if (matching_module_spec.GetFileSpec())
208 m_file = matching_module_spec.GetFileSpec();
209
210 // Copy the platform file spec over
211 if (module_spec.GetPlatformFileSpec())
212 m_platform_file = module_spec.GetPlatformFileSpec();
213 else if (matching_module_spec.GetPlatformFileSpec())
214 m_platform_file = matching_module_spec.GetPlatformFileSpec();
215
216 // Copy the symbol file spec over
217 if (module_spec.GetSymbolFileSpec())
218 m_symfile_spec = module_spec.GetSymbolFileSpec();
219 else if (matching_module_spec.GetSymbolFileSpec())
220 m_symfile_spec = matching_module_spec.GetSymbolFileSpec();
221
222 // Copy the object name over
223 if (matching_module_spec.GetObjectName())
224 m_object_name = matching_module_spec.GetObjectName();
225 else
226 m_object_name = module_spec.GetObjectName();
227
228 // Always trust the object offset (file offset) and object modification time
229 // (for mod time in a BSD static archive) of from the matching module
230 // specification
231 m_object_offset = matching_module_spec.GetObjectOffset();
232 m_object_mod_time = matching_module_spec.GetObjectModificationTime();
233}
234
235Module::Module(const FileSpec &file_spec, const ArchSpec &arch,
236 ConstString object_name, lldb::offset_t object_offset,
237 const llvm::sys::TimePoint<> &object_mod_time)
238 : UserID(g_unique_id++),
239 m_mod_time(FileSystem::Instance().GetModificationTime(file_spec)),
240 m_arch(arch), m_file(file_spec), m_object_name(object_name),
241 m_object_offset(object_offset), m_object_mod_time(object_mod_time),
242 m_unwind_table(*this), m_file_has_changed(false),
244 // Scope for locker below...
245 {
246 std::lock_guard<std::recursive_mutex> guard(
248 GetModuleCollection().push_back(this);
249 }
250
252 LLDB_LOGF(log, "%p Module::Module((%s) '%s')", static_cast<void *>(this),
253 m_arch.GetArchitectureName(),
255}
256
260 std::lock_guard<std::recursive_mutex> guard(
262 GetModuleCollection().push_back(this);
263}
264
266 // Lock our module down while we tear everything down to make sure we don't
267 // get any access to the module while it is being destroyed
268 std::lock_guard<std::recursive_mutex> guard(m_mutex);
269 // Scope for locker below...
270 {
271 std::lock_guard<std::recursive_mutex> guard(
274 ModuleCollection::iterator end = modules.end();
275 ModuleCollection::iterator pos = std::find(modules.begin(), end, this);
276 assert(pos != end);
277 modules.erase(pos);
278 }
280 LLDB_LOGF(log, "%p Module::~Module((%s) '%s')", static_cast<void *>(this),
281 m_arch.GetArchitectureName(),
283 // Release any auto pointers before we start tearing down our member
284 // variables since the object file and symbol files might need to make
285 // function calls back into this module object. The ordering is important
286 // here because symbol files can require the module object file. So we tear
287 // down the symbol file first, then the object file.
288 m_sections_up.reset();
289 m_symfile_up.reset();
290 m_objfile_sp.reset();
291}
292
294 lldb::addr_t header_addr, Status &error,
295 size_t size_to_read) {
296 if (m_objfile_sp) {
297 error = Status::FromErrorString("object file already exists");
298 } else {
299 std::lock_guard<std::recursive_mutex> guard(m_mutex);
300 if (process_sp) {
301 m_did_load_objfile = true;
302 std::shared_ptr<DataBufferHeap> data_sp =
303 std::make_shared<DataBufferHeap>(size_to_read, 0);
304 Status readmem_error;
305 const size_t bytes_read =
306 process_sp->ReadMemory(header_addr, data_sp->GetBytes(),
307 data_sp->GetByteSize(), readmem_error);
308 if (bytes_read < size_to_read)
309 data_sp->SetByteSize(bytes_read);
310 if (data_sp->GetByteSize() > 0) {
311 m_objfile_sp = ObjectFile::FindPlugin(shared_from_this(), process_sp,
312 header_addr, data_sp);
313 if (m_objfile_sp) {
314 m_memory_module_addr = header_addr;
315
316 // Once we get the object file, update our module with the object
317 // file's architecture since it might differ in vendor/os if some
318 // parts were unknown.
319 m_arch = m_objfile_sp->GetArchitecture();
320
321 // Augment the arch with the target's information in case
322 // we are unable to extract the os/environment from memory.
323 m_arch.MergeFrom(process_sp->GetTarget().GetArchitecture());
324
325 m_unwind_table.ModuleWasUpdated();
326 } else {
328 "unable to find suitable object file plug-in");
329 }
330 } else {
332 "unable to read header from memory: %s", readmem_error.AsCString());
333 }
334 } else {
335 error = Status::FromErrorString("invalid process");
336 }
337 }
338 return m_objfile_sp.get();
339}
340
342 if (!m_did_set_uuid.load()) {
343 std::lock_guard<std::recursive_mutex> guard(m_mutex);
344 if (!m_did_set_uuid.load()) {
345 ObjectFile *obj_file = GetObjectFile();
346
347 if (obj_file != nullptr) {
348 m_uuid = obj_file->GetUUID();
349 m_did_set_uuid = true;
350 }
351 }
352 }
353 return m_uuid;
354}
355
356llvm::Expected<TypeSystemSP>
358 return m_type_system_map.GetTypeSystemForLanguage(language, this, true);
359}
360
362 llvm::function_ref<bool(lldb::TypeSystemSP)> callback) {
363 m_type_system_map.ForEach(callback);
364}
365
368 size_t num_comp_units = symbols ? symbols->GetNumCompileUnits() : 0;
369 if (num_comp_units == 0)
370 return;
371
372 for (size_t cu_idx = 0; cu_idx < num_comp_units; cu_idx++) {
373 SymbolContext sc;
374 sc.module_sp = shared_from_this();
375 sc.comp_unit = symbols->GetCompileUnitAtIndex(cu_idx).get();
376 if (!sc.comp_unit)
377 continue;
378
379 symbols->ParseVariablesForContext(sc);
380
381 symbols->ParseFunctions(*sc.comp_unit);
382
383 sc.comp_unit->ForeachFunction([&sc, &symbols](const FunctionSP &f) {
384 symbols->ParseBlocksRecursive(*f);
385
386 // Parse the variables for this function and all its blocks
387 sc.function = f.get();
388 symbols->ParseVariablesForContext(sc);
389 return false;
390 });
391
392 // Parse all types for this compile unit
393 symbols->ParseTypes(*sc.comp_unit);
394 }
395}
396
398 sc->module_sp = shared_from_this();
399}
400
401ModuleSP Module::CalculateSymbolContextModule() { return shared_from_this(); }
402
404 s->Printf(", Module{%p}", static_cast<void *>(this));
405}
406
409 return symbols->GetNumCompileUnits();
410 return 0;
411}
412
414 std::lock_guard<std::recursive_mutex> guard(m_mutex);
415 size_t num_comp_units = GetNumCompileUnits();
416 CompUnitSP cu_sp;
417
418 if (index < num_comp_units) {
419 if (SymbolFile *symbols = GetSymbolFile())
420 cu_sp = symbols->GetCompileUnitAtIndex(index);
421 }
422 return cu_sp;
423}
424
427 if (section_list)
428 return so_addr.ResolveAddressUsingFileSections(vm_addr, section_list.get());
429 return false;
430}
431
433 const Address &so_addr, lldb::SymbolContextItem resolve_scope,
434 SymbolContext &sc, bool resolve_tail_call_address) {
435 std::lock_guard<std::recursive_mutex> guard(m_mutex);
436 uint32_t resolved_flags = 0;
437
438 // Clear the result symbol context in case we don't find anything, but don't
439 // clear the target
440 sc.Clear(false);
441
442 // Get the section from the section/offset address.
443 SectionSP section_sp(so_addr.GetSection());
444
445 // Make sure the section matches this module before we try and match anything
446 if (section_sp && section_sp->GetModule().get() == this) {
447 // If the section offset based address resolved itself, then this is the
448 // right module.
449 sc.module_sp = shared_from_this();
450 resolved_flags |= eSymbolContextModule;
451
452 SymbolFile *symfile = GetSymbolFile();
453 if (!symfile)
454 return resolved_flags;
455
456 // Resolve the compile unit, function, block, line table or line entry if
457 // requested.
458 if (resolve_scope & eSymbolContextCompUnit ||
459 resolve_scope & eSymbolContextFunction ||
460 resolve_scope & eSymbolContextBlock ||
461 resolve_scope & eSymbolContextLineEntry ||
462 resolve_scope & eSymbolContextVariable) {
463 symfile->SetLoadDebugInfoEnabled();
464 resolved_flags |=
465 symfile->ResolveSymbolContext(so_addr, resolve_scope, sc);
466
467 if ((resolve_scope & eSymbolContextLineEntry) && sc.line_entry.IsValid())
469 }
470
471 // Resolve the symbol if requested, but don't re-look it up if we've
472 // already found it.
473 if (resolve_scope & eSymbolContextSymbol &&
474 !(resolved_flags & eSymbolContextSymbol)) {
475 Symtab *symtab = symfile->GetSymtab();
476 if (symtab && so_addr.IsSectionOffset()) {
477 Symbol *matching_symbol = nullptr;
478
479 addr_t file_address = so_addr.GetFileAddress();
480 Symbol *symbol_at_address =
481 symtab->FindSymbolAtFileAddress(file_address);
482 if (symbol_at_address &&
483 symbol_at_address->GetType() != lldb::eSymbolTypeInvalid) {
484 matching_symbol = symbol_at_address;
485 } else {
487 file_address, [&matching_symbol](Symbol *symbol) -> bool {
488 if (symbol->GetType() != eSymbolTypeInvalid) {
489 matching_symbol = symbol;
490 return false; // Stop iterating
491 }
492 return true; // Keep iterating
493 });
494 }
495
496 sc.symbol = matching_symbol;
497
498 if (sc.symbol) {
499 if (sc.symbol->IsSynthetic()) {
500 // We have a synthetic symbol so lets check if the object file from
501 // the symbol file in the symbol vendor is different than the
502 // object file for the module, and if so search its symbol table to
503 // see if we can come up with a better symbol. For example dSYM
504 // files on MacOSX have an unstripped symbol table inside of them.
505 ObjectFile *symtab_objfile = symtab->GetObjectFile();
506 if (symtab_objfile && symtab_objfile->IsStripped()) {
507 ObjectFile *symfile_objfile = symfile->GetObjectFile();
508 if (symfile_objfile != symtab_objfile) {
509 Symtab *symfile_symtab = symfile_objfile->GetSymtab();
510 if (symfile_symtab) {
511 Symbol *symbol =
512 symfile_symtab->FindSymbolContainingFileAddress(
513 so_addr.GetFileAddress());
514 if (symbol && !symbol->IsSynthetic()) {
515 sc.symbol = symbol;
516 }
517 }
518 }
519 }
520 }
521 resolved_flags |= eSymbolContextSymbol;
522 }
523 }
524 }
525
526 // For function symbols, so_addr may be off by one. This is a convention
527 // consistent with FDE row indices in eh_frame sections, but requires extra
528 // logic here to permit symbol lookup for disassembly and unwind.
529 if (resolve_scope & eSymbolContextSymbol &&
530 !(resolved_flags & eSymbolContextSymbol) && resolve_tail_call_address &&
531 so_addr.IsSectionOffset()) {
532 Address previous_addr = so_addr;
533 previous_addr.Slide(-1);
534
535 bool do_resolve_tail_call_address = false; // prevent recursion
536 const uint32_t flags = ResolveSymbolContextForAddress(
537 previous_addr, resolve_scope, sc, do_resolve_tail_call_address);
538 if (flags & eSymbolContextSymbol) {
539 AddressRange addr_range;
540 if (sc.GetAddressRange(eSymbolContextFunction | eSymbolContextSymbol, 0,
541 false, addr_range)) {
542 if (addr_range.GetBaseAddress().GetSection() ==
543 so_addr.GetSection()) {
544 // If the requested address is one past the address range of a
545 // function (i.e. a tail call), or the decremented address is the
546 // start of a function (i.e. some forms of trampoline), indicate
547 // that the symbol has been resolved.
548 if (so_addr.GetOffset() ==
549 addr_range.GetBaseAddress().GetOffset() ||
550 so_addr.GetOffset() == addr_range.GetBaseAddress().GetOffset() +
551 addr_range.GetByteSize()) {
552 resolved_flags |= flags;
553 }
554 } else {
555 sc.symbol =
556 nullptr; // Don't trust the symbol if the sections didn't match.
557 }
558 }
559 }
560 }
561 }
562 return resolved_flags;
563}
564
566 const char *file_path, uint32_t line, bool check_inlines,
567 lldb::SymbolContextItem resolve_scope, SymbolContextList &sc_list) {
568 FileSpec file_spec(file_path);
569 return ResolveSymbolContextsForFileSpec(file_spec, line, check_inlines,
570 resolve_scope, sc_list);
571}
572
574 const FileSpec &file_spec, uint32_t line, bool check_inlines,
575 lldb::SymbolContextItem resolve_scope, SymbolContextList &sc_list) {
576 std::lock_guard<std::recursive_mutex> guard(m_mutex);
577 LLDB_SCOPED_TIMERF("Module::ResolveSymbolContextForFilePath (%s:%u, "
578 "check_inlines = %s, resolve_scope = 0x%8.8x)",
579 file_spec.GetPath().c_str(), line,
580 check_inlines ? "yes" : "no", resolve_scope);
581
582 const uint32_t initial_count = sc_list.GetSize();
583
584 if (SymbolFile *symbols = GetSymbolFile()) {
585 // TODO: Handle SourceLocationSpec column information
586 SourceLocationSpec location_spec(file_spec, line, /*column=*/std::nullopt,
587 check_inlines, /*exact_match=*/false);
588
589 symbols->ResolveSymbolContext(location_spec, resolve_scope, sc_list);
590 }
591
592 return sc_list.GetSize() - initial_count;
593}
594
596 const CompilerDeclContext &parent_decl_ctx,
597 size_t max_matches, VariableList &variables) {
598 if (SymbolFile *symbols = GetSymbolFile())
599 symbols->FindGlobalVariables(name, parent_decl_ctx, max_matches, variables);
600}
601
603 size_t max_matches, VariableList &variables) {
604 SymbolFile *symbols = GetSymbolFile();
605 if (symbols)
606 symbols->FindGlobalVariables(regex, max_matches, variables);
607}
608
610 SymbolContextList &sc_list) {
611 const size_t num_compile_units = GetNumCompileUnits();
612 SymbolContext sc;
613 sc.module_sp = shared_from_this();
614 for (size_t i = 0; i < num_compile_units; ++i) {
615 sc.comp_unit = GetCompileUnitAtIndex(i).get();
616 if (sc.comp_unit) {
618 sc_list.Append(sc);
619 }
620 }
621}
622
624 ConstString lookup_name)
625 : m_name(lookup_info.GetName()), m_lookup_name(lookup_name),
626 m_language(lookup_info.GetLanguageType()),
627 m_name_type_mask(lookup_info.GetNameTypeMask()) {}
628
630 FunctionNameType name_type_mask,
631 LanguageType lang_type)
632 : m_name(name), m_lookup_name(lookup_name), m_language(lang_type) {
633 std::optional<ConstString> basename;
634 Language *lang = Language::FindPlugin(lang_type);
635
636 if (name_type_mask & eFunctionNameTypeAuto) {
637 if (lang) {
638 auto info = lang->GetFunctionNameInfo(name);
639 if (info.first != eFunctionNameTypeNone) {
640 m_name_type_mask |= info.first;
641 if (!basename && info.second)
642 basename = info.second;
643 }
644 }
645
646 // NOTE: There are several ways to get here, but this is a fallback path in
647 // case the above does not succeed at extracting any useful information from
648 // the loaded language plugins.
649 if (m_name_type_mask == eFunctionNameTypeNone)
650 m_name_type_mask = eFunctionNameTypeFull;
651
652 } else {
653 m_name_type_mask = name_type_mask;
654 if (lang) {
655 auto info = lang->GetFunctionNameInfo(name);
656 if (info.first & m_name_type_mask) {
657 // If the user asked for FunctionNameTypes that aren't possible,
658 // then filter those out. (e.g. asking for Selectors on
659 // C++ symbols, or even if the symbol given can't be a selector in
660 // ObjC)
661 m_name_type_mask &= info.first;
662 basename = info.second;
663 } else if (name_type_mask & eFunctionNameTypeFull &&
664 info.first != eFunctionNameTypeNone && !basename &&
665 info.second) {
666 // Still try and get a basename in case someone specifies a name type
667 // mask of eFunctionNameTypeFull and a name like "A::func"
668 basename = info.second;
669 }
670 }
671 }
672
673 if (basename) {
674 // The name supplied was incomplete for lookup purposes. For example, in C++
675 // we may have gotten something like "a::count". In this case, we want to do
676 // a lookup on the basename "count" and then make sure any matching results
677 // contain "a::count" so that it would match "b::a::count" and "a::count".
678 // This is why we set match_name_after_lookup to true.
679 m_lookup_name.SetString(*basename);
681 }
682}
683
684std::vector<Module::LookupInfo> Module::LookupInfo::MakeLookupInfos(
685 ConstString name, lldb::FunctionNameType name_type_mask,
686 lldb::LanguageType lang_type, ConstString lookup_name_override) {
687 std::vector<LanguageType> lang_types;
688 if (lang_type != eLanguageTypeUnknown) {
689 lang_types.push_back(lang_type);
690 } else {
691 // If the language type was not specified, look up in every language
692 // available.
693 Language::ForEach([&](Language *lang) {
694 auto lang_type = lang->GetLanguageType();
695 if (!llvm::is_contained(lang_types, lang_type))
696 lang_types.push_back(lang_type);
698 });
699
700 if (lang_types.empty())
702 }
703
704 ConstString lookup_name = lookup_name_override ? lookup_name_override : name;
705
706 std::vector<Module::LookupInfo> infos;
707 infos.reserve(lang_types.size());
708 for (LanguageType lang_type : lang_types) {
709 Module::LookupInfo info(name, lookup_name, name_type_mask, lang_type);
710 infos.push_back(info);
711 }
712 return infos;
713}
714
716 ConstString function_name, LanguageType language_type) const {
717 // We always keep unnamed symbols
718 if (!function_name)
719 return true;
720
721 // If we match exactly, we can return early
722 if (m_name == function_name)
723 return true;
724
725 // If function_name is mangled, we'll need to demangle it.
726 // In the pathologial case where the function name "looks" mangled but is
727 // actually demangled (e.g. a method named _Zonk), this operation should be
728 // relatively inexpensive since no demangling is actually occuring. See
729 // Mangled::SetValue for more context.
730 const bool function_name_may_be_mangled =
732 ConstString demangled_function_name = function_name;
733 if (function_name_may_be_mangled) {
734 Mangled mangled_function_name(function_name);
735 demangled_function_name = mangled_function_name.GetDemangledName();
736 }
737
738 // If the symbol has a language, then let the language make the match.
739 // Otherwise just check that the demangled function name contains the
740 // demangled user-provided name.
741 if (Language *language = Language::FindPlugin(language_type))
742 return language->DemangledNameContainsPath(m_name, demangled_function_name);
743
744 llvm::StringRef function_name_ref = demangled_function_name;
745 return function_name_ref.contains(m_name);
746}
747
749 size_t start_idx) const {
751 SymbolContext sc;
752 size_t i = start_idx;
753 while (i < sc_list.GetSize()) {
754 if (!sc_list.GetContextAtIndex(i, sc))
755 break;
756
757 bool keep_it =
759 if (keep_it)
760 ++i;
761 else
762 sc_list.RemoveContextAtIndex(i);
763 }
764 }
765
766 // If we have only full name matches we might have tried to set breakpoint on
767 // "func" and specified eFunctionNameTypeFull, but we might have found
768 // "a::func()", "a::b::func()", "c::func()", "func()" and "func". Only
769 // "func()" and "func" should end up matching.
771 if (lang && m_name_type_mask == eFunctionNameTypeFull) {
772 SymbolContext sc;
773 size_t i = start_idx;
774 while (i < sc_list.GetSize()) {
775 if (!sc_list.GetContextAtIndex(i, sc))
776 break;
777 // Make sure the mangled and demangled names don't match before we try to
778 // pull anything out
780 ConstString full_name(sc.GetFunctionName());
781 if (mangled_name != m_name && full_name != m_name) {
782 std::unique_ptr<Language::MethodName> cpp_method =
783 lang->GetMethodName(full_name);
784 if (cpp_method->IsValid()) {
785 if (cpp_method->GetContext().empty()) {
786 if (cpp_method->GetBasename().compare(m_name) != 0) {
787 sc_list.RemoveContextAtIndex(i);
788 continue;
789 }
790 } else {
791 std::string qualified_name;
792 llvm::StringRef anon_prefix("(anonymous namespace)");
793 if (cpp_method->GetContext() == anon_prefix)
794 qualified_name = cpp_method->GetBasename().str();
795 else
796 qualified_name = cpp_method->GetScopeQualifiedName();
797 if (qualified_name != m_name.GetCString()) {
798 sc_list.RemoveContextAtIndex(i);
799 continue;
800 }
801 }
802 }
803 }
804 ++i;
805 }
806 }
807}
808
809void Module::FindFunctions(llvm::ArrayRef<Module::LookupInfo> lookup_infos,
810 const CompilerDeclContext &parent_decl_ctx,
811 const ModuleFunctionSearchOptions &options,
812 SymbolContextList &sc_list) {
813 for (auto &lookup_info : lookup_infos) {
814 SymbolFile *symbols = GetSymbolFile();
815 if (!symbols)
816 continue;
817
818 symbols->FindFunctions(lookup_info, parent_decl_ctx,
819 options.include_inlines, sc_list);
820 if (options.include_symbols)
821 if (Symtab *symtab = symbols->GetSymtab())
822 symtab->FindFunctionSymbols(lookup_info.GetLookupName(),
823 lookup_info.GetNameTypeMask(), sc_list);
824 }
825}
826
828 const CompilerDeclContext &parent_decl_ctx,
829 FunctionNameType name_type_mask,
830 const ModuleFunctionSearchOptions &options,
831 SymbolContextList &sc_list) {
832 std::vector<LookupInfo> lookup_infos =
834 for (auto &lookup_info : lookup_infos) {
835 const size_t old_size = sc_list.GetSize();
836 FindFunctions(lookup_info, parent_decl_ctx, options, sc_list);
837 if (name_type_mask & eFunctionNameTypeAuto) {
838 const size_t new_size = sc_list.GetSize();
839 if (old_size < new_size)
840 lookup_info.Prune(sc_list, old_size);
841 }
842 }
843}
844
845void Module::FindFunctions(llvm::ArrayRef<CompilerContext> compiler_ctx,
846 FunctionNameType name_type_mask,
847 const ModuleFunctionSearchOptions &options,
848 SymbolContextList &sc_list) {
849 if (compiler_ctx.empty() ||
850 compiler_ctx.back().kind != CompilerContextKind::Function)
851 return;
852 ConstString name = compiler_ctx.back().name;
853 SymbolContextList unfiltered;
854 FindFunctions(name, CompilerDeclContext(), name_type_mask, options,
855 unfiltered);
856 // Filter by context.
857 for (auto &sc : unfiltered)
858 if (sc.function && compiler_ctx.equals(sc.function->GetCompilerContext()))
859 sc_list.Append(sc);
860}
861
863 const ModuleFunctionSearchOptions &options,
864 SymbolContextList &sc_list) {
865 const size_t start_size = sc_list.GetSize();
866
867 if (SymbolFile *symbols = GetSymbolFile()) {
868 symbols->FindFunctions(regex, options.include_inlines, sc_list);
869
870 // Now check our symbol table for symbols that are code symbols if
871 // requested
872 if (options.include_symbols) {
873 Symtab *symtab = symbols->GetSymtab();
874 if (symtab) {
875 std::vector<uint32_t> symbol_indexes;
878 symbol_indexes);
879 const size_t num_matches = symbol_indexes.size();
880 if (num_matches) {
881 SymbolContext sc(this);
882 const size_t end_functions_added_index = sc_list.GetSize();
883 size_t num_functions_added_to_sc_list =
884 end_functions_added_index - start_size;
885 if (num_functions_added_to_sc_list == 0) {
886 // No functions were added, just symbols, so we can just append
887 // them
888 for (size_t i = 0; i < num_matches; ++i) {
889 sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]);
890 SymbolType sym_type = sc.symbol->GetType();
891 if (sc.symbol && (sym_type == eSymbolTypeCode ||
892 sym_type == eSymbolTypeResolver))
893 sc_list.Append(sc);
894 }
895 } else {
896 typedef std::map<lldb::addr_t, uint32_t> FileAddrToIndexMap;
897 FileAddrToIndexMap file_addr_to_index;
898 for (size_t i = start_size; i < end_functions_added_index; ++i) {
899 const SymbolContext &sc = sc_list[i];
900 if (sc.block)
901 continue;
902 file_addr_to_index[sc.function->GetAddress().GetFileAddress()] =
903 i;
904 }
905
906 FileAddrToIndexMap::const_iterator end = file_addr_to_index.end();
907 // Functions were added so we need to merge symbols into any
908 // existing function symbol contexts
909 for (size_t i = start_size; i < num_matches; ++i) {
910 sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]);
911 SymbolType sym_type = sc.symbol->GetType();
912 if (sc.symbol && sc.symbol->ValueIsAddress() &&
913 (sym_type == eSymbolTypeCode ||
914 sym_type == eSymbolTypeResolver)) {
915 FileAddrToIndexMap::const_iterator pos =
916 file_addr_to_index.find(
918 if (pos == end)
919 sc_list.Append(sc);
920 else
921 sc_list.SetSymbolAtIndex(pos->second, sc.symbol);
922 }
923 }
924 }
925 }
926 }
927 }
928 }
929}
930
932 const FileSpec &file, uint32_t line,
933 Function *function,
934 std::vector<Address> &output_local,
935 std::vector<Address> &output_extern) {
936 SearchFilterByModule filter(target_sp, m_file);
937
938 // TODO: Handle SourceLocationSpec column information
939 SourceLocationSpec location_spec(file, line, /*column=*/std::nullopt,
940 /*check_inlines=*/true,
941 /*exact_match=*/false);
942 AddressResolverFileLine resolver(location_spec);
943 resolver.ResolveAddress(filter);
944
945 for (size_t n = 0; n < resolver.GetNumberOfAddresses(); n++) {
946 Address addr = resolver.GetAddressRangeAtIndex(n).GetBaseAddress();
948 if (f && f == function)
949 output_local.push_back(addr);
950 else
951 output_extern.push_back(addr);
952 }
953}
954
955void Module::FindTypes(const TypeQuery &query, TypeResults &results) {
956 if (SymbolFile *symbols = GetSymbolFile())
957 symbols->FindTypes(query, results);
958}
959
962 Debugger::DebuggerList requestors =
964 Debugger::DebuggerList interruptors;
965 if (requestors.empty())
966 return interruptors;
967
968 for (auto debugger_sp : requestors) {
969 if (!debugger_sp->InterruptRequested())
970 continue;
971 if (debugger_sp->GetTargetList().AnyTargetContainsModule(module))
972 interruptors.push_back(debugger_sp);
973 }
974 return interruptors;
975}
976
977SymbolFile *Module::GetSymbolFile(bool can_create, Stream *feedback_strm) {
978 if (!m_did_load_symfile.load()) {
979 std::lock_guard<std::recursive_mutex> guard(m_mutex);
980 if (!m_did_load_symfile.load() && can_create) {
981 Debugger::DebuggerList interruptors =
983 if (!interruptors.empty()) {
984 for (auto debugger_sp : interruptors) {
985 REPORT_INTERRUPTION(*(debugger_sp.get()),
986 "Interrupted fetching symbols for module {0}",
987 this->GetFileSpec());
988 }
989 return nullptr;
990 }
991 ObjectFile *obj_file = GetObjectFile();
992 if (obj_file != nullptr) {
994 m_symfile_up.reset(
995 SymbolVendor::FindPlugin(shared_from_this(), feedback_strm));
996 m_did_load_symfile = true;
997 m_unwind_table.ModuleWasUpdated();
998 }
999 }
1000 }
1001 return m_symfile_up ? m_symfile_up->GetSymbolFile() : nullptr;
1002}
1003
1004Symtab *Module::GetSymtab(bool can_create) {
1005 if (SymbolFile *symbols = GetSymbolFile(can_create))
1006 return symbols->GetSymtab(can_create);
1007 return nullptr;
1008}
1009
1011 ConstString object_name) {
1012 // Container objects whose paths do not specify a file directly can call this
1013 // function to correct the file and object names.
1014 m_file = file;
1016 m_object_name = object_name;
1017}
1018
1019const ArchSpec &Module::GetArchitecture() const { return m_arch; }
1020
1022 std::string spec(GetFileSpec().GetPath());
1023 if (m_object_name) {
1024 spec += '(';
1025 spec += m_object_name.GetCString();
1026 spec += ')';
1027 }
1028 if (m_memory_module_addr.has_value()) {
1029 StreamString s;
1030 s.Printf("(0x%" PRIx64 ")", m_memory_module_addr.value());
1031 spec += s.GetData();
1032 }
1033 return spec;
1034}
1035
1036void Module::GetDescription(llvm::raw_ostream &s,
1037 lldb::DescriptionLevel level) {
1038 if (level >= eDescriptionLevelFull) {
1039 if (m_arch.IsValid())
1040 s << llvm::formatv("({0}) ", m_arch.GetArchitectureName());
1041 }
1042
1043 if (level == eDescriptionLevelBrief) {
1044 const char *filename = m_file.GetFilename().GetCString();
1045 if (filename)
1046 s << filename;
1047 } else {
1048 char path[PATH_MAX];
1049 if (m_file.GetPath(path, sizeof(path)))
1050 s << path;
1051 }
1052
1053 const char *object_name = m_object_name.GetCString();
1054 if (object_name)
1055 s << llvm::formatv("({0})", object_name);
1056 if (m_memory_module_addr.has_value())
1057 s << llvm::formatv("({0})", m_memory_module_addr.value());
1058}
1059
1061 // We have provided the DataExtractor for this module to avoid accessing the
1062 // filesystem. We never want to reload those files.
1063 if (m_extractor_sp)
1064 return false;
1065 if (!m_file_has_changed)
1068 return m_file_has_changed;
1069}
1070
1072 std::optional<lldb::user_id_t> debugger_id) {
1073 ConstString file_name = GetFileSpec().GetFilename();
1074 if (file_name.IsEmpty())
1075 return;
1076
1077 StreamString ss;
1078 ss << file_name
1079 << " was compiled with optimization - stepping may behave "
1080 "oddly; variables may not be available";
1081 llvm::StringRef msg = ss.GetString();
1082 Debugger::ReportWarning(msg.str(), debugger_id, GetDiagnosticOnceFlag(msg));
1083}
1084
1086 LanguageType language, std::optional<lldb::user_id_t> debugger_id) {
1087 StreamString ss;
1088 ss << "this version of LLDB has no plugin for the language \""
1090 << "\". "
1091 "Inspection of frame variables will be limited";
1092 llvm::StringRef msg = ss.GetString();
1093 Debugger::ReportWarning(msg.str(), debugger_id, GetDiagnosticOnceFlag(msg));
1094}
1095
1097 const llvm::formatv_object_base &payload) {
1099 if (FileHasChanged()) {
1101 StreamString strm;
1102 strm.PutCString("the object file ");
1104 strm.PutCString(" has been modified\n");
1105 strm.PutCString(payload.str());
1106 strm.PutCString("The debug session should be aborted as the original "
1107 "debug information has been overwritten.");
1108 Debugger::ReportError(std::string(strm.GetString()));
1109 }
1110 }
1111}
1112
1113std::once_flag *Module::GetDiagnosticOnceFlag(llvm::StringRef msg) {
1114 std::lock_guard<std::recursive_mutex> guard(m_diagnostic_mutex);
1115 auto &once_ptr = m_shown_diagnostics[llvm::stable_hash_name(msg)];
1116 if (!once_ptr)
1117 once_ptr = std::make_unique<std::once_flag>();
1118 return once_ptr.get();
1119}
1120
1121void Module::ReportError(const llvm::formatv_object_base &payload) {
1122 StreamString strm;
1124 std::string msg = payload.str();
1125 strm << ' ' << msg;
1127}
1128
1129void Module::ReportWarning(const llvm::formatv_object_base &payload) {
1130 StreamString strm;
1132 std::string msg = payload.str();
1133 strm << ' ' << msg;
1134 Debugger::ReportWarning(strm.GetString().str(), {},
1136}
1137
1138void Module::LogMessage(Log *log, const llvm::formatv_object_base &payload) {
1139 StreamString log_message;
1141 log_message.PutCString(": ");
1142 log_message.PutCString(payload.str());
1143 log->PutCString(log_message.GetData());
1144}
1145
1147 Log *log, const llvm::formatv_object_base &payload) {
1148 StreamString log_message;
1150 log_message.PutCString(": ");
1151 log_message.PutCString(payload.str());
1152 if (log->GetVerbose()) {
1153 std::string back_trace;
1154 llvm::raw_string_ostream stream(back_trace);
1155 llvm::sys::PrintStackTrace(stream);
1156 log_message.PutCString(back_trace);
1157 }
1158 log->PutCString(log_message.GetData());
1159}
1160
1162 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1163 // s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
1164 s->Indent();
1165 s->Printf("Module %s\n", GetSpecificationDescription().c_str());
1166
1167 s->IndentMore();
1168
1169 ObjectFile *objfile = GetObjectFile();
1170 if (objfile)
1171 objfile->Dump(s);
1172
1173 if (SymbolFile *symbols = GetSymbolFile())
1174 symbols->Dump(*s);
1175
1176 s->IndentLess();
1177}
1178
1180
1182 if (!m_did_load_objfile.load()) {
1183 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1184 if (!m_did_load_objfile.load()) {
1185 LLDB_SCOPED_TIMERF("Module::GetObjectFile () module = %s",
1186 GetFileSpec().GetFilename().AsCString(""));
1187 lldb::offset_t data_offset = 0;
1188 lldb::offset_t file_size = 0;
1189
1190 if (m_extractor_sp)
1191 file_size = m_extractor_sp->GetByteSize();
1192 else if (m_file)
1194
1195 if (file_size > m_object_offset) {
1196 m_did_load_objfile = true;
1197 // FindPlugin will modify its extractor_sp argument. Do not let it
1198 // modify our m_extractor_sp member.
1199 DataExtractorSP extractor_sp = m_extractor_sp;
1201 shared_from_this(), &m_file, m_object_offset,
1202 file_size - m_object_offset, extractor_sp, data_offset);
1203 if (m_objfile_sp) {
1204 // Once we get the object file, update our module with the object
1205 // file's architecture since it might differ in vendor/os if some
1206 // parts were unknown. But since the matching arch might already be
1207 // more specific than the generic COFF architecture, only merge in
1208 // those values that overwrite unspecified unknown values.
1209 m_arch.MergeFrom(m_objfile_sp->GetArchitecture());
1210
1211 m_unwind_table.ModuleWasUpdated();
1212 } else {
1213 ReportError("failed to load objfile for {0}\nDebugging will be "
1214 "degraded for this module.",
1215 GetFileSpec().GetPath().c_str());
1216 }
1217 }
1218 }
1219 }
1220 return m_objfile_sp.get();
1221}
1222
1224 // Populate m_sections_up with sections from objfile.
1225 if (!m_sections_up) {
1226 ObjectFile *obj_file = GetObjectFile();
1227 if (obj_file != nullptr)
1229 }
1230 return m_sections_up.get();
1231}
1232
1236
1240
1242 Stream *feedback_strm) {
1244 GetSymbolFile(can_create, feedback_strm));
1245}
1246
1248 return LockedPtr<Symtab>(m_mutex, GetSymtab(can_create));
1249}
1250
1252 ObjectFile *obj_file = GetObjectFile();
1253 if (obj_file)
1254 obj_file->SectionFileAddressesChanged();
1255 if (SymbolFile *symbols = GetSymbolFile())
1256 symbols->SectionFileAddressesChanged();
1257}
1258
1264
1266 if (!m_sections_up)
1267 m_sections_up = std::make_unique<SectionList>();
1268 return m_sections_up.get();
1269}
1270
1272 SymbolType symbol_type) {
1274 "Module::FindFirstSymbolWithNameAndType (name = %s, type = %i)",
1275 name.AsCString(""), symbol_type);
1276 if (Symtab *symtab = GetSymtab())
1277 return symtab->FindFirstSymbolWithNameAndType(
1278 name, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny);
1279 return nullptr;
1280}
1282 Symtab *symtab, std::vector<uint32_t> &symbol_indexes,
1283 SymbolContextList &sc_list) {
1284 // No need to protect this call using m_mutex all other method calls are
1285 // already thread safe.
1286
1287 size_t num_indices = symbol_indexes.size();
1288 if (num_indices > 0) {
1289 SymbolContext sc;
1291 for (size_t i = 0; i < num_indices; i++) {
1292 sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]);
1293 if (sc.symbol)
1294 sc_list.Append(sc);
1295 }
1296 }
1297}
1298
1299void Module::FindFunctionSymbols(ConstString name, uint32_t name_type_mask,
1300 SymbolContextList &sc_list) {
1301 LLDB_SCOPED_TIMERF("Module::FindSymbolsFunctions (name = %s, mask = 0x%8.8x)",
1302 name.AsCString(""), name_type_mask);
1303 if (Symtab *symtab = GetSymtab())
1304 symtab->FindFunctionSymbols(name, name_type_mask, sc_list);
1305}
1306
1308 SymbolType symbol_type,
1309 SymbolContextList &sc_list) {
1310 // No need to protect this call using m_mutex all other method calls are
1311 // already thread safe.
1312 if (Symtab *symtab = GetSymtab()) {
1313 std::vector<uint32_t> symbol_indexes;
1314 symtab->FindAllSymbolsWithNameAndType(name, symbol_type, symbol_indexes);
1315 SymbolIndicesToSymbolContextList(symtab, symbol_indexes, sc_list);
1316 }
1317}
1318
1320 const RegularExpression &regex, SymbolType symbol_type,
1321 SymbolContextList &sc_list, Mangled::NamePreference mangling_preference) {
1322 // No need to protect this call using m_mutex all other method calls are
1323 // already thread safe.
1325 "Module::FindSymbolsMatchingRegExAndType (regex = %s, type = %i)",
1326 regex.GetText().str().c_str(), symbol_type);
1327 if (Symtab *symtab = GetSymtab()) {
1328 std::vector<uint32_t> symbol_indexes;
1329 symtab->FindAllSymbolsMatchingRexExAndType(
1330 regex, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny,
1331 symbol_indexes, mangling_preference);
1332 SymbolIndicesToSymbolContextList(symtab, symbol_indexes, sc_list);
1333 }
1334}
1335
1338 if (!sym_file)
1339 return;
1340
1341 // Load the object file symbol table and any symbols from the SymbolFile that
1342 // get appended using SymbolFile::AddSymbols(...).
1343 if (Symtab *symtab = sym_file->GetSymtab())
1344 symtab->PreloadSymbols();
1345
1346 // Now let the symbol file preload its data and the symbol table will be
1347 // available without needing to take the module lock.
1348 sym_file->PreloadSymbols();
1349}
1350
1352 if (!FileSystem::Instance().Exists(file))
1353 return;
1354 if (m_symfile_up) {
1355 // Remove any sections in the unified section list that come from the
1356 // current symbol vendor.
1357 SectionList *section_list = GetSectionList();
1358 SymbolFile *symbol_file = GetSymbolFile();
1359 if (section_list && symbol_file) {
1360 ObjectFile *obj_file = symbol_file->GetObjectFile();
1361 // Make sure we have an object file and that the symbol vendor's objfile
1362 // isn't the same as the module's objfile before we remove any sections
1363 // for it...
1364 if (obj_file) {
1365 // Check to make sure we aren't trying to specify the file we already
1366 // have
1367 if (obj_file->GetFileSpec() == file) {
1368 // We are being told to add the exact same file that we already have
1369 // we don't have to do anything.
1370 return;
1371 }
1372
1373 // Cleare the current symtab as we are going to replace it with a new
1374 // one
1375 obj_file->ClearSymtab();
1376
1377 // The symbol file might be a directory bundle ("/tmp/a.out.dSYM")
1378 // instead of a full path to the symbol file within the bundle
1379 // ("/tmp/a.out.dSYM/Contents/Resources/DWARF/a.out"). So we need to
1380 // check this
1381 if (FileSystem::Instance().IsDirectory(file)) {
1382 std::string new_path(file.GetPath());
1383 std::string old_path(obj_file->GetFileSpec().GetPath());
1384 if (llvm::StringRef(old_path).starts_with(new_path)) {
1385 // We specified the same bundle as the symbol file that we already
1386 // have
1387 return;
1388 }
1389 }
1390
1391 if (obj_file != m_objfile_sp.get()) {
1392 size_t num_sections = section_list->GetNumSections(0);
1393 for (size_t idx = num_sections; idx > 0; --idx) {
1394 lldb::SectionSP section_sp(
1395 section_list->GetSectionAtIndex(idx - 1));
1396 if (section_sp->GetObjectFile() == obj_file) {
1397 section_list->DeleteSection(idx - 1);
1398 }
1399 }
1400 }
1401 }
1402 }
1403 // Keep all old symbol files around in case there are any lingering type
1404 // references in any SBValue objects that might have been handed out.
1405 m_old_symfiles.push_back(std::move(m_symfile_up));
1406 }
1407 m_symfile_spec = file;
1408 m_symfile_up.reset();
1409 m_did_load_symfile = false;
1410}
1411
1413 if (GetObjectFile() == nullptr)
1414 return false;
1415 else
1416 return GetObjectFile()->IsExecutable();
1417}
1418
1420 ObjectFile *obj_file = GetObjectFile();
1421 if (obj_file) {
1422 SectionList *sections = GetSectionList();
1423 if (sections != nullptr) {
1424 size_t num_sections = sections->GetSize();
1425 for (size_t sect_idx = 0; sect_idx < num_sections; sect_idx++) {
1426 SectionSP section_sp = sections->GetSectionAtIndex(sect_idx);
1427 if (section_sp->GetLoadBaseAddress(target) != LLDB_INVALID_ADDRESS) {
1428 return true;
1429 }
1430 }
1431 }
1432 }
1433 return false;
1434}
1435
1436bool Module::SetArchitecture(const ArchSpec &new_arch) {
1437 if (!m_arch.IsValid()) {
1438 m_arch = new_arch;
1439 return true;
1440 }
1441 return m_arch.IsCompatibleMatch(new_arch);
1442}
1443
1445 bool value_is_offset, bool &changed) {
1446 ObjectFile *object_file = GetObjectFile();
1447 if (object_file != nullptr) {
1448 changed = object_file->SetLoadAddress(target, value, value_is_offset);
1449 return true;
1450 } else {
1451 changed = false;
1452 }
1453 return false;
1454}
1455
1456bool Module::MatchesModuleSpec(const ModuleSpec &module_ref) {
1457 const UUID &uuid = module_ref.GetUUID();
1458
1459 if (uuid.IsValid()) {
1460 // If the UUID matches, then nothing more needs to match...
1461 return (uuid == GetUUID());
1462 }
1463
1464 const FileSpec &file_spec = module_ref.GetFileSpec();
1465 if (!FileSpec::Match(file_spec, m_file) &&
1466 !FileSpec::Match(file_spec, m_platform_file))
1467 return false;
1468
1469 const FileSpec &platform_file_spec = module_ref.GetPlatformFileSpec();
1470 if (!FileSpec::Match(platform_file_spec, GetPlatformFileSpec()))
1471 return false;
1472
1473 const ArchSpec &arch = module_ref.GetArchitecture();
1474 if (arch.IsValid()) {
1475 if (!m_arch.IsCompatibleMatch(arch))
1476 return false;
1477 }
1478
1479 ConstString object_name = module_ref.GetObjectName();
1480 if (object_name) {
1481 if (object_name != GetObjectName())
1482 return false;
1483 }
1484 return true;
1485}
1486
1487bool Module::FindSourceFile(const FileSpec &orig_spec, FileSpec &new_spec) {
1488 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1490 if (auto remapped = m_source_mappings.FindFile(orig_spec)) {
1491 new_spec = *remapped;
1492 return true;
1493 }
1494 return false;
1495}
1496
1498 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1500}
1501
1503 // Must be called with m_mutex held.
1504 if (m_prefix_map_search_dirs.empty())
1505 return;
1506
1508 llvm::vfs::FileSystem &vfs = *llvm::vfs::getRealFileSystem();
1509 // Track visited directories so two starting paths that share ancestors
1510 // don't redundantly walk the same directory.
1511 llvm::DenseSet<ConstString> searched;
1512 for (ConstString start_cs : m_prefix_map_search_dirs) {
1513 for (FileSpec current(start_cs.GetStringRef());;) {
1514 ConstString directory_cs(current.GetPath());
1515 if (!searched.insert(directory_cs).second)
1516 break;
1517 FileSpec map_file(current);
1518 map_file.AppendPathComponent("compilation-prefix-map.json");
1519 llvm::ErrorOr<std::unique_ptr<llvm::vfs::File>> file =
1520 vfs.openFileForRead(map_file.GetPath());
1521 if (file && *file) {
1522 LLDB_LOG(log, "found compilation-prefix-map.json at {0}",
1523 map_file.GetPath());
1524 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> buf =
1525 (*file)->getBuffer(map_file.GetPath());
1526 if (buf && *buf) {
1527 llvm::Expected<llvm::json::Value> val =
1528 llvm::json::parse((*buf)->getBuffer());
1529 if (!val) {
1530 LLDB_LOG_ERROR(log, val.takeError(), "failed to parse {1}: {0}",
1531 map_file.GetPath());
1532 continue;
1533 }
1534 if (llvm::json::Object *obj = val->getAsObject()) {
1535 for (const llvm::json::Object::value_type &kv : *obj)
1536 if (std::optional<llvm::StringRef> to = kv.second.getAsString()) {
1537 LLDB_LOG(log, "applying prefix map: '{0}' -> '{1}'", kv.first,
1538 *to);
1539 m_source_mappings.AppendUnique(kv.first.str(), to->str(),
1540 /*notify=*/false);
1541 }
1542 }
1543 }
1544 break;
1545 }
1546 FileSpec parent = current;
1547 parent.RemoveLastPathComponent();
1548 if (parent == current)
1549 break;
1550 current = parent;
1551 }
1552 }
1554}
1555
1556std::optional<std::string> Module::RemapSourceFile(llvm::StringRef path) {
1557 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1559 if (auto remapped = m_source_mappings.RemapPath(path))
1560 return remapped->GetPath();
1561 return {};
1562}
1563
1564void Module::RegisterXcodeSDK(llvm::StringRef sdk_name,
1565 llvm::StringRef sysroot) {
1566 Progress progress("Looking for Xcode SDK", sdk_name.str());
1567 auto sdk_path_or_err =
1568 HostInfo::GetSDKRoot(HostInfo::SDKOptions{sdk_name.str()});
1569
1570 if (!sdk_path_or_err) {
1571 Debugger::ReportError("Error while searching for Xcode SDK: " +
1572 toString(sdk_path_or_err.takeError()),
1573 /*debugger_id=*/std::nullopt,
1574 GetDiagnosticOnceFlag(sdk_name));
1575 return;
1576 }
1577
1578 auto sdk_path = *sdk_path_or_err;
1579 if (sdk_path.empty())
1580 return;
1581 // If the SDK changed for a previously registered source path, update it.
1582 // This could happend with -fdebug-prefix-map, otherwise it's unlikely.
1583 if (!m_source_mappings.Replace(sysroot, sdk_path, true))
1584 // In the general case, however, append it to the list.
1585 m_source_mappings.Append(sysroot, sdk_path, false);
1586}
1587
1588bool Module::MergeArchitecture(const ArchSpec &arch_spec) {
1589 if (!arch_spec.IsValid())
1590 return false;
1592 "module has arch %s, merging/replacing with arch %s",
1593 m_arch.GetTriple().getTriple().c_str(),
1594 arch_spec.GetTriple().getTriple().c_str());
1595 if (!m_arch.IsCompatibleMatch(arch_spec)) {
1596 // The new architecture is different, we just need to replace it.
1597 return SetArchitecture(arch_spec);
1598 }
1599
1600 // Merge bits from arch_spec into "merged_arch" and set our architecture.
1601 ArchSpec merged_arch(m_arch);
1602 merged_arch.MergeFrom(arch_spec);
1603 // SetArchitecture() is a no-op if m_arch is already valid.
1604 m_arch = ArchSpec();
1605 return SetArchitecture(merged_arch);
1606}
1607
1609 m_symtab_parse_time.reset();
1610 m_symtab_index_time.reset();
1611 SymbolFile *sym_file = GetSymbolFile();
1612 if (sym_file)
1613 sym_file->ResetStatistics();
1614}
1615
1616llvm::VersionTuple Module::GetVersion() {
1617 if (ObjectFile *obj_file = GetObjectFile())
1618 return obj_file->GetVersion();
1619 return llvm::VersionTuple();
1620}
1621
1623 ObjectFile *obj_file = GetObjectFile();
1624
1625 if (obj_file)
1626 return obj_file->GetIsDynamicLinkEditor();
1627
1628 return false;
1629}
1630
1631uint32_t Module::Hash() {
1632 std::string identifier;
1633 llvm::raw_string_ostream id_strm(identifier);
1634 id_strm << m_arch.GetTriple().str() << '-' << m_file.GetPath();
1635 if (m_object_name)
1636 id_strm << '(' << m_object_name << ')';
1637 if (m_object_offset > 0)
1638 id_strm << m_object_offset;
1639 const auto mtime = llvm::sys::toTimeT(m_object_mod_time);
1640 if (mtime > 0)
1641 id_strm << mtime;
1642 return llvm::djbHash(identifier);
1643}
1644
1645std::string Module::GetCacheKey() {
1646 std::string key;
1647 llvm::raw_string_ostream strm(key);
1648 strm << m_arch.GetTriple().str() << '-' << m_file.GetFilename();
1649 if (m_object_name)
1650 strm << '(' << m_object_name << ')';
1651 strm << '-' << llvm::format_hex(Hash(), 10);
1652 return key;
1653}
1654
1656 if (!ModuleList::GetGlobalModuleListProperties().GetEnableLLDBIndexCache())
1657 return nullptr;
1658 // NOTE: intentional leak so we don't crash if global destructor chain gets
1659 // called as other threads still use the result of this function
1660 static DataFileCache *g_data_file_cache =
1662 .GetLLDBIndexCachePath()
1663 .GetPath());
1664 return g_data_file_cache;
1665}
static llvm::raw_ostream & error(Stream &strm)
static lldb::user_id_t g_unique_id
Definition Debugger.cpp:106
#define REPORT_INTERRUPTION(debugger,...)
Definition Debugger.h:521
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition Log.h:364
#define LLDB_LOGF(log,...)
Definition Log.h:378
#define LLDB_LOG_ERROR(log, error,...)
Definition Log.h:394
std::vector< Module * > ModuleCollection
Definition Module.cpp:90
static ModuleCollection & GetModuleCollection()
Definition Module.cpp:92
static Debugger::DebuggerList DebuggersOwningModuleRequestingInterruption(Module &module)
Definition Module.cpp:961
#define LLDB_SCOPED_TIMER()
Definition Timer.h:83
#define LLDB_SCOPED_TIMERF(...)
Definition Timer.h:86
A section + offset based address range class.
Address & GetBaseAddress()
Get accessor for the base address of the range.
lldb::addr_t GetByteSize() const
Get accessor for the byte size of this range.
"lldb/Core/AddressResolverFileLine.h" This class finds address for source file and line.
virtual void ResolveAddress(SearchFilter &filter)
AddressRange & GetAddressRangeAtIndex(size_t idx)
A section + offset based address class.
Definition Address.h:62
bool ResolveAddressUsingFileSections(lldb::addr_t addr, const SectionList *sections)
Resolve a file virtual address using a section list.
Definition Address.cpp:249
lldb::SectionSP GetSection() const
Get const accessor for the section.
Definition Address.h:432
Function * CalculateSymbolContextFunction() const
Definition Address.cpp:859
bool Slide(int64_t offset)
Definition Address.h:452
lldb::addr_t GetFileAddress() const
Get the file address.
Definition Address.cpp:281
lldb::addr_t GetOffset() const
Get the section relative offset value.
Definition Address.h:329
bool IsSectionOffset() const
Check if an address is section offset.
Definition Address.h:342
An architecture specification class.
Definition ArchSpec.h:32
bool IsValid() const
Tests if this ArchSpec is valid.
Definition ArchSpec.h:370
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition ArchSpec.h:460
void MergeFrom(const ArchSpec &other)
Merges fields from another ArchSpec into this ArchSpec.
Definition ArchSpec.cpp:810
const char * GetArchitectureName() const
Returns a static string representing the current architecture.
Definition ArchSpec.cpp:557
const FileSpec & GetPrimaryFile() const
Return the primary source spec associated with this compile unit.
void ForeachFunction(llvm::function_ref< bool(const lldb::FunctionSP &)> lambda) const
Apply a lambda to each function in this compile unit.
Represents a generic declaration context in a program.
A uniqued constant string class.
Definition ConstString.h:40
bool IsEmpty() const
Test for empty string.
const char * AsCString(const char *value_if_empty) const
Get the string value as a C string.
This class enables data to be cached into a directory using the llvm caching code.
static void ReportWarning(std::string message, std::optional< lldb::user_id_t > debugger_id=std::nullopt, std::once_flag *once=nullptr)
Report warning events.
static void ReportError(std::string message, std::optional< lldb::user_id_t > debugger_id=std::nullopt, std::once_flag *once=nullptr)
Report error events.
std::vector< lldb::DebuggerSP > DebuggerList
Definition Debugger.h:102
static DebuggerList DebuggersRequestingInterruption()
A file utility class.
Definition FileSpec.h:57
void AppendPathComponent(llvm::StringRef component)
Definition FileSpec.cpp:454
static bool Match(const FileSpec &pattern, const FileSpec &file)
Match FileSpec pattern against FileSpec file.
Definition FileSpec.cpp:301
const ConstString & GetFilename() const
Filename string const get accessor.
Definition FileSpec.h:250
bool RemoveLastPathComponent()
Removes the last path component by replacing the current path with its parent.
Definition FileSpec.cpp:465
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
uint64_t GetByteSize(const FileSpec &file_spec) const
Returns the on-disk size of the given file in bytes.
llvm::sys::TimePoint GetModificationTime(const FileSpec &file_spec) const
Returns the modification time of the given file.
static FileSystem & Instance()
A class that describes a function.
Definition Function.h:392
const Address & GetAddress() const
Return the address of the function (its entry point).
Definition Function.h:445
static void ForEach(llvm::function_ref< IterationAction(Language *)> callback)
Definition Language.cpp:127
static Language * FindPlugin(lldb::LanguageType language)
Definition Language.cpp:84
static const char * GetNameForLanguageType(lldb::LanguageType language)
Returns the internal LLDB name for the specified language.
Definition Language.cpp:305
virtual std::unique_ptr< Language::MethodName > GetMethodName(ConstString name) const
Definition Language.h:307
virtual lldb::LanguageType GetLanguageType() const =0
virtual std::pair< lldb::FunctionNameType, std::optional< ConstString > > GetFunctionNameInfo(ConstString name) const
Definition Language.h:312
void PutCString(const char *cstr)
Definition Log.cpp:145
bool GetVerbose() const
Definition Log.cpp:300
A class that handles mangled names.
Definition Mangled.h:34
ConstString GetDemangledName() const
Demangled name get accessor.
Definition Mangled.cpp:284
static Mangled::ManglingScheme GetManglingScheme(llvm::StringRef name)
Try to identify the mangling scheme used.
Definition Mangled.cpp:43
static ModuleListProperties & GetGlobalModuleListProperties()
bool FindMatchingModuleSpec(const ModuleSpec &module_spec, ModuleSpec &match_module_spec) const
Definition ModuleSpec.h:366
uint64_t GetObjectOffset() const
Definition ModuleSpec.h:111
ConstString & GetObjectName()
Definition ModuleSpec.h:107
FileSpec & GetPlatformFileSpec()
Definition ModuleSpec.h:69
FileSpec & GetFileSpec()
Definition ModuleSpec.h:57
ArchSpec & GetArchitecture()
Definition ModuleSpec.h:93
FileSpec & GetSymbolFileSpec()
Definition ModuleSpec.h:81
llvm::sys::TimePoint & GetObjectModificationTime()
Definition ModuleSpec.h:121
lldb::DataExtractorSP GetExtractor() const
Definition ModuleSpec.h:131
A class that encapsulates name lookup information.
Definition Module.h:933
lldb::FunctionNameType GetNameTypeMask() const
Definition Module.h:974
lldb::LanguageType GetLanguageType() const
Definition Module.h:976
ConstString m_lookup_name
The actual name will lookup when calling in the object or symbol file.
Definition Module.h:989
lldb::FunctionNameType m_name_type_mask
One or more bits from lldb::FunctionNameType that indicate what kind of names we are looking for.
Definition Module.h:996
bool NameMatchesLookupInfo(ConstString function_name, lldb::LanguageType language_type=lldb::eLanguageTypeUnknown) const
Definition Module.cpp:715
lldb::LanguageType m_language
Limit matches to only be for this language.
Definition Module.h:992
ConstString m_name
What the user originally typed.
Definition Module.h:986
ConstString GetName() const
Definition Module.h:970
static std::vector< LookupInfo > MakeLookupInfos(ConstString name, lldb::FunctionNameType name_type_mask, lldb::LanguageType lang_type, ConstString lookup_name_override={})
Creates a vector of lookup infos for function name resolution.
Definition Module.cpp:684
void Prune(SymbolContextList &sc_list, size_t start_idx) const
Definition Module.cpp:748
bool m_match_name_after_lookup
If true, then demangled names that match will need to contain "m_name" in order to be considered a ma...
Definition Module.h:1000
A class that describes an executable image and its associated object and symbol files.
Definition Module.h:91
const lldb_private::UUID & GetUUID()
Get a reference to the UUID value contained in this object.
Definition Module.cpp:341
uint32_t ResolveSymbolContextForFilePath(const char *file_path, uint32_t line, bool check_inlines, lldb::SymbolContextItem resolve_scope, SymbolContextList &sc_list)
Resolve items in the symbol context for a given file and line.
Definition Module.cpp:565
std::atomic< bool > m_did_set_uuid
Definition Module.h:1119
void ReportWarningOptimization(std::optional< lldb::user_id_t > debugger_id)
Definition Module.cpp:1071
PathMappingList m_source_mappings
Module specific source remappings for when you have debug info for a module that doesn't match where ...
Definition Module.h:1101
llvm::sys::TimePoint m_object_mod_time
Definition Module.h:1077
virtual ObjectFile * GetObjectFile()
Get the object file representation for the current architecture.
Definition Module.cpp:1181
void FindGlobalVariables(ConstString name, const CompilerDeclContext &parent_decl_ctx, size_t max_matches, VariableList &variable_list)
Find global and static variables by name.
Definition Module.cpp:595
void ReportWarning(const char *format, Args &&...args)
Definition Module.h:813
FileSpec m_file
The file representation on disk for this module (if there is one).
Definition Module.h:1060
virtual SymbolFile * GetSymbolFile(bool can_create=true, Stream *feedback_strm=nullptr)
Get the module's symbol file.
Definition Module.cpp:977
static DataFileCache * GetIndexCache()
Get the global index file cache.
Definition Module.cpp:1655
std::vector< lldb::SymbolVendorUP > m_old_symfiles
If anyone calls Module::SetSymbolFileFileSpec() and changes the symbol file,.
Definition Module.h:1093
void ReportWarningUnsupportedLanguage(lldb::LanguageType language, std::optional< lldb::user_id_t > debugger_id)
Definition Module.cpp:1085
std::once_flag * GetDiagnosticOnceFlag(llvm::StringRef msg)
Definition Module.cpp:1113
void FindCompileUnits(const FileSpec &path, SymbolContextList &sc_list)
Find compile units by partial or full path.
Definition Module.cpp:609
ConstString GetObjectName() const
Definition Module.cpp:1179
uint32_t Hash()
Get a unique hash for this module.
Definition Module.cpp:1631
lldb::ModuleSP CalculateSymbolContextModule() override
Definition Module.cpp:401
static Module * GetAllocatedModuleAtIndex(size_t idx)
Definition Module.cpp:124
std::optional< std::string > RemapSourceFile(llvm::StringRef path)
Remaps a source file given path into new_path.
Definition Module.cpp:1556
std::recursive_mutex m_diagnostic_mutex
Definition Module.h:1138
bool FindSourceFile(const FileSpec &orig_spec, FileSpec &new_spec)
Finds a source file given a file spec using the module source path remappings (if any).
Definition Module.cpp:1487
void FindFunctions(llvm::ArrayRef< LookupInfo > lookup_infos, const CompilerDeclContext &parent_decl_ctx, const ModuleFunctionSearchOptions &options, SymbolContextList &sc_list)
Find functions by a vector of lookup infos.
UUID m_uuid
Each module is assumed to have a unique identifier to help match it up to debug symbols.
Definition Module.h:1058
llvm::sys::TimePoint m_mod_time
The modification time for this module when it was created.
Definition Module.h:1055
lldb::CompUnitSP GetCompileUnitAtIndex(size_t idx)
Definition Module.cpp:413
LockedPtr< SectionList > GetSectionListLocked()
Like GetSectionList, but the returned handle holds the Module mutex for its lifetime.
Definition Module.cpp:1237
uint32_t ResolveSymbolContextForAddress(const Address &so_addr, lldb::SymbolContextItem resolve_scope, SymbolContext &sc, bool resolve_tail_call_address=false)
Resolve the symbol context for the given address.
Definition Module.cpp:432
void SetFileSpecAndObjectName(const FileSpec &file, ConstString object_name)
Definition Module.cpp:1010
std::recursive_mutex m_mutex
A mutex to keep this object happy in multi-threaded environments.
Definition Module.h:1051
static std::recursive_mutex & GetAllocationModuleCollectionMutex()
Definition Module.cpp:106
bool SetLoadAddress(Target &target, lldb::addr_t value, bool value_is_offset, bool &changed)
Set the load address for all sections in a module to be the file address plus slide.
Definition Module.cpp:1444
void SetSymbolFileFileSpec(const FileSpec &file)
Definition Module.cpp:1351
void RegisterXcodeSDK(llvm::StringRef sdk, llvm::StringRef sysroot)
This callback will be called by SymbolFile implementations when parsing a compile unit that contains ...
Definition Module.cpp:1564
void AddPrefixMapSearchDir(FileSpec dir)
Register a directory to be searched for compilation-prefix-map.json on the first call to RemapSourceF...
Definition Module.cpp:1497
void FindSymbolsWithNameAndType(ConstString name, lldb::SymbolType symbol_type, SymbolContextList &sc_list)
Definition Module.cpp:1307
void CalculateSymbolContext(SymbolContext *sc) override
Reconstruct the object's symbol context into sc.
Definition Module.cpp:397
LockedPtr< Symtab > GetSymtabLocked(bool can_create=true)
Like GetSymtab, but the returned handle holds the Module mutex for its lifetime.
Definition Module.cpp:1247
FileSpec m_symfile_spec
If this path is valid, then this is the file that will be used as the symbol file for this module.
Definition Module.h:1067
std::optional< lldb::addr_t > m_memory_module_addr
For a Module read from memory, the address it was read from.
Definition Module.h:1074
lldb::DataExtractorSP m_extractor_sp
DataExtractor containing the module image, if it was provided at construction time.
Definition Module.h:1082
StatsDuration m_symtab_index_time
We store a symbol named index time duration here because we might have an object file and a symbol fi...
Definition Module.h:1130
bool ResolveFileAddress(lldb::addr_t vm_addr, Address &so_addr)
Definition Module.cpp:425
ArchSpec m_arch
The architecture for this module.
Definition Module.h:1057
void ReportError(const char *format, Args &&...args)
Definition Module.h:818
const FileSpec & GetPlatformFileSpec() const
Get accessor for the module platform file specification.
Definition Module.h:461
lldb::SymbolVendorUP m_symfile_up
A pointer to the symbol vendor for this module.
Definition Module.h:1091
const Symbol * FindFirstSymbolWithNameAndType(ConstString name, lldb::SymbolType symbol_type=lldb::eSymbolTypeAny)
Find a symbol in the object file's symbol table.
Definition Module.cpp:1271
llvm::DenseMap< llvm::stable_hash, std::unique_ptr< std::once_flag > > m_shown_diagnostics
A set of hashes of all warnings and errors, to avoid reporting them multiple times to the same Debugg...
Definition Module.h:1137
Module(const FileSpec &file_spec, const ArchSpec &arch, ConstString object_name=ConstString(), lldb::offset_t object_offset=0, const llvm::sys::TimePoint<> &object_mod_time=llvm::sys::TimePoint<>())
Construct with file specification and architecture.
Definition Module.cpp:235
llvm::VersionTuple GetVersion()
Definition Module.cpp:1616
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.
Definition Module.cpp:931
void LoadPrefixMapsIfNeeded()
Search each registered directory upward for compilation-prefix-map.json and apply any found mappings ...
Definition Module.cpp:1502
void DumpSymbolContext(Stream *s) override
Dump the object's symbol context to the stream s.
Definition Module.cpp:403
void FindFunctionSymbols(ConstString name, uint32_t name_type_mask, SymbolContextList &sc_list)
Find a function symbols in the object file's symbol table.
Definition Module.cpp:1299
Symtab * GetSymtab(bool can_create=true)
Get the module's symbol table.
Definition Module.cpp:1004
size_t GetNumCompileUnits()
Get the number of compile units for this module.
Definition Module.cpp:407
ConstString m_object_name
The name an object within this module that is selected, or empty of the module is represented by m_fi...
Definition Module.h:1070
void LogMessage(Log *log, const char *format, Args &&...args)
Definition Module.h:801
bool MatchesModuleSpec(const ModuleSpec &module_ref)
Definition Module.cpp:1456
~Module() override
Destructor.
Definition Module.cpp:265
static size_t GetNumberAllocatedModules()
Definition Module.cpp:118
ObjectFile * GetMemoryObjectFile(const lldb::ProcessSP &process_sp, lldb::addr_t header_addr, Status &error, size_t size_to_read=512)
Load an object file from memory.
Definition Module.cpp:293
TypeSystemMap m_type_system_map
A map of any type systems associated with this module.
Definition Module.h:1097
uint64_t m_object_offset
Definition Module.h:1076
void ForEachTypeSystem(llvm::function_ref< bool(lldb::TypeSystemSP)> callback)
Call callback for each TypeSystem in this Module.
Definition Module.cpp:361
lldb::SectionListUP m_sections_up
Unified section list for module that is used by the ObjectFile and ObjectFile instances for the debug...
Definition Module.h:1113
bool IsExecutable()
Tells whether this module is capable of being the main executable for a process.
Definition Module.cpp:1412
FileSpec m_platform_file
The path to the module on the platform on which it is being debugged.
Definition Module.h:1062
bool MergeArchitecture(const ArchSpec &arch_spec)
Update the ArchSpec to a more specific variant.
Definition Module.cpp:1588
bool FileHasChanged() const
Definition Module.cpp:1060
const ArchSpec & GetArchitecture() const
Get const accessor for the module architecture.
Definition Module.cpp:1019
friend class ObjectFile
Definition Module.h:1149
void LogMessageVerboseBacktrace(Log *log, const char *format, Args &&...args)
Definition Module.h:806
bool GetIsDynamicLinkEditor()
Definition Module.cpp:1622
std::string GetCacheKey()
Get a unique cache key for the current module.
Definition Module.cpp:1645
virtual SectionList * GetSectionList()
Get the unified section list for the module.
Definition Module.cpp:1223
llvm::Expected< lldb::TypeSystemSP > GetTypeSystemForLanguage(lldb::LanguageType language)
Definition Module.cpp:357
void Dump(Stream *s)
Dump a description of this object to a Stream.
Definition Module.cpp:1161
uint32_t ResolveSymbolContextsForFileSpec(const FileSpec &file_spec, uint32_t line, bool check_inlines, lldb::SymbolContextItem resolve_scope, SymbolContextList &sc_list)
Resolve items in the symbol context for a given file and line.
Definition Module.cpp:573
lldb::ObjectFileSP m_objfile_sp
A shared pointer to the object file parser for this module as it may or may not be shared with the Sy...
Definition Module.h:1084
void ReportErrorIfModifyDetected(const char *format, Args &&...args)
Definition Module.h:825
void FindSymbolsMatchingRegExAndType(const RegularExpression &regex, lldb::SymbolType symbol_type, SymbolContextList &sc_list, Mangled::NamePreference mangling_preference=Mangled::ePreferDemangled)
Definition Module.cpp:1319
std::atomic< bool > m_did_load_symfile
Definition Module.h:1118
UnwindTable & GetUnwindTable()
Returns a reference to the UnwindTable for this Module.
Definition Module.cpp:1259
LockedPtr< SymbolFile > GetSymbolFileLocked(bool can_create=true, Stream *feedback_strm=nullptr)
Like GetSymbolFile, but the returned handle holds the Module mutex for its lifetime.
Definition Module.cpp:1241
std::string GetSpecificationDescription() const
Get the module path and object name.
Definition Module.cpp:1021
UnwindTable m_unwind_table
Table of FuncUnwinders objects created for this Module's functions.
Definition Module.h:1087
const FileSpec & GetFileSpec() const
Get const accessor for the module file specification.
Definition Module.h:447
bool IsLoadedInTarget(Target *target)
Tells whether this module has been loaded in the target passed in.
Definition Module.cpp:1419
void GetDescription(llvm::raw_ostream &s, lldb::DescriptionLevel level=lldb::eDescriptionLevelFull)
Definition Module.cpp:1036
bool m_first_file_changed_log
Definition Module.h:1121
void SymbolIndicesToSymbolContextList(Symtab *symtab, std::vector< uint32_t > &symbol_indexes, SymbolContextList &sc_list)
Definition Module.cpp:1281
llvm::DenseSet< ConstString > m_prefix_map_search_dirs
Directories registered via AddPrefixMapSearchDir, searched lazily on the first call to RemapSourceFil...
Definition Module.h:1106
const llvm::sys::TimePoint & GetModificationTime() const
Definition Module.h:483
virtual void SectionFileAddressesChanged()
Notify the module that the file addresses for the Sections have been updated.
Definition Module.cpp:1251
std::atomic< bool > m_did_load_objfile
Definition Module.h:1117
friend class SymbolFile
Definition Module.h:1150
void FindTypes(const TypeQuery &query, TypeResults &results)
Find types using a type-matching object that contains all search parameters.
Definition Module.cpp:955
bool SetArchitecture(const ArchSpec &new_arch)
Definition Module.cpp:1436
SectionList * GetUnifiedSectionList()
Definition Module.cpp:1265
StatsDuration m_symtab_parse_time
See if the module was modified after it was initially opened.
Definition Module.h:1126
void ParseAllDebugSymbols()
A debugging function that will cause everything in a module to be parsed.
Definition Module.cpp:366
LockedPtr< ObjectFile > GetObjectFileLocked()
Like GetObjectFile, but the returned handle holds the Module mutex for its lifetime,...
Definition Module.cpp:1233
virtual bool SetLoadAddress(Target &target, lldb::addr_t value, bool value_is_offset)
Sets the load address for an entire module, assuming a rigid slide of sections, if possible in the im...
Definition ObjectFile.h:381
virtual void Dump(Stream *s)=0
Dump a description of this object to a Stream.
static lldb::ObjectFileSP FindPlugin(const lldb::ModuleSP &module_sp, const FileSpec *file_spec, lldb::offset_t file_offset, lldb::offset_t file_size, lldb::DataExtractorSP extractor_sp, lldb::offset_t &data_offset)
Find a ObjectFile plug-in that can parse file_spec.
virtual bool IsStripped()=0
Detect if this object file has been stripped of local symbols.
Symtab * GetSymtab(bool can_create=true)
Gets the symbol table for the currently selected architecture (and object for archives).
virtual bool IsExecutable() const =0
Tells whether this object file is capable of being the main executable for a process.
virtual void ClearSymtab()
Frees the symbol table.
virtual FileSpec & GetFileSpec()
Get accessor to the object file specification.
Definition ObjectFile.h:280
virtual void CreateSections(SectionList &unified_section_list)=0
virtual void SectionFileAddressesChanged()
Notify the ObjectFile that the file addresses in the Sections for this module have been changed.
Definition ObjectFile.h:310
static ModuleSpecList GetModuleSpecifications(const FileSpec &file, lldb::offset_t file_offset, lldb::offset_t file_size, lldb::DataExtractorSP=lldb::DataExtractorSP())
virtual UUID GetUUID()=0
Gets the UUID for this object file.
virtual bool GetIsDynamicLinkEditor()
Return true if this file is a dynamic link editor (dyld)
Definition ObjectFile.h:635
A Progress indicator helper class.
Definition Progress.h:60
llvm::StringRef GetText() const
Access the regular expression text.
This is a SearchFilter that restricts the search to a given module.
size_t GetNumSections(uint32_t depth) const
Definition Section.cpp:538
size_t GetSize() const
Definition Section.h:77
bool DeleteSection(size_t idx)
Definition Section.cpp:491
lldb::SectionSP GetSectionAtIndex(size_t idx) const
Definition Section.cpp:549
"lldb/Core/SourceLocationSpec.h" A source location specifier class.
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
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition Status.cpp:194
const char * GetData() const
llvm::StringRef GetString() const
A stream class that can stream formatted output to a file.
Definition Stream.h:28
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
Definition Stream.h:405
size_t Indent(llvm::StringRef s="")
Indent the current line in the stream.
Definition Stream.cpp:157
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition Stream.cpp:134
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition Stream.cpp:63
void IndentLess(unsigned amount=2)
Decrement the current indentation level.
Definition Stream.cpp:204
void IndentMore(unsigned amount=2)
Increment the current indentation level.
Definition Stream.cpp:201
Defines a list of symbol context objects.
bool GetContextAtIndex(size_t idx, SymbolContext &sc) const
Get accessor for a symbol context at index idx.
uint32_t GetSize() const
Get accessor for a symbol context list size.
void SetSymbolAtIndex(size_t idx, Symbol *symbol)
Replace the symbol in the symbol context at index idx.
void Append(const SymbolContext &sc)
Append a new symbol context to the list.
Defines a symbol context baton that can be handed other debug core functions.
lldb::LanguageType GetLanguage() const
Function * function
The Function for a given query.
ConstString GetFunctionName(Mangled::NamePreference preference=Mangled::ePreferDemangled) const
Find a name of the innermost function for the symbol context.
Block * block
The Block for a given query.
lldb::ModuleSP module_sp
The Module for a given query.
CompileUnit * comp_unit
The CompileUnit for a given query.
void Clear(bool clear_target)
Clear the object's state.
bool GetAddressRange(uint32_t scope, uint32_t range_idx, bool use_inline_block_range, AddressRange &range) const
Get the address range contained within a symbol context.
Symbol * symbol
The Symbol for a given query.
lldb::TargetSP target_sp
The Target for a given query.
LineEntry line_entry
The LineEntry for a given query.
virtual void SectionFileAddressesChanged()=0
Notify the SymbolFile that the file addresses in the Sections for this module have been changed.
virtual void SetLoadDebugInfoEnabled()
Specify debug info should be loaded.
Definition SymbolFile.h:141
virtual void FindGlobalVariables(ConstString name, const CompilerDeclContext &parent_decl_ctx, uint32_t max_matches, VariableList &variables)
virtual Symtab * GetSymtab(bool can_create=true)=0
virtual void FindTypes(const TypeQuery &query, TypeResults &results)
Find types using a type-matching object that contains all search parameters.
Definition SymbolFile.h:330
virtual void FindFunctions(const Module::LookupInfo &lookup_info, const CompilerDeclContext &parent_decl_ctx, bool include_inlines, SymbolContextList &sc_list)
virtual ObjectFile * GetObjectFile()=0
virtual void ResetStatistics()
Reset the statistics for the symbol file.
Definition SymbolFile.h:444
virtual uint32_t ResolveSymbolContext(const Address &so_addr, lldb::SymbolContextItem resolve_scope, SymbolContext &sc)=0
virtual void Dump(Stream &s)=0
static void DownloadSymbolFileAsync(const UUID &uuid)
Locate the symbol file for the given UUID on a background thread.
static SymbolVendor * FindPlugin(const lldb::ModuleSP &module_sp, Stream *feedback_strm)
bool ValueIsAddress() const
Definition Symbol.cpp:165
bool IsSynthetic() const
Definition Symbol.h:183
Address & GetAddressRef()
Definition Symbol.h:73
lldb::SymbolType GetType() const
Definition Symbol.h:169
Symbol * SymbolAtIndex(size_t idx)
Definition Symtab.cpp:225
void ForEachSymbolContainingFileAddress(lldb::addr_t file_addr, std::function< bool(Symbol *)> const &callback)
Definition Symtab.cpp:1046
Symbol * FindSymbolAtFileAddress(lldb::addr_t file_addr)
Definition Symtab.cpp:1015
Symbol * FindSymbolContainingFileAddress(lldb::addr_t file_addr)
Definition Symtab.cpp:1030
ObjectFile * GetObjectFile() const
Definition Symtab.h:137
uint32_t AppendSymbolIndexesMatchingRegExAndType(const RegularExpression &regex, lldb::SymbolType symbol_type, std::vector< uint32_t > &indexes, Mangled::NamePreference name_preference=Mangled::ePreferDemangled)
Definition Symtab.cpp:746
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
Represents UUID's of various sizes.
Definition UUID.h:27
bool IsValid() const
Definition UUID.h:69
#define LLDB_INVALID_ADDRESS
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:327
Locked< T *, Mutex > LockedPtr
Exclusive (write) access aliases.
Definition Locked.h:149
std::string toString(FormatterBytecode::OpCodes op)
std::shared_ptr< lldb_private::Function > FunctionSP
std::shared_ptr< lldb_private::TypeSystem > TypeSystemSP
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
@ eDescriptionLevelBrief
@ eDescriptionLevelFull
uint64_t offset_t
Definition lldb-types.h:85
LanguageType
Programming language type.
@ eLanguageTypeUnknown
Unknown or invalid language value.
@ eLanguageTypeObjC
Objective-C.
@ eLanguageTypeC_plus_plus
ISO C++:1998.
std::shared_ptr< lldb_private::Process > ProcessSP
SymbolType
Symbol types.
@ eSymbolTypeResolver
std::shared_ptr< lldb_private::Section > SectionSP
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::Target > TargetSP
std::shared_ptr< lldb_private::DataExtractor > DataExtractorSP
std::shared_ptr< lldb_private::Module > ModuleSP
std::shared_ptr< lldb_private::CompileUnit > CompUnitSP
bool IsValid() const
Check if a line entry object is valid.
Definition LineEntry.cpp:35
void ApplyFileMappings(lldb::TargetSP target_sp)
Apply file mappings from target.source-map to the LineEntry's file.
Options used by Module::FindFunctions.
Definition Module.h:67
bool include_inlines
Include inlined functions.
Definition Module.h:71
bool include_symbols
Include the symbol table.
Definition Module.h:69
UserID(lldb::user_id_t uid=LLDB_INVALID_UID)
Construct with optional user ID.
Definition UserID.h:33
#define PATH_MAX