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