aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Expression/IRExecutionUnit.cpp
diff options
context:
space:
mode:
authorMichael Buch <michaelbuch12@gmail.com>2025-03-06 21:07:22 +0000
committerGitHub <noreply@github.com>2025-03-06 21:07:22 +0000
commit542d52b1e8a0a7e04538f608487603124c70e1ab (patch)
tree0b6e3b5bc6494d4f4ba69e844c5aa2b425541366 /lldb/source/Expression/IRExecutionUnit.cpp
parent9a0e652ec7e38b4ae18b744071d4d3906210bc04 (diff)
downloadllvm-542d52b1e8a0a7e04538f608487603124c70e1ab.tar.gz
llvm-542d52b1e8a0a7e04538f608487603124c70e1ab.tar.bz2
llvm-542d52b1e8a0a7e04538f608487603124c70e1ab.zip
[lldb][Expression] Allow specifying a preferred ModuleList for lookup during expression evaluation (#129733)
The `TestMemoryHistory.py`/`TestReportData.py` are currently failing on the x86 macOS CI (started after we upgraded the Xcode SDK on that machien). The LLDB ASAN utility expression is failing to run with following error: ``` (lldb) image lookup -n __asan_get_alloc_stack 1 match found in /usr/lib/system/libsystem_sanitizers.dylib: Address: libsystem_sanitizers.dylib[0x00007ffd11e673f7] (libsystem_sanitizers.dylib.__TEXT.__text + 11287) Summary: libsystem_sanitizers.dylib`__asan_get_alloc_stack 1 match found in /Users/michaelbuch/Git/lldb-build-main-no-modules/lib/clang/21/lib/darwin/libclang_rt.asan_osx_dynamic.dylib: Address: libclang_rt.asan_osx_dynamic.dylib[0x0000000000009ec0] (libclang_rt.asan_osx_dynamic.dylib.__TEXT.__text + 34352) Summary: libclang_rt.asan_osx_dynamic.dylib`::__asan_get_alloc_stack(__sanitizer::uptr, __sanitizer::uptr *, __sanitizer::uptr, __sanitizer::u32 *) at asan_debugging.cpp:132 (lldb) memory history 'pointer' Assertion failed: ((uintptr_t)addr == report.access.address), function __asan_get_alloc_stack, file debugger_abi.cpp, line 62. warning: cannot evaluate AddressSanitizer expression: error: Expression execution was interrupted: signal SIGABRT. The process has been returned to the state before expression evaluation. ``` The reason for this is that the system sanitizer dylib and the locally built libclang_rt contain the same symbol `__asan_get_alloc_stack`, and depending on the order in which they're loaded, we may pick the one from the wrong dylib (this probably changed during the buildbot upgrade and is why it only now started failing). Based on discussion with @wrotki we always want to pick the one that's in the libclang_rt dylib if it was loaded, and libsystem_sanitizers otherwise. This patch addresses this by adding a "preferred lookup context list" to the expression evaluator. Currently this is only exposed in the `EvaluateExpressionOptions`. We make it a `SymbolContextList` in case we want the lookup contexts to be contexts other than modules (e.g., source files, etc.). In `IRExecutionUnit` we make it a `ModuleList` because it makes the symbol lookup implementation simpler and we only do module lookups here anyway. If we ever need it to be a `SymbolContext`, that transformation shouldn't be too difficult.
Diffstat (limited to 'lldb/source/Expression/IRExecutionUnit.cpp')
-rw-r--r--lldb/source/Expression/IRExecutionUnit.cpp31
1 files changed, 26 insertions, 5 deletions
diff --git a/lldb/source/Expression/IRExecutionUnit.cpp b/lldb/source/Expression/IRExecutionUnit.cpp
index c8b4ddf705ec..06b0cb7769f6 100644
--- a/lldb/source/Expression/IRExecutionUnit.cpp
+++ b/lldb/source/Expression/IRExecutionUnit.cpp
@@ -52,7 +52,7 @@ IRExecutionUnit::IRExecutionUnit(std::unique_ptr<llvm::LLVMContext> &context_up,
m_cpu_features(cpu_features), m_name(name), m_sym_ctx(sym_ctx),
m_did_jit(false), m_function_load_addr(LLDB_INVALID_ADDRESS),
m_function_end_load_addr(LLDB_INVALID_ADDRESS),
- m_reported_allocations(false) {}
+ m_reported_allocations(false), m_preferred_modules() {}
lldb::addr_t IRExecutionUnit::WriteNow(const uint8_t *bytes, size_t size,
Status &error) {
@@ -782,8 +782,11 @@ IRExecutionUnit::FindInSymbols(const std::vector<ConstString> &names,
}
ModuleList non_local_images = target->GetImages();
- // We'll process module_sp separately, before the other modules.
+ // We'll process module_sp and any preferred modules separately, before the
+ // other modules.
non_local_images.Remove(sc.module_sp);
+ for (size_t i = 0; i < m_preferred_modules.GetSize(); ++i)
+ non_local_images.Remove(m_preferred_modules.GetModuleAtIndex(i));
LoadAddressResolver resolver(target, symbol_was_missing_weak);
@@ -794,9 +797,11 @@ IRExecutionUnit::FindInSymbols(const std::vector<ConstString> &names,
for (const ConstString &name : names) {
// The lookup order here is as follows:
// 1) Functions in `sc.module_sp`
- // 2) Functions in the other modules
- // 3) Symbols in `sc.module_sp`
- // 4) Symbols in the other modules
+ // 2) Functions in the preferred modules list
+ // 3) Functions in the other modules
+ // 4) Symbols in `sc.module_sp`
+ // 5) Symbols in the preferred modules list
+ // 6) Symbols in the other modules
if (sc.module_sp) {
SymbolContextList sc_list;
sc.module_sp->FindFunctions(name, CompilerDeclContext(),
@@ -808,6 +813,14 @@ IRExecutionUnit::FindInSymbols(const std::vector<ConstString> &names,
{
SymbolContextList sc_list;
+ m_preferred_modules.FindFunctions(name, lldb::eFunctionNameTypeFull,
+ function_options, sc_list);
+ if (auto load_addr = resolver.Resolve(sc_list))
+ return *load_addr;
+ }
+
+ {
+ SymbolContextList sc_list;
non_local_images.FindFunctions(name, lldb::eFunctionNameTypeFull,
function_options, sc_list);
if (auto load_addr = resolver.Resolve(sc_list))
@@ -824,6 +837,14 @@ IRExecutionUnit::FindInSymbols(const std::vector<ConstString> &names,
{
SymbolContextList sc_list;
+ m_preferred_modules.FindSymbolsWithNameAndType(name, lldb::eSymbolTypeAny,
+ sc_list);
+ if (auto load_addr = resolver.Resolve(sc_list))
+ return *load_addr;
+ }
+
+ {
+ SymbolContextList sc_list;
non_local_images.FindSymbolsWithNameAndType(name, lldb::eSymbolTypeAny,
sc_list);
if (auto load_addr = resolver.Resolve(sc_list))