llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[lldb][Expression] Allow specifying a preferred ModuleList for lookup during expression evaluation

Open Michael137 opened this issue 11 months ago • 1 comments

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.

(cherry picked from commit https://github.com/swiftlang/llvm-project/commit/542d52b1e8a0a7e04538f608487603124c70e1ab)

Michael137 avatar Mar 24 '25 15:03 Michael137

@swift-ci test

Michael137 avatar Mar 24 '25 15:03 Michael137