llvm.org GIT mirror llvm / 8364bad
Verify that no compile units share the same line table in "llvm-dwarfdump --verify" Check to make sure no compile units have the same DW_AT_stmt_list values. Report a verification error if they do. Differential Revision: https://reviews.llvm.org/D32771 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@302039 91177308-0d34-0410-b5e6-96231b3b80d8 Greg Clayton 3 years ago
2 changed file(s) with 100 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
446446 }
447447
448448 bool HandleDebugLine() {
449 std::map StmtListToDie;
449450 bool Success = true;
450451 OS << "Verifying .debug_line...\n";
451452 for (const auto &CU : DCtx.compile_units()) {
452453 uint32_t LineTableOffset = 0;
453 auto StmtFormValue = CU->getUnitDIE().find(DW_AT_stmt_list);
454 auto CUDie = CU->getUnitDIE();
455 auto StmtFormValue = CUDie.find(DW_AT_stmt_list);
454456 if (!StmtFormValue) {
455457 // No line table for this compile unit.
456458 continue;
467469 // Skip this line table as it isn't valid. No need to create an error
468470 // here because we validate this in the .debug_info verifier.
469471 continue;
472 } else {
473 auto Iter = StmtListToDie.find(LineTableOffset);
474 if (Iter != StmtListToDie.end()) {
475 Success = false;
476 OS << "error: two compile unit DIEs, "
477 << format("0x%08" PRIx32, Iter->second.getOffset()) << " and "
478 << format("0x%08" PRIx32, CUDie.getOffset())
479 << ", have the same DW_AT_stmt_list section offset:\n";
480 Iter->second.dump(OS, 0);
481 CUDie.dump(OS, 0);
482 OS << '\n';
483 // Already verified this line table before, no need to do it again.
484 continue;
485 }
486 StmtListToDie[LineTableOffset] = CUDie;
470487 }
471488 }
472489 auto LineTable = DCtx.getLineTableForUnit(CU.get());
474491 Success = false;
475492 OS << "error: .debug_line[" << format("0x%08" PRIx32, LineTableOffset)
476493 << "] was not able to be parsed for CU:\n";
477 CU->getUnitDIE().dump(OS, 0);
494 CUDie.dump(OS, 0);
478495 OS << '\n';
479496 continue;
480497 }
20602060 "file index 5 (valid values are [1,1]):");
20612061 }
20622062
2063 TEST(DWARFDebugInfo, TestDwarfVerifyCUDontShareLineTable) {
2064 // Create a two compile units where both compile units share the same
2065 // DW_AT_stmt_list value and verify we report the error correctly.
2066 StringRef yamldata = R"(
2067 debug_str:
2068 - ''
2069 - /tmp/main.c
2070 - /tmp/foo.c
2071 debug_abbrev:
2072 - Code: 0x00000001
2073 Tag: DW_TAG_compile_unit
2074 Children: DW_CHILDREN_no
2075 Attributes:
2076 - Attribute: DW_AT_name
2077 Form: DW_FORM_strp
2078 - Attribute: DW_AT_stmt_list
2079 Form: DW_FORM_sec_offset
2080 debug_info:
2081 - Length:
2082 TotalLength: 16
2083 Version: 4
2084 AbbrOffset: 0
2085 AddrSize: 8
2086 Entries:
2087 - AbbrCode: 0x00000001
2088 Values:
2089 - Value: 0x0000000000000001
2090 - Value: 0x0000000000000000
2091 - Length:
2092 TotalLength: 16
2093 Version: 4
2094 AbbrOffset: 0
2095 AddrSize: 8
2096 Entries:
2097 - AbbrCode: 0x00000001
2098 Values:
2099 - Value: 0x000000000000000D
2100 - Value: 0x0000000000000000
2101 debug_line:
2102 - Length:
2103 TotalLength: 60
2104 Version: 2
2105 PrologueLength: 34
2106 MinInstLength: 1
2107 DefaultIsStmt: 1
2108 LineBase: 251
2109 LineRange: 14
2110 OpcodeBase: 13
2111 StandardOpcodeLengths: [ 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1 ]
2112 IncludeDirs:
2113 - /tmp
2114 Files:
2115 - Name: main.c
2116 DirIdx: 1
2117 ModTime: 0
2118 Length: 0
2119 Opcodes:
2120 - Opcode: DW_LNS_extended_op
2121 ExtLen: 9
2122 SubOpcode: DW_LNE_set_address
2123 Data: 4096
2124 - Opcode: DW_LNS_advance_line
2125 SData: 9
2126 Data: 4096
2127 - Opcode: DW_LNS_copy
2128 Data: 4096
2129 - Opcode: DW_LNS_advance_pc
2130 Data: 256
2131 - Opcode: DW_LNS_extended_op
2132 ExtLen: 1
2133 SubOpcode: DW_LNE_end_sequence
2134 Data: 256
2135 )";
2136 auto ErrOrSections = DWARFYAML::EmitDebugSections(yamldata);
2137 ASSERT_TRUE((bool)ErrOrSections);
2138 DWARFContextInMemory DwarfContext(*ErrOrSections, 8);
2139 VerifyError(DwarfContext, "error: two compile unit DIEs, 0x0000000b and "
2140 "0x0000001f, have the same DW_AT_stmt_list section "
2141 "offset:");
2142 }
2143
20632144 } // end anonymous namespace