LCOV - code coverage report
Current view: top level - include/llvm/DebugInfo/DWARF - DWARFVerifier.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 2 2 100.0 %
Date: 2017-09-14 15:23:50 Functions: 0 0 -
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- DWARFVerifier.h ----------------------------------------------------===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : 
      10             : #ifndef LLVM_DEBUGINFO_DWARF_DWARFVERIFIER_H
      11             : #define LLVM_DEBUGINFO_DWARF_DWARFVERIFIER_H
      12             : 
      13             : #include "llvm/DebugInfo/DIContext.h"
      14             : 
      15             : #include <cstdint>
      16             : #include <map>
      17             : #include <set>
      18             : 
      19             : namespace llvm {
      20             : class raw_ostream;
      21             : struct DWARFAttribute;
      22             : class DWARFContext;
      23             : class DWARFDie;
      24             : class DWARFUnit;
      25             : class DWARFAcceleratorTable;
      26             : class DWARFDataExtractor;
      27             : class DWARFDebugAbbrev;
      28             : class DataExtractor;
      29             : struct DWARFSection;
      30             : 
      31             : /// A class that verifies DWARF debug information given a DWARF Context.
      32          42 : class DWARFVerifier {
      33             :   raw_ostream &OS;
      34             :   DWARFContext &DCtx;
      35             :   DIDumpOptions DumpOpts;
      36             :   /// A map that tracks all references (converted absolute references) so we
      37             :   /// can verify each reference points to a valid DIE and not an offset that
      38             :   /// lies between to valid DIEs.
      39             :   std::map<uint64_t, std::set<uint32_t>> ReferenceToDIEOffsets;
      40             :   uint32_t NumDebugLineErrors = 0;
      41             : 
      42             :   /// Verifies the abbreviations section.
      43             :   ///
      44             :   /// This function currently checks that:
      45             :   /// --No abbreviation declaration has more than one attributes with the same
      46             :   /// name.
      47             :   ///
      48             :   /// \param Abbrev Pointer to the abbreviations section we are verifying
      49             :   /// Abbrev can be a pointer to either .debug_abbrev or debug_abbrev.dwo.
      50             :   ///
      51             :   /// \returns The number of errors that occured during verification.
      52             :   unsigned verifyAbbrevSection(const DWARFDebugAbbrev *Abbrev);
      53             : 
      54             :   /// Verifies the header of a unit in the .debug_info section.
      55             :   ///
      56             :   /// This function currently checks for:
      57             :   /// - Unit is in 32-bit DWARF format. The function can be modified to
      58             :   /// support 64-bit format.
      59             :   /// - The DWARF version is valid
      60             :   /// - The unit type is valid (if unit is in version >=5)
      61             :   /// - The unit doesn't extend beyond .debug_info section
      62             :   /// - The address size is valid
      63             :   /// - The offset in the .debug_abbrev section is valid
      64             :   ///
      65             :   /// \param DebugInfoData The .debug_info section data
      66             :   /// \param Offset A reference to the offset start of the unit. The offset will
      67             :   /// be updated to point to the next unit in .debug_info
      68             :   /// \param UnitIndex The index of the unit to be verified
      69             :   /// \param UnitType A reference to the type of the unit
      70             :   /// \param isUnitDWARF64 A reference to a flag that shows whether the unit is
      71             :   /// in 64-bit format.
      72             :   ///
      73             :   /// \returns true if the header is verified successfully, false otherwise.
      74             :   bool verifyUnitHeader(const DWARFDataExtractor DebugInfoData,
      75             :                         uint32_t *Offset, unsigned UnitIndex, uint8_t &UnitType,
      76             :                         bool &isUnitDWARF64);
      77             : 
      78             : 
      79             :   bool verifyUnitContents(DWARFUnit Unit);
      80             : 
      81             :   /// Verify that all Die ranges are valid.
      82             :   ///
      83             :   /// This function currently checks for:
      84             :   /// - cases in which lowPC >= highPC
      85             :   ///
      86             :   /// \returns Number of errors that occured during verification.
      87             :   unsigned verifyDieRanges(const DWARFDie &Die);
      88             : 
      89             :   /// Verifies the attribute's DWARF attribute and its value.
      90             :   ///
      91             :   /// This function currently checks for:
      92             :   /// - DW_AT_ranges values is a valid .debug_ranges offset
      93             :   /// - DW_AT_stmt_list is a valid .debug_line offset
      94             :   ///
      95             :   /// \param Die          The DWARF DIE that owns the attribute value
      96             :   /// \param AttrValue    The DWARF attribute value to check
      97             :   ///
      98             :   /// \returns NumErrors The number of errors occured during verification of
      99             :   /// attributes' values in a .debug_info section unit
     100             :   unsigned verifyDebugInfoAttribute(const DWARFDie &Die,
     101             :                                     DWARFAttribute &AttrValue);
     102             : 
     103             :   /// Verifies the attribute's DWARF form.
     104             :   ///
     105             :   /// This function currently checks for:
     106             :   /// - All DW_FORM_ref values that are CU relative have valid CU offsets
     107             :   /// - All DW_FORM_ref_addr values have valid .debug_info offsets
     108             :   /// - All DW_FORM_strp values have valid .debug_str offsets
     109             :   ///
     110             :   /// \param Die          The DWARF DIE that owns the attribute value
     111             :   /// \param AttrValue    The DWARF attribute value to check
     112             :   ///
     113             :   /// \returns NumErrors The number of errors occured during verification of
     114             :   /// attributes' forms in a .debug_info section unit
     115             :   unsigned verifyDebugInfoForm(const DWARFDie &Die, DWARFAttribute &AttrValue);
     116             : 
     117             :   /// Verifies the all valid references that were found when iterating through
     118             :   /// all of the DIE attributes.
     119             :   ///
     120             :   /// This function will verify that all references point to DIEs whose DIE
     121             :   /// offset matches. This helps to ensure if a DWARF link phase moved things
     122             :   /// around, that it doesn't create invalid references by failing to relocate
     123             :   /// CU relative and absolute references.
     124             :   ///
     125             :   /// \returns NumErrors The number of errors occured during verification of
     126             :   /// references for the .debug_info section
     127             :   unsigned verifyDebugInfoReferences();
     128             : 
     129             :   /// Verify the the DW_AT_stmt_list encoding and value and ensure that no
     130             :   /// compile units that have the same DW_AT_stmt_list value.
     131             :   void verifyDebugLineStmtOffsets();
     132             : 
     133             :   /// Verify that all of the rows in the line table are valid.
     134             :   ///
     135             :   /// This function currently checks for:
     136             :   /// - addresses within a sequence that decrease in value
     137             :   /// - invalid file indexes
     138             :   void verifyDebugLineRows();
     139             : 
     140             :   /// Verify that an Apple-style accelerator table is valid.
     141             :   ///
     142             :   /// This function currently checks that:
     143             :   /// - The fixed part of the header fits in the section
     144             :   /// - The size of the section is as large as what the header describes
     145             :   /// - There is at least one atom
     146             :   /// - The form for each atom is valid
     147             :   /// - The tag for each DIE in the table is valid
     148             :   /// - The buckets have a valid index, or they are empty
     149             :   /// - Each hashdata offset is valid
     150             :   /// - Each DIE is valid
     151             :   ///
     152             :   /// \param AccelSection pointer to the section containing the acceleration table
     153             :   /// \param StrData pointer to the string section
     154             :   /// \param SectionName the name of the table we're verifying
     155             :   ///
     156             :   /// \returns The number of errors occured during verification
     157             :   unsigned verifyAccelTable(const DWARFSection *AccelSection,
     158             :                             DataExtractor *StrData, const char *SectionName);
     159             : 
     160             : public:
     161             :   DWARFVerifier(raw_ostream &S, DWARFContext &D, DIDumpOptions DumpOpts = {})
     162          42 :       : OS(S), DCtx(D), DumpOpts(std::move(DumpOpts)) {}
     163             :   /// Verify the information in any of the following sections, if available:
     164             :   /// .debug_abbrev, debug_abbrev.dwo
     165             :   ///
     166             :   /// Any errors are reported to the stream that was this object was
     167             :   /// constructed with.
     168             :   ///
     169             :   /// \returns true if .debug_abbrev and .debug_abbrev.dwo verify successfully,
     170             :   /// false otherwise.
     171             :   bool handleDebugAbbrev();
     172             : 
     173             :   /// Verify the information in the .debug_info section.
     174             :   ///
     175             :   /// Any errors are reported to the stream that was this object was
     176             :   /// constructed with.
     177             :   ///
     178             :   /// \returns true if the .debug_info verifies successfully, false otherwise.
     179             :   bool handleDebugInfo();
     180             : 
     181             :   /// Verify the information in the .debug_line section.
     182             :   ///
     183             :   /// Any errors are reported to the stream that was this object was
     184             :   /// constructed with.
     185             :   ///
     186             :   /// \returns true if the .debug_line verifies successfully, false otherwise.
     187             :   bool handleDebugLine();
     188             : 
     189             :   /// Verify the information in accelerator tables, if they exist.
     190             :   ///
     191             :   /// Any errors are reported to the stream that was this object was
     192             :   /// constructed with.
     193             :   ///
     194             :   /// \returns true if the existing Apple-style accelerator tables verify
     195             :   /// successfully, false otherwise.
     196             :   bool handleAccelTables();
     197             : };
     198             : 
     199             : } // end namespace llvm
     200             : 
     201             : #endif // LLVM_DEBUGINFO_DWARF_DWARFCONTEXT_H

Generated by: LCOV version 1.13