LCOV - code coverage report
Current view: top level - lib/ObjectYAML - DWARFVisitor.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 77 91 84.6 %
Date: 2017-09-14 15:23:50 Functions: 2 4 50.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===--- DWARFVisitor.cpp ---------------------------------------*- C++ -*-===//
       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             : //===----------------------------------------------------------------------===//
      11             : 
      12             : #include "DWARFVisitor.h"
      13             : #include "llvm/ObjectYAML/DWARFYAML.h"
      14             : 
      15             : using namespace llvm;
      16             : 
      17             : template <typename T>
      18          64 : void DWARFYAML::VisitorImpl<T>::onVariableSizeValue(uint64_t U, unsigned Size) {
      19          64 :   switch (Size) {
      20           9 :   case 8:
      21           9 :     onValue((uint64_t)U);
      22           9 :     break;
      23          55 :   case 4:
      24          55 :     onValue((uint32_t)U);
      25          55 :     break;
      26           0 :   case 2:
      27           0 :     onValue((uint16_t)U);
      28           0 :     break;
      29           0 :   case 1:
      30           0 :     onValue((uint8_t)U);
      31           0 :     break;
      32           0 :   default:
      33           0 :     llvm_unreachable("Invalid integer write size.");
      34             :   }
      35          64 : }
      36             : 
      37             : static unsigned getOffsetSize(const DWARFYAML::Unit &Unit) {
      38          55 :   return Unit.Length.isDWARF64() ? 8 : 4;
      39             : }
      40             : 
      41             : static unsigned getRefSize(const DWARFYAML::Unit &Unit) {
      42           3 :   if (Unit.Version == 2)
      43           1 :     return Unit.AddrSize;
      44             :   return getOffsetSize(Unit);
      45             : }
      46             : 
      47          23 : template <typename T> void DWARFYAML::VisitorImpl<T>::traverseDebugInfo() {
      48         109 :   for (auto &Unit : DebugInfo.CompileUnits) {
      49          17 :     onStartCompileUnit(Unit);
      50          17 :     auto FirstAbbrevCode = Unit.Entries[0].AbbrCode;
      51             : 
      52         119 :     for (auto &Entry : Unit.Entries) {
      53          51 :       onStartDIE(Unit, Entry);
      54         102 :       if (Entry.AbbrCode == 0u)
      55          10 :         continue;
      56          82 :       auto &Abbrev = DebugInfo.AbbrevDecls[Entry.AbbrCode - FirstAbbrevCode];
      57          82 :       auto FormVal = Entry.Values.begin();
      58          82 :       auto AbbrForm = Abbrev.Attributes.begin();
      59         154 :       for (;
      60         893 :            FormVal != Entry.Values.end() && AbbrForm != Abbrev.Attributes.end();
      61             :            ++FormVal, ++AbbrForm) {
      62         154 :         onForm(*AbbrForm, *FormVal);
      63         154 :         dwarf::Form Form = AbbrForm->Form;
      64             :         bool Indirect;
      65             :         do {
      66         154 :           Indirect = false;
      67         154 :           switch (Form) {
      68           8 :           case dwarf::DW_FORM_addr:
      69           8 :             onVariableSizeValue(FormVal->Value, Unit.AddrSize);
      70             :             break;
      71           3 :           case dwarf::DW_FORM_ref_addr:
      72           3 :             onVariableSizeValue(FormVal->Value, getRefSize(Unit));
      73             :             break;
      74          10 :           case dwarf::DW_FORM_exprloc:
      75             :           case dwarf::DW_FORM_block:
      76          20 :             onValue((uint64_t)FormVal->BlockData.size(), true);
      77          50 :             onValue(
      78          10 :                 MemoryBufferRef(StringRef((const char *)&FormVal->BlockData[0],
      79          10 :                                           FormVal->BlockData.size()),
      80             :                                 ""));
      81             :             break;
      82           1 :           case dwarf::DW_FORM_block1: {
      83           2 :             auto writeSize = FormVal->BlockData.size();
      84           1 :             onValue((uint8_t)writeSize);
      85           5 :             onValue(
      86           1 :                 MemoryBufferRef(StringRef((const char *)&FormVal->BlockData[0],
      87           1 :                                           FormVal->BlockData.size()),
      88             :                                 ""));
      89             :             break;
      90             :           }
      91           1 :           case dwarf::DW_FORM_block2: {
      92           2 :             auto writeSize = FormVal->BlockData.size();
      93           1 :             onValue((uint16_t)writeSize);
      94           5 :             onValue(
      95           1 :                 MemoryBufferRef(StringRef((const char *)&FormVal->BlockData[0],
      96           1 :                                           FormVal->BlockData.size()),
      97             :                                 ""));
      98             :             break;
      99             :           }
     100           1 :           case dwarf::DW_FORM_block4: {
     101           2 :             auto writeSize = FormVal->BlockData.size();
     102           1 :             onValue((uint32_t)writeSize);
     103           5 :             onValue(
     104           1 :                 MemoryBufferRef(StringRef((const char *)&FormVal->BlockData[0],
     105           1 :                                           FormVal->BlockData.size()),
     106             :                                 ""));
     107             :             break;
     108             :           }
     109          34 :           case dwarf::DW_FORM_data1:
     110             :           case dwarf::DW_FORM_ref1:
     111             :           case dwarf::DW_FORM_flag:
     112             :           case dwarf::DW_FORM_strx1:
     113             :           case dwarf::DW_FORM_addrx1:
     114          34 :             onValue((uint8_t)FormVal->Value);
     115             :             break;
     116           5 :           case dwarf::DW_FORM_data2:
     117             :           case dwarf::DW_FORM_ref2:
     118             :           case dwarf::DW_FORM_strx2:
     119             :           case dwarf::DW_FORM_addrx2:
     120           5 :             onValue((uint16_t)FormVal->Value);
     121             :             break;
     122          24 :           case dwarf::DW_FORM_data4:
     123             :           case dwarf::DW_FORM_ref4:
     124             :           case dwarf::DW_FORM_ref_sup4:
     125             :           case dwarf::DW_FORM_strx4:
     126             :           case dwarf::DW_FORM_addrx4:
     127          24 :             onValue((uint32_t)FormVal->Value);
     128             :             break;
     129           2 :           case dwarf::DW_FORM_data8:
     130             :           case dwarf::DW_FORM_ref8:
     131             :           case dwarf::DW_FORM_ref_sup8:
     132           2 :             onValue((uint64_t)FormVal->Value);
     133             :             break;
     134           1 :           case dwarf::DW_FORM_sdata:
     135           1 :             onValue((int64_t)FormVal->Value, true);
     136             :             break;
     137           2 :           case dwarf::DW_FORM_udata:
     138             :           case dwarf::DW_FORM_ref_udata:
     139           2 :             onValue((uint64_t)FormVal->Value, true);
     140             :             break;
     141           1 :           case dwarf::DW_FORM_string:
     142           1 :             onValue(FormVal->CStr);
     143             :             break;
     144           0 :           case dwarf::DW_FORM_indirect:
     145           0 :             onValue((uint64_t)FormVal->Value, true);
     146           0 :             Indirect = true;
     147           0 :             Form = static_cast<dwarf::Form>((uint64_t)FormVal->Value);
     148             :             ++FormVal;
     149             :             break;
     150          53 :           case dwarf::DW_FORM_strp:
     151             :           case dwarf::DW_FORM_sec_offset:
     152             :           case dwarf::DW_FORM_GNU_ref_alt:
     153             :           case dwarf::DW_FORM_GNU_strp_alt:
     154             :           case dwarf::DW_FORM_line_strp:
     155             :           case dwarf::DW_FORM_strp_sup:
     156          53 :             onVariableSizeValue(FormVal->Value, getOffsetSize(Unit));
     157             :             break;
     158           1 :           case dwarf::DW_FORM_ref_sig8:
     159           1 :             onValue((uint64_t)FormVal->Value);
     160             :             break;
     161           0 :           case dwarf::DW_FORM_GNU_addr_index:
     162             :           case dwarf::DW_FORM_GNU_str_index:
     163           0 :             onValue((uint64_t)FormVal->Value, true);
     164             :             break;
     165             :           default:
     166             :             break;
     167             :           }
     168             :         } while (Indirect);
     169             :       }
     170          41 :       onEndDIE(Unit, Entry);
     171             :     }
     172          17 :     onEndCompileUnit(Unit);
     173             :   }
     174          23 : }
     175             : 
     176             : // Explicitly instantiate the two template expansions.
     177             : template class DWARFYAML::VisitorImpl<DWARFYAML::Data>;
     178             : template class DWARFYAML::VisitorImpl<const DWARFYAML::Data>;

Generated by: LCOV version 1.13