[Lldb-commits] [PATCH] D155197: [lldb][NFC] Refactor test to enable subsequent reuse

Felipe de Azevedo Piovezan via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Jul 13 06:36:35 PDT 2023


fdeazeve created this revision.
Herald added a project: All.
fdeazeve requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155197

Files:
  lldb/unittests/Expression/DWARFExpressionTest.cpp


Index: lldb/unittests/Expression/DWARFExpressionTest.cpp
===================================================================
--- lldb/unittests/Expression/DWARFExpressionTest.cpp
+++ lldb/unittests/Expression/DWARFExpressionTest.cpp
@@ -500,19 +500,26 @@
                                             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);
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155197.539996.patch
Type: text/x-patch
Size: 1717 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230713/6894147d/attachment.bin>


More information about the lldb-commits mailing list