LCOV - code coverage report
Current view: top level - lib/DebugInfo/DWARF - DWARFDebugMacro.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 35 47 74.5 %
Date: 2018-06-17 00:07:59 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- DWARFDebugMacro.cpp ------------------------------------------------===//
       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             : #include "llvm/DebugInfo/DWARF/DWARFDebugMacro.h"
      11             : #include "llvm/BinaryFormat/Dwarf.h"
      12             : #include "llvm/Support/WithColor.h"
      13             : #include "llvm/Support/raw_ostream.h"
      14             : #include <cstdint>
      15             : 
      16             : using namespace llvm;
      17             : using namespace dwarf;
      18             : 
      19           2 : void DWARFDebugMacro::dump(raw_ostream &OS) const {
      20             :   unsigned IndLevel = 0;
      21         326 :   for (const Entry &E : Macros) {
      22             :     // There should not be DW_MACINFO_end_file when IndLevel is Zero. However,
      23             :     // this check handles the case of corrupted ".debug_macinfo" section.
      24         162 :     if (IndLevel > 0)
      25          17 :       IndLevel -= (E.Type == DW_MACINFO_end_file);
      26             :     // Print indentation.
      27         200 :     for (unsigned I = 0; I < IndLevel; I++)
      28          19 :       OS << "  ";
      29         162 :     IndLevel += (E.Type == DW_MACINFO_start_file);
      30             : 
      31         324 :     WithColor(OS, HighlightColor::Macro).get() << MacinfoString(E.Type);
      32         162 :     switch (E.Type) {
      33             :     default:
      34             :       // Got a corrupted ".debug_macinfo" section (invalid macinfo type).
      35             :       break;
      36         150 :     case DW_MACINFO_define:
      37             :     case DW_MACINFO_undef:
      38         150 :       OS << " - lineno: " << E.Line;
      39         150 :       OS << " macro: " << E.MacroStr;
      40         150 :       break;
      41           6 :     case DW_MACINFO_start_file:
      42           6 :       OS << " - lineno: " << E.Line;
      43           6 :       OS << " filenum: " << E.File;
      44           6 :       break;
      45             :     case DW_MACINFO_end_file:
      46             :       break;
      47           0 :     case DW_MACINFO_vendor_ext:
      48           0 :       OS << " - constant: " << E.ExtConstant;
      49           0 :       OS << " string: " << E.ExtStr;
      50           0 :       break;
      51             :     }
      52         162 :     OS << "\n";
      53             :   }
      54           2 : }
      55             : 
      56         193 : void DWARFDebugMacro::parse(DataExtractor data) {
      57         193 :   uint32_t Offset = 0;
      58         872 :   while (data.isValidOffset(Offset)) {
      59             :     // A macro list entry consists of:
      60             :     Entry E;
      61             :     // 1. Macinfo type
      62         274 :     E.Type = data.getULEB128(&Offset);
      63             : 
      64         274 :     if (E.Type == 0) {
      65             :       // Reached end of ".debug_macinfo" section.
      66         112 :       return;
      67             :     }
      68             : 
      69         162 :     switch (E.Type) {
      70           0 :     default:
      71             :       // Got a corrupted ".debug_macinfo" section (invalid macinfo type).
      72             :       // Push the corrupted entry to the list and halt parsing.
      73           0 :       E.Type = DW_MACINFO_invalid;
      74           0 :       Macros.push_back(E);
      75           0 :       return;
      76         150 :     case DW_MACINFO_define:
      77             :     case DW_MACINFO_undef:
      78             :       // 2. Source line
      79         150 :       E.Line = data.getULEB128(&Offset);
      80             :       // 3. Macro string
      81         150 :       E.MacroStr = data.getCStr(&Offset);
      82         150 :       break;
      83           6 :     case DW_MACINFO_start_file:
      84             :       // 2. Source line
      85           6 :       E.Line = data.getULEB128(&Offset);
      86             :       // 3. Source file id
      87           6 :       E.File = data.getULEB128(&Offset);
      88           6 :       break;
      89             :     case DW_MACINFO_end_file:
      90             :       break;
      91           0 :     case DW_MACINFO_vendor_ext:
      92             :       // 2. Vendor extension constant
      93           0 :       E.ExtConstant = data.getULEB128(&Offset);
      94             :       // 3. Vendor extension string
      95           0 :       E.ExtStr = data.getCStr(&Offset);
      96           0 :       break;
      97             :     }
      98             : 
      99         162 :     Macros.push_back(E);
     100             :   }
     101             : }

Generated by: LCOV version 1.13