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

Generated by: LCOV version 1.13