[lldb/DWARF] Fix evaluator crash when accessing empty stack.

This patch fixes a crash that happens on the DWARF expression evaluator
when trying to access the top of the stack while it's empty.

rdar://60512489

Differential Revision: https://reviews.llvm.org/D77108

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
This commit is contained in:
Med Ismail Bennani 2020-03-31 02:33:42 +02:00
parent e4a778052e
commit f3a7d790df
No known key found for this signature in database
GPG key ID: 9040401522D38F4E
2 changed files with 10 additions and 0 deletions

View file

@ -2318,6 +2318,12 @@ bool DWARFExpression::Evaluate(
// rather is a constant value. The value from the top of the stack is the
// value to be used. This is the actual object value and not the location.
case DW_OP_stack_value:
if (stack.empty()) {
if (error_ptr)
error_ptr->SetErrorString(
"Expression stack needs at least 1 item for DW_OP_stack_value.");
return false;
}
stack.back().SetValueType(Value::eValueTypeScalar);
break;

View file

@ -234,6 +234,10 @@ TEST(DWARFExpression, DW_OP_convert) {
llvm::Failed());
}
TEST(DWARFExpression, DW_OP_stack_value) {
EXPECT_THAT_EXPECTED(Evaluate({DW_OP_stack_value}), llvm::Failed());
}
TEST(DWARFExpression, DW_OP_piece) {
EXPECT_THAT_EXPECTED(Evaluate({DW_OP_const2u, 0x11, 0x22, DW_OP_piece, 2,
DW_OP_const2u, 0x33, 0x44, DW_OP_piece, 2}),