Skip to content

Commit f62b898

Browse files
committed
[DebugInfo] Add unit test for compact expression printer
Add a unit test for the compact DWARF expression printer which will be used by the llvm-objdump --debug-vars option. Differential revision: https://reviews.llvm.org/D75250
1 parent 3a5dded commit f62b898

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

llvm/unittests/DebugInfo/DWARF/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ add_llvm_unittest(DebugInfoDWARFTests
1818
DWARFDebugInfoTest.cpp
1919
DWARFDebugLineTest.cpp
2020
DWARFDieTest.cpp
21+
DWARFExpressionCompactPrinterTest.cpp
2122
DWARFFormValueTest.cpp
2223
DWARFLocationExpressionTest.cpp
2324
)
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
//===- llvm/unittest/DebugInfo/DWARFExpressionCompactPrinterTest.cpp ------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "llvm/ADT/ArrayRef.h"
10+
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
11+
#include "llvm/DebugInfo/DWARF/DWARFDie.h"
12+
#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
13+
#include "llvm/MC/MCInstrInfo.h"
14+
#include "llvm/Support/DataExtractor.h"
15+
#include "llvm/Support/TargetRegistry.h"
16+
#include "llvm/Support/TargetSelect.h"
17+
#include "llvm/Testing/Support/Error.h"
18+
#include "gtest/gtest.h"
19+
#include "DwarfGenerator.h"
20+
21+
using namespace llvm;
22+
using namespace dwarf;
23+
24+
namespace {
25+
class DWARFExpressionCompactPrinterTest : public ::testing::Test {
26+
public:
27+
std::unique_ptr<MCRegisterInfo> MRI;
28+
29+
DWARFExpressionCompactPrinterTest() {
30+
InitializeAllTargets();
31+
InitializeAllTargetMCs();
32+
InitializeAllAsmPrinters();
33+
34+
std::string TripleName = "armv8a-linux-gnueabi";
35+
std::string ErrorStr;
36+
37+
const Target *TheTarget =
38+
TargetRegistry::lookupTarget(TripleName, ErrorStr);
39+
40+
if (!TheTarget)
41+
return;
42+
43+
MRI.reset(TheTarget->createMCRegInfo(TripleName));
44+
}
45+
46+
void TestExprPrinter(ArrayRef<uint8_t> ExprData, StringRef Expected);
47+
};
48+
} // namespace
49+
50+
void DWARFExpressionCompactPrinterTest::TestExprPrinter(
51+
ArrayRef<uint8_t> ExprData, StringRef Expected) {
52+
// If we didn't build ARM, do not run the test.
53+
if (!MRI)
54+
return;
55+
56+
// Print the expression, passing in the subprogram DIE, and check that the
57+
// result is as expected.
58+
std::string Result;
59+
raw_string_ostream OS(Result);
60+
DataExtractor DE(ExprData, true, 8);
61+
DWARFExpression Expr(DE, 8);
62+
Expr.printCompact(OS, *MRI);
63+
EXPECT_EQ(OS.str(), Expected);
64+
}
65+
66+
TEST_F(DWARFExpressionCompactPrinterTest, Test_OP_reg0) {
67+
TestExprPrinter({DW_OP_reg0}, "R0");
68+
}
69+
70+
TEST_F(DWARFExpressionCompactPrinterTest, Test_OP_reg10) {
71+
TestExprPrinter({DW_OP_reg10}, "R10");
72+
}
73+
74+
TEST_F(DWARFExpressionCompactPrinterTest, Test_OP_regx) {
75+
TestExprPrinter({DW_OP_regx, 0x80, 0x02}, "D0");
76+
}

0 commit comments

Comments
 (0)