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
57
58#include "llvm/ADT/STLExtras.h"
59#include "llvm/Support/Compiler.h"
60#include "llvm/Support/DJB.h"
61#include "llvm/Support/FileSystem.h"
62#include "llvm/Support/FormatVariadic.h"
63#include "llvm/Support/JSON.h"
64#include "llvm/Support/Signals.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
133Module::Module(const ModuleSpec &module_spec)
134 : m_file_has_changed(false), m_first_file_changed_log(false) {
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 data_sp = module_spec.GetData();
153 lldb::offset_t file_size = 0;
154 if (data_sp)
155 file_size = data_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 module_spec.GetFileSpec(), 0, file_size, modules_specs, data_sp) == 0)
162 return;
163
164 // Now make sure that one of the module specifications matches what we just
165 // extract. We might have a module specification that specifies a file
166 // "/usr/lib/dyld" with UUID XXX, but we might have a local version of
167 // "/usr/lib/dyld" that has
168 // UUID YYY and we don't want those to match. If they don't match, just don't
169 // fill any ivars in so we don't accidentally grab the wrong file later since
170 // they don't match...
171 ModuleSpec matching_module_spec;
172 if (!modules_specs.FindMatchingModuleSpec(module_spec,
173 matching_module_spec)) {
174 if (log) {
175 LLDB_LOGF(log, "Found local object file but the specs didn't match");
176 }
177 return;
178 }
179
180 // Set m_data_sp if it was initially provided in the ModuleSpec. Note that
181 // we cannot use the data_sp variable here, because it will have been
182 // modified by GetModuleSpecifications().
183 if (auto module_spec_data_sp = module_spec.GetData()) {
184 m_data_sp = module_spec_data_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 : m_mod_time(FileSystem::Instance().GetModificationTime(file_spec)),
239 m_arch(arch), m_file(file_spec), m_object_name(object_name),
240 m_object_offset(object_offset), m_object_mod_time(object_mod_time),
241 m_file_has_changed(false), m_first_file_changed_log(false) {
242 // Scope for locker below...
243 {
244 std::lock_guard<std::recursive_mutex> guard(
246 GetModuleCollection().push_back(this);
247 }
248
250 if (log != nullptr)
251 LLDB_LOGF(log, "%p Module::Module((%s) '%s%s%s%s')",
252 static_cast<void *>(this), m_arch.GetArchitectureName(),
253 m_file.GetPath().c_str(), m_object_name.IsEmpty() ? "" : "(",
254 m_object_name.AsCString(""), m_object_name.IsEmpty() ? "" : ")");
255}
256
257Module::Module() : m_file_has_changed(false), m_first_file_changed_log(false) {
258 std::lock_guard<std::recursive_mutex> guard(
260 GetModuleCollection().push_back(this);
261}
262
264 // Lock our module down while we tear everything down to make sure we don't
265 // get any access to the module while it is being destroyed
266 std::lock_guard<std::recursive_mutex> guard(m_mutex);
267 // Scope for locker below...
268 {
269 std::lock_guard<std::recursive_mutex> guard(
272 ModuleCollection::iterator end = modules.end();
273 ModuleCollection::iterator pos = std::find(modules.begin(), end, this);
274 assert(pos != end);
275 modules.erase(pos);
276 }
278 if (log != nullptr)
279 LLDB_LOGF(log, "%p Module::~Module((%s) '%s%s%s%s')",
280 static_cast<void *>(this), m_arch.GetArchitectureName(),
281 m_file.GetPath().c_str(), m_object_name.IsEmpty() ? "" : "(",
282 m_object_name.AsCString(""), m_object_name.IsEmpty() ? "" : ")");
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.SetErrorString("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 StreamString s;
315 s.Printf("0x%16.16" PRIx64, header_addr);
317
318 // Once we get the object file, update our module with the object
319 // file's architecture since it might differ in vendor/os if some
320 // parts were unknown.
321 m_arch = m_objfile_sp->GetArchitecture();
322
323 // Augment the arch with the target's information in case
324 // we are unable to extract the os/environment from memory.
325 m_arch.MergeFrom(process_sp->GetTarget().GetArchitecture());
326 } else {
327 error.SetErrorString("unable to find suitable object file plug-in");
328 }
329 } else {
330 error.SetErrorStringWithFormat("unable to read header from memory: %s",
331 readmem_error.AsCString());
332 }
333 } else {
334 error.SetErrorString("invalid process");
335 }
336 }
337 return m_objfile_sp.get();
338}
339
341 if (!m_did_set_uuid.load()) {
342 std::lock_guard<std::recursive_mutex> guard(m_mutex);
343 if (!m_did_set_uuid.load()) {
344 ObjectFile *obj_file = GetObjectFile();
345
346 if (obj_file != nullptr) {
347 m_uuid = obj_file->GetUUID();
348 m_did_set_uuid = true;
349 }
350 }
351 }
352 return m_uuid;
353}
354
356 std::lock_guard<std::recursive_mutex> guard(m_mutex);
357 if (!m_did_set_uuid) {
358 m_uuid = uuid;
359 m_did_set_uuid = true;
360 } else {
361 lldbassert(0 && "Attempting to overwrite the existing module UUID");
362 }
363}
364
365llvm::Expected<TypeSystemSP>
367 return m_type_system_map.GetTypeSystemForLanguage(language, this, true);
368}
369
371 llvm::function_ref<bool(lldb::TypeSystemSP)> callback) {
372 m_type_system_map.ForEach(callback);
373}
374
376 std::lock_guard<std::recursive_mutex> guard(m_mutex);
377 size_t num_comp_units = GetNumCompileUnits();
378 if (num_comp_units == 0)
379 return;
380
381 SymbolFile *symbols = GetSymbolFile();
382
383 for (size_t cu_idx = 0; cu_idx < num_comp_units; cu_idx++) {
384 SymbolContext sc;
385 sc.module_sp = shared_from_this();
386 sc.comp_unit = symbols->GetCompileUnitAtIndex(cu_idx).get();
387 if (!sc.comp_unit)
388 continue;
389
390 symbols->ParseVariablesForContext(sc);
391
392 symbols->ParseFunctions(*sc.comp_unit);
393
394 sc.comp_unit->ForeachFunction([&sc, &symbols](const FunctionSP &f) {
395 symbols->ParseBlocksRecursive(*f);
396
397 // Parse the variables for this function and all its blocks
398 sc.function = f.get();
399 symbols->ParseVariablesForContext(sc);
400 return false;
401 });
402
403 // Parse all types for this compile unit
404 symbols->ParseTypes(*sc.comp_unit);
405 }
406}
407
409 sc->module_sp = shared_from_this();
410}
411
412ModuleSP Module::CalculateSymbolContextModule() { return shared_from_this(); }
413
415 s->Printf(", Module{%p}", static_cast<void *>(this));
416}
417
419 std::lock_guard<std::recursive_mutex> guard(m_mutex);
420 if (SymbolFile *symbols = GetSymbolFile())
421 return symbols->GetNumCompileUnits();
422 return 0;
423}
424
426 std::lock_guard<std::recursive_mutex> guard(m_mutex);
427 size_t num_comp_units = GetNumCompileUnits();
428 CompUnitSP cu_sp;
429
430 if (index < num_comp_units) {
431 if (SymbolFile *symbols = GetSymbolFile())
432 cu_sp = symbols->GetCompileUnitAtIndex(index);
433 }
434 return cu_sp;
435}
436
438 std::lock_guard<std::recursive_mutex> guard(m_mutex);
439 SectionList *section_list = GetSectionList();
440 if (section_list)
441 return so_addr.ResolveAddressUsingFileSections(vm_addr, section_list);
442 return false;
443}
444
446 const Address &so_addr, lldb::SymbolContextItem resolve_scope,
447 SymbolContext &sc, bool resolve_tail_call_address) {
448 std::lock_guard<std::recursive_mutex> guard(m_mutex);
449 uint32_t resolved_flags = 0;
450
451 // Clear the result symbol context in case we don't find anything, but don't
452 // clear the target
453 sc.Clear(false);
454
455 // Get the section from the section/offset address.
456 SectionSP section_sp(so_addr.GetSection());
457
458 // Make sure the section matches this module before we try and match anything
459 if (section_sp && section_sp->GetModule().get() == this) {
460 // If the section offset based address resolved itself, then this is the
461 // right module.
462 sc.module_sp = shared_from_this();
463 resolved_flags |= eSymbolContextModule;
464
465 SymbolFile *symfile = GetSymbolFile();
466 if (!symfile)
467 return resolved_flags;
468
469 // Resolve the compile unit, function, block, line table or line entry if
470 // requested.
471 if (resolve_scope & eSymbolContextCompUnit ||
472 resolve_scope & eSymbolContextFunction ||
473 resolve_scope & eSymbolContextBlock ||
474 resolve_scope & eSymbolContextLineEntry ||
475 resolve_scope & eSymbolContextVariable) {
476 symfile->SetLoadDebugInfoEnabled();
477 resolved_flags |=
478 symfile->ResolveSymbolContext(so_addr, resolve_scope, sc);
479 }
480
481 // Resolve the symbol if requested, but don't re-look it up if we've
482 // already found it.
483 if (resolve_scope & eSymbolContextSymbol &&
484 !(resolved_flags & eSymbolContextSymbol)) {
485 Symtab *symtab = symfile->GetSymtab();
486 if (symtab && so_addr.IsSectionOffset()) {
487 Symbol *matching_symbol = nullptr;
488
490 so_addr.GetFileAddress(),
491 [&matching_symbol](Symbol *symbol) -> bool {
492 if (symbol->GetType() != eSymbolTypeInvalid) {
493 matching_symbol = symbol;
494 return false; // Stop iterating
495 }
496 return true; // Keep iterating
497 });
498 sc.symbol = matching_symbol;
499 if (!sc.symbol && resolve_scope & eSymbolContextFunction &&
500 !(resolved_flags & eSymbolContextFunction)) {
501 bool verify_unique = false; // No need to check again since
502 // ResolveSymbolContext failed to find a
503 // symbol at this address.
504 if (ObjectFile *obj_file = sc.module_sp->GetObjectFile())
505 sc.symbol =
506 obj_file->ResolveSymbolForAddress(so_addr, verify_unique);
507 }
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 FunctionNameType name_type_mask,
636 LanguageType language)
637 : m_name(name), m_lookup_name(), m_language(language) {
638 const char *name_cstr = name.GetCString();
639 llvm::StringRef basename;
640 llvm::StringRef context;
641
642 if (name_type_mask & eFunctionNameTypeAuto) {
644 m_name_type_mask = eFunctionNameTypeFull;
645 else if ((language == eLanguageTypeUnknown ||
646 Language::LanguageIsObjC(language)) &&
648 m_name_type_mask = eFunctionNameTypeFull;
649 else if (Language::LanguageIsC(language)) {
650 m_name_type_mask = eFunctionNameTypeFull;
651 } else {
652 if ((language == eLanguageTypeUnknown ||
653 Language::LanguageIsObjC(language)) &&
655 m_name_type_mask |= eFunctionNameTypeSelector;
656
657 CPlusPlusLanguage::MethodName cpp_method(name);
658 basename = cpp_method.GetBasename();
659 if (basename.empty()) {
661 basename))
662 m_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
663 else
664 m_name_type_mask |= eFunctionNameTypeFull;
665 } else {
666 m_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
667 }
668 }
669 } else {
670 m_name_type_mask = name_type_mask;
671 if (name_type_mask & eFunctionNameTypeMethod ||
672 name_type_mask & eFunctionNameTypeBase) {
673 // If they've asked for a CPP method or function name and it can't be
674 // that, we don't even need to search for CPP methods or names.
675 CPlusPlusLanguage::MethodName cpp_method(name);
676 if (cpp_method.IsValid()) {
677 basename = cpp_method.GetBasename();
678
679 if (!cpp_method.GetQualifiers().empty()) {
680 // There is a "const" or other qualifier following the end of the
681 // function parens, this can't be a eFunctionNameTypeBase
682 m_name_type_mask &= ~(eFunctionNameTypeBase);
683 if (m_name_type_mask == eFunctionNameTypeNone)
684 return;
685 }
686 } else {
687 // If the CPP method parser didn't manage to chop this up, try to fill
688 // in the base name if we can. If a::b::c is passed in, we need to just
689 // look up "c", and then we'll filter the result later.
691 basename);
692 }
693 }
694
695 if (name_type_mask & eFunctionNameTypeSelector) {
696 if (!ObjCLanguage::IsPossibleObjCSelector(name_cstr)) {
697 m_name_type_mask &= ~(eFunctionNameTypeSelector);
698 if (m_name_type_mask == eFunctionNameTypeNone)
699 return;
700 }
701 }
702
703 // Still try and get a basename in case someone specifies a name type mask
704 // of eFunctionNameTypeFull and a name like "A::func"
705 if (basename.empty()) {
706 if (name_type_mask & eFunctionNameTypeFull &&
708 CPlusPlusLanguage::MethodName cpp_method(name);
709 basename = cpp_method.GetBasename();
710 if (basename.empty())
712 basename);
713 }
714 }
715 }
716
717 if (!basename.empty()) {
718 // The name supplied was a partial C++ path like "a::count". In this case
719 // we want to do a lookup on the basename "count" and then make sure any
720 // matching results contain "a::count" so that it would match "b::a::count"
721 // and "a::count". This is why we set "match_name_after_lookup" to true
722 m_lookup_name.SetString(basename);
723 m_match_name_after_lookup = true;
724 } else {
725 // The name is already correct, just use the exact name as supplied, and we
726 // won't need to check if any matches contain "name"
727 m_lookup_name = name;
728 m_match_name_after_lookup = false;
729 }
730}
731
733 ConstString function_name, LanguageType language_type) const {
734 // We always keep unnamed symbols
735 if (!function_name)
736 return true;
737
738 // If we match exactly, we can return early
739 if (m_name == function_name)
740 return true;
741
742 // If function_name is mangled, we'll need to demangle it.
743 // In the pathologial case where the function name "looks" mangled but is
744 // actually demangled (e.g. a method named _Zonk), this operation should be
745 // relatively inexpensive since no demangling is actually occuring. See
746 // Mangled::SetValue for more context.
747 const bool function_name_may_be_mangled =
749 ConstString demangled_function_name = function_name;
750 if (function_name_may_be_mangled) {
751 Mangled mangled_function_name(function_name);
752 demangled_function_name = mangled_function_name.GetDemangledName();
753 }
754
755 // If the symbol has a language, then let the language make the match.
756 // Otherwise just check that the demangled function name contains the
757 // demangled user-provided name.
758 if (Language *language = Language::FindPlugin(language_type))
759 return language->DemangledNameContainsPath(m_name, demangled_function_name);
760
761 llvm::StringRef function_name_ref = demangled_function_name;
762 return function_name_ref.contains(m_name);
763}
764
766 size_t start_idx) const {
767 if (m_match_name_after_lookup && m_name) {
768 SymbolContext sc;
769 size_t i = start_idx;
770 while (i < sc_list.GetSize()) {
771 if (!sc_list.GetContextAtIndex(i, sc))
772 break;
773
774 bool keep_it =
775 NameMatchesLookupInfo(sc.GetFunctionName(), sc.GetLanguage());
776 if (keep_it)
777 ++i;
778 else
779 sc_list.RemoveContextAtIndex(i);
780 }
781 }
782
783 // If we have only full name matches we might have tried to set breakpoint on
784 // "func" and specified eFunctionNameTypeFull, but we might have found
785 // "a::func()", "a::b::func()", "c::func()", "func()" and "func". Only
786 // "func()" and "func" should end up matching.
787 if (m_name_type_mask == eFunctionNameTypeFull) {
788 SymbolContext sc;
789 size_t i = start_idx;
790 while (i < sc_list.GetSize()) {
791 if (!sc_list.GetContextAtIndex(i, sc))
792 break;
793 // Make sure the mangled and demangled names don't match before we try to
794 // pull anything out
796 ConstString full_name(sc.GetFunctionName());
797 if (mangled_name != m_name && full_name != m_name) {
798 CPlusPlusLanguage::MethodName cpp_method(full_name);
799 if (cpp_method.IsValid()) {
800 if (cpp_method.GetContext().empty()) {
801 if (cpp_method.GetBasename().compare(m_name) != 0) {
802 sc_list.RemoveContextAtIndex(i);
803 continue;
804 }
805 } else {
806 std::string qualified_name;
807 llvm::StringRef anon_prefix("(anonymous namespace)");
808 if (cpp_method.GetContext() == anon_prefix)
809 qualified_name = cpp_method.GetBasename().str();
810 else
811 qualified_name = cpp_method.GetScopeQualifiedName();
812 if (qualified_name != m_name.GetCString()) {
813 sc_list.RemoveContextAtIndex(i);
814 continue;
815 }
816 }
817 }
818 }
819 ++i;
820 }
821 }
822}
823
825 const CompilerDeclContext &parent_decl_ctx,
826 const ModuleFunctionSearchOptions &options,
827 SymbolContextList &sc_list) {
828 // Find all the functions (not symbols, but debug information functions...
829 if (SymbolFile *symbols = GetSymbolFile()) {
830 symbols->FindFunctions(lookup_info, parent_decl_ctx,
831 options.include_inlines, sc_list);
832 // Now check our symbol table for symbols that are code symbols if
833 // requested
834 if (options.include_symbols) {
835 if (Symtab *symtab = symbols->GetSymtab()) {
836 symtab->FindFunctionSymbols(lookup_info.GetLookupName(),
837 lookup_info.GetNameTypeMask(), sc_list);
838 }
839 }
840 }
841}
842
844 const CompilerDeclContext &parent_decl_ctx,
845 FunctionNameType name_type_mask,
846 const ModuleFunctionSearchOptions &options,
847 SymbolContextList &sc_list) {
848 const size_t old_size = sc_list.GetSize();
849 LookupInfo lookup_info(name, name_type_mask, eLanguageTypeUnknown);
850 FindFunctions(lookup_info, parent_decl_ctx, options, sc_list);
851 if (name_type_mask & eFunctionNameTypeAuto) {
852 const size_t new_size = sc_list.GetSize();
853 if (old_size < new_size)
854 lookup_info.Prune(sc_list, old_size);
855 }
856}
857
859 const ModuleFunctionSearchOptions &options,
860 SymbolContextList &sc_list) {
861 const size_t start_size = sc_list.GetSize();
862
863 if (SymbolFile *symbols = GetSymbolFile()) {
864 symbols->FindFunctions(regex, options.include_inlines, sc_list);
865
866 // Now check our symbol table for symbols that are code symbols if
867 // requested
868 if (options.include_symbols) {
869 Symtab *symtab = symbols->GetSymtab();
870 if (symtab) {
871 std::vector<uint32_t> symbol_indexes;
874 symbol_indexes);
875 const size_t num_matches = symbol_indexes.size();
876 if (num_matches) {
877 SymbolContext sc(this);
878 const size_t end_functions_added_index = sc_list.GetSize();
879 size_t num_functions_added_to_sc_list =
880 end_functions_added_index - start_size;
881 if (num_functions_added_to_sc_list == 0) {
882 // No functions were added, just symbols, so we can just append
883 // them
884 for (size_t i = 0; i < num_matches; ++i) {
885 sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]);
886 SymbolType sym_type = sc.symbol->GetType();
887 if (sc.symbol && (sym_type == eSymbolTypeCode ||
888 sym_type == eSymbolTypeResolver))
889 sc_list.Append(sc);
890 }
891 } else {
892 typedef std::map<lldb::addr_t, uint32_t> FileAddrToIndexMap;
893 FileAddrToIndexMap file_addr_to_index;
894 for (size_t i = start_size; i < end_functions_added_index; ++i) {
895 const SymbolContext &sc = sc_list[i];
896 if (sc.block)
897 continue;
898 file_addr_to_index[sc.function->GetAddressRange()
900 .GetFileAddress()] = i;
901 }
902
903 FileAddrToIndexMap::const_iterator end = file_addr_to_index.end();
904 // Functions were added so we need to merge symbols into any
905 // existing function symbol contexts
906 for (size_t i = start_size; i < num_matches; ++i) {
907 sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]);
908 SymbolType sym_type = sc.symbol->GetType();
909 if (sc.symbol && sc.symbol->ValueIsAddress() &&
910 (sym_type == eSymbolTypeCode ||
911 sym_type == eSymbolTypeResolver)) {
912 FileAddrToIndexMap::const_iterator pos =
913 file_addr_to_index.find(
915 if (pos == end)
916 sc_list.Append(sc);
917 else
918 sc_list[pos->second].symbol = sc.symbol;
919 }
920 }
921 }
922 }
923 }
924 }
925 }
926}
927
929 const FileSpec &file, uint32_t line,
930 Function *function,
931 std::vector<Address> &output_local,
932 std::vector<Address> &output_extern) {
933 SearchFilterByModule filter(target_sp, m_file);
934
935 // TODO: Handle SourceLocationSpec column information
936 SourceLocationSpec location_spec(file, line, /*column=*/std::nullopt,
937 /*check_inlines=*/true,
938 /*exact_match=*/false);
939 AddressResolverFileLine resolver(location_spec);
940 resolver.ResolveAddress(filter);
941
942 for (size_t n = 0; n < resolver.GetNumberOfAddresses(); n++) {
943 Address addr = resolver.GetAddressRangeAtIndex(n).GetBaseAddress();
945 if (f && f == function)
946 output_local.push_back(addr);
947 else
948 output_extern.push_back(addr);
949 }
950}
951
953 ConstString name, const CompilerDeclContext &parent_decl_ctx,
954 size_t max_matches,
955 llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
956 TypeMap &types) {
957 if (SymbolFile *symbols = GetSymbolFile())
958 symbols->FindTypes(name, parent_decl_ctx, max_matches,
959 searched_symbol_files, types);
960}
961
963 const CompilerDeclContext &parent_decl_ctx,
964 size_t max_matches, TypeList &type_list) {
965 TypeMap types_map;
966 llvm::DenseSet<lldb_private::SymbolFile *> searched_symbol_files;
967 FindTypes_Impl(type_name, parent_decl_ctx, max_matches, searched_symbol_files,
968 types_map);
969 if (types_map.GetSize()) {
970 SymbolContext sc;
971 sc.module_sp = shared_from_this();
972 sc.SortTypeList(types_map, type_list);
973 }
974}
975
977 bool exact_match) {
978 TypeList type_list;
979 llvm::DenseSet<lldb_private::SymbolFile *> searched_symbol_files;
980 FindTypes(name, exact_match, 1, searched_symbol_files, type_list);
981 if (type_list.GetSize())
982 return type_list.GetTypeAtIndex(0);
983 return TypeSP();
984}
985
987 ConstString name, bool exact_match, size_t max_matches,
988 llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
989 TypeList &types) {
990 const char *type_name_cstr = name.GetCString();
991 llvm::StringRef type_scope;
992 llvm::StringRef type_basename;
993 TypeClass type_class = eTypeClassAny;
994 TypeMap typesmap;
995
996 if (Type::GetTypeScopeAndBasename(type_name_cstr, type_scope, type_basename,
997 type_class)) {
998 // Check if "name" starts with "::" which means the qualified type starts
999 // from the root namespace and implies and exact match. The typenames we
1000 // get back from clang do not start with "::" so we need to strip this off
1001 // in order to get the qualified names to match
1002 exact_match = type_scope.consume_front("::");
1003
1004 ConstString type_basename_const_str(type_basename);
1005 FindTypes_Impl(type_basename_const_str, CompilerDeclContext(), max_matches,
1006 searched_symbol_files, typesmap);
1007 if (typesmap.GetSize())
1008 typesmap.RemoveMismatchedTypes(type_scope, type_basename, type_class,
1009 exact_match);
1010 } else {
1011 // The type is not in a namespace/class scope, just search for it by
1012 // basename
1013 if (type_class != eTypeClassAny && !type_basename.empty()) {
1014 // The "type_name_cstr" will have been modified if we have a valid type
1015 // class prefix (like "struct", "class", "union", "typedef" etc).
1017 UINT_MAX, searched_symbol_files, typesmap);
1018 typesmap.RemoveMismatchedTypes(type_scope, type_basename, type_class,
1019 exact_match);
1020 } else {
1021 FindTypes_Impl(name, CompilerDeclContext(), UINT_MAX,
1022 searched_symbol_files, typesmap);
1023 if (exact_match) {
1024 typesmap.RemoveMismatchedTypes(type_scope, name, type_class,
1025 exact_match);
1026 }
1027 }
1028 }
1029 if (typesmap.GetSize()) {
1030 SymbolContext sc;
1031 sc.module_sp = shared_from_this();
1032 sc.SortTypeList(typesmap, types);
1033 }
1034}
1035
1037 llvm::ArrayRef<CompilerContext> pattern, LanguageSet languages,
1038 llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
1039 TypeMap &types) {
1040 // If a scoped timer is needed, place it in a SymbolFile::FindTypes override.
1041 // A timer here is too high volume for some cases, for example when calling
1042 // FindTypes on each object file.
1043 if (SymbolFile *symbols = GetSymbolFile())
1044 symbols->FindTypes(pattern, languages, searched_symbol_files, types);
1045}
1046
1049 Debugger::DebuggerList requestors
1051 Debugger::DebuggerList interruptors;
1052 if (requestors.empty())
1053 return interruptors;
1054
1055 for (auto debugger_sp : requestors) {
1056 if (!debugger_sp->InterruptRequested())
1057 continue;
1058 if (debugger_sp->GetTargetList()
1059 .AnyTargetContainsModule(module))
1060 interruptors.push_back(debugger_sp);
1061 }
1062 return interruptors;
1063}
1064
1065SymbolFile *Module::GetSymbolFile(bool can_create, Stream *feedback_strm) {
1066 if (!m_did_load_symfile.load()) {
1067 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1068 if (!m_did_load_symfile.load() && can_create) {
1069 Debugger::DebuggerList interruptors
1071 if (!interruptors.empty()) {
1072 for (auto debugger_sp : interruptors) {
1073 REPORT_INTERRUPTION(*(debugger_sp.get()),
1074 "Interrupted fetching symbols for module {0}",
1075 this->GetFileSpec());
1076 }
1077 return nullptr;
1078 }
1079 ObjectFile *obj_file = GetObjectFile();
1080 if (obj_file != nullptr) {
1082 m_symfile_up.reset(
1083 SymbolVendor::FindPlugin(shared_from_this(), feedback_strm));
1084 m_did_load_symfile = true;
1085 }
1086 }
1087 }
1088 return m_symfile_up ? m_symfile_up->GetSymbolFile() : nullptr;
1089}
1090
1092 if (SymbolFile *symbols = GetSymbolFile())
1093 return symbols->GetSymtab();
1094 return nullptr;
1095}
1096
1098 ConstString object_name) {
1099 // Container objects whose paths do not specify a file directly can call this
1100 // function to correct the file and object names.
1101 m_file = file;
1103 m_object_name = object_name;
1104}
1105
1106const ArchSpec &Module::GetArchitecture() const { return m_arch; }
1107
1109 std::string spec(GetFileSpec().GetPath());
1110 if (m_object_name) {
1111 spec += '(';
1112 spec += m_object_name.GetCString();
1113 spec += ')';
1114 }
1115 return spec;
1116}
1117
1118void Module::GetDescription(llvm::raw_ostream &s,
1119 lldb::DescriptionLevel level) {
1120 if (level >= eDescriptionLevelFull) {
1121 if (m_arch.IsValid())
1122 s << llvm::formatv("({0}) ", m_arch.GetArchitectureName());
1123 }
1124
1125 if (level == eDescriptionLevelBrief) {
1126 const char *filename = m_file.GetFilename().GetCString();
1127 if (filename)
1128 s << filename;
1129 } else {
1130 char path[PATH_MAX];
1131 if (m_file.GetPath(path, sizeof(path)))
1132 s << path;
1133 }
1134
1135 const char *object_name = m_object_name.GetCString();
1136 if (object_name)
1137 s << llvm::formatv("({0})", object_name);
1138}
1139
1141 // We have provided the DataBuffer for this module to avoid accessing the
1142 // filesystem. We never want to reload those files.
1143 if (m_data_sp)
1144 return false;
1145 if (!m_file_has_changed)
1148 return m_file_has_changed;
1149}
1150
1152 std::optional<lldb::user_id_t> debugger_id) {
1153 ConstString file_name = GetFileSpec().GetFilename();
1154 if (file_name.IsEmpty())
1155 return;
1156
1157 StreamString ss;
1158 ss << file_name
1159 << " was compiled with optimization - stepping may behave "
1160 "oddly; variables may not be available.";
1161 Debugger::ReportWarning(std::string(ss.GetString()), debugger_id,
1163}
1164
1166 LanguageType language, std::optional<lldb::user_id_t> debugger_id) {
1167 StreamString ss;
1168 ss << "This version of LLDB has no plugin for the language \""
1170 << "\". "
1171 "Inspection of frame variables will be limited.";
1172 Debugger::ReportWarning(std::string(ss.GetString()), debugger_id,
1174}
1175
1177 const llvm::formatv_object_base &payload) {
1179 if (FileHasChanged()) {
1181 StreamString strm;
1182 strm.PutCString("the object file ");
1184 strm.PutCString(" has been modified\n");
1185 strm.PutCString(payload.str());
1186 strm.PutCString("The debug session should be aborted as the original "
1187 "debug information has been overwritten.");
1188 Debugger::ReportError(std::string(strm.GetString()));
1189 }
1190 }
1191}
1192
1193void Module::ReportError(const llvm::formatv_object_base &payload) {
1194 StreamString strm;
1196 strm.PutChar(' ');
1197 strm.PutCString(payload.str());
1198 Debugger::ReportError(strm.GetString().str());
1199}
1200
1201void Module::ReportWarning(const llvm::formatv_object_base &payload) {
1202 StreamString strm;
1204 strm.PutChar(' ');
1205 strm.PutCString(payload.str());
1206 Debugger::ReportWarning(std::string(strm.GetString()));
1207}
1208
1209void Module::LogMessage(Log *log, const llvm::formatv_object_base &payload) {
1210 StreamString log_message;
1212 log_message.PutCString(": ");
1213 log_message.PutCString(payload.str());
1214 log->PutCString(log_message.GetData());
1215}
1216
1218 Log *log, const llvm::formatv_object_base &payload) {
1219 StreamString log_message;
1221 log_message.PutCString(": ");
1222 log_message.PutCString(payload.str());
1223 if (log->GetVerbose()) {
1224 std::string back_trace;
1225 llvm::raw_string_ostream stream(back_trace);
1226 llvm::sys::PrintStackTrace(stream);
1227 log_message.PutCString(back_trace);
1228 }
1229 log->PutCString(log_message.GetData());
1230}
1231
1233 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1234 // s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
1235 s->Indent();
1236 s->Printf("Module %s%s%s%s\n", m_file.GetPath().c_str(),
1237 m_object_name ? "(" : "",
1239 m_object_name ? ")" : "");
1240
1241 s->IndentMore();
1242
1243 ObjectFile *objfile = GetObjectFile();
1244 if (objfile)
1245 objfile->Dump(s);
1246
1247 if (SymbolFile *symbols = GetSymbolFile())
1248 symbols->Dump(*s);
1249
1250 s->IndentLess();
1251}
1252
1254
1256 if (!m_did_load_objfile.load()) {
1257 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1258 if (!m_did_load_objfile.load()) {
1259 LLDB_SCOPED_TIMERF("Module::GetObjectFile () module = %s",
1260 GetFileSpec().GetFilename().AsCString(""));
1261 lldb::offset_t data_offset = 0;
1262 lldb::offset_t file_size = 0;
1263
1264 if (m_data_sp)
1265 file_size = m_data_sp->GetByteSize();
1266 else if (m_file)
1268
1269 if (file_size > m_object_offset) {
1270 m_did_load_objfile = true;
1271 // FindPlugin will modify its data_sp argument. Do not let it
1272 // modify our m_data_sp member.
1273 auto data_sp = m_data_sp;
1275 shared_from_this(), &m_file, m_object_offset,
1276 file_size - m_object_offset, data_sp, data_offset);
1277 if (m_objfile_sp) {
1278 // Once we get the object file, update our module with the object
1279 // file's architecture since it might differ in vendor/os if some
1280 // parts were unknown. But since the matching arch might already be
1281 // more specific than the generic COFF architecture, only merge in
1282 // those values that overwrite unspecified unknown values.
1283 m_arch.MergeFrom(m_objfile_sp->GetArchitecture());
1284 } else {
1285 ReportError("failed to load objfile for {0}\nDebugging will be "
1286 "degraded for this module.",
1287 GetFileSpec().GetPath().c_str());
1288 }
1289 }
1290 }
1291 }
1292 return m_objfile_sp.get();
1293}
1294
1296 // Populate m_sections_up with sections from objfile.
1297 if (!m_sections_up) {
1298 ObjectFile *obj_file = GetObjectFile();
1299 if (obj_file != nullptr)
1301 }
1302 return m_sections_up.get();
1303}
1304
1306 ObjectFile *obj_file = GetObjectFile();
1307 if (obj_file)
1308 obj_file->SectionFileAddressesChanged();
1309 if (SymbolFile *symbols = GetSymbolFile())
1310 symbols->SectionFileAddressesChanged();
1311}
1312
1314 if (!m_unwind_table) {
1315 m_unwind_table.emplace(*this);
1316 if (!m_symfile_spec)
1318 }
1319 return *m_unwind_table;
1320}
1321
1323 if (!m_sections_up)
1324 m_sections_up = std::make_unique<SectionList>();
1325 return m_sections_up.get();
1326}
1327
1329 SymbolType symbol_type) {
1331 "Module::FindFirstSymbolWithNameAndType (name = %s, type = %i)",
1332 name.AsCString(), symbol_type);
1333 if (Symtab *symtab = GetSymtab())
1334 return symtab->FindFirstSymbolWithNameAndType(
1335 name, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny);
1336 return nullptr;
1337}
1339 Symtab *symtab, std::vector<uint32_t> &symbol_indexes,
1340 SymbolContextList &sc_list) {
1341 // No need to protect this call using m_mutex all other method calls are
1342 // already thread safe.
1343
1344 size_t num_indices = symbol_indexes.size();
1345 if (num_indices > 0) {
1346 SymbolContext sc;
1348 for (size_t i = 0; i < num_indices; i++) {
1349 sc.symbol = symtab->SymbolAtIndex(symbol_indexes[i]);
1350 if (sc.symbol)
1351 sc_list.Append(sc);
1352 }
1353 }
1354}
1355
1356void Module::FindFunctionSymbols(ConstString name, uint32_t name_type_mask,
1357 SymbolContextList &sc_list) {
1358 LLDB_SCOPED_TIMERF("Module::FindSymbolsFunctions (name = %s, mask = 0x%8.8x)",
1359 name.AsCString(), name_type_mask);
1360 if (Symtab *symtab = GetSymtab())
1361 symtab->FindFunctionSymbols(name, name_type_mask, sc_list);
1362}
1363
1365 SymbolType symbol_type,
1366 SymbolContextList &sc_list) {
1367 // No need to protect this call using m_mutex all other method calls are
1368 // already thread safe.
1369 if (Symtab *symtab = GetSymtab()) {
1370 std::vector<uint32_t> symbol_indexes;
1371 symtab->FindAllSymbolsWithNameAndType(name, symbol_type, symbol_indexes);
1372 SymbolIndicesToSymbolContextList(symtab, symbol_indexes, sc_list);
1373 }
1374}
1375
1377 const RegularExpression &regex, SymbolType symbol_type,
1378 SymbolContextList &sc_list, Mangled::NamePreference mangling_preference) {
1379 // No need to protect this call using m_mutex all other method calls are
1380 // already thread safe.
1382 "Module::FindSymbolsMatchingRegExAndType (regex = %s, type = %i)",
1383 regex.GetText().str().c_str(), symbol_type);
1384 if (Symtab *symtab = GetSymtab()) {
1385 std::vector<uint32_t> symbol_indexes;
1386 symtab->FindAllSymbolsMatchingRexExAndType(
1387 regex, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny,
1388 symbol_indexes, mangling_preference);
1389 SymbolIndicesToSymbolContextList(symtab, symbol_indexes, sc_list);
1390 }
1391}
1392
1394 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1395 SymbolFile *sym_file = GetSymbolFile();
1396 if (!sym_file)
1397 return;
1398
1399 // Load the object file symbol table and any symbols from the SymbolFile that
1400 // get appended using SymbolFile::AddSymbols(...).
1401 if (Symtab *symtab = sym_file->GetSymtab())
1402 symtab->PreloadSymbols();
1403
1404 // Now let the symbol file preload its data and the symbol table will be
1405 // available without needing to take the module lock.
1406 sym_file->PreloadSymbols();
1407}
1408
1410 if (!FileSystem::Instance().Exists(file))
1411 return;
1412 if (m_symfile_up) {
1413 // Remove any sections in the unified section list that come from the
1414 // current symbol vendor.
1415 SectionList *section_list = GetSectionList();
1416 SymbolFile *symbol_file = GetSymbolFile();
1417 if (section_list && symbol_file) {
1418 ObjectFile *obj_file = symbol_file->GetObjectFile();
1419 // Make sure we have an object file and that the symbol vendor's objfile
1420 // isn't the same as the module's objfile before we remove any sections
1421 // for it...
1422 if (obj_file) {
1423 // Check to make sure we aren't trying to specify the file we already
1424 // have
1425 if (obj_file->GetFileSpec() == file) {
1426 // We are being told to add the exact same file that we already have
1427 // we don't have to do anything.
1428 return;
1429 }
1430
1431 // Cleare the current symtab as we are going to replace it with a new
1432 // one
1433 obj_file->ClearSymtab();
1434
1435 // Clear the unwind table too, as that may also be affected by the
1436 // symbol file information.
1437 m_unwind_table.reset();
1438
1439 // The symbol file might be a directory bundle ("/tmp/a.out.dSYM")
1440 // instead of a full path to the symbol file within the bundle
1441 // ("/tmp/a.out.dSYM/Contents/Resources/DWARF/a.out"). So we need to
1442 // check this
1443
1444 if (FileSystem::Instance().IsDirectory(file)) {
1445 std::string new_path(file.GetPath());
1446 std::string old_path(obj_file->GetFileSpec().GetPath());
1447 if (llvm::StringRef(old_path).startswith(new_path)) {
1448 // We specified the same bundle as the symbol file that we already
1449 // have
1450 return;
1451 }
1452 }
1453
1454 if (obj_file != m_objfile_sp.get()) {
1455 size_t num_sections = section_list->GetNumSections(0);
1456 for (size_t idx = num_sections; idx > 0; --idx) {
1457 lldb::SectionSP section_sp(
1458 section_list->GetSectionAtIndex(idx - 1));
1459 if (section_sp->GetObjectFile() == obj_file) {
1460 section_list->DeleteSection(idx - 1);
1461 }
1462 }
1463 }
1464 }
1465 }
1466 // Keep all old symbol files around in case there are any lingering type
1467 // references in any SBValue objects that might have been handed out.
1468 m_old_symfiles.push_back(std::move(m_symfile_up));
1469 }
1470 m_symfile_spec = file;
1471 m_symfile_up.reset();
1472 m_did_load_symfile = false;
1473}
1474
1476 if (GetObjectFile() == nullptr)
1477 return false;
1478 else
1479 return GetObjectFile()->IsExecutable();
1480}
1481
1483 ObjectFile *obj_file = GetObjectFile();
1484 if (obj_file) {
1485 SectionList *sections = GetSectionList();
1486 if (sections != nullptr) {
1487 size_t num_sections = sections->GetSize();
1488 for (size_t sect_idx = 0; sect_idx < num_sections; sect_idx++) {
1489 SectionSP section_sp = sections->GetSectionAtIndex(sect_idx);
1490 if (section_sp->GetLoadBaseAddress(target) != LLDB_INVALID_ADDRESS) {
1491 return true;
1492 }
1493 }
1494 }
1495 }
1496 return false;
1497}
1498
1500 Stream &feedback_stream) {
1501 if (!target) {
1502 error.SetErrorString("invalid destination Target");
1503 return false;
1504 }
1505
1506 LoadScriptFromSymFile should_load =
1507 target->TargetProperties::GetLoadScriptFromSymbolFile();
1508
1509 if (should_load == eLoadScriptFromSymFileFalse)
1510 return false;
1511
1512 Debugger &debugger = target->GetDebugger();
1513 const ScriptLanguage script_language = debugger.GetScriptLanguage();
1514 if (script_language != eScriptLanguageNone) {
1515
1516 PlatformSP platform_sp(target->GetPlatform());
1517
1518 if (!platform_sp) {
1519 error.SetErrorString("invalid Platform");
1520 return false;
1521 }
1522
1523 FileSpecList file_specs = platform_sp->LocateExecutableScriptingResources(
1524 target, *this, feedback_stream);
1525
1526 const uint32_t num_specs = file_specs.GetSize();
1527 if (num_specs) {
1528 ScriptInterpreter *script_interpreter = debugger.GetScriptInterpreter();
1529 if (script_interpreter) {
1530 for (uint32_t i = 0; i < num_specs; ++i) {
1531 FileSpec scripting_fspec(file_specs.GetFileSpecAtIndex(i));
1532 if (scripting_fspec &&
1533 FileSystem::Instance().Exists(scripting_fspec)) {
1534 if (should_load == eLoadScriptFromSymFileWarn) {
1535 feedback_stream.Printf(
1536 "warning: '%s' contains a debug script. To run this script "
1537 "in "
1538 "this debug session:\n\n command script import "
1539 "\"%s\"\n\n"
1540 "To run all discovered debug scripts in this session:\n\n"
1541 " settings set target.load-script-from-symbol-file "
1542 "true\n",
1543 GetFileSpec().GetFileNameStrippingExtension().GetCString(),
1544 scripting_fspec.GetPath().c_str());
1545 return false;
1546 }
1547 StreamString scripting_stream;
1548 scripting_fspec.Dump(scripting_stream.AsRawOstream());
1549 LoadScriptOptions options;
1550 bool did_load = script_interpreter->LoadScriptingModule(
1551 scripting_stream.GetData(), options, error);
1552 if (!did_load)
1553 return false;
1554 }
1555 }
1556 } else {
1557 error.SetErrorString("invalid ScriptInterpreter");
1558 return false;
1559 }
1560 }
1561 }
1562 return true;
1563}
1564
1565bool Module::SetArchitecture(const ArchSpec &new_arch) {
1566 if (!m_arch.IsValid()) {
1567 m_arch = new_arch;
1568 return true;
1569 }
1570 return m_arch.IsCompatibleMatch(new_arch);
1571}
1572
1574 bool value_is_offset, bool &changed) {
1575 ObjectFile *object_file = GetObjectFile();
1576 if (object_file != nullptr) {
1577 changed = object_file->SetLoadAddress(target, value, value_is_offset);
1578 return true;
1579 } else {
1580 changed = false;
1581 }
1582 return false;
1583}
1584
1585bool Module::MatchesModuleSpec(const ModuleSpec &module_ref) {
1586 const UUID &uuid = module_ref.GetUUID();
1587
1588 if (uuid.IsValid()) {
1589 // If the UUID matches, then nothing more needs to match...
1590 return (uuid == GetUUID());
1591 }
1592
1593 const FileSpec &file_spec = module_ref.GetFileSpec();
1594 if (!FileSpec::Match(file_spec, m_file) &&
1595 !FileSpec::Match(file_spec, m_platform_file))
1596 return false;
1597
1598 const FileSpec &platform_file_spec = module_ref.GetPlatformFileSpec();
1599 if (!FileSpec::Match(platform_file_spec, GetPlatformFileSpec()))
1600 return false;
1601
1602 const ArchSpec &arch = module_ref.GetArchitecture();
1603 if (arch.IsValid()) {
1604 if (!m_arch.IsCompatibleMatch(arch))
1605 return false;
1606 }
1607
1608 ConstString object_name = module_ref.GetObjectName();
1609 if (object_name) {
1610 if (object_name != GetObjectName())
1611 return false;
1612 }
1613 return true;
1614}
1615
1616bool Module::FindSourceFile(const FileSpec &orig_spec,
1617 FileSpec &new_spec) const {
1618 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1619 if (auto remapped = m_source_mappings.FindFile(orig_spec)) {
1620 new_spec = *remapped;
1621 return true;
1622 }
1623 return false;
1624}
1625
1626std::optional<std::string> Module::RemapSourceFile(llvm::StringRef path) const {
1627 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1628 if (auto remapped = m_source_mappings.RemapPath(path))
1629 return remapped->GetPath();
1630 return {};
1631}
1632
1633void Module::RegisterXcodeSDK(llvm::StringRef sdk_name,
1634 llvm::StringRef sysroot) {
1635 auto sdk_path_or_err =
1636 HostInfo::GetSDKRoot(HostInfo::SDKOptions{sdk_name.str()});
1637
1638 if (!sdk_path_or_err) {
1639 Debugger::ReportError("Error while searching for Xcode SDK: " +
1640 toString(sdk_path_or_err.takeError()));
1641 return;
1642 }
1643
1644 auto sdk_path = *sdk_path_or_err;
1645 if (sdk_path.empty())
1646 return;
1647 // If the SDK changed for a previously registered source path, update it.
1648 // This could happend with -fdebug-prefix-map, otherwise it's unlikely.
1649 if (!m_source_mappings.Replace(sysroot, sdk_path, true))
1650 // In the general case, however, append it to the list.
1651 m_source_mappings.Append(sysroot, sdk_path, false);
1652}
1653
1654bool Module::MergeArchitecture(const ArchSpec &arch_spec) {
1655 if (!arch_spec.IsValid())
1656 return false;
1658 "module has arch %s, merging/replacing with arch %s",
1659 m_arch.GetTriple().getTriple().c_str(),
1660 arch_spec.GetTriple().getTriple().c_str());
1661 if (!m_arch.IsCompatibleMatch(arch_spec)) {
1662 // The new architecture is different, we just need to replace it.
1663 return SetArchitecture(arch_spec);
1664 }
1665
1666 // Merge bits from arch_spec into "merged_arch" and set our architecture.
1667 ArchSpec merged_arch(m_arch);
1668 merged_arch.MergeFrom(arch_spec);
1669 // SetArchitecture() is a no-op if m_arch is already valid.
1670 m_arch = ArchSpec();
1671 return SetArchitecture(merged_arch);
1672}
1673
1674llvm::VersionTuple Module::GetVersion() {
1675 if (ObjectFile *obj_file = GetObjectFile())
1676 return obj_file->GetVersion();
1677 return llvm::VersionTuple();
1678}
1679
1681 ObjectFile *obj_file = GetObjectFile();
1682
1683 if (obj_file)
1684 return obj_file->GetIsDynamicLinkEditor();
1685
1686 return false;
1687}
1688
1689uint32_t Module::Hash() {
1690 std::string identifier;
1691 llvm::raw_string_ostream id_strm(identifier);
1692 id_strm << m_arch.GetTriple().str() << '-' << m_file.GetPath();
1693 if (m_object_name)
1694 id_strm << '(' << m_object_name << ')';
1695 if (m_object_offset > 0)
1696 id_strm << m_object_offset;
1697 const auto mtime = llvm::sys::toTimeT(m_object_mod_time);
1698 if (mtime > 0)
1699 id_strm << mtime;
1700 return llvm::djbHash(id_strm.str());
1701}
1702
1703std::string Module::GetCacheKey() {
1704 std::string key;
1705 llvm::raw_string_ostream strm(key);
1706 strm << m_arch.GetTriple().str() << '-' << m_file.GetFilename();
1707 if (m_object_name)
1708 strm << '(' << m_object_name << ')';
1709 strm << '-' << llvm::format_hex(Hash(), 10);
1710 return strm.str();
1711}
1712
1714 if (!ModuleList::GetGlobalModuleListProperties().GetEnableLLDBIndexCache())
1715 return nullptr;
1716 // NOTE: intentional leak so we don't crash if global destructor chain gets
1717 // called as other threads still use the result of this function
1718 static DataFileCache *g_data_file_cache =
1720 .GetLLDBIndexCachePath()
1721 .GetPath());
1722 return g_data_file_cache;
1723}
static llvm::raw_ostream & error(Stream &strm)
#define REPORT_INTERRUPTION(debugger,...)
Definition: Debugger.h:480
#define lldbassert(x)
Definition: LLDBAssert.h:15
#define LLDB_LOGF(log,...)
Definition: Log.h:349
std::vector< Module * > ModuleCollection
Definition: Module.cpp:90
static ModuleCollection & GetModuleCollection()
Definition: Module.cpp:92
static Debugger::DebuggerList DebuggersOwningModuleRequestingInterruption(Module &module)
Definition: Module.cpp:1048
#define LLDB_SCOPED_TIMER()
Definition: Timer.h:83
#define LLDB_SCOPED_TIMERF(...)
Definition: Timer.h:86
A section + offset based address range class.
Definition: AddressRange.h:25
Address & GetBaseAddress()
Get accessor for the base address of the range.
Definition: AddressRange.h:209
lldb::addr_t GetByteSize() const
Get accessor for the byte size of this range.
Definition: AddressRange.h:221
"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:59
bool ResolveAddressUsingFileSections(lldb::addr_t addr, const SectionList *sections)
Resolve a file virtual address using a section list.
Definition: Address.cpp:248
lldb::SectionSP GetSection() const
Get const accessor for the section.
Definition: Address.h:429
Function * CalculateSymbolContextFunction() const
Definition: Address.cpp:865
bool Slide(int64_t offset)
Definition: Address.h:449
lldb::addr_t GetFileAddress() const
Get the file address.
Definition: Address.cpp:291
lldb::addr_t GetOffset() const
Get the section relative offset value.
Definition: Address.h:319
bool IsSectionOffset() const
Check if an address is section offset.
Definition: Address.h:332
An architecture specification class.
Definition: ArchSpec.h:31
bool IsValid() const
Tests if this ArchSpec is valid.
Definition: ArchSpec.h:348
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition: ArchSpec.h:450
void MergeFrom(const ArchSpec &other)
Merges fields from another ArchSpec into this ArchSpec.
Definition: ArchSpec.cpp:809
bool IsCompatibleMatch(const ArchSpec &rhs) const
Shorthand for IsMatch(rhs, CompatibleMatch).
Definition: ArchSpec.h:502
const char * GetArchitectureName() const
Returns a static string representing the current architecture.
Definition: ArchSpec.cpp:552
static bool IsCPPMangledName(llvm::StringRef name)
static bool ExtractContextAndIdentifier(const char *name, llvm::StringRef &context, llvm::StringRef &identifier)
const FileSpec & GetPrimaryFile() const
Return the primary source file associated with this compile unit.
Definition: CompileUnit.h:227
void ForeachFunction(llvm::function_ref< bool(const lldb::FunctionSP &)> lambda) const
Apply a lambda to each function in this compile unit.
Definition: CompileUnit.cpp:61
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.
Definition: ConstString.h:182
bool IsEmpty() const
Test for empty string.
Definition: ConstString.h:293
void SetString(llvm::StringRef s)
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:205
This class enables data to be cached into a directory using the llvm caching code.
Definition: DataFileCache.h:45
A class to manage flag bits.
Definition: Debugger.h:79
static void ReportWarning(std::string message, std::optional< lldb::user_id_t > debugger_id=std::nullopt, std::once_flag *once=nullptr)
Report warning events.
Definition: Debugger.cpp:1532
lldb::ScriptLanguage GetScriptLanguage() const
Definition: Debugger.cpp:344
static void ReportError(std::string message, std::optional< lldb::user_id_t > debugger_id=std::nullopt, std::once_flag *once=nullptr)
Report error events.
Definition: Debugger.cpp:1539
ScriptInterpreter * GetScriptInterpreter(bool can_create=true, std::optional< lldb::ScriptLanguage > language={})
Definition: Debugger.cpp:1632
std::vector< lldb::DebuggerSP > DebuggerList
Definition: Debugger.h:89
static DebuggerList DebuggersRequestingInterruption()
Definition: Debugger.cpp:1309
A file collection class.
Definition: FileSpecList.h:24
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:304
const ConstString & GetFilename() const
Filename string const get accessor.
Definition: FileSpec.h:245
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Definition: FileSpec.cpp:370
void Dump(llvm::raw_ostream &s) const
Dump this object to a Stream.
Definition: FileSpec.cpp:328
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:399
const AddressRange & GetAddressRange()
Definition: Function.h:447
static Language * FindPlugin(lldb::LanguageType language)
Definition: Language.cpp:53
static const char * GetNameForLanguageType(lldb::LanguageType language)
Definition: Language.cpp:235
static bool LanguageIsC(lldb::LanguageType language)
Definition: Language.cpp:293
static bool LanguageIsObjC(lldb::LanguageType language)
Definition: Language.cpp:283
void PutCString(const char *cstr)
Definition: Log.cpp:134
bool GetVerbose() const
Definition: Log.cpp:313
A class that handles mangled names.
Definition: Mangled.h:33
static Mangled::ManglingScheme GetManglingScheme(llvm::StringRef const name)
Try to identify the mangling scheme used.
Definition: Mangled.cpp:41
ConstString GetDemangledName() const
Demangled name get accessor.
Definition: Mangled.cpp:260
static ModuleListProperties & GetGlobalModuleListProperties()
Definition: ModuleList.cpp:751
bool FindMatchingModuleSpec(const ModuleSpec &module_spec, ModuleSpec &match_module_spec) const
Definition: ModuleSpec.h:333
uint64_t GetObjectOffset() const
Definition: ModuleSpec.h:107
ConstString & GetObjectName()
Definition: ModuleSpec.h:103
FileSpec & GetPlatformFileSpec()
Definition: ModuleSpec.h:65
FileSpec & GetFileSpec()
Definition: ModuleSpec.h:53
lldb::DataBufferSP GetData() const
Definition: ModuleSpec.h:127
ArchSpec & GetArchitecture()
Definition: ModuleSpec.h:89
FileSpec & GetSymbolFileSpec()
Definition: ModuleSpec.h:77
llvm::sys::TimePoint & GetObjectModificationTime()
Definition: ModuleSpec.h:117
A class that encapsulates name lookup information.
Definition: Module.h:949
lldb::FunctionNameType GetNameTypeMask() const
Definition: Module.h:964
ConstString GetLookupName() const
Definition: Module.h:960
bool NameMatchesLookupInfo(ConstString function_name, lldb::LanguageType language_type=lldb::eLanguageTypeUnknown) const
Definition: Module.cpp:732
ConstString m_name
What the user originally typed.
Definition: Module.h:980
void Prune(SymbolContextList &sc_list, size_t start_idx) const
Definition: Module.cpp:765
A class that describes an executable image and its associated object and symbol files.
Definition: Module.h:88
const lldb_private::UUID & GetUUID()
Get a reference to the UUID value contained in this object.
Definition: Module.cpp:340
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:1092
void ReportWarningOptimization(std::optional< lldb::user_id_t > debugger_id)
Definition: Module.cpp:1151
std::once_flag m_optimization_warning
Definition: Module.h:1105
lldb::TypeSP FindFirstType(const SymbolContext &sc, ConstString type_name, bool exact_match)
Definition: Module.cpp:976
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:1083
llvm::sys::TimePoint m_object_mod_time
Definition: Module.h:1059
virtual ObjectFile * GetObjectFile()
Get the object file representation for the current architecture.
Definition: Module.cpp:1255
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:840
FileSpec m_file
The file representation on disk for this module (if there is one).
Definition: Module.h:1045
void FindTypes(ConstString type_name, bool exact_match, size_t max_matches, llvm::DenseSet< lldb_private::SymbolFile * > &searched_symbol_files, TypeList &types)
Find types by name.
Definition: Module.cpp:986
virtual SymbolFile * GetSymbolFile(bool can_create=true, Stream *feedback_strm=nullptr)
Get the module's symbol file.
Definition: Module.cpp:1065
static DataFileCache * GetIndexCache()
Get the global index file cache.
Definition: Module.cpp:1713
std::vector< lldb::SymbolVendorUP > m_old_symfiles
If anyone calls Module::SetSymbolFileFileSpec() and changes the symbol file,.
Definition: Module.h:1075
void ReportWarningUnsupportedLanguage(lldb::LanguageType language, std::optional< lldb::user_id_t > debugger_id)
Definition: Module.cpp:1165
void FindTypes_Impl(ConstString name, const CompilerDeclContext &parent_decl_ctx, size_t max_matches, llvm::DenseSet< lldb_private::SymbolFile * > &searched_symbol_files, TypeMap &types)
Definition: Module.cpp:952
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:1253
uint32_t Hash()
Get a unique hash for this module.
Definition: Module.cpp:1689
lldb::ModuleSP CalculateSymbolContextModule() override
Definition: Module.cpp:412
void FindTypesInNamespace(ConstString type_name, const CompilerDeclContext &parent_decl_ctx, size_t max_matches, TypeList &type_list)
Find types by name that are in a namespace.
Definition: Module.cpp:962
std::once_flag m_language_warning
Definition: Module.h:1106
static Module * GetAllocatedModuleAtIndex(size_t idx)
Definition: Module.cpp:124
UUID m_uuid
Each module is assumed to have a unique identifier to help match it up to debug symbols.
Definition: Module.h:1043
std::optional< std::string > RemapSourceFile(llvm::StringRef path) const
Remaps a source file given path into new_path.
Definition: Module.cpp:1626
llvm::sys::TimePoint m_mod_time
The modification time for this module when it was created.
Definition: Module.h:1040
lldb::CompUnitSP GetCompileUnitAtIndex(size_t idx)
Definition: Module.cpp:425
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:445
void SetFileSpecAndObjectName(const FileSpec &file, ConstString object_name)
Definition: Module.cpp:1097
std::recursive_mutex m_mutex
A mutex to keep this object happy in multi-threaded environments.
Definition: Module.h:1036
static std::recursive_mutex & GetAllocationModuleCollectionMutex()
Definition: Module.cpp:106
lldb::DataBufferSP m_data_sp
DataBuffer containing the module image, if it was provided at construction time.
Definition: Module.h:1064
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:1573
void SetSymbolFileFileSpec(const FileSpec &file)
Definition: Module.cpp:1409
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:1633
void FindSymbolsWithNameAndType(ConstString name, lldb::SymbolType symbol_type, SymbolContextList &sc_list)
Definition: Module.cpp:1364
void CalculateSymbolContext(SymbolContext *sc) override
Reconstruct the object's symbol context into sc.
Definition: Module.cpp:408
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:1052
bool ResolveFileAddress(lldb::addr_t vm_addr, Address &so_addr)
Definition: Module.cpp:437
ArchSpec m_arch
The architecture for this module.
Definition: Module.h:1042
void ReportError(const char *format, Args &&...args)
Definition: Module.h:845
const FileSpec & GetPlatformFileSpec() const
Get accessor for the module platform file specification.
Definition: Module.h:511
lldb::SymbolVendorUP m_symfile_up
A pointer to the symbol vendor for this module.
Definition: Module.h:1073
const Symbol * FindFirstSymbolWithNameAndType(ConstString name, lldb::SymbolType symbol_type=lldb::eSymbolTypeAny)
Find a symbol in the object file's symbol table.
Definition: Module.cpp:1328
llvm::VersionTuple GetVersion()
Definition: Module.cpp:1674
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:928
void FindFunctions(const LookupInfo &lookup_info, const CompilerDeclContext &parent_decl_ctx, const ModuleFunctionSearchOptions &options, SymbolContextList &sc_list)
Find functions by lookup info.
Definition: Module.cpp:824
void DumpSymbolContext(Stream *s) override
Dump the object's symbol context to the stream s.
Definition: Module.cpp:414
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:1356
size_t GetNumCompileUnits()
Get the number of compile units for this module.
Definition: Module.cpp:418
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:1055
void LogMessage(Log *log, const char *format, Args &&...args)
Definition: Module.h:828
bool MatchesModuleSpec(const ModuleSpec &module_ref)
Definition: Module.cpp:1585
Symtab * GetSymtab()
Definition: Module.cpp:1091
~Module() override
Destructor.
Definition: Module.cpp:263
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
bool LoadScriptingResourceInTarget(Target *target, Status &error, Stream &feedback_stream)
Definition: Module.cpp:1499
TypeSystemMap m_type_system_map
A map of any type systems associated with this module.
Definition: Module.h:1079
uint64_t m_object_offset
Definition: Module.h:1058
void ForEachTypeSystem(llvm::function_ref< bool(lldb::TypeSystemSP)> callback)
Call callback for each TypeSystem in this Module.
Definition: Module.cpp:370
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:1086
bool IsExecutable()
Tells whether this module is capable of being the main executable for a process.
Definition: Module.cpp:1475
FileSpec m_platform_file
The path to the module on the platform on which it is being debugged.
Definition: Module.h:1047
bool MergeArchitecture(const ArchSpec &arch_spec)
Update the ArchSpec to a more specific variant.
Definition: Module.cpp:1654
bool FileHasChanged() const
Definition: Module.cpp:1140
const ArchSpec & GetArchitecture() const
Get const accessor for the module architecture.
Definition: Module.cpp:1106
void LogMessageVerboseBacktrace(Log *log, const char *format, Args &&...args)
Definition: Module.h:833
bool GetIsDynamicLinkEditor()
Definition: Module.cpp:1680
std::string GetCacheKey()
Get a unique cache key for the current module.
Definition: Module.cpp:1703
std::optional< UnwindTable > m_unwind_table
Table of FuncUnwinders objects created for this Module's functions.
Definition: Module.h:1069
virtual SectionList * GetSectionList()
Get the unified section list for the module.
Definition: Module.cpp:1295
llvm::Expected< lldb::TypeSystemSP > GetTypeSystemForLanguage(lldb::LanguageType language)
Definition: Module.cpp:366
void Dump(Stream *s)
Dump a description of this object to a Stream.
Definition: Module.cpp:1232
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:1066
void ReportErrorIfModifyDetected(const char *format, Args &&...args)
Definition: Module.h:852
void FindSymbolsMatchingRegExAndType(const RegularExpression &regex, lldb::SymbolType symbol_type, SymbolContextList &sc_list, Mangled::NamePreference mangling_preference=Mangled::ePreferDemangled)
Definition: Module.cpp:1376
std::atomic< bool > m_did_load_symfile
Definition: Module.h:1091
UnwindTable & GetUnwindTable()
Returns a reference to the UnwindTable for this Module.
Definition: Module.cpp:1313
std::string GetSpecificationDescription() const
Get the module path and object name.
Definition: Module.cpp:1108
const FileSpec & GetFileSpec() const
Get const accessor for the module file specification.
Definition: Module.h:497
bool IsLoadedInTarget(Target *target)
Tells whether this module has been loaded in the target passed in.
Definition: Module.cpp:1482
void GetDescription(llvm::raw_ostream &s, lldb::DescriptionLevel level=lldb::eDescriptionLevelFull)
Definition: Module.cpp:1118
void SetUUID(const lldb_private::UUID &uuid)
Definition: Module.cpp:355
bool m_first_file_changed_log
Definition: Module.h:1094
void SymbolIndicesToSymbolContextList(Symtab *symtab, std::vector< uint32_t > &symbol_indexes, SymbolContextList &sc_list)
Definition: Module.cpp:1338
virtual void SectionFileAddressesChanged()
Notify the module that the file addresses for the Sections have been updated.
Definition: Module.cpp:1305
std::atomic< bool > m_did_load_objfile
Definition: Module.h:1090
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:1616
bool SetArchitecture(const ArchSpec &new_arch)
Definition: Module.cpp:1565
SectionList * GetUnifiedSectionList()
Definition: Module.cpp:1322
void ParseAllDebugSymbols()
A debugging function that will cause everything in a module to be parsed.
Definition: Module.cpp:375
static bool IsPossibleObjCSelector(const char *name)
Definition: ObjCLanguage.h:183
static bool IsPossibleObjCMethodName(const char *name)
Definition: ObjCLanguage.h:175
A plug-in interface definition class for object file parsers.
Definition: ObjectFile.h:44
static lldb::ObjectFileSP FindPlugin(const lldb::ModuleSP &module_sp, const FileSpec *file_spec, lldb::offset_t file_offset, lldb::offset_t file_size, lldb::DataBufferSP &data_sp, lldb::offset_t &data_offset)
Find a ObjectFile plug-in that can parse file_spec.
Definition: ObjectFile.cpp:53
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:398
virtual void Dump(Stream *s)=0
Dump a description of this object to a Stream.
Symtab * GetSymtab()
Gets the symbol table for the currently selected architecture (and object for archives).
Definition: ObjectFile.cpp:727
virtual bool IsStripped()=0
Detect if this object file has been stripped of local symbols.
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.
Definition: ObjectFile.cpp:576
virtual FileSpec & GetFileSpec()
Get accessor to the object file specification.
Definition: ObjectFile.h:274
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:304
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:640
static size_t GetModuleSpecifications(const FileSpec &file, lldb::offset_t file_offset, lldb::offset_t file_size, ModuleSpecList &specs, lldb::DataBufferSP data_sp=lldb::DataBufferSP())
Definition: ObjectFile.cpp:187
std::optional< FileSpec > FindFile(const FileSpec &orig_spec) const
Finds a source file given a file spec using the path remappings.
bool Replace(llvm::StringRef path, llvm::StringRef replacement, bool notify)
void Append(llvm::StringRef path, llvm::StringRef replacement, bool notify)
bool RemapPath(ConstString path, ConstString &new_path) const
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={})
This is a SearchFilter that restricts the search to a given module.
Definition: SearchFilter.h:314
size_t GetNumSections(uint32_t depth) const
Definition: Section.cpp:533
size_t GetSize() const
Definition: Section.h:75
bool DeleteSection(size_t idx)
Definition: Section.cpp:486
lldb::SectionSP GetSectionAtIndex(size_t idx) const
Definition: Section.cpp:544
"lldb/Core/SourceLocationSpec.h" A source location specifier class.
An error handling class.
Definition: Status.h:44
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition: Status.cpp:130
const char * GetData() const
Definition: StreamString.h:43
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:357
size_t Indent(llvm::StringRef s="")
Indent the current line in the stream.
Definition: Stream.cpp:130
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:63
size_t PutChar(char ch)
Definition: Stream.cpp:104
void IndentLess(unsigned amount=2)
Decrement the current indentation level.
Definition: Stream.cpp:171
void IndentMore(unsigned amount=2)
Increment the current indentation level.
Definition: Stream.cpp:168
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.
const_iterator end() const
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.
Definition: SymbolContext.h:33
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.
void SortTypeList(TypeMap &type_map, TypeList &type_list) const
Sorts the types in TypeMap according to SymbolContext to TypeList.
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.
Provides public interface for all SymbolFiles.
Definition: SymbolFile.h:50
virtual size_t ParseTypes(CompileUnit &comp_unit)=0
virtual Symtab * GetSymtab()=0
virtual void SetLoadDebugInfoEnabled()
Specify debug info should be loaded.
Definition: SymbolFile.h:140
virtual void PreloadSymbols()
Definition: SymbolFile.cpp:32
virtual void FindGlobalVariables(ConstString name, const CompilerDeclContext &parent_decl_ctx, uint32_t max_matches, VariableList &variables)
Definition: SymbolFile.cpp:115
virtual size_t ParseFunctions(CompileUnit &comp_unit)=0
virtual size_t ParseBlocksRecursive(Function &func)=0
virtual lldb::CompUnitSP GetCompileUnitAtIndex(uint32_t idx)=0
virtual size_t ParseVariablesForContext(const SymbolContext &sc)=0
virtual ObjectFile * GetObjectFile()=0
virtual uint32_t ResolveSymbolContext(const Address &so_addr, lldb::SymbolContextItem resolve_scope, SymbolContext &sc)=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:167
bool IsSynthetic() const
Definition: Symbol.h:180
Address & GetAddressRef()
Definition: Symbol.h:71
lldb::SymbolType GetType() const
Definition: Symbol.h:167
Symbol * SymbolAtIndex(size_t idx)
Definition: Symtab.cpp:216
void ForEachSymbolContainingFileAddress(lldb::addr_t file_addr, std::function< bool(Symbol *)> const &callback)
Definition: Symtab.cpp:1048
Symbol * FindSymbolContainingFileAddress(lldb::addr_t file_addr)
Definition: Symtab.cpp:1032
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:745
Debugger & GetDebugger()
Definition: Target.h:1053
lldb::PlatformSP GetPlatform()
Definition: Target.h:1431
uint32_t GetSize() const
Definition: TypeList.cpp:60
lldb::TypeSP GetTypeAtIndex(uint32_t idx)
Definition: TypeList.cpp:66
uint32_t GetSize() const
Definition: TypeMap.cpp:75
void RemoveMismatchedTypes(llvm::StringRef type_scope, llvm::StringRef type_basename, lldb::TypeClass type_class, bool exact_match)
Definition: TypeMap.cpp:130
llvm::Expected< lldb::TypeSystemSP > GetTypeSystemForLanguage(lldb::LanguageType language, Module *module, bool can_create)
Definition: TypeSystem.cpp:307
void ForEach(std::function< bool(lldb::TypeSystemSP)> const &callback)
Definition: TypeSystem.cpp:223
static bool GetTypeScopeAndBasename(llvm::StringRef name, llvm::StringRef &scope, llvm::StringRef &basename, lldb::TypeClass &type_class)
Definition: Type.cpp:635
bool IsValid() const
Definition: UUID.h:69
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:82
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition: Log.h:314
LoadScriptFromSymFile
Definition: Target.h:50
@ eLoadScriptFromSymFileFalse
Definition: Target.h:52
@ eLoadScriptFromSymFileWarn
Definition: Target.h:53
const char * toString(AppleArm64ExceptionClass EC)
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::Function > FunctionSP
Definition: lldb-forward.h:343
ScriptLanguage
Script interpreter types.
@ eScriptLanguageNone
std::shared_ptr< lldb_private::TypeSystem > TypeSystemSP
Definition: lldb-forward.h:453
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
@ eDescriptionLevelBrief
@ eDescriptionLevelFull
std::shared_ptr< lldb_private::Platform > PlatformSP
Definition: lldb-forward.h:376
uint64_t offset_t
Definition: lldb-types.h:83
LanguageType
Programming language type.
@ eLanguageTypeUnknown
Unknown or invalid language value.
std::shared_ptr< lldb_private::Type > TypeSP
Definition: lldb-forward.h:445
std::shared_ptr< lldb_private::Process > ProcessSP
Definition: lldb-forward.h:377
SymbolType
Symbol types.
@ eSymbolTypeResolver
std::shared_ptr< lldb_private::Section > SectionSP
Definition: lldb-forward.h:402
uint64_t addr_t
Definition: lldb-types.h:79
std::shared_ptr< lldb_private::Target > TargetSP
Definition: lldb-forward.h:432
std::shared_ptr< lldb_private::Module > ModuleSP
Definition: lldb-forward.h:361
std::shared_ptr< lldb_private::CompileUnit > CompUnitSP
Definition: lldb-forward.h:323
A SmallBitVector that represents a set of source languages (lldb::LanguageType).
Definition: TypeSystem.h:51
Options used by Module::FindFunctions.
Definition: Module.h:65
bool include_inlines
Include inlined functions.
Definition: Module.h:69
bool include_symbols
Include the symbol table.
Definition: Module.h:67
#define PATH_MAX