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