Index: include/llvm/DebugInfo/DWARF/DWARFVerifier.h =================================================================== --- include/llvm/DebugInfo/DWARF/DWARFVerifier.h +++ include/llvm/DebugInfo/DWARF/DWARFVerifier.h @@ -96,6 +96,9 @@ std::map> ReferenceToDIEOffsets; uint32_t NumDebugLineErrors = 0; + raw_ostream &error() const { return OS << "error: "; } + raw_ostream &warning() const { return OS << "warning: "; } + /// Verifies the abbreviations section. /// /// This function currently checks that: Index: lib/DebugInfo/DWARF/DWARFVerifier.cpp =================================================================== --- lib/DebugInfo/DWARF/DWARFVerifier.cpp +++ lib/DebugInfo/DWARF/DWARFVerifier.cpp @@ -148,19 +148,20 @@ if (!ValidLength || !ValidVersion || !ValidAddrSize || !ValidAbbrevOffset || !ValidType) { Success = false; - OS << format("Units[%d] - start offset: 0x%08x \n", UnitIndex, OffsetStart); + error() << format("Units[%d] - start offset: 0x%08x \n", UnitIndex, + OffsetStart); if (!ValidLength) - OS << "\tError: The length for this unit is too " + OS << "\tThe length for this unit is too " "large for the .debug_info provided.\n"; if (!ValidVersion) - OS << "\tError: The 16 bit unit header version is not valid.\n"; + OS << "\tThe 16 bit unit header version is not valid.\n"; if (!ValidType) - OS << "\tError: The unit type encoding is not valid.\n"; + OS << "\tThe unit type encoding is not valid.\n"; if (!ValidAbbrevOffset) - OS << "\tError: The offset into the .debug_abbrev section is " + OS << "\tThe offset into the .debug_abbrev section is " "not valid.\n"; if (!ValidAddrSize) - OS << "\tError: The address size is unsupported.\n"; + OS << "\t: The address size is unsupported.\n"; } *Offset = OffsetStart + Length + 4; return Success; @@ -183,7 +184,7 @@ DieRangeInfo RI; NumUnitErrors += verifyDieRanges(Die, RI); } else { - OS << "error: Compilation unit without unit DIE.\n"; + error() << "Compilation unit without unit DIE.\n"; NumUnitErrors++; } @@ -200,8 +201,8 @@ for (auto Attribute : AbbrDecl.attributes()) { auto Result = AttributeSet.insert(Attribute.Attr); if (!Result.second) { - OS << "Error: Abbreviation declaration contains multiple " - << AttributeString(Attribute.Attr) << " attributes.\n"; + error() << "Abbreviation declaration contains multiple " + << AttributeString(Attribute.Attr) << " attributes.\n"; AbbrDecl.dump(OS); ++NumErrors; } @@ -290,7 +291,7 @@ ++UnitIdx; } if (UnitIdx == 0 && !hasDIE) { - OS << "Warning: .debug_info is empty.\n"; + warning() << ".debug_info is empty.\n"; isHeaderChainValid = true; } NumDebugInfoErrors += verifyDebugInfoReferences(); @@ -312,9 +313,9 @@ for (auto Range : Ranges) { if (!Range.valid()) { ++NumErrors; - OS << format("error: Invalid address range [0x%08" PRIx64 - " - 0x%08" PRIx64 "].\n", - Range.LowPC, Range.HighPC); + error() << format("Invalid address range [0x%08" PRIx64 " - 0x%08" PRIx64 + "].\n", + Range.LowPC, Range.HighPC); continue; } @@ -322,11 +323,11 @@ const auto IntersectingRange = RI.insert(Range); if (IntersectingRange != RI.Ranges.end()) { ++NumErrors; - OS << format("error: DIE has overlapping address ranges: [0x%08" PRIx64 - " - 0x%08" PRIx64 "] and [0x%08" PRIx64 " - 0x%08" PRIx64 - "].\n", - Range.LowPC, Range.HighPC, IntersectingRange->LowPC, - IntersectingRange->HighPC); + error() << format("DIE has overlapping address ranges: [0x%08" PRIx64 + " - 0x%08" PRIx64 "] and [0x%08" PRIx64 + " - 0x%08" PRIx64 "].\n", + Range.LowPC, Range.HighPC, IntersectingRange->LowPC, + IntersectingRange->HighPC); break; } } @@ -335,7 +336,7 @@ const auto IntersectingChild = ParentRI.insert(RI); if (IntersectingChild != ParentRI.Children.end()) { ++NumErrors; - OS << "error: DIEs have overlapping address ranges:"; + error() << "DIEs have overlapping address ranges:"; Die.dump(OS, 0); IntersectingChild->Die.dump(OS, 0); OS << "\n"; @@ -347,8 +348,8 @@ ParentRI.Die.getTag() == DW_TAG_subprogram); if (ShouldBeContained && !ParentRI.contains(RI)) { ++NumErrors; - OS << "error: DIE address ranges are not " - "contained in its parent's ranges:"; + error() << "DIE address ranges are not " + "contained in its parent's ranges:"; Die.dump(OS, 0); ParentRI.Die.dump(OS, 0); OS << "\n"; @@ -372,14 +373,14 @@ if (auto SectionOffset = AttrValue.Value.getAsSectionOffset()) { if (*SectionOffset >= DObj.getRangeSection().Data.size()) { ++NumErrors; - OS << "error: DW_AT_ranges offset is beyond .debug_ranges " - "bounds:\n"; + error() << "DW_AT_ranges offset is beyond .debug_ranges " + "bounds:\n"; Die.dump(OS, 0, DumpOpts); OS << "\n"; } } else { ++NumErrors; - OS << "error: DIE has invalid DW_AT_ranges encoding:\n"; + error() << "DIE has invalid DW_AT_ranges encoding:\n"; Die.dump(OS, 0, DumpOpts); OS << "\n"; } @@ -389,15 +390,15 @@ if (auto SectionOffset = AttrValue.Value.getAsSectionOffset()) { if (*SectionOffset >= DObj.getLineSection().Data.size()) { ++NumErrors; - OS << "error: DW_AT_stmt_list offset is beyond .debug_line " - "bounds: " - << format("0x%08" PRIx64, *SectionOffset) << "\n"; + error() << "DW_AT_stmt_list offset is beyond .debug_line " + "bounds: " + << format("0x%08" PRIx64, *SectionOffset) << "\n"; Die.dump(OS, 0, DumpOpts); OS << "\n"; } } else { ++NumErrors; - OS << "error: DIE has invalid DW_AT_stmt_list encoding:\n"; + error() << "DIE has invalid DW_AT_stmt_list encoding:\n"; Die.dump(OS, 0, DumpOpts); OS << "\n"; } @@ -429,10 +430,10 @@ auto CUOffset = AttrValue.Value.getRawUValue(); if (CUOffset >= CUSize) { ++NumErrors; - OS << "error: " << FormEncodingString(Form) << " CU offset " - << format("0x%08" PRIx64, CUOffset) - << " is invalid (must be less than CU size of " - << format("0x%08" PRIx32, CUSize) << "):\n"; + error() << FormEncodingString(Form) << " CU offset " + << format("0x%08" PRIx64, CUOffset) + << " is invalid (must be less than CU size of " + << format("0x%08" PRIx32, CUSize) << "):\n"; Die.dump(OS, 0, DumpOpts); OS << "\n"; } else { @@ -451,8 +452,8 @@ if (RefVal) { if (*RefVal >= DObj.getInfoSection().Data.size()) { ++NumErrors; - OS << "error: DW_FORM_ref_addr offset beyond .debug_info " - "bounds:\n"; + error() << "DW_FORM_ref_addr offset beyond .debug_info " + "bounds:\n"; Die.dump(OS, 0, DumpOpts); OS << "\n"; } else { @@ -468,7 +469,7 @@ assert(SecOffset); // DW_FORM_strp is a section offset. if (SecOffset && *SecOffset >= DObj.getStringSection().size()) { ++NumErrors; - OS << "error: DW_FORM_strp offset beyond .debug_str bounds:\n"; + error() << "DW_FORM_strp offset beyond .debug_str bounds:\n"; Die.dump(OS, 0, DumpOpts); OS << "\n"; } @@ -490,8 +491,8 @@ if (Die) continue; ++NumErrors; - OS << "error: invalid DIE reference " << format("0x%08" PRIx64, Pair.first) - << ". Offset is in between DIEs:\n"; + error() << "invalid DIE reference " << format("0x%08" PRIx64, Pair.first) + << ". Offset is in between DIEs:\n"; for (auto Offset : Pair.second) { auto ReferencingDie = DCtx.getDIEForOffset(Offset); ReferencingDie.dump(OS, 0, DumpOpts); @@ -517,8 +518,8 @@ if (LineTableOffset < DCtx.getDWARFObj().getLineSection().Data.size()) { if (!LineTable) { ++NumDebugLineErrors; - OS << "error: .debug_line[" << format("0x%08" PRIx32, LineTableOffset) - << "] was not able to be parsed for CU:\n"; + error() << ".debug_line[" << format("0x%08" PRIx32, LineTableOffset) + << "] was not able to be parsed for CU:\n"; Die.dump(OS, 0, DumpOpts); OS << '\n'; continue; @@ -533,10 +534,10 @@ auto Iter = StmtListToDie.find(LineTableOffset); if (Iter != StmtListToDie.end()) { ++NumDebugLineErrors; - OS << "error: two compile unit DIEs, " - << format("0x%08" PRIx32, Iter->second.getOffset()) << " and " - << format("0x%08" PRIx32, Die.getOffset()) - << ", have the same DW_AT_stmt_list section offset:\n"; + error() << "two compile unit DIEs, " + << format("0x%08" PRIx32, Iter->second.getOffset()) << " and " + << format("0x%08" PRIx32, Die.getOffset()) + << ", have the same DW_AT_stmt_list section offset:\n"; Iter->second.dump(OS, 0, DumpOpts); Die.dump(OS, 0, DumpOpts); OS << '\n'; @@ -565,12 +566,12 @@ // Verify directory index. if (FileName.DirIdx > MaxDirIndex) { ++NumDebugLineErrors; - OS << "error: .debug_line[" - << format("0x%08" PRIx64, - *toSectionOffset(Die.find(DW_AT_stmt_list))) - << "].prologue.file_names[" << FileIndex - << "].dir_idx contains an invalid index: " << FileName.DirIdx - << "\n"; + error() << ".debug_line[" + << format("0x%08" PRIx64, + *toSectionOffset(Die.find(DW_AT_stmt_list))) + << "].prologue.file_names[" << FileIndex + << "].dir_idx contains an invalid index: " << FileName.DirIdx + << "\n"; } // Check file paths for duplicates. @@ -584,11 +585,11 @@ if (It == FullPathMap.end()) FullPathMap[FullPath] = FileIndex; else if (It->second != FileIndex) { - OS << "warning: .debug_line[" - << format("0x%08" PRIx64, - *toSectionOffset(Die.find(DW_AT_stmt_list))) - << "].prologue.file_names[" << FileIndex - << "] is a duplicate of file_names[" << It->second << "]\n"; + warning() << ".debug_line[" + << format("0x%08" PRIx64, + *toSectionOffset(Die.find(DW_AT_stmt_list))) + << "].prologue.file_names[" << FileIndex + << "] is a duplicate of file_names[" << It->second << "]\n"; } FileIndex++; @@ -601,11 +602,11 @@ // Verify row address. if (Row.Address < PrevAddress) { ++NumDebugLineErrors; - OS << "error: .debug_line[" - << format("0x%08" PRIx64, - *toSectionOffset(Die.find(DW_AT_stmt_list))) - << "] row[" << RowIndex - << "] decreases in address from previous row:\n"; + error() << ".debug_line[" + << format("0x%08" PRIx64, + *toSectionOffset(Die.find(DW_AT_stmt_list))) + << "] row[" << RowIndex + << "] decreases in address from previous row:\n"; DWARFDebugLine::Row::dumpTableHeader(OS); if (RowIndex > 0) @@ -617,11 +618,11 @@ // Verify file index. if (Row.File > MaxFileIndex) { ++NumDebugLineErrors; - OS << "error: .debug_line[" - << format("0x%08" PRIx64, - *toSectionOffset(Die.find(DW_AT_stmt_list))) - << "][" << RowIndex << "] has invalid file index " << Row.File - << " (valid values are [1," << MaxFileIndex << "]):\n"; + error() << ".debug_line[" + << format("0x%08" PRIx64, + *toSectionOffset(Die.find(DW_AT_stmt_list))) + << "][" << RowIndex << "] has invalid file index " << Row.File + << " (valid values are [1," << MaxFileIndex << "]):\n"; DWARFDebugLine::Row::dumpTableHeader(OS); Row.dump(OS); OS << '\n'; @@ -652,17 +653,19 @@ DWARFAcceleratorTable AccelTable(AccelSectionData, *StrData); OS << "Verifying " << SectionName << "...\n"; - // Verify that the fixed part of the header is not too short. + // Verify that the fixed part of the header is not too short. if (!AccelSectionData.isValidOffset(AccelTable.getSizeHdr())) { - OS << "\terror: Section is too small to fit a section header.\n"; + error() << "Section is too small to fit a section header.\n"; return 1; } + // Verify that the section is not too short. if (!AccelTable.extract()) { - OS << "\terror: Section is smaller than size described in section header.\n"; + error() << "Section is smaller than size described in section header.\n"; return 1; } + // Verify that all buckets have a valid hash index or are empty. uint32_t NumBuckets = AccelTable.getNumBuckets(); uint32_t NumHashes = AccelTable.getNumHashes(); @@ -674,18 +677,18 @@ for (uint32_t BucketIdx = 0; BucketIdx < NumBuckets; ++BucketIdx) { uint32_t HashIdx = AccelSectionData.getU32(&BucketsOffset); if (HashIdx >= NumHashes && HashIdx != UINT32_MAX) { - OS << format("\terror: Bucket[%d] has invalid hash index: %u.\n", BucketIdx, - HashIdx); + error() << format("Bucket[%d] has invalid hash index: %u.\n", BucketIdx, + HashIdx); ++NumErrors; } } uint32_t NumAtoms = AccelTable.getAtomsDesc().size(); if (NumAtoms == 0) { - OS << "\terror: no atoms; failed to read HashData.\n"; + error() << "No atoms: failed to read HashData.\n"; return 1; } if (!AccelTable.validateForms()) { - OS << "\terror: unsupported form; failed to read HashData.\n"; + error() << "Unsupported form: failed to read HashData.\n"; return 1; } @@ -696,8 +699,8 @@ uint32_t HashDataOffset = AccelSectionData.getU32(&DataOffset); if (!AccelSectionData.isValidOffsetForDataOfSize(HashDataOffset, sizeof(uint64_t))) { - OS << format("\terror: Hash[%d] has invalid HashData offset: 0x%08x.\n", - HashIdx, HashDataOffset); + error() << format("Hash[%d] has invalid HashData offset: 0x%08x.\n", + HashIdx, HashDataOffset); ++NumErrors; } @@ -721,8 +724,8 @@ if (!Name) Name = ""; - OS << format( - "\terror: %s Bucket[%d] Hash[%d] = 0x%08x " + error() << format( + "%s Bucket[%d] Hash[%d] = 0x%08x " "Str[%u] = 0x%08x " "DIE[%d] = 0x%08x is not a valid DIE offset for \"%s\".\n", SectionName, BucketIdx, HashIdx, Hash, StringCount, StrpOffset, @@ -732,10 +735,10 @@ continue; } if ((Tag != dwarf::DW_TAG_null) && (Die.getTag() != Tag)) { - OS << "\terror: Tag " << dwarf::TagString(Tag) - << " in accelerator table does not match Tag " - << dwarf::TagString(Die.getTag()) << " of DIE[" << HashDataIdx - << "].\n"; + error() << "Tag " << dwarf::TagString(Tag) + << " in accelerator table does not match Tag " + << dwarf::TagString(Die.getTag()) << " of DIE[" << HashDataIdx + << "].\n"; ++NumErrors; } } Index: test/tools/llvm-dwarfdump/X86/apple_names_verify_form.s =================================================================== --- test/tools/llvm-dwarfdump/X86/apple_names_verify_form.s +++ test/tools/llvm-dwarfdump/X86/apple_names_verify_form.s @@ -3,9 +3,9 @@ # RUN: | FileCheck %s # CHECK: Verifying .apple_names... -# CHECK-NEXT: error: unsupported form; failed to read HashData. +# CHECK-NEXT: error: Unsupported form: failed to read HashData. -# This test is meant to verify that the -verify option +# This test is meant to verify that the -verify option # in llvm-dwarfdump, correctly identifies that Atom[0].form is unsupported. # As a result, the hashdata cannot be read. Index: test/tools/llvm-dwarfdump/X86/apple_names_verify_num_atoms.s =================================================================== --- test/tools/llvm-dwarfdump/X86/apple_names_verify_num_atoms.s +++ test/tools/llvm-dwarfdump/X86/apple_names_verify_num_atoms.s @@ -3,9 +3,9 @@ # RUN: | FileCheck %s # CHECK: Verifying .apple_names... -# CHECK-NEXT: error: no atoms; failed to read HashData. +# CHECK-NEXT: error: No atoms: failed to read HashData. -# This test is meant to verify that the -verify option +# This test is meant to verify that the -verify option # in llvm-dwarfdump, correctly identifies that there is not Atom. # As a result, the hashdata cannot be read. @@ -21,7 +21,7 @@ .asciz "i" ## string offset=84 .asciz "int" ## string offset=86 .asciz "j" ## string offset=90 - + .section __DWARF,__debug_info,regular,debug Lsection_info: .section __DWARF,__apple_names,regular,debug Index: test/tools/llvm-dwarfdump/X86/verify_debug_abbrev.s =================================================================== --- test/tools/llvm-dwarfdump/X86/verify_debug_abbrev.s +++ test/tools/llvm-dwarfdump/X86/verify_debug_abbrev.s @@ -3,12 +3,12 @@ # RUN: | FileCheck %s # CHECK: Verifying .debug_abbrev... -# CHECK-NEXT: Error: Abbreviation declaration contains multiple DW_AT_stmt_list attributes. +# CHECK-NEXT: error: Abbreviation declaration contains multiple DW_AT_stmt_list attributes. # CHECK-NEXT:[1] DW_TAG_compile_unit DW_CHILDREN_no # CHECK-NEXT: DW_AT_stmt_list DW_FORM_sec_offset # CHECK-NEXT: DW_AT_GNU_dwo_name DW_FORM_strp # CHECK-NEXT: DW_AT_stmt_list DW_FORM_strp{{[[:space:]]}} -# CHECK-NEXT: Error: Abbreviation declaration contains multiple DW_AT_producer attributes. +# CHECK-NEXT: error: Abbreviation declaration contains multiple DW_AT_producer attributes. # CHECK-NEXT:[1] DW_TAG_compile_unit DW_CHILDREN_yes # CHECK-NEXT: DW_AT_GNU_dwo_name DW_FORM_GNU_str_index # CHECK-NEXT: DW_AT_producer DW_FORM_GNU_str_index @@ -41,4 +41,3 @@ .byte 0 # EOM(1) .byte 0 # EOM(2) .byte 0 # EOM(3) - \ No newline at end of file Index: test/tools/llvm-dwarfdump/X86/verify_debug_info.s =================================================================== --- test/tools/llvm-dwarfdump/X86/verify_debug_info.s +++ test/tools/llvm-dwarfdump/X86/verify_debug_info.s @@ -11,9 +11,9 @@ # CHECK-NEXT: DW_AT_comp_dir [DW_FORM_strp] ( .debug_str[0x0000003f] = "/Users/sgravani/Development/tests") # CHECK-NEXT: DW_AT_low_pc [DW_FORM_addr] (0x0000000000000000) # CHECK-NEXT: DW_AT_high_pc [DW_FORM_data4] (0x00000016){{[[:space:]]}} -# CHECK-NEXT: Units[2] - start offset: 0x00000068 -# CHECK-NEXT: Error: The length for this unit is too large for the .debug_info provided. -# CHECK-NEXT: Error: The unit type encoding is not valid. +# CHECK-NEXT: error: Units[2] - start offset: 0x00000068 +# CHECK-NEXT: The length for this unit is too large for the .debug_info provided. +# CHECK-NEXT: The unit type encoding is not valid. .section __TEXT,__text,regular,pure_instructions Index: test/tools/llvm-dwarfdump/X86/verify_unit_header_chain.s =================================================================== --- test/tools/llvm-dwarfdump/X86/verify_unit_header_chain.s +++ test/tools/llvm-dwarfdump/X86/verify_unit_header_chain.s @@ -3,14 +3,14 @@ # RUN: | FileCheck %s # CHECK: Verifying .debug_info Unit Header Chain... -# CHECK-NEXT: Units[1] - start offset: 0x0000000d -# CHECK-NEXT: Error: The unit type encoding is not valid. -# CHECK-NEXT: Error: The address size is unsupported. -# CHECK-NEXT: Units[2] - start offset: 0x00000026 -# CHECK-NEXT: Error: The 16 bit unit header version is not valid. -# CHECK-NEXT: Error: The offset into the .debug_abbrev section is not valid. -# CHECK-NEXT: Units[4] - start offset: 0x00000041 -# CHECK-NEXT: Error: The length for this unit is too large for the .debug_info provided. +# CHECK-NEXT: error: Units[1] - start offset: 0x0000000d +# CHECK-NEXT: The unit type encoding is not valid. +# CHECK-NEXT: The address size is unsupported. +# CHECK-NEXT: error: Units[2] - start offset: 0x00000026 +# CHECK-NEXT: The 16 bit unit header version is not valid. +# CHECK-NEXT: The offset into the .debug_abbrev section is not valid. +# CHECK-NEXT: error: Units[4] - start offset: 0x00000041 +# CHECK-NEXT: The length for this unit is too large for the .debug_info provided. .section __TEXT,__text,regular,pure_instructions .file 1 "basic.c" @@ -73,7 +73,7 @@ .long 0 .quad 0 .long 0 - .byte 0 + .byte 0 .subsections_via_symbols .section __DWARF,__debug_line,regular,debug