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