aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/lldb/source/Core/Module.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/lldb/source/Core/Module.cpp')
-rw-r--r--contrib/llvm-project/lldb/source/Core/Module.cpp283
1 files changed, 136 insertions, 147 deletions
diff --git a/contrib/llvm-project/lldb/source/Core/Module.cpp b/contrib/llvm-project/lldb/source/Core/Module.cpp
index 893e20837124..8f9defabd76f 100644
--- a/contrib/llvm-project/lldb/source/Core/Module.cpp
+++ b/contrib/llvm-project/lldb/source/Core/Module.cpp
@@ -24,6 +24,7 @@
#include "lldb/Interpreter/ScriptInterpreter.h"
#include "lldb/Symbol/CompileUnit.h"
#include "lldb/Symbol/Function.h"
+#include "lldb/Symbol/LocateSymbolFile.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Symbol/Symbol.h"
#include "lldb/Symbol/SymbolContext.h"
@@ -69,6 +70,7 @@
#include <cstdint>
#include <cstring>
#include <map>
+#include <optional>
#include <type_traits>
#include <utility>
@@ -363,11 +365,16 @@ void Module::SetUUID(const lldb_private::UUID &uuid) {
}
}
-llvm::Expected<TypeSystem &>
+llvm::Expected<TypeSystemSP>
Module::GetTypeSystemForLanguage(LanguageType language) {
return m_type_system_map.GetTypeSystemForLanguage(language, this, true);
}
+void Module::ForEachTypeSystem(
+ llvm::function_ref<bool(lldb::TypeSystemSP)> callback) {
+ m_type_system_map.ForEach(callback);
+}
+
void Module::ParseAllDebugSymbols() {
std::lock_guard<std::recursive_mutex> guard(m_mutex);
size_t num_comp_units = GetNumCompileUnits();
@@ -413,8 +420,6 @@ void Module::DumpSymbolContext(Stream *s) {
size_t Module::GetNumCompileUnits() {
std::lock_guard<std::recursive_mutex> guard(m_mutex);
- LLDB_SCOPED_TIMERF("Module::GetNumCompileUnits (module = %p)",
- static_cast<void *>(this));
if (SymbolFile *symbols = GetSymbolFile())
return symbols->GetNumCompileUnits();
return 0;
@@ -592,7 +597,7 @@ uint32_t Module::ResolveSymbolContextsForFileSpec(
if (SymbolFile *symbols = GetSymbolFile()) {
// TODO: Handle SourceLocationSpec column information
- SourceLocationSpec location_spec(file_spec, line, /*column=*/llvm::None,
+ SourceLocationSpec location_spec(file_spec, line, /*column=*/std::nullopt,
check_inlines, /*exact_match=*/false);
symbols->ResolveSymbolContext(location_spec, resolve_scope, sc_list);
@@ -727,6 +732,41 @@ Module::LookupInfo::LookupInfo(ConstString name,
}
}
+bool Module::LookupInfo::NameMatchesLookupInfo(
+ ConstString function_name, LanguageType language_type) const {
+ // We always keep unnamed symbols
+ if (!function_name)
+ return true;
+
+ // If we match exactly, we can return early
+ if (m_name == function_name)
+ return true;
+
+ // If function_name is mangled, we'll need to demangle it.
+ // In the pathologial case where the function name "looks" mangled but is
+ // actually demangled (e.g. a method named _Zonk), this operation should be
+ // relatively inexpensive since no demangling is actually occuring. See
+ // Mangled::SetValue for more context.
+ const bool function_name_may_be_mangled =
+ Mangled::GetManglingScheme(function_name.GetStringRef()) !=
+ Mangled::eManglingSchemeNone;
+ ConstString demangled_function_name = function_name;
+ if (function_name_may_be_mangled) {
+ Mangled mangled_function_name(function_name);
+ demangled_function_name = mangled_function_name.GetDemangledName();
+ }
+
+ // If the symbol has a language, then let the language make the match.
+ // Otherwise just check that the demangled function name contains the
+ // demangled user-provided name.
+ if (Language *language = Language::FindPlugin(language_type))
+ return language->DemangledNameContainsPath(m_name.GetStringRef(),
+ demangled_function_name);
+
+ llvm::StringRef function_name_ref = demangled_function_name.GetStringRef();
+ return function_name_ref.contains(m_name.GetStringRef());
+}
+
void Module::LookupInfo::Prune(SymbolContextList &sc_list,
size_t start_idx) const {
if (m_match_name_after_lookup && m_name) {
@@ -735,21 +775,9 @@ void Module::LookupInfo::Prune(SymbolContextList &sc_list,
while (i < sc_list.GetSize()) {
if (!sc_list.GetContextAtIndex(i, sc))
break;
-
- llvm::StringRef user_name = m_name.GetStringRef();
- bool keep_it = true;
- Language *language = Language::FindPlugin(sc.GetLanguage());
- // If the symbol has a language, then let the language make the match.
- // Otherwise just check that the demangled name contains the user name.
- if (language)
- keep_it = language->DemangledNameContainsPath(m_name.GetStringRef(),
- sc.GetFunctionName());
- else {
- llvm::StringRef full_name = sc.GetFunctionName().GetStringRef();
- // We always keep unnamed symbols:
- if (!full_name.empty())
- keep_it = full_name.contains(user_name);
- }
+
+ bool keep_it =
+ NameMatchesLookupInfo(sc.GetFunctionName(), sc.GetLanguage());
if (keep_it)
++i;
else
@@ -798,51 +826,37 @@ void Module::LookupInfo::Prune(SymbolContextList &sc_list,
}
}
-void Module::FindFunctions(ConstString name,
+void Module::FindFunctions(const Module::LookupInfo &lookup_info,
const CompilerDeclContext &parent_decl_ctx,
- FunctionNameType name_type_mask,
const ModuleFunctionSearchOptions &options,
SymbolContextList &sc_list) {
- const size_t old_size = sc_list.GetSize();
-
// Find all the functions (not symbols, but debug information functions...
- SymbolFile *symbols = GetSymbolFile();
-
- if (name_type_mask & eFunctionNameTypeAuto) {
- LookupInfo lookup_info(name, name_type_mask, eLanguageTypeUnknown);
-
- if (symbols) {
- symbols->FindFunctions(lookup_info.GetLookupName(), parent_decl_ctx,
- lookup_info.GetNameTypeMask(),
- options.include_inlines, sc_list);
-
- // Now check our symbol table for symbols that are code symbols if
- // requested
- if (options.include_symbols) {
- Symtab *symtab = symbols->GetSymtab();
- if (symtab)
- symtab->FindFunctionSymbols(lookup_info.GetLookupName(),
- lookup_info.GetNameTypeMask(), sc_list);
+ if (SymbolFile *symbols = GetSymbolFile()) {
+ symbols->FindFunctions(lookup_info, parent_decl_ctx,
+ options.include_inlines, sc_list);
+ // Now check our symbol table for symbols that are code symbols if
+ // requested
+ if (options.include_symbols) {
+ if (Symtab *symtab = symbols->GetSymtab()) {
+ symtab->FindFunctionSymbols(lookup_info.GetLookupName(),
+ lookup_info.GetNameTypeMask(), sc_list);
}
}
+ }
+}
+void Module::FindFunctions(ConstString name,
+ const CompilerDeclContext &parent_decl_ctx,
+ FunctionNameType name_type_mask,
+ const ModuleFunctionSearchOptions &options,
+ SymbolContextList &sc_list) {
+ const size_t old_size = sc_list.GetSize();
+ LookupInfo lookup_info(name, name_type_mask, eLanguageTypeUnknown);
+ FindFunctions(lookup_info, parent_decl_ctx, options, sc_list);
+ if (name_type_mask & eFunctionNameTypeAuto) {
const size_t new_size = sc_list.GetSize();
-
if (old_size < new_size)
lookup_info.Prune(sc_list, old_size);
- } else {
- if (symbols) {
- symbols->FindFunctions(name, parent_decl_ctx, name_type_mask,
- options.include_inlines, sc_list);
-
- // Now check our symbol table for symbols that are code symbols if
- // requested
- if (options.include_symbols) {
- Symtab *symtab = symbols->GetSymtab();
- if (symtab)
- symtab->FindFunctionSymbols(name, name_type_mask, sc_list);
- }
- }
}
}
@@ -924,7 +938,7 @@ void Module::FindAddressesForLine(const lldb::TargetSP target_sp,
SearchFilterByModule filter(target_sp, m_file);
// TODO: Handle SourceLocationSpec column information
- SourceLocationSpec location_spec(file, line, /*column=*/llvm::None,
+ SourceLocationSpec location_spec(file, line, /*column=*/std::nullopt,
/*check_inlines=*/true,
/*exact_match=*/false);
AddressResolverFileLine resolver(location_spec);
@@ -1112,7 +1126,7 @@ bool Module::FileHasChanged() const {
}
void Module::ReportWarningOptimization(
- llvm::Optional<lldb::user_id_t> debugger_id) {
+ std::optional<lldb::user_id_t> debugger_id) {
ConstString file_name = GetFileSpec().GetFilename();
if (file_name.IsEmpty())
return;
@@ -1126,7 +1140,7 @@ void Module::ReportWarningOptimization(
}
void Module::ReportWarningUnsupportedLanguage(
- LanguageType language, llvm::Optional<lldb::user_id_t> debugger_id) {
+ LanguageType language, std::optional<lldb::user_id_t> debugger_id) {
StreamString ss;
ss << "This version of LLDB has no plugin for the language \""
<< Language::GetNameForLanguageType(language)
@@ -1136,95 +1150,60 @@ void Module::ReportWarningUnsupportedLanguage(
&m_language_warning);
}
-void Module::ReportErrorIfModifyDetected(const char *format, ...) {
+void Module::ReportErrorIfModifyDetected(
+ const llvm::formatv_object_base &payload) {
if (!m_first_file_changed_log) {
if (FileHasChanged()) {
m_first_file_changed_log = true;
- if (format) {
- StreamString strm;
- strm.PutCString("the object file ");
- GetDescription(strm.AsRawOstream(), lldb::eDescriptionLevelFull);
- strm.PutCString(" has been modified\n");
-
- va_list args;
- va_start(args, format);
- strm.PrintfVarArg(format, args);
- va_end(args);
-
- const int format_len = strlen(format);
- if (format_len > 0) {
- const char last_char = format[format_len - 1];
- if (last_char != '\n' && last_char != '\r')
- strm.EOL();
- }
- strm.PutCString("The debug session should be aborted as the original "
- "debug information has been overwritten.");
- Debugger::ReportError(std::string(strm.GetString()));
- }
+ StreamString strm;
+ strm.PutCString("the object file ");
+ GetDescription(strm.AsRawOstream(), lldb::eDescriptionLevelFull);
+ strm.PutCString(" has been modified\n");
+ strm.PutCString(payload.str());
+ strm.PutCString("The debug session should be aborted as the original "
+ "debug information has been overwritten.");
+ Debugger::ReportError(std::string(strm.GetString()));
}
}
}
-void Module::ReportError(const char *format, ...) {
- if (format && format[0]) {
- StreamString strm;
- GetDescription(strm.AsRawOstream(), lldb::eDescriptionLevelBrief);
- strm.PutChar(' ');
-
- va_list args;
- va_start(args, format);
- strm.PrintfVarArg(format, args);
- va_end(args);
-
- Debugger::ReportError(std::string(strm.GetString()));
- }
-}
-
-void Module::ReportWarning(const char *format, ...) {
- if (format && format[0]) {
- StreamString strm;
- GetDescription(strm.AsRawOstream(), lldb::eDescriptionLevelFull);
- strm.PutChar(' ');
-
- va_list args;
- va_start(args, format);
- strm.PrintfVarArg(format, args);
- va_end(args);
-
- Debugger::ReportWarning(std::string(strm.GetString()));
- }
-}
-
-void Module::LogMessage(Log *log, const char *format, ...) {
- if (log != nullptr) {
- StreamString log_message;
- GetDescription(log_message.AsRawOstream(), lldb::eDescriptionLevelFull);
- log_message.PutCString(": ");
- va_list args;
- va_start(args, format);
- log_message.PrintfVarArg(format, args);
- va_end(args);
- log->PutCString(log_message.GetData());
- }
-}
-
-void Module::LogMessageVerboseBacktrace(Log *log, const char *format, ...) {
- if (log != nullptr) {
- StreamString log_message;
- GetDescription(log_message.AsRawOstream(), lldb::eDescriptionLevelFull);
- log_message.PutCString(": ");
- va_list args;
- va_start(args, format);
- log_message.PrintfVarArg(format, args);
- va_end(args);
- if (log->GetVerbose()) {
- std::string back_trace;
- llvm::raw_string_ostream stream(back_trace);
- llvm::sys::PrintStackTrace(stream);
- log_message.PutCString(back_trace);
- }
- log->PutCString(log_message.GetData());
+void Module::ReportError(const llvm::formatv_object_base &payload) {
+ StreamString strm;
+ GetDescription(strm.AsRawOstream(), lldb::eDescriptionLevelBrief);
+ strm.PutChar(' ');
+ strm.PutCString(payload.str());
+ Debugger::ReportError(strm.GetString().str());
+}
+
+void Module::ReportWarning(const llvm::formatv_object_base &payload) {
+ StreamString strm;
+ GetDescription(strm.AsRawOstream(), lldb::eDescriptionLevelFull);
+ strm.PutChar(' ');
+ strm.PutCString(payload.str());
+ Debugger::ReportWarning(std::string(strm.GetString()));
+}
+
+void Module::LogMessage(Log *log, const llvm::formatv_object_base &payload) {
+ StreamString log_message;
+ GetDescription(log_message.AsRawOstream(), lldb::eDescriptionLevelFull);
+ log_message.PutCString(": ");
+ log_message.PutCString(payload.str());
+ log->PutCString(log_message.GetData());
+}
+
+void Module::LogMessageVerboseBacktrace(
+ Log *log, const llvm::formatv_object_base &payload) {
+ StreamString log_message;
+ GetDescription(log_message.AsRawOstream(), lldb::eDescriptionLevelFull);
+ log_message.PutCString(": ");
+ log_message.PutCString(payload.str());
+ if (log->GetVerbose()) {
+ std::string back_trace;
+ llvm::raw_string_ostream stream(back_trace);
+ llvm::sys::PrintStackTrace(stream);
+ log_message.PutCString(back_trace);
}
+ log->PutCString(log_message.GetData());
}
void Module::Dump(Stream *s) {
@@ -1280,7 +1259,7 @@ ObjectFile *Module::GetObjectFile() {
// those values that overwrite unspecified unknown values.
m_arch.MergeFrom(m_objfile_sp->GetArchitecture());
} else {
- ReportError("failed to load objfile for %s",
+ ReportError("failed to load objfile for {0}",
GetFileSpec().GetPath().c_str());
}
}
@@ -1308,8 +1287,11 @@ void Module::SectionFileAddressesChanged() {
}
UnwindTable &Module::GetUnwindTable() {
- if (!m_unwind_table)
+ if (!m_unwind_table) {
m_unwind_table.emplace(*this);
+ if (!m_symfile_spec)
+ Symbols::DownloadSymbolFileAsync(GetUUID());
+ }
return *m_unwind_table;
}
@@ -1367,9 +1349,9 @@ void Module::FindSymbolsWithNameAndType(ConstString name,
}
}
-void Module::FindSymbolsMatchingRegExAndType(const RegularExpression &regex,
- SymbolType symbol_type,
- SymbolContextList &sc_list) {
+void Module::FindSymbolsMatchingRegExAndType(
+ const RegularExpression &regex, SymbolType symbol_type,
+ SymbolContextList &sc_list, Mangled::NamePreference mangling_preference) {
// No need to protect this call using m_mutex all other method calls are
// already thread safe.
LLDB_SCOPED_TIMERF(
@@ -1379,7 +1361,7 @@ void Module::FindSymbolsMatchingRegExAndType(const RegularExpression &regex,
std::vector<uint32_t> symbol_indexes;
symtab->FindAllSymbolsMatchingRexExAndType(
regex, symbol_type, Symtab::eDebugAny, Symtab::eVisibilityAny,
- symbol_indexes);
+ symbol_indexes, mangling_preference);
SymbolIndicesToSymbolContextList(symtab, symbol_indexes, sc_list);
}
}
@@ -1618,8 +1600,7 @@ bool Module::FindSourceFile(const FileSpec &orig_spec,
return false;
}
-llvm::Optional<std::string>
-Module::RemapSourceFile(llvm::StringRef path) const {
+std::optional<std::string> Module::RemapSourceFile(llvm::StringRef path) const {
std::lock_guard<std::recursive_mutex> guard(m_mutex);
if (auto remapped = m_source_mappings.RemapPath(path))
return remapped->GetPath();
@@ -1629,7 +1610,15 @@ Module::RemapSourceFile(llvm::StringRef path) const {
void Module::RegisterXcodeSDK(llvm::StringRef sdk_name,
llvm::StringRef sysroot) {
XcodeSDK sdk(sdk_name.str());
- llvm::StringRef sdk_path(HostInfo::GetXcodeSDKPath(sdk));
+ auto sdk_path_or_err = HostInfo::GetXcodeSDKPath(sdk);
+
+ if (!sdk_path_or_err) {
+ Debugger::ReportError("Error while searching for Xcode SDK: " +
+ toString(sdk_path_or_err.takeError()));
+ return;
+ }
+
+ auto sdk_path = *sdk_path_or_err;
if (sdk_path.empty())
return;
// If the SDK changed for a previously registered source path, update it.