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