mib created this revision.
mib added reviewers: labath, JDevlieghere, aprantl.
mib added projects: LLDB, debug-info.
Herald added a subscriber: lldb-commits.
mib requested review of this revision.

This patch completes https://reviews.llvm.org/D83560. Now that the
compiler can emit `DW_OP_implicit_value` into DWARF expressions, lldb
needed to learn to read these opcodes for variable inspection and
expression evaluation.

This implicit location descriptor specifies an immediate value with two
operands: a length (ULEB128) followed by a block representing the value
in the target memory representation.

Note that, at the moment, this feature is only supported when emitting
DWARFv5 debugging information. However, since dsymutil doesn't support
that version yet, the test is disabled on macOS and only ran in Linux.

rdar://67406091

Signed-off-by: Med Ismail Bennani <medismail.benn...@gmail.com>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89842

Files:
  lldb/source/Expression/DWARFExpression.cpp
  lldb/test/Shell/SymbolFile/DWARF/Inputs/implicit_value.c


Index: lldb/test/Shell/SymbolFile/DWARF/Inputs/implicit_value.c
===================================================================
--- /dev/null
+++ lldb/test/Shell/SymbolFile/DWARF/Inputs/implicit_value.c
@@ -0,0 +1,6 @@
+int main() {
+  double d = 3.14;
+  printf("break here");
+  d *= d;
+  return 0;
+}
Index: lldb/source/Expression/DWARFExpression.cpp
===================================================================
--- lldb/source/Expression/DWARFExpression.cpp
+++ lldb/source/Expression/DWARFExpression.cpp
@@ -846,6 +846,26 @@
   return true;
 }
 
+static bool Evaluate_DW_OP_implicit_value(std::vector<Value> &stack,
+                                          ExecutionContext *exe_ctx,
+                                          RegisterContext *reg_ctx,
+                                          const DataExtractor &opcodes,
+                                          lldb::offset_t &opcode_offset,
+                                          Status *error_ptr, Log *log) {
+
+  const uint32_t len = opcodes.GetULEB128(&opcode_offset);
+  const void *data = opcodes.GetData(&opcode_offset, len);
+
+  if (!data) {
+    LLDB_LOG(log, "Evaluate_DW_OP_implicit_value: could not be read data");
+    return false;
+  }
+
+  Value result(data, len);
+  stack.push_back(result);
+  return true;
+}
+
 bool DWARFExpression::Evaluate(ExecutionContextScope *exe_scope,
                                lldb::addr_t loclist_base_load_addr,
                                const Value *initial_value_ptr,
@@ -2248,6 +2268,23 @@
       }
       break;
 
+    // OPCODE: DW_OP_implicit_value
+    // OPERANDS: 2
+    //      ULEB128  size of the value block in bytes
+    //      uint8_t* block bytes encoding value in target's memory
+    //      representation
+    // DESCRIPTION: Value is immediately stored in block in the debug info with
+    // the memory representation of the target.
+    case DW_OP_implicit_value: {
+      if (!Evaluate_DW_OP_implicit_value(stack, exe_ctx, reg_ctx, opcodes,
+                                         offset, error_ptr, log)) {
+        LLDB_ERRORF(error_ptr, "Could not evaluate %s.",
+                    DW_OP_value_to_name(op));
+        return false;
+      }
+      break;
+    }
+
     // OPCODE: DW_OP_push_object_address
     // OPERANDS: none
     // DESCRIPTION: Pushes the address of the object currently being


Index: lldb/test/Shell/SymbolFile/DWARF/Inputs/implicit_value.c
===================================================================
--- /dev/null
+++ lldb/test/Shell/SymbolFile/DWARF/Inputs/implicit_value.c
@@ -0,0 +1,6 @@
+int main() {
+  double d = 3.14;
+  printf("break here");
+  d *= d;
+  return 0;
+}
Index: lldb/source/Expression/DWARFExpression.cpp
===================================================================
--- lldb/source/Expression/DWARFExpression.cpp
+++ lldb/source/Expression/DWARFExpression.cpp
@@ -846,6 +846,26 @@
   return true;
 }
 
+static bool Evaluate_DW_OP_implicit_value(std::vector<Value> &stack,
+                                          ExecutionContext *exe_ctx,
+                                          RegisterContext *reg_ctx,
+                                          const DataExtractor &opcodes,
+                                          lldb::offset_t &opcode_offset,
+                                          Status *error_ptr, Log *log) {
+
+  const uint32_t len = opcodes.GetULEB128(&opcode_offset);
+  const void *data = opcodes.GetData(&opcode_offset, len);
+
+  if (!data) {
+    LLDB_LOG(log, "Evaluate_DW_OP_implicit_value: could not be read data");
+    return false;
+  }
+
+  Value result(data, len);
+  stack.push_back(result);
+  return true;
+}
+
 bool DWARFExpression::Evaluate(ExecutionContextScope *exe_scope,
                                lldb::addr_t loclist_base_load_addr,
                                const Value *initial_value_ptr,
@@ -2248,6 +2268,23 @@
       }
       break;
 
+    // OPCODE: DW_OP_implicit_value
+    // OPERANDS: 2
+    //      ULEB128  size of the value block in bytes
+    //      uint8_t* block bytes encoding value in target's memory
+    //      representation
+    // DESCRIPTION: Value is immediately stored in block in the debug info with
+    // the memory representation of the target.
+    case DW_OP_implicit_value: {
+      if (!Evaluate_DW_OP_implicit_value(stack, exe_ctx, reg_ctx, opcodes,
+                                         offset, error_ptr, log)) {
+        LLDB_ERRORF(error_ptr, "Could not evaluate %s.",
+                    DW_OP_value_to_name(op));
+        return false;
+      }
+      break;
+    }
+
     // OPCODE: DW_OP_push_object_address
     // OPERANDS: none
     // DESCRIPTION: Pushes the address of the object currently being
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to