Skip to content

Commit c6da2c8

Browse files
authored
[lldb][Commands] Fix memory find for Swift expressions (llvm#143860)
(depends on llvm#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
1 parent daee5ee commit c6da2c8

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

lldb/source/Commands/CommandObjectMemory.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -886,9 +886,10 @@ class CommandObjectMemoryRead : public CommandObjectParsed {
886886
#include "CommandOptions.inc"
887887

888888
static llvm::Error CopyExpressionResult(ValueObject &result,
889-
DataBufferHeap &buffer) {
889+
DataBufferHeap &buffer,
890+
ExecutionContextScope *scope) {
890891
uint64_t value = result.GetValueAsUnsigned(0);
891-
auto size_or_err = result.GetCompilerType().GetByteSize(nullptr);
892+
auto size_or_err = result.GetCompilerType().GetByteSize(scope);
892893
if (!size_or_err)
893894
return size_or_err.takeError();
894895

@@ -928,6 +929,11 @@ EvaluateExpression(llvm::StringRef expression, StackFrame &frame,
928929
return llvm::createStringError(
929930
"expression evaluation failed. pass a string instead");
930931

932+
result_sp = result_sp->GetQualifiedRepresentationIfAvailable(
933+
result_sp->GetDynamicValueType(), /*synthValue=*/true);
934+
if (!result_sp)
935+
return llvm::createStringError("failed to get dynamic result type");
936+
931937
return result_sp;
932938
}
933939

@@ -1082,7 +1088,8 @@ class CommandObjectMemoryFind : public CommandObjectParsed {
10821088

10831089
ValueObjectSP result_sp = *result_or_err;
10841090

1085-
if (auto err = CopyExpressionResult(*result_sp, buffer)) {
1091+
if (auto err = CopyExpressionResult(*result_sp, buffer,
1092+
m_exe_ctx.GetFramePtr())) {
10861093
result.AppendError(llvm::toString(std::move(err)));
10871094
return;
10881095
}

0 commit comments

Comments
 (0)