Index: include/llvm/DebugInfo/DWARF/DWARFVerifier.h =================================================================== --- include/llvm/DebugInfo/DWARF/DWARFVerifier.h +++ include/llvm/DebugInfo/DWARF/DWARFVerifier.h @@ -22,6 +22,7 @@ class DWARFUnit; class DWARFAcceleratorTable; class DWARFDataExtractor; +class DWARFDebugAbbrev; /// A class that verifies DWARF debug information given a DWARF Context. class DWARFVerifier { @@ -34,6 +35,18 @@ uint32_t NumDebugLineErrors = 0; uint32_t NumAppleNamesErrors = 0; + /// Verifies the abbreviations section. + /// + /// This function currently checks that: + /// --No abbreviation declaration has more than one attributes with the same + /// name. + /// + /// \param Abbrev Pointer to the abbreviations section we are verifying + /// Abbrev can be a pointer to either .debug_abbrev or debug_abbrev.dwo. + /// + /// \returns The number of errors that occured during verification. + unsigned verifyAbbrevSection(const DWARFDebugAbbrev *Abbrev); + /// Verifies the header of a unit in the .debug_info section. /// /// This function currently checks for: @@ -114,13 +127,16 @@ public: DWARFVerifier(raw_ostream &S, DWARFContext &D) : OS(S), DCtx(D) {} - /// Verify the information in the .debug_abbrev section. + /// Verify the information in any of the following sections, if available: + /// .debug_abbrev, debug_abbrev.dwo /// - /// Currently, we check that no Abbreviation Declaration has more than one - /// attributes with the same name. + /// Any errors are reported to the stream that was this object was + /// constructed with. /// - /// \returns true if the .debug_abbrev verifies successfully, false otherwise. + /// \returns true if .debug_abbrev and .debug_abbrev.dwo verify successfully, + /// false otherwise. bool handleDebugAbbrev(); + /// Verify the information in the .debug_info section. /// /// Any errors are reported to the stream that was this object was Index: lib/DebugInfo/DWARF/DWARFVerifier.cpp =================================================================== --- lib/DebugInfo/DWARF/DWARFVerifier.cpp +++ lib/DebugInfo/DWARF/DWARFVerifier.cpp @@ -102,17 +102,8 @@ return NumUnitErrors == 0; } -bool DWARFVerifier::handleDebugAbbrev() { - OS << "Verifying .debug_abbrev...\n"; - - const DWARFObject &DObj = DCtx.getDWARFObj(); - if (DObj.getAbbrevSection().empty()) { - OS << "Warning: .debug_abbrev is empty.\n"; - return true; - } - +unsigned DWARFVerifier::verifyAbbrevSection(const DWARFDebugAbbrev *Abbrev) { unsigned NumErrors = 0; - const DWARFDebugAbbrev *Abbrev = DCtx.getDebugAbbrev(); if (Abbrev) { const DWARFAbbreviationDeclarationSet *AbbrDecls = Abbrev->getAbbreviationDeclarationSet(0); @@ -130,6 +121,27 @@ } } } + return NumErrors; +} + +bool DWARFVerifier::handleDebugAbbrev() { + OS << "Verifying .debug_abbrev...\n"; + + const DWARFObject &DObj = DCtx.getDWARFObj(); + bool noDebugAbbrev = DObj.getAbbrevSection().empty(); + bool noDebugAbbrevDWO = DObj.getAbbrevDWOSection().empty(); + + if (noDebugAbbrev && noDebugAbbrevDWO) { + OS << "Warning: .debug_abbrev and .debug_abbrev.dwo are empty.\n"; + return true; + } + + unsigned NumErrors = 0; + if (!noDebugAbbrev) + NumErrors += verifyAbbrevSection(DCtx.getDebugAbbrev()); + + if (!noDebugAbbrevDWO) + NumErrors += verifyAbbrevSection(DCtx.getDebugAbbrevDWO()); return NumErrors == 0; } Index: test/tools/llvm-dwarfdump/X86/verify_debug_abbrev.s =================================================================== --- /dev/null +++ test/tools/llvm-dwarfdump/X86/verify_debug_abbrev.s @@ -0,0 +1,250 @@ +# RUN: llvm-mc %s -filetype obj -triple x86_64-unknown-linux-gnu -o - \ +# RUN: | not llvm-dwarfdump -verify - \ +# RUN: | FileCheck %s + +# CHECK: Verifying .debug_abbrev... +# CHECK-NEXT: Error: Abbreviation declaration with code 1 contains multiple DW_AT_low_pc attributes. +# CHECK-NEXT: Error: Abbreviation declaration with code 1 contains multiple DW_AT_language attributes. + + .text + .file "basic.c" + .globl main # -- Begin function main + .p2align 4, 0x90 + .type main,@function +main: # @main +.Lfunc_begin0: + .file 1 "basic.c" + .loc 1 1 0 # basic.c:1:0 + .cfi_startproc +# BB#0: # %entry + pushq %rbp +.Lcfi0: + .cfi_def_cfa_offset 16 +.Lcfi1: + .cfi_offset %rbp, -16 + movq %rsp, %rbp +.Lcfi2: + .cfi_def_cfa_register %rbp + xorl %eax, %eax + movl $0, -4(%rbp) +.Ltmp0: + .loc 1 2 7 prologue_end # basic.c:2:7 + movl $1, -8(%rbp) + .loc 1 3 3 # basic.c:3:3 + popq %rbp + retq +.Ltmp1: +.Lfunc_end0: + .size main, .Lfunc_end0-main + .cfi_endproc + # -- End function + .section .debug_str,"MS",@progbits,1 +.Lskel_string0: + .asciz "basic.dwo" # string offset=0 +.Lskel_string1: + .asciz "/Users/sgravani/Development/tests" # string offset=10 + .section .debug_loc.dwo,"",@progbits + .section .debug_abbrev,"",@progbits + .byte 1 # Abbreviation Code + .byte 17 # DW_TAG_compile_unit + .byte 0 # DW_CHILDREN_no + .byte 16 # DW_AT_stmt_list + .byte 23 # DW_FORM_sec_offset + .ascii "\260B" # DW_AT_GNU_dwo_name + .byte 14 # DW_FORM_strp + .byte 27 # DW_AT_comp_dir + .byte 14 # DW_FORM_strp + .ascii "\261B" # DW_AT_GNU_dwo_id + .byte 7 # DW_FORM_data8 + .ascii "\263B" # DW_AT_GNU_addr_base + .byte 23 # DW_FORM_sec_offset + .byte 17 # DW_AT_low_pc + .byte 1 # DW_FORM_addr + .byte 17 # DW_AT_low_pc -- Error: Abbreviation declaration with code 1 contains multiple DW_AT_low_pc attributes. + .byte 6 # DW_FORM_data4 + .byte 0 # EOM(1) + .byte 0 # EOM(2) + .byte 0 # EOM(3) + .section .debug_info,"",@progbits +.Lcu_begin0: + .long 44 # Length of Unit + .short 4 # DWARF version number + .long .debug_abbrev # Offset Into Abbrev. Section + .byte 8 # Address Size (in bytes) + .byte 1 # Abbrev [1] 0xb:0x25 DW_TAG_compile_unit + .long .Lline_table_start0 # DW_AT_stmt_list + .long .Lskel_string0 # DW_AT_GNU_dwo_name + .long .Lskel_string1 # DW_AT_comp_dir + .quad -1589219252385671021 # DW_AT_GNU_dwo_id + .long .debug_addr # DW_AT_GNU_addr_base + .quad .Lfunc_begin0 # DW_AT_low_pc + .long .Lfunc_end0-.Lfunc_begin0 # DW_AT_high_pc + .section .debug_ranges,"",@progbits + .section .debug_macinfo,"",@progbits +.Lcu_macro_begin1: + .byte 0 # End Of Macro List Mark + .section .debug_str.dwo,"MS",@progbits,1 +.Linfo_string0: + .asciz "basic.dwo" # string offset=0 +.Linfo_string1: + .asciz "clang version 6.0.0 (trunk 308629) (llvm/trunk 308639)" # string offset=10 +.Linfo_string2: + .asciz "basic.c" # string offset=65 +.Linfo_string3: + .asciz "main" # string offset=73 +.Linfo_string4: + .asciz "int" # string offset=78 +.Linfo_string5: + .asciz "a" # string offset=82 + .section .debug_str_offsets.dwo,"",@progbits + .long 0 + .long 10 + .long 65 + .long 73 + .long 78 + .long 82 + .section .debug_info.dwo,"",@progbits + .long 53 # Length of Unit + .short 4 # DWARF version number + .long 0 # Offset Into Abbrev. Section + .byte 8 # Address Size (in bytes) + .byte 1 # Abbrev [1] 0xb:0x2e DW_TAG_compile_unit + .byte 0 # DW_AT_GNU_dwo_name + .byte 1 # DW_AT_producer + .short 12 # DW_AT_language + .byte 2 # DW_AT_name + .quad -1589219252385671021 # DW_AT_GNU_dwo_id + .byte 2 # Abbrev [2] 0x19:0x1b DW_TAG_subprogram + .byte 0 # DW_AT_low_pc + .long .Lfunc_end0-.Lfunc_begin0 # DW_AT_high_pc + .byte 1 # DW_AT_frame_base + .byte 86 + .byte 3 # DW_AT_name + .byte 1 # DW_AT_decl_file + .byte 1 # DW_AT_decl_line + # DW_AT_prototyped + .long 52 # DW_AT_type + # DW_AT_external + .byte 3 # Abbrev [3] 0x28:0xb DW_TAG_variable + .byte 2 # DW_AT_location + .byte 145 + .byte 120 + .byte 5 # DW_AT_name + .byte 1 # DW_AT_decl_file + .byte 2 # DW_AT_decl_line + .long 52 # DW_AT_type + .byte 0 # End Of Children Mark + .byte 4 # Abbrev [4] 0x34:0x4 DW_TAG_base_type + .byte 4 # DW_AT_name + .byte 5 # DW_AT_encoding + .byte 4 # DW_AT_byte_size + .byte 0 # End Of Children Mark + .section .debug_abbrev.dwo,"",@progbits + .byte 1 # Abbreviation Code + .byte 17 # DW_TAG_compile_unit + .byte 1 # DW_CHILDREN_yes + .ascii "\260B" # DW_AT_GNU_dwo_name + .ascii "\202>" # DW_FORM_GNU_str_index + .byte 37 # DW_AT_producer + .ascii "\202>" # DW_FORM_GNU_str_index + .byte 19 # DW_AT_language + .byte 5 # DW_FORM_data2 + .byte 19 # DW_AT_language -- Error: Abbreviation declaration with code 1 contains multiple DW_AT_language attributes. + .ascii "\202>" # DW_FORM_GNU_str_index + .ascii "\261B" # DW_AT_GNU_dwo_id + .byte 7 # DW_FORM_data8 + .byte 0 # EOM(1) + .byte 0 # EOM(2) + .byte 2 # Abbreviation Code + .byte 46 # DW_TAG_subprogram + .byte 1 # DW_CHILDREN_yes + .byte 17 # DW_AT_low_pc + .ascii "\201>" # DW_FORM_GNU_addr_index + .byte 18 # DW_AT_high_pc + .byte 6 # DW_FORM_data4 + .byte 64 # DW_AT_frame_base + .byte 24 # DW_FORM_exprloc + .byte 3 # DW_AT_name + .ascii "\202>" # DW_FORM_GNU_str_index + .byte 58 # DW_AT_decl_file + .byte 11 # DW_FORM_data1 + .byte 59 # DW_AT_decl_line + .byte 11 # DW_FORM_data1 + .byte 39 # DW_AT_prototyped + .byte 25 # DW_FORM_flag_present + .byte 73 # DW_AT_type + .byte 19 # DW_FORM_ref4 + .byte 63 # DW_AT_external + .byte 25 # DW_FORM_flag_present + .byte 0 # EOM(1) + .byte 0 # EOM(2) + .byte 3 # Abbreviation Code + .byte 52 # DW_TAG_variable + .byte 0 # DW_CHILDREN_no + .byte 2 # DW_AT_location + .byte 24 # DW_FORM_exprloc + .byte 3 # DW_AT_name + .ascii "\202>" # DW_FORM_GNU_str_index + .byte 58 # DW_AT_decl_file + .byte 11 # DW_FORM_data1 + .byte 59 # DW_AT_decl_line + .byte 11 # DW_FORM_data1 + .byte 73 # DW_AT_type + .byte 19 # DW_FORM_ref4 + .byte 0 # EOM(1) + .byte 0 # EOM(2) + .byte 4 # Abbreviation Code + .byte 36 # DW_TAG_base_type + .byte 0 # DW_CHILDREN_no + .byte 3 # DW_AT_name + .ascii "\202>" # DW_FORM_GNU_str_index + .byte 62 # DW_AT_encoding + .byte 11 # DW_FORM_data1 + .byte 11 # DW_AT_byte_size + .byte 11 # DW_FORM_data1 + .byte 0 # EOM(1) + .byte 0 # EOM(2) + .byte 0 # EOM(3) + .section .debug_line.dwo,"",@progbits +.Ltmp2: + .long (.Ltmp3-.Ltmp2)-4 + .short 2 + .long (.Ltmp4-.Ltmp2)-10 + .byte 1 + .byte 1 + .byte -5 + .byte 14 + .byte 1 + .byte 0 + .byte 0 +.Ltmp4: +.Ltmp3: + .section .debug_addr,"",@progbits + .quad .Lfunc_begin0 + .section .debug_pubnames,"",@progbits + .long .LpubNames_end0-.LpubNames_begin0 # Length of Public Names Info +.LpubNames_begin0: + .short 2 # DWARF Version + .long .Lcu_begin0 # Offset of Compilation Unit Info + .long 48 # Compilation Unit Length + .long 25 # DIE offset + .asciz "main" # External Name + .long 0 # End Mark +.LpubNames_end0: + .section .debug_pubtypes,"",@progbits + .long .LpubTypes_end0-.LpubTypes_begin0 # Length of Public Types Info +.LpubTypes_begin0: + .short 2 # DWARF Version + .long .Lcu_begin0 # Offset of Compilation Unit Info + .long 48 # Compilation Unit Length + .long 52 # DIE offset + .asciz "int" # External Name + .long 0 # End Mark +.LpubTypes_end0: + + .ident "clang version 6.0.0 (trunk 308629) (llvm/trunk 308639)" + .section ".note.GNU-stack","",@progbits + .section .debug_line,"",@progbits +.Lline_table_start0: + +