[llvm] c0cf5f5 - [llvm-objdump] Add simple memory expressions to variable display

Oliver Stannard via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 16 03:55:20 PDT 2020


Author: Oliver Stannard
Date: 2020-03-16T10:54:41Z
New Revision: c0cf5f5da9a7bf1bdf43ed53287b0f634fc53045

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

LOG: [llvm-objdump] Add simple memory expressions to variable display

Add the DW_OP_breg0..DW_OP_breg31 and DW_OP_bregx opcodes to the DWARF
expression printer.

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp b/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
index d180076e73fd..735d805ece77 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
@@ -387,6 +387,20 @@ static bool printCompactDWARFExpr(raw_ostream &OS, DWARFExpression::iterator I,
       S << MRI.getName(*LLVMRegNum);
       break;
     }
+    case dwarf::DW_OP_bregx: {
+      int DwarfRegNum = Op.getRawOperand(0);
+      int64_t Offset = Op.getRawOperand(1);
+      Optional<unsigned> LLVMRegNum = MRI.getLLVMRegNum(DwarfRegNum, false);
+      if (!LLVMRegNum) {
+        OS << "<unknown register " << DwarfRegNum << ">";
+        return false;
+      }
+      raw_svector_ostream S(Stack.emplace_back().String);
+      S << MRI.getName(*LLVMRegNum);
+      if (Offset)
+        S << format("%+" PRId64, Offset);
+      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
@@ -399,6 +413,19 @@ static bool printCompactDWARFExpr(raw_ostream &OS, DWARFExpression::iterator I,
         }
         raw_svector_ostream S(Stack.emplace_back(PrintedExpr::Value).String);
         S << MRI.getName(*LLVMRegNum);
+      } else if (Opcode >= dwarf::DW_OP_breg0 &&
+                 Opcode <= dwarf::DW_OP_breg31) {
+        int DwarfRegNum = Opcode - dwarf::DW_OP_breg0;
+        int64_t Offset = Op.getRawOperand(0);
+        Optional<unsigned> LLVMRegNum = MRI.getLLVMRegNum(DwarfRegNum, false);
+        if (!LLVMRegNum) {
+          OS << "<unknown register " << DwarfRegNum << ">";
+          return false;
+        }
+        raw_svector_ostream S(Stack.emplace_back().String);
+        S << MRI.getName(*LLVMRegNum);
+        if (Offset)
+          S << format("%+" PRId64, Offset);
       } else {
         // If we hit an unknown operand, we don't know its effect on the stack,
         // so bail out on the whole expression.
@@ -412,7 +439,11 @@ static bool printCompactDWARFExpr(raw_ostream &OS, DWARFExpression::iterator I,
   }
 
   assert(Stack.size() == 1 && "expected one value on stack");
-  OS << Stack.front().String;
+
+  if (Stack.front().Kind == PrintedExpr::Address)
+    OS << "[" << Stack.front().String << "]";
+  else
+    OS << Stack.front().String;
 
   return true;
 }

diff  --git a/llvm/unittests/DebugInfo/DWARF/DWARFExpressionCompactPrinterTest.cpp b/llvm/unittests/DebugInfo/DWARF/DWARFExpressionCompactPrinterTest.cpp
index d411c9204f0a..4cdd6079cdc4 100644
--- a/llvm/unittests/DebugInfo/DWARF/DWARFExpressionCompactPrinterTest.cpp
+++ b/llvm/unittests/DebugInfo/DWARF/DWARFExpressionCompactPrinterTest.cpp
@@ -74,3 +74,27 @@ TEST_F(DWARFExpressionCompactPrinterTest, Test_OP_reg10) {
 TEST_F(DWARFExpressionCompactPrinterTest, Test_OP_regx) {
   TestExprPrinter({DW_OP_regx, 0x80, 0x02}, "D0");
 }
+
+TEST_F(DWARFExpressionCompactPrinterTest, Test_OP_breg0) {
+  TestExprPrinter({DW_OP_breg0, 0x04}, "[R0+4]");
+}
+
+TEST_F(DWARFExpressionCompactPrinterTest, Test_OP_breg0_large_offset) {
+  TestExprPrinter({DW_OP_breg0, 0x80, 0x02}, "[R0+256]");
+}
+
+TEST_F(DWARFExpressionCompactPrinterTest, Test_OP_breg13) {
+  TestExprPrinter({DW_OP_breg13, 0x10}, "[SP+16]");
+}
+
+TEST_F(DWARFExpressionCompactPrinterTest, Test_OP_breg13_zero_offset) {
+  TestExprPrinter({DW_OP_breg13, 0x00}, "[SP]");
+}
+
+TEST_F(DWARFExpressionCompactPrinterTest, Test_OP_breg0_negative) {
+  TestExprPrinter({DW_OP_breg0, 0x70}, "[R0-16]");
+}
+
+TEST_F(DWARFExpressionCompactPrinterTest, Test_OP_bregx) {
+  TestExprPrinter({DW_OP_bregx, 0x0d, 0x28}, "[SP+40]");
+}


        


More information about the llvm-commits mailing list