diff options
author | David Blaikie <dblaikie@gmail.com> | 2021-08-12 22:56:43 -0700 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2021-08-13 19:09:41 -0700 |
commit | 2af4db7d5cc8e752634a249cf328b27836810245 (patch) | |
tree | d6db3954f2f8cd8a5ed29d5b81f14ff2e1a4dd00 /llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp | |
parent | 50efbf9cbeed9d202e9f66a0d154489811918944 (diff) | |
download | llvm-2af4db7d5cc8e752634a249cf328b27836810245.zip llvm-2af4db7d5cc8e752634a249cf328b27836810245.tar.gz llvm-2af4db7d5cc8e752634a249cf328b27836810245.tar.bz2 |
Migrate DWARFVerifier tests to lit-based yaml instead of gtest with embedded yaml
Improves maintainability (edit/modify the tests without recompiling) and
error messages (previously the failure would be a gtest failure
mentioning nothing of the input or desired text) and the option to
improve tests with more checks.
(maybe these tests shouldn't all be in separate files - we could
probably have DWARF yaml that contains multiple errors while still being
fairly maintainable - the various invalid offsets (ref_addr, rnglists,
ranges, etc) could probably be all in one test, but for the simple sake
of the migration I just did the mechanical thing here)
Diffstat (limited to 'llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp')
-rw-r--r-- | llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp | 1051 |
1 files changed, 1 insertions, 1050 deletions
diff --git a/llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp b/llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp index 9a48066..9073a3f 100644 --- a/llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp +++ b/llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp @@ -36,6 +36,7 @@ using namespace llvm; using namespace dwarf; using namespace utils; +using ::testing::HasSubstr; namespace { @@ -1851,649 +1852,6 @@ TEST(DWARFDebugInfo, TestImplicitConstAbbrevs) { EXPECT_EQ(DIEs.find(Val2)->second, AbbrevPtrVal2); } -void VerifyWarning(DWARFContext &DwarfContext, StringRef Error) { - SmallString<1024> Str; - raw_svector_ostream Strm(Str); - EXPECT_TRUE(DwarfContext.verify(Strm)); - EXPECT_TRUE(Str.str().contains(Error)); -} - -void VerifyError(DWARFContext &DwarfContext, StringRef Error) { - SmallString<1024> Str; - raw_svector_ostream Strm(Str); - EXPECT_FALSE(DwarfContext.verify(Strm)); - EXPECT_TRUE(Str.str().contains(Error)); -} - -void VerifySuccess(DWARFContext &DwarfContext) { - SmallString<1024> Str; - raw_svector_ostream Strm(Str); - EXPECT_TRUE(DwarfContext.verify(Strm)); -} - -TEST(DWARFDebugInfo, TestDwarfVerifyInvalidCURef) { - // Create a single compile unit with a single function that has a DW_AT_type - // that is CU relative. The CU offset is not valid because it is larger than - // the compile unit itself. - - const char *yamldata = R"( - debug_str: - - '' - - /tmp/main.c - - main - debug_abbrev: - - Table: - - Code: 0x00000001 - Tag: DW_TAG_compile_unit - Children: DW_CHILDREN_yes - Attributes: - - Attribute: DW_AT_name - Form: DW_FORM_strp - - Code: 0x00000002 - Tag: DW_TAG_subprogram - Children: DW_CHILDREN_no - Attributes: - - Attribute: DW_AT_name - Form: DW_FORM_strp - - Attribute: DW_AT_type - Form: DW_FORM_ref4 - debug_info: - - Version: 4 - AddrSize: 8 - Entries: - - AbbrCode: 0x00000001 - Values: - - Value: 0x0000000000000001 - - AbbrCode: 0x00000002 - Values: - - Value: 0x000000000000000D - - Value: 0x0000000000001234 - - AbbrCode: 0x00000000 - )"; - auto ErrOrSections = DWARFYAML::emitDebugSections(StringRef(yamldata)); - ASSERT_TRUE((bool)ErrOrSections); - std::unique_ptr<DWARFContext> DwarfContext = - DWARFContext::create(*ErrOrSections, 8); - VerifyError(*DwarfContext, "error: DW_FORM_ref4 CU offset 0x00001234 is " - "invalid (must be less than CU size of " - "0x0000001a):"); -} - -TEST(DWARFDebugInfo, TestDwarfVerifyInvalidRefAddr) { - // Create a single compile unit with a single function that has an invalid - // DW_AT_type with an invalid .debug_info offset in its DW_FORM_ref_addr. - const char *yamldata = R"( - debug_str: - - '' - - /tmp/main.c - - main - debug_abbrev: - - Table: - - Code: 0x00000001 - Tag: DW_TAG_compile_unit - Children: DW_CHILDREN_yes - Attributes: - - Attribute: DW_AT_name - Form: DW_FORM_strp - - Code: 0x00000002 - Tag: DW_TAG_subprogram - Children: DW_CHILDREN_no - Attributes: - - Attribute: DW_AT_name - Form: DW_FORM_strp - - Attribute: DW_AT_type - Form: DW_FORM_ref_addr - debug_info: - - Version: 4 - AddrSize: 8 - Entries: - - AbbrCode: 0x00000001 - Values: - - Value: 0x0000000000000001 - - AbbrCode: 0x00000002 - Values: - - Value: 0x000000000000000D - - Value: 0x0000000000001234 - - AbbrCode: 0x00000000 - )"; - auto ErrOrSections = DWARFYAML::emitDebugSections(StringRef(yamldata)); - ASSERT_TRUE((bool)ErrOrSections); - std::unique_ptr<DWARFContext> DwarfContext = - DWARFContext::create(*ErrOrSections, 8); - VerifyError(*DwarfContext, - "error: DW_FORM_ref_addr offset beyond .debug_info bounds:"); -} - -TEST(DWARFDebugInfo, TestDwarfVerifyInvalidRanges) { - // Create a single compile unit with a DW_AT_ranges whose section offset - // isn't valid. - const char *yamldata = R"( - debug_str: - - '' - - /tmp/main.c - debug_abbrev: - - Table: - - Code: 0x00000001 - Tag: DW_TAG_compile_unit - Children: DW_CHILDREN_no - Attributes: - - Attribute: DW_AT_name - Form: DW_FORM_strp - - Attribute: DW_AT_ranges - Form: DW_FORM_sec_offset - debug_info: - - Version: 4 - AddrSize: 8 - Entries: - - AbbrCode: 0x00000001 - Values: - - Value: 0x0000000000000001 - - Value: 0x0000000000001000 - )"; - auto ErrOrSections = DWARFYAML::emitDebugSections(StringRef(yamldata)); - ASSERT_TRUE((bool)ErrOrSections); - std::unique_ptr<DWARFContext> DwarfContext = - DWARFContext::create(*ErrOrSections, 8); - VerifyError( - *DwarfContext, - "error: DW_AT_ranges offset is beyond .debug_ranges bounds: 0x00001000"); -} - -TEST(DWARFDebugInfo, TestDwarfVerifyInvalidRnglists) { - // Create a single compile unit with a DW_AT_ranges whose section offset - // isn't valid. - const char *yamldata = R"( - debug_str: - - '' - - /tmp/main.c - debug_abbrev: - - Table: - - Code: 0x00000001 - Tag: DW_TAG_compile_unit - Children: DW_CHILDREN_no - Attributes: - - Attribute: DW_AT_name - Form: DW_FORM_strp - - Attribute: DW_AT_ranges - Form: DW_FORM_sec_offset - debug_info: - - Version: 5 - UnitType: DW_UT_compile - AddrSize: 8 - Entries: - - AbbrCode: 0x00000001 - Values: - - Value: 0x0000000000000001 - - Value: 0x0000000000001000 - )"; - auto ErrOrSections = DWARFYAML::emitDebugSections(StringRef(yamldata)); - ASSERT_TRUE((bool)ErrOrSections); - std::unique_ptr<DWARFContext> DwarfContext = - DWARFContext::create(*ErrOrSections, 8); - VerifyError(*DwarfContext, "error: DW_AT_ranges offset is beyond " - ".debug_rnglists bounds: 0x00001000"); -} - -TEST(DWARFDebugInfo, TestDwarfVerifyInvalidStmtList) { - // Create a single compile unit with a DW_AT_stmt_list whose section offset - // isn't valid. - const char *yamldata = R"( - debug_str: - - '' - - /tmp/main.c - debug_abbrev: - - Table: - - Code: 0x00000001 - Tag: DW_TAG_compile_unit - Children: DW_CHILDREN_no - Attributes: - - Attribute: DW_AT_name - Form: DW_FORM_strp - - Attribute: DW_AT_stmt_list - Form: DW_FORM_sec_offset - debug_info: - - Version: 4 - AddrSize: 8 - Entries: - - AbbrCode: 0x00000001 - Values: - - Value: 0x0000000000000001 - - Value: 0x0000000000001000 - )"; - auto ErrOrSections = DWARFYAML::emitDebugSections(StringRef(yamldata)); - ASSERT_TRUE((bool)ErrOrSections); - std::unique_ptr<DWARFContext> DwarfContext = - DWARFContext::create(*ErrOrSections, 8); - VerifyError( - *DwarfContext, - "error: DW_AT_stmt_list offset is beyond .debug_line bounds: 0x00001000"); -} - -TEST(DWARFDebugInfo, TestDwarfVerifyInvalidStrp) { - // Create a single compile unit with a single function that has an invalid - // DW_FORM_strp for the DW_AT_name. - const char *yamldata = R"( - debug_str: - - '' - debug_abbrev: - - Table: - - Code: 0x00000001 - Tag: DW_TAG_compile_unit - Children: DW_CHILDREN_no - Attributes: - - Attribute: DW_AT_name - Form: DW_FORM_strp - debug_info: - - Version: 4 - AddrSize: 8 - Entries: - - AbbrCode: 0x00000001 - Values: - - Value: 0x0000000000001234 - )"; - auto ErrOrSections = DWARFYAML::emitDebugSections(StringRef(yamldata)); - ASSERT_TRUE((bool)ErrOrSections); - std::unique_ptr<DWARFContext> DwarfContext = - DWARFContext::create(*ErrOrSections, 8); - VerifyError(*DwarfContext, - "error: DW_FORM_strp offset beyond .debug_str bounds:"); -} - -TEST(DWARFDebugInfo, TestDwarfVerifyInvalidRefAddrBetween) { - // Create a single compile unit with a single function that has a DW_AT_type - // with a valid .debug_info offset, but the offset is between two DIEs. - const char *yamldata = R"( - debug_str: - - '' - - /tmp/main.c - - main - debug_abbrev: - - Table: - - Code: 0x00000001 - Tag: DW_TAG_compile_unit - Children: DW_CHILDREN_yes - Attributes: - - Attribute: DW_AT_name - Form: DW_FORM_strp - - Code: 0x00000002 - Tag: DW_TAG_subprogram - Children: DW_CHILDREN_no - Attributes: - - Attribute: DW_AT_name - Form: DW_FORM_strp - - Attribute: DW_AT_type - Form: DW_FORM_ref_addr - debug_info: - - Version: 4 - AddrSize: 8 - Entries: - - AbbrCode: 0x00000001 - Values: - - Value: 0x0000000000000001 - - AbbrCode: 0x00000002 - Values: - - Value: 0x000000000000000D - - Value: 0x0000000000000011 - - AbbrCode: 0x00000000 - )"; - auto ErrOrSections = DWARFYAML::emitDebugSections(StringRef(yamldata)); - ASSERT_TRUE((bool)ErrOrSections); - std::unique_ptr<DWARFContext> DwarfContext = - DWARFContext::create(*ErrOrSections, 8); - VerifyError( - *DwarfContext, - "error: invalid DIE reference 0x00000011. Offset is in between DIEs:"); -} - -TEST(DWARFDebugInfo, TestDwarfVerifyInvalidLineSequence) { - // Create a single compile unit whose line table has a sequence in it where - // the address decreases. - StringRef yamldata = R"( - debug_str: - - '' - - /tmp/main.c - debug_abbrev: - - Table: - - Code: 0x00000001 - Tag: DW_TAG_compile_unit - Children: DW_CHILDREN_no - Attributes: - - Attribute: DW_AT_name - Form: DW_FORM_strp - - Attribute: DW_AT_stmt_list - Form: DW_FORM_sec_offset - debug_info: - - Version: 4 - AddrSize: 8 - Entries: - - AbbrCode: 0x00000001 - Values: - - Value: 0x0000000000000001 - - Value: 0x0000000000000000 - debug_line: - - Version: 2 - MinInstLength: 1 - DefaultIsStmt: 1 - LineBase: 251 - LineRange: 14 - OpcodeBase: 13 - StandardOpcodeLengths: [ 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1 ] - IncludeDirs: - - /tmp - Files: - - Name: main.c - DirIdx: 1 - ModTime: 0 - Length: 0 - Opcodes: - - Opcode: DW_LNS_extended_op - ExtLen: 9 - SubOpcode: DW_LNE_set_address - Data: 4112 - - Opcode: DW_LNS_advance_line - SData: 9 - Data: 4112 - - Opcode: DW_LNS_copy - Data: 4112 - - Opcode: DW_LNS_advance_pc - Data: 18446744073709551600 - - Opcode: DW_LNS_extended_op - ExtLen: 1 - SubOpcode: DW_LNE_end_sequence - Data: 18446744073709551600 - )"; - auto ErrOrSections = DWARFYAML::emitDebugSections(yamldata); - ASSERT_TRUE((bool)ErrOrSections); - std::unique_ptr<DWARFContext> DwarfContext = - DWARFContext::create(*ErrOrSections, 8); - VerifyError(*DwarfContext, "error: .debug_line[0x00000000] row[1] decreases " - "in address from previous row:"); -} - -TEST(DWARFDebugInfo, TestDwarfVerifyInvalidLineFileIndex) { - // Create a single compile unit whose line table has a line table row with - // an invalid file index. - StringRef yamldata = R"( - debug_str: - - '' - - /tmp/main.c - debug_abbrev: - - Table: - - Code: 0x00000001 - Tag: DW_TAG_compile_unit - Children: DW_CHILDREN_no - Attributes: - - Attribute: DW_AT_name - Form: DW_FORM_strp - - Attribute: DW_AT_stmt_list - Form: DW_FORM_sec_offset - debug_info: - - Version: 4 - AddrSize: 8 - Entries: - - AbbrCode: 0x00000001 - Values: - - Value: 0x0000000000000001 - - Value: 0x0000000000000000 - debug_line: - - Version: 2 - MinInstLength: 1 - DefaultIsStmt: 1 - LineBase: 251 - LineRange: 14 - OpcodeBase: 13 - StandardOpcodeLengths: [ 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1 ] - IncludeDirs: - - /tmp - Files: - - Name: main.c - DirIdx: 1 - ModTime: 0 - Length: 0 - Opcodes: - - Opcode: DW_LNS_extended_op - ExtLen: 9 - SubOpcode: DW_LNE_set_address - Data: 4096 - - Opcode: DW_LNS_advance_line - SData: 9 - Data: 4096 - - Opcode: DW_LNS_copy - Data: 4096 - - Opcode: DW_LNS_advance_pc - Data: 16 - - Opcode: DW_LNS_set_file - Data: 5 - - Opcode: DW_LNS_extended_op - ExtLen: 1 - SubOpcode: DW_LNE_end_sequence - Data: 5 - )"; - auto ErrOrSections = DWARFYAML::emitDebugSections(yamldata); - ASSERT_TRUE((bool)ErrOrSections); - std::unique_ptr<DWARFContext> DwarfContext = - DWARFContext::create(*ErrOrSections, 8); - VerifyError(*DwarfContext, "error: .debug_line[0x00000000][1] has invalid " - "file index 5 (valid values are [1,1]):"); -} - -TEST(DWARFDebugInfo, TestDwarfVerifyInvalidLineTablePorlogueDirIndex) { - // Create a single compile unit whose line table has a prologue with an - // invalid dir index. - StringRef yamldata = R"( - debug_str: - - '' - - /tmp/main.c - debug_abbrev: - - Table: - - Code: 0x00000001 - Tag: DW_TAG_compile_unit - Children: DW_CHILDREN_no - Attributes: - - Attribute: DW_AT_name - Form: DW_FORM_strp - - Attribute: DW_AT_stmt_list - Form: DW_FORM_sec_offset - debug_info: - - Version: 4 - AddrSize: 8 - Entries: - - AbbrCode: 0x00000001 - Values: - - Value: 0x0000000000000001 - - Value: 0x0000000000000000 - debug_line: - - Version: 2 - MinInstLength: 1 - DefaultIsStmt: 1 - LineBase: 251 - LineRange: 14 - OpcodeBase: 13 - StandardOpcodeLengths: [ 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1 ] - IncludeDirs: - - /tmp - Files: - - Name: main.c - DirIdx: 2 - ModTime: 0 - Length: 0 - Opcodes: - - Opcode: DW_LNS_extended_op - ExtLen: 9 - SubOpcode: DW_LNE_set_address - Data: 4096 - - Opcode: DW_LNS_advance_line - SData: 9 - Data: 4096 - - Opcode: DW_LNS_copy - Data: 4096 - - Opcode: DW_LNS_advance_pc - Data: 16 - - Opcode: DW_LNS_set_file - Data: 1 - - Opcode: DW_LNS_extended_op - ExtLen: 1 - SubOpcode: DW_LNE_end_sequence - Data: 1 - )"; - auto ErrOrSections = DWARFYAML::emitDebugSections(yamldata); - ASSERT_TRUE((bool)ErrOrSections); - std::unique_ptr<DWARFContext> DwarfContext = - DWARFContext::create(*ErrOrSections, 8); - VerifyError(*DwarfContext, - "error: .debug_line[0x00000000].prologue." - "file_names[1].dir_idx contains an invalid index: 2"); -} - -TEST(DWARFDebugInfo, TestDwarfVerifyDuplicateFileWarning) { - // Create a single compile unit whose line table has a prologue with an - // invalid dir index. - StringRef yamldata = R"( - debug_str: - - '' - - /tmp/main.c - debug_abbrev: - - Table: - - Code: 0x00000001 - Tag: DW_TAG_compile_unit - Children: DW_CHILDREN_no - Attributes: - - Attribute: DW_AT_name - Form: DW_FORM_strp - - Attribute: DW_AT_stmt_list - Form: DW_FORM_sec_offset - debug_info: - - Version: 4 - AddrSize: 8 - Entries: - - AbbrCode: 0x00000001 - Values: - - Value: 0x0000000000000001 - - Value: 0x0000000000000000 - debug_line: - - Version: 2 - MinInstLength: 1 - DefaultIsStmt: 1 - LineBase: 251 - LineRange: 14 - OpcodeBase: 13 - StandardOpcodeLengths: [ 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1 ] - IncludeDirs: - - /tmp - Files: - - Name: main.c - DirIdx: 1 - ModTime: 0 - Length: 0 - - Name: main.c - DirIdx: 1 - ModTime: 0 - Length: 0 - Opcodes: - - Opcode: DW_LNS_extended_op - ExtLen: 9 - SubOpcode: DW_LNE_set_address - Data: 4096 - - Opcode: DW_LNS_advance_line - SData: 9 - Data: 4096 - - Opcode: DW_LNS_copy - Data: 4096 - - Opcode: DW_LNS_advance_pc - Data: 16 - - Opcode: DW_LNS_set_file - Data: 1 - - Opcode: DW_LNS_extended_op - ExtLen: 1 - SubOpcode: DW_LNE_end_sequence - Data: 2 - )"; - auto ErrOrSections = DWARFYAML::emitDebugSections(yamldata); - ASSERT_TRUE((bool)ErrOrSections); - std::unique_ptr<DWARFContext> DwarfContext = - DWARFContext::create(*ErrOrSections, 8); - VerifyWarning(*DwarfContext, - "warning: .debug_line[0x00000000].prologue.file_names[2] is " - "a duplicate of file_names[1]"); -} - -TEST(DWARFDebugInfo, TestDwarfVerifyCUDontShareLineTable) { - // Create a two compile units where both compile units share the same - // DW_AT_stmt_list value and verify we report the error correctly. - StringRef yamldata = R"( - debug_str: - - '' - - /tmp/main.c - - /tmp/foo.c - debug_abbrev: - - Table: - - Code: 0x00000001 - Tag: DW_TAG_compile_unit - Children: DW_CHILDREN_no - Attributes: - - Attribute: DW_AT_name - Form: DW_FORM_strp - - Attribute: DW_AT_stmt_list - Form: DW_FORM_sec_offset - debug_info: - - Version: 4 - AddrSize: 8 - Entries: - - AbbrCode: 0x00000001 - Values: - - Value: 0x0000000000000001 - - Value: 0x0000000000000000 - - Length: 16 - Version: 4 - AbbrevTableID: 0 - AddrSize: 8 - Entries: - - AbbrCode: 0x00000001 - Values: - - Value: 0x000000000000000D - - Value: 0x0000000000000000 - debug_line: - - Version: 2 - MinInstLength: 1 - DefaultIsStmt: 1 - LineBase: 251 - LineRange: 14 - OpcodeBase: 13 - StandardOpcodeLengths: [ 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1 ] - IncludeDirs: - - /tmp - Files: - - Name: main.c - DirIdx: 1 - ModTime: 0 - Length: 0 - Opcodes: - - Opcode: DW_LNS_extended_op - ExtLen: 9 - SubOpcode: DW_LNE_set_address - Data: 4096 - - Opcode: DW_LNS_advance_line - SData: 9 - Data: 4096 - - Opcode: DW_LNS_copy - Data: 4096 - - Opcode: DW_LNS_advance_pc - Data: 256 - - Opcode: DW_LNS_extended_op - ExtLen: 1 - SubOpcode: DW_LNE_end_sequence - Data: 256 - )"; - auto ErrOrSections = DWARFYAML::emitDebugSections(yamldata); - ASSERT_TRUE((bool)ErrOrSections); - std::unique_ptr<DWARFContext> DwarfContext = - DWARFContext::create(*ErrOrSections, 8); - VerifyError(*DwarfContext, - "error: two compile unit DIEs, 0x0000000b and " - "0x0000001f, have the same DW_AT_stmt_list section " - "offset:"); -} - TEST(DWARFDebugInfo, TestErrorReporting) { Triple Triple("x86_64-pc-linux"); if (!isConfigurationSupported(Triple)) @@ -2528,413 +1886,6 @@ TEST(DWARFDebugInfo, TestErrorReporting) { EXPECT_TRUE(Errors == 2); } -TEST(DWARFDebugInfo, TestDwarfVerifyCURangesIncomplete) { - // Create a single compile unit with a single function. The compile - // unit has a DW_AT_ranges attribute that doesn't fully contain the - // address range of the function. The verification should fail due to - // the CU ranges not containing all of the address ranges of all of the - // functions. - StringRef yamldata = R"( - debug_str: - - '' - - /tmp/main.c - debug_abbrev: - - Table: - - Code: 0x00000001 - Tag: DW_TAG_compile_unit - Children: DW_CHILDREN_yes - Attributes: - - Attribute: DW_AT_low_pc - Form: DW_FORM_addr - - Attribute: DW_AT_high_pc - Form: DW_FORM_addr - - Attribute: DW_AT_name - Form: DW_FORM_strp - - Code: 0x00000002 - Tag: DW_TAG_subprogram - Children: DW_CHILDREN_no - Attributes: - - Attribute: DW_AT_low_pc - Form: DW_FORM_addr - - Attribute: DW_AT_high_pc - Form: DW_FORM_addr - debug_info: - - Version: 4 - AddrSize: 8 - Entries: - - AbbrCode: 0x00000001 - Values: - - Value: 0x0000000000001000 - - Value: 0x0000000000001500 - - Value: 0x0000000000000001 - - AbbrCode: 0x00000002 - Values: - - Value: 0x0000000000001000 - - Value: 0x0000000000002000 - - AbbrCode: 0x00000000 - )"; - auto ErrOrSections = DWARFYAML::emitDebugSections(yamldata); - ASSERT_TRUE((bool)ErrOrSections); - std::unique_ptr<DWARFContext> DwarfContext = - DWARFContext::create(*ErrOrSections, 8); - VerifyError(*DwarfContext, "error: DIE address ranges are not " - "contained in its parent's ranges:"); -} - -TEST(DWARFDebugInfo, TestDwarfVerifyLexicalBlockRanges) { - // Create a single compile unit with a single function that has a lexical - // block whose address range is not contained in the function address range. - StringRef yamldata = R"( - debug_str: - - '' - - /tmp/main.c - - main - debug_abbrev: - - Table: - - Code: 0x00000001 - Tag: DW_TAG_compile_unit - Children: DW_CHILDREN_yes - Attributes: - - Attribute: DW_AT_name - Form: DW_FORM_strp - - Code: 0x00000002 - Tag: DW_TAG_subprogram - Children: DW_CHILDREN_yes - Attributes: - - Attribute: DW_AT_name - Form: DW_FORM_strp - - Attribute: DW_AT_low_pc - Form: DW_FORM_addr - - Attribute: DW_AT_high_pc - Form: DW_FORM_addr - - Code: 0x00000003 - Tag: DW_TAG_lexical_block - Children: DW_CHILDREN_no - Attributes: - - Attribute: DW_AT_low_pc - Form: DW_FORM_addr - - Attribute: DW_AT_high_pc - Form: DW_FORM_addr - debug_info: - - Version: 4 - AddrSize: 8 - Entries: - - AbbrCode: 0x00000001 - Values: - - Value: 0x0000000000000001 - - AbbrCode: 0x00000002 - Values: - - Value: 0x000000000000000D - - Value: 0x0000000000001000 - - Value: 0x0000000000002000 - - AbbrCode: 0x00000003 - Values: - - Value: 0x0000000000001000 - - Value: 0x0000000000002001 - - AbbrCode: 0x00000000 - - AbbrCode: 0x00000000 - )"; - auto ErrOrSections = DWARFYAML::emitDebugSections(yamldata); - ASSERT_TRUE((bool)ErrOrSections); - std::unique_ptr<DWARFContext> DwarfContext = - DWARFContext::create(*ErrOrSections, 8); - VerifyError(*DwarfContext, "error: DIE address ranges are not " - "contained in its parent's ranges:"); -} - -TEST(DWARFDebugInfo, TestDwarfVerifyOverlappingFunctionRanges) { - // Create a single compile unit with a two functions that have overlapping - // address ranges. - StringRef yamldata = R"( - debug_str: - - '' - - /tmp/main.c - - main - - foo - debug_abbrev: - - Table: - - Code: 0x00000001 - Tag: DW_TAG_compile_unit - Children: DW_CHILDREN_yes - Attributes: - - Attribute: DW_AT_name - Form: DW_FORM_strp - - Code: 0x00000002 - Tag: DW_TAG_subprogram - Children: DW_CHILDREN_no - Attributes: - - Attribute: DW_AT_name - Form: DW_FORM_strp - - Attribute: DW_AT_low_pc - Form: DW_FORM_addr - - Attribute: DW_AT_high_pc - Form: DW_FORM_addr - debug_info: - - Version: 4 - AddrSize: 8 - Entries: - - AbbrCode: 0x00000001 - Values: - - Value: 0x0000000000000001 - - AbbrCode: 0x00000002 - Values: - - Value: 0x000000000000000D - - Value: 0x0000000000001000 - - Value: 0x0000000000002000 - - AbbrCode: 0x00000002 - Values: - - Value: 0x0000000000000012 - - Value: 0x0000000000001FFF - - Value: 0x0000000000002000 - - AbbrCode: 0x00000000 - )"; - auto ErrOrSections = DWARFYAML::emitDebugSections(yamldata); - ASSERT_TRUE((bool)ErrOrSections); - std::unique_ptr<DWARFContext> DwarfContext = - DWARFContext::create(*ErrOrSections, 8); - VerifyError(*DwarfContext, "error: DIEs have overlapping address ranges:"); -} - -TEST(DWARFDebugInfo, TestDwarfVerifyOverlappingLexicalBlockRanges) { - // Create a single compile unit with a one function that has two lexical - // blocks with overlapping address ranges. - StringRef yamldata = R"( - debug_str: - - '' - - /tmp/main.c - - main - debug_abbrev: - - Table: - - Code: 0x00000001 - Tag: DW_TAG_compile_unit - Children: DW_CHILDREN_yes - Attributes: - - Attribute: DW_AT_low_pc - Form: DW_FORM_addr - - Attribute: DW_AT_high_pc - Form: DW_FORM_addr - - Attribute: DW_AT_name - Form: DW_FORM_strp - - Code: 0x00000002 - Tag: DW_TAG_subprogram - Children: DW_CHILDREN_yes - Attributes: - - Attribute: DW_AT_name - Form: DW_FORM_strp - - Attribute: DW_AT_low_pc - Form: DW_FORM_addr - - Attribute: DW_AT_high_pc - Form: DW_FORM_addr - - Code: 0x00000003 - Tag: DW_TAG_lexical_block - Children: DW_CHILDREN_no - Attributes: - - Attribute: DW_AT_low_pc - Form: DW_FORM_addr - - Attribute: DW_AT_high_pc - Form: DW_FORM_addr - debug_info: - - Version: 4 - AddrSize: 8 - Entries: - - AbbrCode: 0x00000001 - Values: - - Value: 0x0000000000001000 - - Value: 0x0000000000002000 - - Value: 0x0000000000000001 - - AbbrCode: 0x00000002 - Values: - - Value: 0x000000000000000D - - Value: 0x0000000000001000 - - Value: 0x0000000000002000 - - AbbrCode: 0x00000003 - Values: - - Value: 0x0000000000001100 - - Value: 0x0000000000001300 - - AbbrCode: 0x00000003 - Values: - - Value: 0x00000000000012FF - - Value: 0x0000000000001300 - - AbbrCode: 0x00000000 - - AbbrCode: 0x00000000 - )"; - auto ErrOrSections = DWARFYAML::emitDebugSections(yamldata); - ASSERT_TRUE((bool)ErrOrSections); - std::unique_ptr<DWARFContext> DwarfContext = - DWARFContext::create(*ErrOrSections, 8); - VerifyError(*DwarfContext, "error: DIEs have overlapping address ranges:"); -} - -TEST(DWARFDebugInfo, TestDwarfVerifyInvalidDIERange) { - // Create a single compile unit with a single function that has an invalid - // address range where the high PC is smaller than the low PC. - StringRef yamldata = R"( - debug_str: - - '' - - /tmp/main.c - - main - debug_abbrev: - - Table: - - Code: 0x00000001 - Tag: DW_TAG_compile_unit - Children: DW_CHILDREN_yes - Attributes: - - Attribute: DW_AT_name - Form: DW_FORM_strp - - Code: 0x00000002 - Tag: DW_TAG_subprogram - Children: DW_CHILDREN_no - Attributes: - - Attribute: DW_AT_name - Form: DW_FORM_strp - - Attribute: DW_AT_low_pc - Form: DW_FORM_addr - - Attribute: DW_AT_high_pc - Form: DW_FORM_addr - debug_info: - - Version: 4 - AddrSize: 8 - Entries: - - AbbrCode: 0x00000001 - Values: - - Value: 0x0000000000000001 - - AbbrCode: 0x00000002 - Values: - - Value: 0x000000000000000D - - Value: 0x0000000000001000 - - Value: 0x0000000000000900 - - AbbrCode: 0x00000000 - )"; - auto ErrOrSections = DWARFYAML::emitDebugSections(yamldata); - ASSERT_TRUE((bool)ErrOrSections); - std::unique_ptr<DWARFContext> DwarfContext = - DWARFContext::create(*ErrOrSections, 8); - VerifyError(*DwarfContext, "error: Invalid address range"); -} - -TEST(DWARFDebugInfo, TestDwarfVerifyElidedDoesntFail) { - // Create a single compile unit with two functions: one that has a valid range - // and one whose low and high PC are the same. When the low and high PC are - // the same, this indicates the function was dead code stripped. We want to - // ensure that verification succeeds. - StringRef yamldata = R"( - debug_str: - - '' - - /tmp/main.c - - main - - elided - debug_abbrev: - - Table: - - Code: 0x00000001 - Tag: DW_TAG_compile_unit - Children: DW_CHILDREN_yes - Attributes: - - Attribute: DW_AT_low_pc - Form: DW_FORM_addr - - Attribute: DW_AT_high_pc - Form: DW_FORM_addr - - Attribute: DW_AT_name - Form: DW_FORM_strp - - Code: 0x00000002 - Tag: DW_TAG_subprogram - Children: DW_CHILDREN_no - Attributes: - - Attribute: DW_AT_name - Form: DW_FORM_strp - - Attribute: DW_AT_low_pc - Form: DW_FORM_addr - - Attribute: DW_AT_high_pc - Form: DW_FORM_addr - debug_info: - - Version: 4 - AddrSize: 8 - Entries: - - AbbrCode: 0x00000001 - Values: - - Value: 0x0000000000001000 - - Value: 0x0000000000002000 - - Value: 0x0000000000000001 - - AbbrCode: 0x00000002 - Values: - - Value: 0x000000000000000D - - Value: 0x0000000000001000 - - Value: 0x0000000000002000 - - AbbrCode: 0x00000002 - Values: - - Value: 0x0000000000000012 - - Value: 0x0000000000002000 - - Value: 0x0000000000002000 - - AbbrCode: 0x00000000 - )"; - auto ErrOrSections = DWARFYAML::emitDebugSections(yamldata); - ASSERT_TRUE((bool)ErrOrSections); - std::unique_ptr<DWARFContext> DwarfContext = - DWARFContext::create(*ErrOrSections, 8); - VerifySuccess(*DwarfContext); -} - -TEST(DWARFDebugInfo, TestDwarfVerifyNestedFunctions) { - // Create a single compile unit with a nested function which is not contained - // in its parent. Although LLVM doesn't generate this, it is valid accoridng - // to the DWARF standard. - StringRef yamldata = R"( - debug_str: - - '' - - /tmp/main.c - - main - - nested - debug_abbrev: - - Table: - - Code: 0x00000001 - Tag: DW_TAG_compile_unit - Children: DW_CHILDREN_yes - Attributes: - - Attribute: DW_AT_low_pc - Form: DW_FORM_addr - - Attribute: DW_AT_high_pc - Form: DW_FORM_addr - - Attribute: DW_AT_name - Form: DW_FORM_strp - - Code: 0x00000002 - Tag: DW_TAG_subprogram - Children: DW_CHILDREN_yes - Attributes: - - Attribute: DW_AT_name - Form: DW_FORM_strp - - Attribute: DW_AT_low_pc - Form: DW_FORM_addr - - Attribute: DW_AT_high_pc - Form: DW_FORM_addr - debug_info: - - Version: 4 - AddrSize: 8 - Entries: - - AbbrCode: 0x00000001 - Values: - - Value: 0x0000000000001000 - - Value: 0x0000000000002000 - - Value: 0x0000000000000001 - - AbbrCode: 0x00000002 - Values: - - Value: 0x000000000000000D - - Value: 0x0000000000001000 - - Value: 0x0000000000001500 - - AbbrCode: 0x00000002 - Values: - - Value: 0x0000000000000012 - - Value: 0x0000000000001500 - - Value: 0x0000000000002000 - - AbbrCode: 0x00000000 - - AbbrCode: 0x00000000 - - AbbrCode: 0x00000000 - )"; - auto ErrOrSections = DWARFYAML::emitDebugSections(yamldata); - ASSERT_TRUE((bool)ErrOrSections); - std::unique_ptr<DWARFContext> DwarfContext = - DWARFContext::create(*ErrOrSections, 8); - VerifySuccess(*DwarfContext); -} - TEST(DWARFDebugInfo, TestDWARFDieRangeInfoContains) { DWARFVerifier::DieRangeInfo Empty; ASSERT_TRUE(Empty.contains(Empty)); |