Skip to content

Commit f55ab6f

Browse files
committed
Fix a buffer-size bug when the first DW_OP_piece is undefined
and document the shortcomings of LLDB's partially defined DW_OP_piece handling. This would manifest as "DW_OP_piece for offset foo but top of stack is of size bar". rdar://problem/46262998 Differential Revision: https://reviews.llvm.org/D72880
1 parent 7b0d58e commit f55ab6f

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lldb/source/Expression/DWARFExpression.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -2071,6 +2071,10 @@ bool DWARFExpression::Evaluate(
20712071
// not available. Fill with zeros for now by resizing the data and
20722072
// appending it
20732073
curr_piece.ResizeData(piece_byte_size);
2074+
// Note that "0" is not a correct value for the unknown bits.
2075+
// It would be better to also return a mask of valid bits together
2076+
// with the expression result, so the debugger can print missing
2077+
// members as "<optimized out>" or something.
20742078
::memset(curr_piece.GetBuffer().GetBytes(), 0, piece_byte_size);
20752079
pieces.AppendDataToHostBuffer(curr_piece);
20762080
} else {
@@ -2193,8 +2197,8 @@ bool DWARFExpression::Evaluate(
21932197
return false;
21942198
}
21952199
}
2196-
op_piece_offset += piece_byte_size;
21972200
}
2201+
op_piece_offset += piece_byte_size;
21982202
}
21992203
} break;
22002204

lldb/unittests/Expression/DWARFExpressionTest.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -355,4 +355,9 @@ TEST(DWARFExpression, DW_OP_piece) {
355355
EXPECT_THAT_EXPECTED(Evaluate({DW_OP_const2u, 0x11, 0x22, DW_OP_piece, 2,
356356
DW_OP_const2u, 0x33, 0x44, DW_OP_piece, 2}),
357357
llvm::HasValue(GetScalar(32, 0x44332211, true)));
358+
EXPECT_THAT_EXPECTED(
359+
Evaluate({DW_OP_piece, 1, DW_OP_const1u, 0xff, DW_OP_piece, 1}),
360+
// Note that the "00" should really be "undef", but we can't
361+
// represent that yet.
362+
llvm::HasValue(GetScalar(16, 0xff00, true)));
358363
}

0 commit comments

Comments
 (0)