From: Felipe de Azevedo Piovezan Date: Thu, 13 Jul 2023 13:12:01 +0000 (-0400) Subject: [lldb][NFC] Refactor test to enable subsequent reuse X-Git-Tag: upstream/17.0.6~1164 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=00c60496775b611d92bae5a69d4e6794ecad4084;p=platform%2Fupstream%2Fllvm.git [lldb][NFC] Refactor test to enable subsequent reuse On a subsequent commit, I intend to update the expression and call the evaluate function more times. This refactors enables reusing some of the existing code for that. Differential Revision: https://reviews.llvm.org/D155197 --- diff --git a/lldb/unittests/Expression/DWARFExpressionTest.cpp b/lldb/unittests/Expression/DWARFExpressionTest.cpp index 7d153d7..e35f35b 100644 --- a/lldb/unittests/Expression/DWARFExpressionTest.cpp +++ b/lldb/unittests/Expression/DWARFExpressionTest.cpp @@ -500,19 +500,26 @@ DWARF: platform_sp, target_sp); ExecutionContext exe_ctx(target_sp, false); + + auto evaluate = [&](DWARFExpression &expr, Status &status, Value &result) { + DataExtractor extractor; + expr.GetExpressionData(extractor); + return DWARFExpression::Evaluate( + &exe_ctx, /*reg_ctx*/ nullptr, /*module_sp*/ {}, extractor, dwarf_cu, + lldb::eRegisterKindLLDB, + /*initial_value_ptr*/ nullptr, + /*object_address_ptr*/ nullptr, result, &status); + }; + // DW_OP_addrx takes a single leb128 operand, the index in the addr table: - uint8_t expr[] = {DW_OP_addrx, 0x01}; - DataExtractor extractor(expr, sizeof(expr), lldb::eByteOrderLittle, + uint8_t expr_data[] = {DW_OP_addrx, 0x01}; + DataExtractor extractor(expr_data, sizeof(expr_data), lldb::eByteOrderLittle, /*addr_size*/ 4); - Value result; - Status status; - ASSERT_TRUE(DWARFExpression::Evaluate( - &exe_ctx, /*reg_ctx*/ nullptr, /*module_sp*/ {}, extractor, dwarf_cu, - lldb::eRegisterKindLLDB, - /*initial_value_ptr*/ nullptr, - /*object_address_ptr*/ nullptr, result, &status)) - << status.ToError(); + DWARFExpression expr(extractor); + Status status; + Value result; + ASSERT_TRUE(evaluate(expr, status, result)) << status.ToError(); ASSERT_EQ(result.GetValueType(), Value::ValueType::LoadAddress); ASSERT_EQ(result.GetScalar().UInt(), 0x5678u); }