56#include "llvm/ADT/STLExtras.h"
57#include "llvm/Support/Compiler.h"
58#include "llvm/Support/DJB.h"
59#include "llvm/Support/FileSystem.h"
60#include "llvm/Support/FormatVariadic.h"
61#include "llvm/Support/JSON.h"
62#include "llvm/Support/MemoryBuffer.h"
63#include "llvm/Support/Signals.h"
64#include "llvm/Support/VirtualFileSystem.h"
65#include "llvm/Support/raw_ostream.h"
101 return *g_module_collection;
110 static std::recursive_mutex *g_module_collection_mutex =
111 new std::recursive_mutex;
112 return *g_module_collection_mutex;
116 std::lock_guard<std::recursive_mutex> guard(
122 std::lock_guard<std::recursive_mutex> guard(
125 if (idx < modules.size())
137 std::lock_guard<std::recursive_mutex> guard(
143 LLDB_LOGF(log,
"%p Module::Module((%s) '%s%s%s%s')",
144 static_cast<void *
>(
this),
154 file_size = extractor_sp->GetByteSize();
164 module_spec.
GetFileSpec(), object_offset, object_size, extractor_sp);
165 if (modules_specs.
GetSize() == 0)
177 matching_module_spec)) {
178 LLDB_LOGF(log,
"Found local object file but the specs didn't match");
185 if (
auto module_spec_extractor_sp = module_spec.
GetExtractor()) {
240 const llvm::sys::TimePoint<> &object_mod_time)
249 std::lock_guard<std::recursive_mutex> guard(
255 LLDB_LOGF(log,
"%p Module::Module((%s) '%s')",
static_cast<void *
>(
this),
256 m_arch.GetArchitectureName(),
263 std::lock_guard<std::recursive_mutex> guard(
271 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
274 std::lock_guard<std::recursive_mutex> guard(
277 ModuleCollection::iterator end = modules.end();
278 ModuleCollection::iterator pos = std::find(modules.begin(), end,
this);
283 LLDB_LOGF(log,
"%p Module::~Module((%s) '%s')",
static_cast<void *
>(
this),
284 m_arch.GetArchitectureName(),
298 bool disable_memory_symtab_caching,
299 size_t size_to_read) {
303 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
306 std::shared_ptr<DataBufferHeap> data_sp =
307 std::make_shared<DataBufferHeap>(size_to_read, 0);
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) {
316 header_addr, data_sp);
320 disable_memory_symtab_caching);
329 m_arch.MergeFrom(process_sp->GetTarget().GetArchitecture());
334 "unable to find suitable object file plug-in");
338 "unable to read header from memory: %s", readmem_error.
AsCString());
348 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
366 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
370 if (obj_file !=
nullptr) {
379llvm::Expected<TypeSystemSP>
391 size_t num_comp_units = symbols ? symbols->GetNumCompileUnits() : 0;
392 if (num_comp_units == 0)
395 for (
size_t cu_idx = 0; cu_idx < num_comp_units; cu_idx++) {
398 sc.
comp_unit = symbols->GetCompileUnitAtIndex(cu_idx).
get();
402 symbols->ParseVariablesForContext(sc);
407 symbols->ParseBlocksRecursive(*f);
411 symbols->ParseVariablesForContext(sc);
427 s->
Printf(
", Module{%p}",
static_cast<void *
>(
this));
432 return symbols->GetNumCompileUnits();
437 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
441 if (index < num_comp_units) {
443 cu_sp = symbols->GetCompileUnitAtIndex(index);
456 const Address &so_addr, lldb::SymbolContextItem resolve_scope,
458 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
459 uint32_t resolved_flags = 0;
469 if (section_sp && section_sp->GetModule().get() ==
this) {
473 resolved_flags |= eSymbolContextModule;
477 return resolved_flags;
481 if (resolve_scope & eSymbolContextCompUnit ||
482 resolve_scope & eSymbolContextFunction ||
483 resolve_scope & eSymbolContextBlock ||
484 resolve_scope & eSymbolContextLineEntry ||
485 resolve_scope & eSymbolContextVariable) {
496 if (resolve_scope & eSymbolContextSymbol &&
497 !(resolved_flags & eSymbolContextSymbol)) {
500 Symbol *matching_symbol =
nullptr;
503 Symbol *symbol_at_address =
505 if (symbol_at_address &&
507 matching_symbol = symbol_at_address;
510 file_address, [&matching_symbol](
Symbol *symbol) ->
bool {
512 matching_symbol = symbol;
519 sc.
symbol = matching_symbol;
529 if (symtab_objfile && symtab_objfile->
IsStripped()) {
531 if (symfile_objfile != symtab_objfile) {
533 if (symfile_symtab) {
544 resolved_flags |= eSymbolContextSymbol;
552 if (resolve_scope & eSymbolContextSymbol &&
553 !(resolved_flags & eSymbolContextSymbol) && resolve_tail_call_address &&
555 Address previous_addr = so_addr;
556 previous_addr.
Slide(-1);
558 bool do_resolve_tail_call_address =
false;
560 previous_addr, resolve_scope, sc, do_resolve_tail_call_address);
561 if (flags & eSymbolContextSymbol) {
563 if (sc.
GetAddressRange(eSymbolContextFunction | eSymbolContextSymbol, 0,
564 false, addr_range)) {
575 resolved_flags |= flags;
585 return resolved_flags;
589 const char *file_path, uint32_t line,
bool check_inlines,
593 resolve_scope, sc_list);
597 const FileSpec &file_spec, uint32_t line,
bool check_inlines,
599 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
601 "check_inlines = %s, resolve_scope = 0x%8.8x)",
602 file_spec.
GetPath().c_str(), line,
603 check_inlines ?
"yes" :
"no", resolve_scope);
605 const uint32_t initial_count = sc_list.
GetSize();
610 check_inlines,
false);
612 symbols->ResolveSymbolContext(location_spec, resolve_scope, sc_list);
615 return sc_list.
GetSize() - initial_count;
622 symbols->FindGlobalVariables(name, parent_decl_ctx, max_matches, variables);
637 for (
size_t i = 0; i < num_compile_units; ++i) {
654 FunctionNameType name_type_mask,
657 m_lookup_name(lookup_name_override ? lookup_name_override : name),
658 m_language(lang_type) {
659 std::optional<ConstString> basename;
662 if (name_type_mask & eFunctionNameTypeAuto) {
665 if (info.first != eFunctionNameTypeNone) {
667 if (!basename && info.second)
668 basename = info.second;
688 basename = info.second;
689 }
else if (name_type_mask & eFunctionNameTypeFull &&
690 info.first != eFunctionNameTypeNone && !basename &&
694 basename = info.second;
699 if (basename && !lookup_name_override) {
711 ConstString name, lldb::FunctionNameType name_type_mask,
713 std::vector<LanguageType> lang_types;
715 lang_types.push_back(lang_type);
721 if (!llvm::is_contained(lang_types, lang_type))
722 lang_types.push_back(lang_type);
726 if (lang_types.empty())
730 std::vector<Module::LookupInfo> infos;
731 infos.reserve(lang_types.size());
739 llvm::any_of(infos, [&info](
const LookupInfo &other) {
740 return info.EqualsIgnoringLanguage(other);
743 infos.push_back(info);
762 if (
m_name == function_name)
770 const bool function_name_may_be_mangled =
772 ConstString demangled_function_name = function_name;
773 if (function_name_may_be_mangled) {
774 Mangled mangled_function_name(function_name);
782 return language->DemangledNameContainsPath(
m_name, demangled_function_name);
784 llvm::StringRef function_name_ref = demangled_function_name;
785 return function_name_ref.contains(
m_name);
789 size_t start_idx)
const {
792 size_t i = start_idx;
793 while (i < sc_list.
GetSize()) {
813 size_t i = start_idx;
814 while (i < sc_list.
GetSize()) {
822 std::unique_ptr<Language::MethodName> cpp_method =
824 if (cpp_method->IsValid()) {
825 if (cpp_method->GetContext().empty()) {
826 if (cpp_method->GetBasename().compare(
m_name) != 0) {
831 std::string qualified_name;
832 llvm::StringRef anon_prefix(
"(anonymous namespace)");
833 if (cpp_method->GetContext() == anon_prefix)
834 qualified_name = cpp_method->GetBasename().str();
836 qualified_name = cpp_method->GetScopeQualifiedName();
837 if (qualified_name !=
m_name.GetCString()) {
853 for (
auto &lookup_info : lookup_infos) {
862 symtab->FindFunctionSymbols(lookup_info.GetLookupName(),
863 lookup_info.GetNameTypeMask(), sc_list);
869 FunctionNameType name_type_mask,
872 std::vector<LookupInfo> lookup_infos =
874 for (
auto &lookup_info : lookup_infos) {
875 const size_t old_size = sc_list.
GetSize();
876 FindFunctions(lookup_info, parent_decl_ctx, options, sc_list);
877 if (name_type_mask & eFunctionNameTypeAuto) {
878 const size_t new_size = sc_list.
GetSize();
879 if (old_size < new_size)
880 lookup_info.Prune(sc_list, old_size);
886 FunctionNameType name_type_mask,
887 const ModuleFunctionSearchOptions &options,
888 SymbolContextList &sc_list) {
889 if (compiler_ctx.empty() ||
892 ConstString name = compiler_ctx.back().name;
893 SymbolContextList unfiltered;
894 FindFunctions(name, CompilerDeclContext(), name_type_mask, options,
897 for (
auto &sc : unfiltered)
898 if (sc.function && compiler_ctx.equals(sc.function->GetCompilerContext()))
905 const size_t start_size = sc_list.
GetSize();
915 std::vector<uint32_t> symbol_indexes;
919 const size_t num_matches = symbol_indexes.size();
922 const size_t end_functions_added_index = sc_list.
GetSize();
923 size_t num_functions_added_to_sc_list =
924 end_functions_added_index - start_size;
925 if (num_functions_added_to_sc_list == 0) {
928 for (
size_t i = 0; i < num_matches; ++i) {
936 typedef std::map<lldb::addr_t, uint32_t> FileAddrToIndexMap;
937 FileAddrToIndexMap file_addr_to_index;
938 for (
size_t i = start_size; i < end_functions_added_index; ++i) {
946 FileAddrToIndexMap::const_iterator end = file_addr_to_index.end();
949 for (
size_t i = start_size; i < num_matches; ++i) {
955 FileAddrToIndexMap::const_iterator pos =
956 file_addr_to_index.find(
972 const FileSpec &file, uint32_t line,
974 std::vector<Address> &output_local,
975 std::vector<Address> &output_extern) {
988 if (f && f == function)
989 output_local.push_back(addr);
991 output_extern.push_back(addr);
1005 if (requestors.empty())
1006 return interruptors;
1008 for (
auto debugger_sp : requestors) {
1009 if (!debugger_sp->InterruptRequested())
1011 if (debugger_sp->GetTargetList().AnyTargetContainsModule(module))
1012 interruptors.push_back(debugger_sp);
1014 return interruptors;
1019 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
1023 if (!interruptors.empty()) {
1024 for (
auto debugger_sp : interruptors) {
1026 "Interrupted fetching symbols for module {0}",
1027 this->GetFileSpec());
1032 if (obj_file !=
nullptr) {
1054 return eSymtabStateNone;
1056 if (
Symtab *symtab = objfile->GetSymtab(
false))
1057 return symtab->GetState();
1058 return eSymtabStateNone;
1062 std::string object_name) {
1091 s << llvm::formatv(
"({0}) ",
m_arch.GetArchitectureName());
1095 llvm::StringRef filename =
m_file.GetFilename();
1096 if (!filename.empty())
1100 if (
m_file.GetPath(path,
sizeof(path)))
1122 std::optional<lldb::user_id_t> debugger_id) {
1124 if (file_name.empty())
1129 <<
" was compiled with optimization - stepping may behave "
1130 "oddly; variables may not be available";
1137 LanguageType language, std::optional<lldb::user_id_t> debugger_id) {
1139 ss <<
"this version of LLDB has no plugin for the language \""
1142 "Inspection of frame variables will be limited";
1149 const llvm::formatv_object_base &payload) {
1158 strm.
PutCString(
"The debug session should be aborted as the original "
1159 "debug information has been overwritten.");
1170 bool internal_error) {
1173 std::string msg = payload.str();
1186 std::string msg = payload.str();
1201 Log *log,
const llvm::formatv_object_base &payload) {
1207 std::string back_trace;
1208 llvm::raw_string_ostream stream(back_trace);
1209 llvm::sys::PrintStackTrace(stream);
1216 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
1237 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
1251 const bool data_backed_object =
1262 extractor_sp, data_offset);
1273 ReportError(
"failed to load objfile for {0}\nDebugging will be "
1274 "degraded for this module.",
1305 return object_file->GetEntryPointAddress();
1346 "Module::FindFirstSymbolWithNameAndType (name = %s, type = %i)",
1349 return symtab->FindFirstSymbolWithNameAndType(
1354 Symtab *symtab, std::vector<uint32_t> &symbol_indexes,
1359 size_t num_indices = symbol_indexes.size();
1360 if (num_indices > 0) {
1363 for (
size_t i = 0; i < num_indices; i++) {
1376 symtab->FindFunctionSymbols(name, name_type_mask, sc_list);
1385 std::vector<uint32_t> symbol_indexes;
1386 symtab->FindAllSymbolsWithNameAndType(name, symbol_type, symbol_indexes);
1397 "Module::FindSymbolsMatchingRegExAndType (regex = %s, type = %i)",
1398 regex.
GetText().str().c_str(), symbol_type);
1400 std::vector<uint32_t> symbol_indexes;
1401 symtab->FindAllSymbolsMatchingRexExAndType(
1403 symbol_indexes, mangling_preference);
1418 if (
Symtab *symtab = sym_file->GetSymtab())
1419 symtab->PreloadSymbols();
1423 sym_file->PreloadSymbols();
1434 if (section_list && symbol_file) {
1457 std::string new_path(file.
GetPath());
1459 if (llvm::StringRef(old_path).starts_with(new_path)) {
1468 for (
size_t idx = num_sections; idx > 0; --idx) {
1471 if (section_sp->GetObjectFile() == obj_file) {
1499 if (sections !=
nullptr) {
1500 size_t num_sections = sections->
GetSize();
1501 for (
size_t sect_idx = 0; sect_idx < num_sections; sect_idx++) {
1517 return m_arch.IsCompatibleMatch(new_arch);
1521 bool value_is_offset,
bool &changed) {
1525 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
1527 if (object_file !=
nullptr) {
1528 changed = object_file->
SetLoadAddress(target, value, value_is_offset);
1555 if (!
m_arch.IsCompatibleMatch(arch))
1564 std::optional<lldb::addr_t> load_addr = module_ref.
GetLoadAddress();
1571 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
1574 new_spec = *remapped;
1581 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
1591 llvm::vfs::FileSystem &vfs = *llvm::vfs::getRealFileSystem();
1594 llvm::StringSet<> searched;
1596 for (
FileSpec current(start.getKey());;) {
1597 if (!searched.insert(current.GetPath()).second)
1601 llvm::ErrorOr<std::unique_ptr<llvm::vfs::File>> file =
1602 vfs.openFileForRead(map_file.
GetPath());
1603 if (file && *file) {
1604 LLDB_LOG(log,
"found compilation-prefix-map.json at {0}",
1606 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> buf =
1607 (*file)->getBuffer(map_file.
GetPath());
1609 llvm::Expected<llvm::json::Value> val =
1610 llvm::json::parse((*buf)->getBuffer());
1616 if (llvm::json::Object *obj = val->getAsObject()) {
1617 for (
const llvm::json::Object::value_type &kv : *obj)
1618 if (std::optional<llvm::StringRef> to = kv.second.getAsString()) {
1619 LLDB_LOG(log,
"applying prefix map: '{0}' -> '{1}'", kv.first,
1630 if (parent == current)
1639 std::lock_guard<std::recursive_mutex> guard(
m_mutex);
1642 return remapped->GetPath();
1647 llvm::StringRef sysroot) {
1648 Progress progress(
"Looking for Xcode SDK", sdk_name.str());
1649 auto sdk_path_or_err =
1650 HostInfo::GetSDKRoot(HostInfo::SDKOptions{sdk_name.str()});
1652 if (!sdk_path_or_err) {
1659 auto sdk_path = *sdk_path_or_err;
1660 if (sdk_path.empty())
1673 "module has arch %s, merging/replacing with arch %s",
1674 m_arch.GetTriple().getTriple().c_str(),
1675 arch_spec.
GetTriple().getTriple().c_str());
1676 if (!
m_arch.IsCompatibleMatch(arch_spec)) {
1699 return obj_file->GetVersion();
1700 return llvm::VersionTuple();
1713 std::string identifier;
1714 llvm::raw_string_ostream id_strm(identifier);
1715 id_strm <<
m_arch.GetTriple().str() <<
'-' <<
m_file.GetPath();
1723 return llvm::djbHash(identifier);
1728 llvm::raw_string_ostream strm(key);
1729 strm <<
m_arch.GetTriple().str() <<
'-' <<
m_file.GetFilename();
1732 strm <<
'-' << llvm::format_hex(
Hash(), 10);
1741 bool lldb_index_enabled =
false;
1753 lldb_index_enabled =
1758 if (!lldb_index_enabled)
1764 return g_data_file_cache;
static llvm::raw_ostream & error(Stream &strm)
static lldb::user_id_t g_unique_id
#define REPORT_INTERRUPTION(debugger,...)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
#define LLDB_LOGF(log,...)
#define LLDB_LOG_ERROR(log, error,...)
std::vector< Module * > ModuleCollection
static ModuleCollection & GetModuleCollection()
static Debugger::DebuggerList DebuggersOwningModuleRequestingInterruption(Module &module)
#define LLDB_SCOPED_TIMER()
#define LLDB_SCOPED_TIMERF(...)
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.
size_t GetNumberOfAddresses()
virtual void ResolveAddress(SearchFilter &filter)
AddressRange & GetAddressRangeAtIndex(size_t idx)
A section + offset based address class.
bool ResolveAddressUsingFileSections(lldb::addr_t addr, const SectionList *sections)
Resolve a file virtual address using a section list.
lldb::SectionSP GetSection() const
Get const accessor for the section.
Function * CalculateSymbolContextFunction() const
bool Slide(int64_t offset)
lldb::addr_t GetFileAddress() const
Get the file address.
lldb::addr_t GetOffset() const
Get the section relative offset value.
bool IsSectionOffset() const
Check if an address is section offset.
An architecture specification class.
bool IsValid() const
Tests if this ArchSpec is valid.
llvm::Triple & GetTriple()
Architecture triple accessor.
void MergeFrom(const ArchSpec &other)
Merges fields from another ArchSpec into this ArchSpec.
const char * GetArchitectureName() const
Returns a static string representing the current architecture.
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.
const char * AsCString(const char *value_if_empty) const
Get the string value as a C string.
This class enables data to be cached into a directory using the llvm caching code.
static void ReportInternalError(std::string message, std::optional< lldb::user_id_t > debugger_id=std::nullopt, std::once_flag *once=nullptr)
Report an error that may be a bug in LLDB.
static void ReportWarning(std::string message, std::optional< lldb::user_id_t > debugger_id=std::nullopt, std::once_flag *once=nullptr)
Report warning events.
static void ReportError(std::string message, std::optional< lldb::user_id_t > debugger_id=std::nullopt, std::once_flag *once=nullptr)
Report error events.
std::vector< lldb::DebuggerSP > DebuggerList
static DebuggerList DebuggersRequestingInterruption()
void AppendPathComponent(llvm::StringRef component)
static bool Match(const FileSpec &pattern, const FileSpec &file)
Match FileSpec pattern against FileSpec file.
bool RemoveLastPathComponent()
Removes the last path component by replacing the current path with its parent.
llvm::StringRef GetFilename() const
Filename string const get accessor.
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
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.
const Address & GetAddress() const
Return the address of the function (its entry point).
static void ForEach(llvm::function_ref< IterationAction(Language *)> callback)
static Language * FindPlugin(lldb::LanguageType language)
static const char * GetNameForLanguageType(lldb::LanguageType language)
Returns the internal LLDB name for the specified language.
virtual std::unique_ptr< Language::MethodName > GetMethodName(llvm::StringRef name) const
virtual lldb::LanguageType GetLanguageType() const =0
virtual std::pair< lldb::FunctionNameType, std::optional< ConstString > > GetFunctionNameInfo(ConstString name) const
void PutCString(const char *cstr)
A class that handles mangled names.
ConstString GetDemangledName() const
Demangled name get accessor.
static Mangled::ManglingScheme GetManglingScheme(llvm::StringRef name)
Try to identify the mangling scheme used.
bool GetLLDBIndexCacheForceDisable() const
bool GetLLDBIndexCacheTypeMemoryModuleHeaderBytes() const
FileSpec GetLLDBIndexCachePath() const
bool GetLLDBIndexCacheTypeSymtab() const
bool GetLLDBIndexCacheTypeDwarfIndex() const
bool GetLLDBIndexCacheTypeMemoryModuleSymtab() const
static ModuleListProperties & GetGlobalModuleListProperties()
bool FindMatchingModuleSpec(const ModuleSpec &module_spec, ModuleSpec &match_module_spec) const
PathMappingList & GetSourceMappingList() const
void SetObjectSize(uint64_t object_size)
uint64_t GetObjectOffset() const
FileSpec & GetPlatformFileSpec()
const std::string & GetObjectName() const
ArchSpec & GetArchitecture()
void SetObjectOffset(uint64_t object_offset)
FileSpec & GetSymbolFileSpec()
llvm::sys::TimePoint & GetObjectModificationTime()
lldb::DataExtractorSP GetExtractor() const
void SetObjectName(std::string name)
uint64_t GetObjectSize() const
std::optional< lldb::addr_t > GetLoadAddress() const
Get the load address of a module in process memory.
A class that encapsulates name lookup information.
lldb::FunctionNameType GetNameTypeMask() const
bool EqualsIgnoringLanguage(const LookupInfo &other) const
Returns true if this lookup equals other in everything but the language.
lldb::LanguageType GetLanguageType() const
ConstString m_lookup_name
The actual name will lookup when calling in the object or symbol file.
lldb::FunctionNameType m_name_type_mask
One or more bits from lldb::FunctionNameType that indicate what kind of names we are looking for.
bool NameMatchesLookupInfo(ConstString function_name, lldb::LanguageType language_type=lldb::eLanguageTypeUnknown) const
lldb::LanguageType m_language
Limit matches to only be for this language.
ConstString m_name
What the user originally typed.
ConstString GetName() const
static std::vector< LookupInfo > MakeLookupInfos(ConstString name, lldb::FunctionNameType name_type_mask, lldb::LanguageType lang_type, ConstString lookup_name_override={})
Creates a vector of lookup infos for function name resolution.
void Prune(SymbolContextList &sc_list, size_t start_idx) const
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...
A class that describes an executable image and its associated object and symbol files.
std::atomic< bool > m_did_preload_symbols
const lldb_private::UUID & GetUUID()
Get a reference to the UUID value contained in this object.
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.
std::atomic< bool > m_did_set_uuid
void ReportWarningOptimization(std::optional< lldb::user_id_t > debugger_id)
@ eLLDBIndexTypeDwarfIndex
@ eLLDBIndexTypeMemoryModuleSymtab
@ eLLDBIndexTypeMemoryModuleHeaderBytes
PathMappingList m_source_mappings
Module specific source remappings for when you have debug info for a module that doesn't match where ...
llvm::sys::TimePoint m_object_mod_time
virtual ObjectFile * GetObjectFile()
Get the object file representation for the current architecture.
void FindGlobalVariables(ConstString name, const CompilerDeclContext &parent_decl_ctx, size_t max_matches, VariableList &variable_list)
Find global and static variables by name.
void ReportWarning(const char *format, Args &&...args)
FileSpec m_file
The file representation on disk for this module (if there is one).
virtual SymbolFile * GetSymbolFile(bool can_create=true, Stream *feedback_strm=nullptr)
Get the module's symbol file.
std::vector< lldb::SymbolVendorUP > m_old_symfiles
If anyone calls Module::SetSymbolFileFileSpec() and changes the symbol file,.
void ReportWarningUnsupportedLanguage(lldb::LanguageType language, std::optional< lldb::user_id_t > debugger_id)
Module(const FileSpec &file_spec, const ArchSpec &arch, std::string object_name=std::string(), lldb::offset_t object_offset=0, const llvm::sys::TimePoint<> &object_mod_time=llvm::sys::TimePoint<>())
Construct with file specification and architecture.
void FindCompileUnits(const FileSpec &path, SymbolContextList &sc_list)
Find compile units by partial or full path.
uint32_t Hash()
Get a unique hash for this module.
lldb::ModuleSP CalculateSymbolContextModule() override
static Module * GetAllocatedModuleAtIndex(size_t idx)
std::optional< std::string > RemapSourceFile(llvm::StringRef path)
Remaps a source file given path into new_path.
bool FindSourceFile(const FileSpec &orig_spec, FileSpec &new_spec)
Finds a source file given a file spec using the module source path remappings (if any).
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.
llvm::sys::TimePoint m_mod_time
The modification time for this module when it was created.
lldb::CompUnitSP GetCompileUnitAtIndex(size_t idx)
llvm::StringRef GetObjectName() const
LockedPtr< SectionList > GetSectionListLocked()
Like GetSectionList, but the returned handle holds the Module mutex for its lifetime.
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.
std::recursive_mutex m_mutex
A mutex to keep this object happy in multi-threaded environments.
static std::recursive_mutex & GetAllocationModuleCollectionMutex()
void SetFileSpecAndObjectName(const FileSpec &file, std::string object_name)
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.
void SetSymbolFileFileSpec(const FileSpec &file)
Address GetObjectFileEntryPointAddress()
Get the entry point address of this module's object file.
void RegisterXcodeSDK(llvm::StringRef sdk, llvm::StringRef sysroot)
This callback will be called by SymbolFile implementations when parsing a compile unit that contains ...
void AddPrefixMapSearchDir(FileSpec dir)
Register a directory to be searched for compilation-prefix-map.json on the first call to RemapSourceF...
void FindSymbolsWithNameAndType(ConstString name, lldb::SymbolType symbol_type, SymbolContextList &sc_list)
void CalculateSymbolContext(SymbolContext *sc) override
Reconstruct the object's symbol context into sc.
LockedPtr< Symtab > GetSymtabLocked(bool can_create=true)
Like GetSymtab, but the returned handle holds the Module mutex for its lifetime.
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.
ThreadSafeDenseSet< llvm::stable_hash > m_shown_diagnostics
Hashes of the warnings and errors already reported, to report each once.
std::optional< lldb::addr_t > m_memory_module_addr
For a Module read from memory, the address it was read from.
lldb::DataExtractorSP m_extractor_sp
DataExtractor containing the module image, if it was provided at construction time.
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...
static DataFileCache * GetIndexCache(LLDBIndexType type)
Get the global index file cache.
bool ResolveFileAddress(lldb::addr_t vm_addr, Address &so_addr)
ArchSpec m_arch
The architecture for this module.
void ReportError(const char *format, Args &&...args)
const FileSpec & GetPlatformFileSpec() const
Get accessor for the module platform file specification.
lldb::SymbolVendorUP m_symfile_up
A pointer to the symbol vendor for this module.
const Symbol * FindFirstSymbolWithNameAndType(ConstString name, lldb::SymbolType symbol_type=lldb::eSymbolTypeAny)
Find a symbol in the object file's symbol table.
llvm::VersionTuple GetVersion()
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.
void LoadPrefixMapsIfNeeded()
Search each registered directory upward for compilation-prefix-map.json and apply any found mappings ...
std::string m_object_name
The name an object within this module that is selected, or empty of the module is represented by m_fi...
void DumpSymbolContext(Stream *s) override
Dump the object's symbol context to the stream s.
void FindFunctionSymbols(ConstString name, uint32_t name_type_mask, SymbolContextList &sc_list)
Find a function symbols in the object file's symbol table.
llvm::StringSet m_prefix_map_search_dirs
Directories registered via AddPrefixMapSearchDir, searched lazily on the first call to RemapSourceFil...
Symtab * GetSymtab(bool can_create=true)
Get the module's symbol table.
size_t GetNumCompileUnits()
Get the number of compile units for this module.
void LogMessage(Log *log, const char *format, Args &&...args)
bool MatchesModuleSpec(const ModuleSpec &module_ref)
~Module() override
Destructor.
static size_t GetNumberAllocatedModules()
ModuleSpec GetModuleSpec()
Describe this module, preserving the parsed object's bounds and any already-provided bytes.
TypeSystemMap m_type_system_map
A map of any type systems associated with this module.
ObjectFile * GetMemoryObjectFile(const lldb::ProcessSP &process_sp, lldb::addr_t header_addr, Status &error, bool disable_memory_symtab_caching, size_t size_to_read=512)
Load an object file from memory.
void ForEachTypeSystem(llvm::function_ref< bool(lldb::TypeSystemSP)> callback)
Call callback for each TypeSystem in this Module.
lldb::SectionListUP m_sections_up
Unified section list for module that is used by the ObjectFile and ObjectFile instances for the debug...
bool IsExecutable()
Tells whether this module is capable of being the main executable for a process.
FileSpec m_platform_file
The path to the module on the platform on which it is being debugged.
bool MergeArchitecture(const ArchSpec &arch_spec)
Update the ArchSpec to a more specific variant.
bool FileHasChanged() const
const ArchSpec & GetArchitecture() const
Get const accessor for the module architecture.
void LogMessageVerboseBacktrace(Log *log, const char *format, Args &&...args)
bool GetIsDynamicLinkEditor()
std::string GetCacheKey()
Get a unique cache key for the current module.
virtual SectionList * GetSectionList()
Get the unified section list for the module.
llvm::Expected< lldb::TypeSystemSP > GetTypeSystemForLanguage(lldb::LanguageType language)
void Dump(Stream *s)
Dump a description of this object to a Stream.
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.
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...
void ReportErrorIfModifyDetected(const char *format, Args &&...args)
void FindSymbolsMatchingRegExAndType(const RegularExpression ®ex, lldb::SymbolType symbol_type, SymbolContextList &sc_list, Mangled::NamePreference mangling_preference=Mangled::ePreferDemangled)
std::atomic< bool > m_did_load_symfile
UnwindTable & GetUnwindTable()
Returns a reference to the UnwindTable for this Module.
LockedPtr< SymbolFile > GetSymbolFileLocked(bool can_create=true, Stream *feedback_strm=nullptr)
Like GetSymbolFile, but the returned handle holds the Module mutex for its lifetime.
std::string GetSpecificationDescription() const
Get the module path and object name.
UnwindTable m_unwind_table
Table of FuncUnwinders objects created for this Module's functions.
uint32_t GetSymtabState()
Get a bitmask of lldb::SymtabState flags describing the object file's symbol table state.
const FileSpec & GetFileSpec() const
Get const accessor for the module file specification.
bool IsLoadedInTarget(Target *target)
Tells whether this module has been loaded in the target passed in.
void GetDescription(llvm::raw_ostream &s, lldb::DescriptionLevel level=lldb::eDescriptionLevelFull)
ModuleSpecList GetSeparateDebugInfoFiles()
std::recursive_mutex m_sections_mutex
Guards the lazy construction of m_sections_up.
bool m_first_file_changed_log
void SymbolIndicesToSymbolContextList(Symtab *symtab, std::vector< uint32_t > &symbol_indexes, SymbolContextList &sc_list)
bool ShouldReportDiagnostic(llvm::StringRef msg)
Returns true the first time msg is passed.
const llvm::sys::TimePoint & GetModificationTime() const
virtual void SectionFileAddressesChanged()
Notify the module that the file addresses for the Sections have been updated.
std::atomic< bool > m_did_load_objfile
void FindTypes(const TypeQuery &query, TypeResults &results)
Find types using a type-matching object that contains all search parameters.
bool SetArchitecture(const ArchSpec &new_arch)
SectionList * GetUnifiedSectionList()
StatsDuration m_symtab_parse_time
See if the module was modified after it was initially opened.
void ParseAllDebugSymbols()
A debugging function that will cause everything in a module to be parsed.
LockedPtr< ObjectFile > GetObjectFileLocked()
Like GetObjectFile, but the returned handle holds the Module mutex for its lifetime,...
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...
virtual void Dump(Stream *s)=0
Dump a description of this object to a Stream.
static lldb::ObjectFileSP FindPlugin(const lldb::ModuleSP &module_sp, const FileSpec *file_spec, lldb::offset_t file_offset, lldb::offset_t file_size, lldb::DataExtractorSP extractor_sp, lldb::offset_t &data_offset)
Find a ObjectFile plug-in that can parse file_spec.
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 lldb::addr_t GetFileOffset() const
Returns the offset into a file at which this object resides.
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.
virtual void SectionFileAddressesChanged()
Notify the ObjectFile that the file addresses in the Sections for this module have been changed.
virtual SectionList * GetSectionList(bool update_module_section_list=true)
Gets the section list for the currently selected architecture (and object for archives).
static ModuleSpecList GetModuleSpecifications(const FileSpec &file, lldb::offset_t file_offset, lldb::offset_t file_size, lldb::DataExtractorSP=lldb::DataExtractorSP())
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)
virtual lldb::addr_t GetByteSize() const
A Progress indicator helper class.
llvm::StringRef GetText() const
Access the regular expression text.
This is a SearchFilter that restricts the search to a given module.
size_t GetNumSections(uint32_t depth) const
bool DeleteSection(size_t idx)
lldb::SectionSP GetSectionAtIndex(size_t idx) const
"lldb/Core/SourceLocationSpec.h" A source location specifier class.
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
static Status FromErrorString(const char *str)
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
const char * GetData() const
llvm::StringRef GetString() const
A stream class that can stream formatted output to a file.
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
size_t Indent(llvm::StringRef s="")
Indent the current line in the stream.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
void IndentLess(unsigned amount=2)
Decrement the current indentation level.
void IndentMore(unsigned amount=2)
Increment the current indentation level.
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 SetSymbolAtIndex(size_t idx, Symbol *symbol)
Replace the symbol in the symbol context at index idx.
bool RemoveContextAtIndex(size_t idx)
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 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.
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 void FindTypes(const TypeQuery &query, TypeResults &results)
Find types using a type-matching object that contains all search parameters.
virtual void FindFunctions(const Module::LookupInfo &lookup_info, const CompilerDeclContext &parent_decl_ctx, bool include_inlines, SymbolContextList &sc_list)
virtual lldb_private::ModuleSpecList GetSeparateDebugInfoFiles()
Return a map of separate debug info files that are loaded.
virtual ObjectFile * GetObjectFile()=0
virtual void ResetStatistics()
Reset the statistics for the symbol file.
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
Address & GetAddressRef()
lldb::SymbolType GetType() const
Symbol * SymbolAtIndex(size_t idx)
void ForEachSymbolContainingFileAddress(lldb::addr_t file_addr, std::function< bool(Symbol *)> const &callback)
Symbol * FindSymbolAtFileAddress(lldb::addr_t file_addr)
Symbol * FindSymbolContainingFileAddress(lldb::addr_t file_addr)
ObjectFile * GetObjectFile() const
uint32_t AppendSymbolIndexesMatchingRegExAndType(const RegularExpression ®ex, lldb::SymbolType symbol_type, std::vector< uint32_t > &indexes, Mangled::NamePreference name_preference=Mangled::ePreferDemangled)
A class that contains all state required for type lookups.
This class tracks the state and results of a TypeQuery.
Represents UUID's of various sizes.
#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.
Locked< T *, Mutex > LockedPtr
Exclusive (write) access aliases.
std::string toString(FormatterBytecode::OpCodes op)
std::shared_ptr< lldb_private::Function > FunctionSP
std::shared_ptr< lldb_private::TypeSystem > TypeSystemSP
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
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
std::shared_ptr< lldb_private::Section > SectionSP
std::shared_ptr< lldb_private::Target > TargetSP
std::shared_ptr< lldb_private::DataExtractor > DataExtractorSP
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.
void ApplyFileMappings(lldb::TargetSP target_sp)
Apply file mappings from target.source-map to the LineEntry's file.
Options used by Module::FindFunctions.
bool include_inlines
Include inlined functions.
bool include_symbols
Include the symbol table.
UserID(lldb::user_id_t uid=LLDB_INVALID_UID)
Construct with optional user ID.