[PATCH] D75250: [DebugInfo] Add unit test for compact expression printer

Oliver Stannard (Linaro) via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 27 06:31:07 PST 2020


ostannard created this revision.
ostannard added reviewers: aprantl, jhenderson.
Herald added a subscriber: mgorny.
Herald added a project: LLVM.

Add a unit test for the compact DWARF expression printer which will be used by the llvm-objdump --debug-vars option.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75250

Files:
  llvm/unittests/DebugInfo/DWARF/CMakeLists.txt
  llvm/unittests/DebugInfo/DWARF/DWARFExpressionCompactPrinterTest.cpp


Index: llvm/unittests/DebugInfo/DWARF/DWARFExpressionCompactPrinterTest.cpp
===================================================================
--- /dev/null
+++ llvm/unittests/DebugInfo/DWARF/DWARFExpressionCompactPrinterTest.cpp
@@ -0,0 +1,73 @@
+//===- llvm/unittest/DebugInfo/DWARFLocationExpressionTest.cpp ------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/DebugInfo/DWARF/DWARFContext.h"
+#include "llvm/DebugInfo/DWARF/DWARFDie.h"
+#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
+#include "llvm/MC/MCInstrInfo.h"
+#include "llvm/Support/DataExtractor.h"
+#include "llvm/Support/TargetRegistry.h"
+#include "llvm/Support/TargetSelect.h"
+#include "llvm/Testing/Support/Error.h"
+#include "gtest/gtest.h"
+#include "DwarfGenerator.h"
+
+using namespace llvm;
+using namespace dwarf;
+
+namespace {
+class DWARFExpressionCompactPrinterTest : public ::testing::Test {
+public:
+  std::unique_ptr<MCRegisterInfo> MRI;
+
+  DWARFExpressionCompactPrinterTest() {
+    InitializeAllTargets();
+    InitializeAllTargetMCs();
+    InitializeAllAsmPrinters();
+
+    std::string TripleName = "armv8a-linux-gnueabi";
+    std::string ErrorStr;
+
+    const Target *TheTarget =
+        TargetRegistry::lookupTarget(TripleName, ErrorStr);
+
+    // If we didn't build ARM, do not run the test.
+    if (!TheTarget)
+      return;
+
+    MRI.reset(TheTarget->createMCRegInfo(TripleName));
+  }
+
+  void TestExprPrinter(ArrayRef<uint8_t> ExprData, StringRef Expected);
+};
+} // namespace
+
+void DWARFExpressionCompactPrinterTest::TestExprPrinter(
+    ArrayRef<uint8_t> ExprData, StringRef Expected) {
+  // Print the expression, passing in the subprogram DIE, and check that the
+  // result is as expected.
+  std::string Result;
+  raw_string_ostream OS(Result);
+  DataExtractor DE(ExprData, true, 8);
+  DWARFExpression Expr(DE, 8);
+  Expr.printCompact(OS, MRI.get());
+  EXPECT_EQ(OS.str(), Expected);
+}
+
+TEST_F(DWARFExpressionCompactPrinterTest, Test_OP_reg0) {
+  TestExprPrinter({DW_OP_reg0}, "R0");
+}
+
+TEST_F(DWARFExpressionCompactPrinterTest, Test_OP_reg10) {
+  TestExprPrinter({DW_OP_reg10}, "R10");
+}
+
+TEST_F(DWARFExpressionCompactPrinterTest, Test_OP_regx) {
+  TestExprPrinter({DW_OP_regx, 0x80, 0x02}, "D0");
+}
Index: llvm/unittests/DebugInfo/DWARF/CMakeLists.txt
===================================================================
--- llvm/unittests/DebugInfo/DWARF/CMakeLists.txt
+++ llvm/unittests/DebugInfo/DWARF/CMakeLists.txt
@@ -19,6 +19,7 @@
   DWARFDieTest.cpp
   DWARFFormValueTest.cpp
   DWARFLocationExpressionTest.cpp
+  DWARFExpressionCompactPrinterTest.cpp
   )
 
 target_link_libraries(DebugInfoDWARFTests PRIVATE LLVMTestingSupport)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75250.246928.patch
Type: text/x-patch
Size: 2988 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200227/419dc33f/attachment.bin>


More information about the llvm-commits mailing list