1 //===- DWARFVerifier.h ----------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_DEBUGINFO_DWARF_DWARFVERIFIER_H
11 #define LLVM_DEBUGINFO_DWARF_DWARFVERIFIER_H
19 struct DWARFAttribute;
23 class DWARFAcceleratorTable;
24 class DWARFDataExtractor;
26 /// A class that verifies DWARF debug information given a DWARF Context.
30 /// A map that tracks all references (converted absolute references) so we
31 /// can verify each reference points to a valid DIE and not an offset that
32 /// lies between to valid DIEs.
33 std::map<uint64_t, std::set<uint32_t>> ReferenceToDIEOffsets;
34 uint32_t NumDebugLineErrors = 0;
35 uint32_t NumAppleNamesErrors = 0;
37 /// Verifies the header of a unit in the .debug_info section.
39 /// This function currently checks for:
40 /// - Unit is in 32-bit DWARF format. The function can be modified to
41 /// support 64-bit format.
42 /// - The DWARF version is valid
43 /// - The unit type is valid (if unit is in version >=5)
44 /// - The unit doesn't extend beyond .debug_info section
45 /// - The address size is valid
46 /// - The offset in the .debug_abbrev section is valid
48 /// \param DebugInfoData The .debug_info section data
49 /// \param Offset A reference to the offset start of the unit. The offset will
50 /// be updated to point to the next unit in .debug_info
51 /// \param UnitIndex The index of the unit to be verified
52 /// \param UnitType A reference to the type of the unit
53 /// \param isUnitDWARF64 A reference to a flag that shows whether the unit is
56 /// \returns true if the header is verified successfully, false otherwise.
57 bool verifyUnitHeader(const DWARFDataExtractor DebugInfoData,
58 uint32_t *Offset, unsigned UnitIndex, uint8_t &UnitType,
62 bool verifyUnitContents(DWARFUnit Unit);
63 /// Verifies the attribute's DWARF attribute and its value.
65 /// This function currently checks for:
66 /// - DW_AT_ranges values is a valid .debug_ranges offset
67 /// - DW_AT_stmt_list is a valid .debug_line offset
69 /// \param Die The DWARF DIE that owns the attribute value
70 /// \param AttrValue The DWARF attribute value to check
72 /// \returns NumErrors The number of errors occured during verification of
73 /// attributes' values in a .debug_info section unit
74 unsigned verifyDebugInfoAttribute(const DWARFDie &Die,
75 DWARFAttribute &AttrValue);
77 /// Verifies the attribute's DWARF form.
79 /// This function currently checks for:
80 /// - All DW_FORM_ref values that are CU relative have valid CU offsets
81 /// - All DW_FORM_ref_addr values have valid .debug_info offsets
82 /// - All DW_FORM_strp values have valid .debug_str offsets
84 /// \param Die The DWARF DIE that owns the attribute value
85 /// \param AttrValue The DWARF attribute value to check
87 /// \returns NumErrors The number of errors occured during verification of
88 /// attributes' forms in a .debug_info section unit
89 unsigned verifyDebugInfoForm(const DWARFDie &Die, DWARFAttribute &AttrValue);
91 /// Verifies the all valid references that were found when iterating through
92 /// all of the DIE attributes.
94 /// This function will verify that all references point to DIEs whose DIE
95 /// offset matches. This helps to ensure if a DWARF link phase moved things
96 /// around, that it doesn't create invalid references by failing to relocate
97 /// CU relative and absolute references.
99 /// \returns NumErrors The number of errors occured during verification of
100 /// references for the .debug_info section
101 unsigned verifyDebugInfoReferences();
103 /// Verify the the DW_AT_stmt_list encoding and value and ensure that no
104 /// compile units that have the same DW_AT_stmt_list value.
105 void verifyDebugLineStmtOffsets();
107 /// Verify that all of the rows in the line table are valid.
109 /// This function currently checks for:
110 /// - addresses within a sequence that decrease in value
111 /// - invalid file indexes
112 void verifyDebugLineRows();
115 DWARFVerifier(raw_ostream &S, DWARFContext &D)
117 /// Verify the information in the .debug_info section.
119 /// Any errors are reported to the stream that was this object was
120 /// constructed with.
122 /// \returns true if the .debug_info verifies successfully, false otherwise.
123 bool handleDebugInfo();
125 /// Verify the information in the .debug_line section.
127 /// Any errors are reported to the stream that was this object was
128 /// constructed with.
130 /// \returns true if the .debug_line verifies successfully, false otherwise.
131 bool handleDebugLine();
133 /// Verify the information in the .apple_names accelerator table.
135 /// Any errors are reported to the stream that was this object was
136 /// constructed with.
138 /// \returns true if the .apple_names verifies successfully, false otherwise.
139 bool handleAppleNames();
142 } // end namespace llvm
144 #endif // LLVM_DEBUGINFO_DWARF_DWARFCONTEXT_H