diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2018-07-28 10:51:19 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2018-07-28 10:51:19 +0000 |
commit | eb11fae6d08f479c0799db45860a98af528fa6e7 (patch) | |
tree | 44d492a50c8c1a7eb8e2d17ea3360ec4d066f042 /unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp | |
parent | b8a2042aa938069e862750553db0e4d82d25822c (diff) |
Notes
Diffstat (limited to 'unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp')
-rw-r--r-- | unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp | 110 |
1 files changed, 77 insertions, 33 deletions
diff --git a/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp b/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp index cb7bf82d86f6..442dea3c52f7 100644 --- a/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp +++ b/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp @@ -1,4 +1,4 @@ -//===- llvm/unittest/DebugInfo/DWARFFormValueTest.cpp ---------------------===// +//===- llvm/unittest/DebugInfo/DWARFDebugInfoTest.cpp ---------------------===// // // The LLVM Compiler Infrastructure // @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include "DwarfGenerator.h" +#include "DwarfUtils.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallString.h" @@ -15,7 +16,6 @@ #include "llvm/ADT/Triple.h" #include "llvm/BinaryFormat/Dwarf.h" #include "llvm/CodeGen/AsmPrinter.h" -#include "llvm/Config/llvm-config.h" #include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h" #include "llvm/DebugInfo/DWARF/DWARFContext.h" #include "llvm/DebugInfo/DWARF/DWARFDie.h" @@ -36,36 +36,10 @@ using namespace llvm; using namespace dwarf; +using namespace utils; namespace { -void initLLVMIfNeeded() { - static bool gInitialized = false; - if (!gInitialized) { - gInitialized = true; - InitializeAllTargets(); - InitializeAllTargetMCs(); - InitializeAllAsmPrinters(); - InitializeAllAsmParsers(); - } -} - -Triple getHostTripleForAddrSize(uint8_t AddrSize) { - Triple PT(Triple::normalize(LLVM_HOST_TRIPLE)); - - if (AddrSize == 8 && PT.isArch32Bit()) - return PT.get64BitArchVariant(); - if (AddrSize == 4 && PT.isArch64Bit()) - return PT.get32BitArchVariant(); - return PT; -} - -static bool isConfigurationSupported(Triple &T) { - initLLVMIfNeeded(); - std::string Err; - return TargetRegistry::lookupTarget(T.getTriple(), Err); -} - template <uint16_t Version, class AddrType, class RefAddrType> void TestAllForms() { Triple Triple = getHostTripleForAddrSize(sizeof(AddrType)); @@ -93,12 +67,21 @@ void TestAllForms() { const uint32_t Dwarf32Values[] = {1, 2, 3, 4, 5, 6, 7, 8}; const char *StringValue = "Hello"; const char *StrpValue = "World"; + const char *StrxValue = "Indexed"; + const char *Strx1Value = "Indexed1"; + const char *Strx2Value = "Indexed2"; + const char *Strx3Value = "Indexed3"; + const char *Strx4Value = "Indexed4"; auto ExpectedDG = dwarfgen::Generator::create(Triple, Version); ASSERT_THAT_EXPECTED(ExpectedDG, Succeeded()); dwarfgen::Generator *DG = ExpectedDG.get().get(); dwarfgen::CompileUnit &CU = DG->addCompileUnit(); dwarfgen::DIE CUDie = CU.getUnitDIE(); + + if (Version >= 5) + CUDie.addStrOffsetsBaseAttribute(); + uint16_t Attr = DW_AT_lo_user; //---------------------------------------------------------------------- @@ -148,6 +131,19 @@ void TestAllForms() { const auto Attr_DW_FORM_string = static_cast<dwarf::Attribute>(Attr++); CUDie.addAttribute(Attr_DW_FORM_string, DW_FORM_string, StringValue); + const auto Attr_DW_FORM_strx = static_cast<dwarf::Attribute>(Attr++); + const auto Attr_DW_FORM_strx1 = static_cast<dwarf::Attribute>(Attr++); + const auto Attr_DW_FORM_strx2 = static_cast<dwarf::Attribute>(Attr++); + const auto Attr_DW_FORM_strx3 = static_cast<dwarf::Attribute>(Attr++); + const auto Attr_DW_FORM_strx4 = static_cast<dwarf::Attribute>(Attr++); + if (Version >= 5) { + CUDie.addAttribute(Attr_DW_FORM_strx, DW_FORM_strx, StrxValue); + CUDie.addAttribute(Attr_DW_FORM_strx1, DW_FORM_strx1, Strx1Value); + CUDie.addAttribute(Attr_DW_FORM_strx2, DW_FORM_strx2, Strx2Value); + CUDie.addAttribute(Attr_DW_FORM_strx3, DW_FORM_strx3, Strx3Value); + CUDie.addAttribute(Attr_DW_FORM_strx4, DW_FORM_strx4, Strx4Value); + } + const auto Attr_DW_FORM_strp = static_cast<dwarf::Attribute>(Attr++); CUDie.addAttribute(Attr_DW_FORM_strp, DW_FORM_strp, StrpValue); @@ -307,11 +303,33 @@ void TestAllForms() { //---------------------------------------------------------------------- auto ExtractedStringValue = toString(DieDG.find(Attr_DW_FORM_string)); EXPECT_TRUE((bool)ExtractedStringValue); - EXPECT_TRUE(strcmp(StringValue, *ExtractedStringValue) == 0); + EXPECT_STREQ(StringValue, *ExtractedStringValue); + + if (Version >= 5) { + auto ExtractedStrxValue = toString(DieDG.find(Attr_DW_FORM_strx)); + EXPECT_TRUE((bool)ExtractedStrxValue); + EXPECT_STREQ(StrxValue, *ExtractedStrxValue); + + auto ExtractedStrx1Value = toString(DieDG.find(Attr_DW_FORM_strx1)); + EXPECT_TRUE((bool)ExtractedStrx1Value); + EXPECT_STREQ(Strx1Value, *ExtractedStrx1Value); + + auto ExtractedStrx2Value = toString(DieDG.find(Attr_DW_FORM_strx2)); + EXPECT_TRUE((bool)ExtractedStrx2Value); + EXPECT_STREQ(Strx2Value, *ExtractedStrx2Value); + + auto ExtractedStrx3Value = toString(DieDG.find(Attr_DW_FORM_strx3)); + EXPECT_TRUE((bool)ExtractedStrx3Value); + EXPECT_STREQ(Strx3Value, *ExtractedStrx3Value); + + auto ExtractedStrx4Value = toString(DieDG.find(Attr_DW_FORM_strx4)); + EXPECT_TRUE((bool)ExtractedStrx4Value); + EXPECT_STREQ(Strx4Value, *ExtractedStrx4Value); + } auto ExtractedStrpValue = toString(DieDG.find(Attr_DW_FORM_strp)); EXPECT_TRUE((bool)ExtractedStrpValue); - EXPECT_TRUE(strcmp(StrpValue, *ExtractedStrpValue) == 0); + EXPECT_STREQ(StrpValue, *ExtractedStrpValue); //---------------------------------------------------------------------- // Test reference forms @@ -516,6 +534,11 @@ template <uint16_t Version, class AddrType> void TestChildren() { EXPECT_TRUE(!NullDieDG.getSibling().isValid()); EXPECT_TRUE(!NullDieDG.getFirstChild().isValid()); } + + // Verify the previous sibling of our subprogram is our integer base type. + IntDieDG = NullDieDG.getPreviousSibling(); + EXPECT_TRUE(IntDieDG.isValid()); + EXPECT_EQ(IntDieDG.getTag(), DW_TAG_base_type); } TEST(DWARFDebugInfo, TestDWARF32Version2Addr4Children) { @@ -1098,6 +1121,27 @@ TEST(DWARFDebugInfo, TestRelations) { // Make sure the parent of all the children of the B are the B. EXPECT_EQ(C1.getParent(), C); EXPECT_EQ(C2.getParent(), C); + + // Make sure bidirectional iterator works as expected. + auto Begin = A.begin(); + auto End = A.end(); + auto It = A.begin(); + + EXPECT_EQ(It, Begin); + EXPECT_EQ(*It, B); + ++It; + EXPECT_EQ(*It, C); + ++It; + EXPECT_EQ(*It, D); + ++It; + EXPECT_EQ(It, End); + --It; + EXPECT_EQ(*It, D); + --It; + EXPECT_EQ(*It, C); + --It; + EXPECT_EQ(*It, B); + EXPECT_EQ(It, Begin); } TEST(DWARFDebugInfo, TestDWARFDie) { @@ -1191,7 +1235,7 @@ TEST(DWARFDebugInfo, TestEmptyChildren) { " Attributes:\n" "debug_info:\n" " - Length:\n" - " TotalLength: 9\n" + " TotalLength: 0\n" " Version: 4\n" " AbbrOffset: 0\n" " AddrSize: 8\n" @@ -1201,7 +1245,7 @@ TEST(DWARFDebugInfo, TestEmptyChildren) { " - AbbrCode: 0x00000000\n" " Values:\n"; - auto ErrOrSections = DWARFYAML::EmitDebugSections(StringRef(yamldata)); + auto ErrOrSections = DWARFYAML::EmitDebugSections(StringRef(yamldata), true); ASSERT_TRUE((bool)ErrOrSections); std::unique_ptr<DWARFContext> DwarfContext = DWARFContext::create(*ErrOrSections, 8); |