Skip to content

Commit 14ccba2

Browse files
committed
Promote scalars to load addresses when dereferencing them.
This is a follow-up to 188b074. This is a very narrow fix to a more general problem. LLDB should be better at distinguishing between implict and memory location descriptions. rdar://74902042
1 parent 29034f3 commit 14ccba2

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lldb/source/Expression/DWARFExpression.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,10 +1064,12 @@ bool DWARFExpression::Evaluate(
10641064
return false;
10651065
}
10661066
stack.back().GetScalar() = load_Addr;
1067-
stack.back().SetValueType(Value::ValueType::LoadAddress);
1068-
// Fall through to load address code below...
1067+
// Fall through to load address promotion code below.
10691068
} LLVM_FALLTHROUGH;
10701069
case Value::ValueType::Scalar:
1070+
// Promote Scalar to LoadAddress and fall through.
1071+
stack.back().SetValueType(Value::ValueType::LoadAddress);
1072+
LLVM_FALLTHROUGH;
10711073
case Value::ValueType::LoadAddress:
10721074
if (exe_ctx) {
10731075
if (process) {

lldb/unittests/Expression/DWARFExpressionTest.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ static llvm::Expected<Scalar> Evaluate(llvm::ArrayRef<uint8_t> expr,
4141
switch (result.GetValueType()) {
4242
case Value::ValueType::Scalar:
4343
return result.GetScalar();
44+
case Value::ValueType::LoadAddress:
45+
return LLDB_INVALID_ADDRESS;
4446
case Value::ValueType::HostAddress: {
4547
// Convert small buffers to scalars to simplify the tests.
4648
DataBufferHeap &buf = result.GetBuffer();
@@ -344,6 +346,12 @@ TEST_F(DWARFExpressionMockProcessTest, DW_OP_deref) {
344346
ASSERT_TRUE(process_sp);
345347

346348
ExecutionContext exe_ctx(process_sp);
347-
EXPECT_THAT_EXPECTED(Evaluate({DW_OP_lit4, DW_OP_deref}, {}, {}, &exe_ctx),
349+
// Implicit location: *0x4.
350+
EXPECT_THAT_EXPECTED(Evaluate({DW_OP_lit4, DW_OP_deref, DW_OP_stack_value},
351+
{}, {}, &exe_ctx),
348352
llvm::HasValue(GetScalar(32, 0x07060504, false)));
353+
// Memory location: *(*0x4).
354+
// Evaluate returns LLDB_INVALID_ADDRESS for all load addresses.
355+
EXPECT_THAT_EXPECTED(Evaluate({DW_OP_lit4, DW_OP_deref}, {}, {}, &exe_ctx),
356+
llvm::HasValue(Scalar(LLDB_INVALID_ADDRESS)));
349357
}

0 commit comments

Comments
 (0)