[PATCH] D76225: [llvm-objdump] Add constant value opcodes to variable display

Oliver Stannard (Linaro) via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 16 05:17:14 PDT 2020


ostannard created this revision.
ostannard added reviewers: jhenderson, echristo, MaskRay.
Herald added subscribers: hiraditya, aprantl.
Herald added a project: LLVM.
ostannard added a parent revision: D76224: [llvm-objdump] Add call_frame_cfa locations to variable display.

Add the DW_OP_const* and DW_OP_lit* classes of DWARF expression opcodes, to display variables which have a constant value.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76225

Files:
  llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
  llvm/unittests/DebugInfo/DWARF/DWARFExpressionCompactPrinterTest.cpp


Index: llvm/unittests/DebugInfo/DWARF/DWARFExpressionCompactPrinterTest.cpp
===================================================================
--- llvm/unittests/DebugInfo/DWARF/DWARFExpressionCompactPrinterTest.cpp
+++ llvm/unittests/DebugInfo/DWARF/DWARFExpressionCompactPrinterTest.cpp
@@ -156,3 +156,40 @@
 TEST_F(DWARFExpressionCompactPrinterTest, Test_OP_fbreg_cfa) {
   TestExprPrinter({DW_OP_fbreg, 0x78}, "[CFA-8]", {DW_OP_call_frame_cfa});
 }
+
+TEST_F(DWARFExpressionCompactPrinterTest, Test_OP_constu) {
+  TestExprPrinter({DW_OP_constu, 0x2a, DW_OP_stack_value}, "42");
+  TestExprPrinter({DW_OP_constu, 0x7f, DW_OP_stack_value}, "127");
+  TestExprPrinter({DW_OP_constu, 0x80, 0x01, DW_OP_stack_value}, "128");
+}
+
+TEST_F(DWARFExpressionCompactPrinterTest, Test_OP_consts) {
+  TestExprPrinter({DW_OP_consts, 0x2a, DW_OP_stack_value}, "42");
+  TestExprPrinter({DW_OP_consts, 0x7f, DW_OP_stack_value}, "-1");
+  TestExprPrinter({DW_OP_consts, 0x80, 0x01, DW_OP_stack_value}, "128");
+}
+
+TEST_F(DWARFExpressionCompactPrinterTest, Test_OP_constNu) {
+  TestExprPrinter({DW_OP_const1u, 0x2a, DW_OP_stack_value}, "42");
+  TestExprPrinter({DW_OP_const2u, 0x00, 0x80, DW_OP_stack_value}, "32768");
+  TestExprPrinter({DW_OP_const4u, 0x00, 0x00, 0x00, 0x80, DW_OP_stack_value},
+                  "2147483648");
+  TestExprPrinter({DW_OP_const8u, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x80, DW_OP_stack_value},
+                  "9223372036854775808");
+}
+
+TEST_F(DWARFExpressionCompactPrinterTest, Test_OP_constNs) {
+  TestExprPrinter({DW_OP_const1s, 0x80, DW_OP_stack_value}, "-128");
+  TestExprPrinter({DW_OP_const2s, 0x00, 0x80, DW_OP_stack_value}, "-32768");
+  TestExprPrinter({DW_OP_const4s, 0x00, 0x00, 0x00, 0x80, DW_OP_stack_value},
+                  "-2147483648");
+  TestExprPrinter({DW_OP_const8s, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                   0x80, DW_OP_stack_value},
+                  "-9223372036854775808");
+}
+
+TEST_F(DWARFExpressionCompactPrinterTest, Test_OP_lit) {
+  TestExprPrinter({DW_OP_lit0, DW_OP_stack_value}, "0");
+  TestExprPrinter({DW_OP_lit31, DW_OP_stack_value}, "31");
+}
Index: llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
===================================================================
--- llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
+++ llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
@@ -455,6 +455,28 @@
       S << "CFA";
       break;
     }
+    case dwarf::DW_OP_consts:
+    case dwarf::DW_OP_const1s:
+    case dwarf::DW_OP_const2s:
+    case dwarf::DW_OP_const4s:
+    case dwarf::DW_OP_const8s: {
+      // Signed constant.
+      int64_t Val = Op.getRawOperand(0);
+      raw_svector_ostream S(Stack.emplace_back().String);
+      S << Val;
+      break;
+    }
+    case dwarf::DW_OP_constu:
+    case dwarf::DW_OP_const1u:
+    case dwarf::DW_OP_const2u:
+    case dwarf::DW_OP_const4u:
+    case dwarf::DW_OP_const8u: {
+      // Unsigned constant.
+      uint64_t Val = Op.getRawOperand(0);
+      raw_svector_ostream S(Stack.emplace_back().String);
+      S << Val;
+      break;
+    }
     default:
       if (Opcode >= dwarf::DW_OP_reg0 && Opcode <= dwarf::DW_OP_reg31) {
         // DW_OP_reg<N>: A register, with the register num implied by the
@@ -480,6 +502,11 @@
         S << MRI.getName(*LLVMRegNum);
         if (Offset)
           S << format("%+" PRId64, Offset);
+      } else if (Opcode >= dwarf::DW_OP_lit0 && Opcode <= dwarf::DW_OP_lit31) {
+        // Small unsigned constant.
+        unsigned Val = Opcode - dwarf::DW_OP_lit0;
+        raw_svector_ostream S(Stack.emplace_back().String);
+        S << Val;
       } else {
         // If we hit an unknown operand, we don't know its effect on the stack,
         // so bail out on the whole expression.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76225.250525.patch
Type: text/x-patch
Size: 3793 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200316/bca34b61/attachment.bin>


More information about the llvm-commits mailing list