diff options
author | Michael Buch <michaelbuch12@gmail.com> | 2025-06-12 17:14:31 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-06-12 17:14:31 +0100 |
commit | c6da2c877cb407c0404e58c5ca257d12036ed164 (patch) | |
tree | bd3883f27154419140fe2c7550886d50ea237f12 /lldb/source/Commands/CommandObjectMemory.cpp | |
parent | daee5eee8562d26d234f85152e803b6571b15ee2 (diff) | |
download | llvm-c6da2c877cb407c0404e58c5ca257d12036ed164.zip llvm-c6da2c877cb407c0404e58c5ca257d12036ed164.tar.gz llvm-c6da2c877cb407c0404e58c5ca257d12036ed164.tar.bz2 |
[lldb][Commands] Fix memory find for Swift expressions (#143860)
(depends on https://github.com/llvm/llvm-project/pull/143686)
There were two issues previously preventing `memory find -e` expressions
to succeed when stopped in Swift frames:
1. We weren't getting the dynamic type of the result `ValueObject`.
For Swift this would fail when we tried to produce a scalar value
out of it because the static VO wasn't sufficient to get to the
integer value. Hence we add a call to
`GetQualifiedRepresentationIfAvailable`
(which is what we do for expressions in `OptionArgParser::ToAddress`
too).
2. We weren't passing an `ExecutionContextScope` to `GetByteSize`, which
Swift relied on to get the size of the result type.
My plan is to add an API test for this on the Apple
`swiftlang/llvm-project` fork.
I considered an alternative where we use `OptionArgParser::ToAddress`
for `memory find -e` expressions, but it got a bit icky when trying to
figure out how many bytes we should copy out of the result into the
`DataBufferHeap` (currently we rely on the size of the result variable
type). This gets even trickier when we were to pass an expression that
was actually a hex digit or a number into `ToAddress`.
rdar://152113525
Diffstat (limited to 'lldb/source/Commands/CommandObjectMemory.cpp')
-rw-r--r-- | lldb/source/Commands/CommandObjectMemory.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp index 85ae9f8..ccb06d8 100644 --- a/lldb/source/Commands/CommandObjectMemory.cpp +++ b/lldb/source/Commands/CommandObjectMemory.cpp @@ -886,9 +886,10 @@ protected: #include "CommandOptions.inc" static llvm::Error CopyExpressionResult(ValueObject &result, - DataBufferHeap &buffer) { + DataBufferHeap &buffer, + ExecutionContextScope *scope) { uint64_t value = result.GetValueAsUnsigned(0); - auto size_or_err = result.GetCompilerType().GetByteSize(nullptr); + auto size_or_err = result.GetCompilerType().GetByteSize(scope); if (!size_or_err) return size_or_err.takeError(); @@ -928,6 +929,11 @@ EvaluateExpression(llvm::StringRef expression, StackFrame &frame, return llvm::createStringError( "expression evaluation failed. pass a string instead"); + result_sp = result_sp->GetQualifiedRepresentationIfAvailable( + result_sp->GetDynamicValueType(), /*synthValue=*/true); + if (!result_sp) + return llvm::createStringError("failed to get dynamic result type"); + return result_sp; } @@ -1082,7 +1088,8 @@ protected: ValueObjectSP result_sp = *result_or_err; - if (auto err = CopyExpressionResult(*result_sp, buffer)) { + if (auto err = CopyExpressionResult(*result_sp, buffer, + m_exe_ctx.GetFramePtr())) { result.AppendError(llvm::toString(std::move(err))); return; } |