[llvm] 1d7311e - [llvm-objdump] Add simple memory expressions to variable display
Oliver Stannard via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 14 02:26:22 PDT 2020
Author: Oliver Stannard
Date: 2020-07-14T10:24:59+01:00
New Revision: 1d7311e0524fa94c5ea775623d5008bf66baa300
URL: https://github.com/llvm/llvm-project/commit/1d7311e0524fa94c5ea775623d5008bf66baa300
DIFF: https://github.com/llvm/llvm-project/commit/1d7311e0524fa94c5ea775623d5008bf66baa300.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 d3c1cd5bb88f..ffe2ef7532b9 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
@@ -410,6 +410,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
@@ -422,6 +436,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.
@@ -435,7 +462,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