[Lldb-commits] [lldb] c6da2c8 - [lldb][Commands] Fix memory find for Swift expressions (#143860)
via lldb-commits
lldb-commits at lists.llvm.org
Thu Jun 12 09:14:34 PDT 2025
Author: Michael Buch
Date: 2025-06-12T17:14:31+01:00
New Revision: c6da2c877cb407c0404e58c5ca257d12036ed164
URL: https://github.com/llvm/llvm-project/commit/c6da2c877cb407c0404e58c5ca257d12036ed164
DIFF: https://github.com/llvm/llvm-project/commit/c6da2c877cb407c0404e58c5ca257d12036ed164.diff
LOG: [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
Added:
Modified:
lldb/source/Commands/CommandObjectMemory.cpp
Removed:
################################################################################
diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp
index 85ae9f8f9e8cb..ccb06d8ff4d59 100644
--- a/lldb/source/Commands/CommandObjectMemory.cpp
+++ b/lldb/source/Commands/CommandObjectMemory.cpp
@@ -886,9 +886,10 @@ class CommandObjectMemoryRead : public CommandObjectParsed {
#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 @@ class CommandObjectMemoryFind : public CommandObjectParsed {
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;
}
More information about the lldb-commits
mailing list