[Lldb-commits] [PATCH] D147425: [lldb] fix #61728 wrong parameter value display represented via DW_OP_deref and DW_OP_lt

LU Hongyi via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Sun Apr 2 23:38:55 PDT 2023


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

This patch resolves an issue where a value is incorrectly displayed 
if it is represented by DW_OP_deref and DW_OP_lt combined.

This issue is caused by lldb treating DW_OP_deref generic types 
as unsigned by default, while DW_OP_lt should perform signed
comparison with these generic types by DWARF v5 standard.

This patch resolves this issue by making everything loaded by
DW_OP_deref as signed. As lldb does not really support generic
type, this is probably the best we can do.

A small regression test is also included in this patch.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147425

Files:
  lldb/source/Expression/DWARFExpression.cpp
  lldb/test/API/commands/expression/signed-dw-op-deref/Makefile
  lldb/test/API/commands/expression/signed-dw-op-deref/TestSignedDeref.py
  lldb/test/API/commands/expression/signed-dw-op-deref/main.c


Index: lldb/test/API/commands/expression/signed-dw-op-deref/main.c
===================================================================
--- /dev/null
+++ lldb/test/API/commands/expression/signed-dw-op-deref/main.c
@@ -0,0 +1,12 @@
+#include <stdio.h>
+int a;
+signed char b = -48;
+static int func_12(int p_13) {
+  for (;a;); // break here
+  return 0;
+}
+int main() {
+  func_12(0 > b);
+  printf(0);
+  return 0;
+}
Index: lldb/test/API/commands/expression/signed-dw-op-deref/TestSignedDeref.py
===================================================================
--- /dev/null
+++ lldb/test/API/commands/expression/signed-dw-op-deref/TestSignedDeref.py
@@ -0,0 +1,11 @@
+"""Test that we can print values represented via DW_OP_deref and DW_OP_lt"""
+
+import lldb
+from lldbsuite.test.lldbtest import *
+
+class SignedDerefTestCase(TestBase):
+    def test_signed_div(self):
+        """Test that we can print values represented via DW_OP_deref and DW_OP_lt"""
+        self.build()
+        _, process, _, bkpt = lldbutil.run_to_source_breakpoint(self, '// break here', lldb.SBFileSpec('main.c'))
+        self.expect_expr('p_13', result_type='int', result_value='1')
Index: lldb/test/API/commands/expression/signed-dw-op-deref/Makefile
===================================================================
--- /dev/null
+++ lldb/test/API/commands/expression/signed-dw-op-deref/Makefile
@@ -0,0 +1,5 @@
+C_SOURCES := main.c
+CFLAGS_EXTRAS := -g -O1
+override CC := gcc
+
+include Makefile.rules
Index: lldb/source/Expression/DWARFExpression.cpp
===================================================================
--- lldb/source/Expression/DWARFExpression.cpp
+++ lldb/source/Expression/DWARFExpression.cpp
@@ -1030,6 +1030,7 @@
               if (ABISP abi_sp = process->GetABI())
                 pointer_value = abi_sp->FixCodeAddress(pointer_value);
               stack.back().GetScalar() = pointer_value;
+              stack.back().GetScalar().MakeSigned();
               stack.back().ClearContext();
             } else {
               if (error_ptr)
@@ -1120,6 +1121,7 @@
           break;
         }
         stack.back().GetScalar() = ptr;
+        stack.back().GetScalar().MakeSigned();
         stack.back().ClearContext();
       } break;
       case Value::ValueType::FileAddress: {
@@ -1147,6 +1149,7 @@
 
             stack.back().GetScalar() = DerefSizeExtractDataHelper(
                 addr_bytes, size, objfile->GetByteOrder(), size);
+            stack.back().GetScalar().MakeSigned();
             stack.back().ClearContext();
             break;
           } else {
@@ -1177,6 +1180,7 @@
               stack.back().GetScalar() =
                   DerefSizeExtractDataHelper(addr_bytes, sizeof(addr_bytes),
                                              process->GetByteOrder(), size);
+              stack.back().GetScalar().MakeSigned();
               stack.back().ClearContext();
             } else {
               if (error_ptr)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147425.510407.patch
Type: text/x-patch
Size: 2964 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230403/6e4f240d/attachment.bin>


More information about the lldb-commits mailing list