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