|
| 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