[llvm] 57909b0 - [llvm-objdump] Add entry_value and stack_value opcodes

Oliver Stannard via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 14 02:26:24 PDT 2020


Author: Oliver Stannard
Date: 2020-07-14T10:24:59+01:00
New Revision: 57909b0a53d8167ac8f6079b53d5504c25157fdf

URL: https://github.com/llvm/llvm-project/commit/57909b0a53d8167ac8f6079b53d5504c25157fdf
DIFF: https://github.com/llvm/llvm-project/commit/57909b0a53d8167ac8f6079b53d5504c25157fdf.diff

LOG: [llvm-objdump] Add entry_value and stack_value opcodes

Add the DW_OP_entry_value and DW_OP_stack_value opcodes to the DWARF
expression printer.

Differential revision: https://reviews.llvm.org/D74843

Added: 
    

Modified: 
    llvm/include/llvm/DebugInfo/DWARF/DWARFExpression.h
    llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
    llvm/unittests/DebugInfo/DWARF/DWARFExpressionCompactPrinterTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFExpression.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFExpression.h
index 1aff2624990f..edfa68d49a60 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFExpression.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFExpression.h
@@ -126,6 +126,10 @@ class DWARFExpression {
       return Op;
     }
 
+    iterator skipBytes(uint64_t Add) {
+      return iterator(Expr, Op.EndOffset + Add);
+    }
+
     // Comparison operators are provided out of line.
     friend bool operator==(const iterator &, const iterator &);
   };

diff  --git a/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp b/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
index ffe2ef7532b9..de5e11e084f4 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
@@ -424,6 +424,27 @@ static bool printCompactDWARFExpr(raw_ostream &OS, DWARFExpression::iterator I,
         S << format("%+" PRId64, Offset);
       break;
     }
+    case dwarf::DW_OP_entry_value:
+    case dwarf::DW_OP_GNU_entry_value: {
+      // DW_OP_entry_value contains a sub-expression which must be rendered
+      // separately.
+      uint64_t SubExprLength = Op.getRawOperand(0);
+      DWARFExpression::iterator SubExprEnd = I.skipBytes(SubExprLength);
+      ++I;
+      raw_svector_ostream S(Stack.emplace_back().String);
+      S << "entry(";
+      printCompactDWARFExpr(S, I, SubExprEnd, MRI);
+      S << ")";
+      I = SubExprEnd;
+      continue;
+    }
+    case dwarf::DW_OP_stack_value: {
+      // The top stack entry should be treated as the actual value of tne
+      // variable, rather than the address of the variable in memory.
+      assert(!Stack.empty());
+      Stack.back().Kind = PrintedExpr::Value;
+      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

diff  --git a/llvm/unittests/DebugInfo/DWARF/DWARFExpressionCompactPrinterTest.cpp b/llvm/unittests/DebugInfo/DWARF/DWARFExpressionCompactPrinterTest.cpp
index 4cdd6079cdc4..6fa97794218c 100644
--- a/llvm/unittests/DebugInfo/DWARF/DWARFExpressionCompactPrinterTest.cpp
+++ b/llvm/unittests/DebugInfo/DWARF/DWARFExpressionCompactPrinterTest.cpp
@@ -98,3 +98,18 @@ TEST_F(DWARFExpressionCompactPrinterTest, Test_OP_breg0_negative) {
 TEST_F(DWARFExpressionCompactPrinterTest, Test_OP_bregx) {
   TestExprPrinter({DW_OP_bregx, 0x0d, 0x28}, "[SP+40]");
 }
+
+TEST_F(DWARFExpressionCompactPrinterTest, Test_OP_stack_value) {
+  TestExprPrinter({DW_OP_breg13, 0x04, DW_OP_stack_value}, "SP+4");
+}
+
+TEST_F(DWARFExpressionCompactPrinterTest, Test_OP_entry_value) {
+  TestExprPrinter({DW_OP_entry_value, 0x01, DW_OP_reg0, DW_OP_stack_value},
+                  "entry(R0)");
+}
+
+TEST_F(DWARFExpressionCompactPrinterTest, Test_OP_entry_value_mem) {
+  TestExprPrinter(
+      {DW_OP_entry_value, 0x02, DW_OP_breg13, 0x10, DW_OP_stack_value},
+      "entry([SP+16])");
+}


        


More information about the llvm-commits mailing list