LCOV - code coverage report
Current view: top level - lib/ObjectYAML - DWARFVisitor.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 61 74 82.4 %
Date: 2018-06-17 00:07:59 Functions: 3 4 75.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         122 : void DWARFYAML::VisitorImpl<T>::onVariableSizeValue(uint64_t U, unsigned Size) {
      19         122 :   switch (Size) {
      20          45 :   case 8:
      21          45 :     onValue((uint64_t)U);
      22          45 :     break;
      23          77 :   case 4:
      24          77 :     onValue((uint32_t)U);
      25          77 :     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         122 : }
      36             : 
      37             : static unsigned getOffsetSize(const DWARFYAML::Unit &Unit) {
      38          77 :   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          32 : template <typename T> void DWARFYAML::VisitorImpl<T>::traverseDebugInfo() {
      48          34 :   for (auto &Unit : DebugInfo.CompileUnits) {
      49          26 :     onStartCompileUnit(Unit);
      50          26 :     auto FirstAbbrevCode = Unit.Entries[0].AbbrCode;
      51             : 
      52          28 :     for (auto &Entry : Unit.Entries) {
      53          88 :       onStartDIE(Unit, Entry);
      54          88 :       if (Entry.AbbrCode == 0u)
      55             :         continue;
      56          65 :       auto &Abbrev = DebugInfo.AbbrevDecls[Entry.AbbrCode - FirstAbbrevCode];
      57          64 :       auto FormVal = Entry.Values.begin();
      58          64 :       auto AbbrForm = Abbrev.Attributes.begin();
      59             :       for (;
      60         287 :            FormVal != Entry.Values.end() && AbbrForm != Abbrev.Attributes.end();
      61             :            ++FormVal, ++AbbrForm) {
      62         222 :         onForm(*AbbrForm, *FormVal);
      63         222 :         dwarf::Form Form = AbbrForm->Form;
      64             :         bool Indirect;
      65             :         do {
      66             :           Indirect = false;
      67         222 :           switch (Form) {
      68          44 :           case dwarf::DW_FORM_addr:
      69          44 :             onVariableSizeValue(FormVal->Value, Unit.AddrSize);
      70             :             break;
      71             :           case dwarf::DW_FORM_ref_addr:
      72           3 :             onVariableSizeValue(FormVal->Value, getRefSize(Unit));
      73             :             break;
      74          11 :           case dwarf::DW_FORM_exprloc:
      75             :           case dwarf::DW_FORM_block:
      76          22 :             onValue((uint64_t)FormVal->BlockData.size(), true);
      77          22 :             onValue(
      78             :                 MemoryBufferRef(StringRef((const char *)&FormVal->BlockData[0],
      79             :                                           FormVal->BlockData.size()),
      80             :                                 ""));
      81             :             break;
      82             :           case dwarf::DW_FORM_block1: {
      83           1 :             auto writeSize = FormVal->BlockData.size();
      84           1 :             onValue((uint8_t)writeSize);
      85           2 :             onValue(
      86             :                 MemoryBufferRef(StringRef((const char *)&FormVal->BlockData[0],
      87             :                                           FormVal->BlockData.size()),
      88             :                                 ""));
      89             :             break;
      90             :           }
      91             :           case dwarf::DW_FORM_block2: {
      92           1 :             auto writeSize = FormVal->BlockData.size();
      93           1 :             onValue((uint16_t)writeSize);
      94           2 :             onValue(
      95             :                 MemoryBufferRef(StringRef((const char *)&FormVal->BlockData[0],
      96             :                                           FormVal->BlockData.size()),
      97             :                                 ""));
      98             :             break;
      99             :           }
     100             :           case dwarf::DW_FORM_block4: {
     101           1 :             auto writeSize = FormVal->BlockData.size();
     102           1 :             onValue((uint32_t)writeSize);
     103           2 :             onValue(
     104             :                 MemoryBufferRef(StringRef((const char *)&FormVal->BlockData[0],
     105             :                                           FormVal->BlockData.size()),
     106             :                                 ""));
     107             :             break;
     108             :           }
     109          38 :           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          38 :             onValue((uint8_t)FormVal->Value);
     115             :             break;
     116           6 :           case dwarf::DW_FORM_data2:
     117             :           case dwarf::DW_FORM_ref2:
     118             :           case dwarf::DW_FORM_strx2:
     119             :           case dwarf::DW_FORM_addrx2:
     120           6 :             onValue((uint16_t)FormVal->Value);
     121             :             break;
     122          27 :           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          27 :             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             :             Indirect = true;
     147           0 :             Form = static_cast<dwarf::Form>((uint64_t)FormVal->Value);
     148             :             ++FormVal;
     149             :             break;
     150             :           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          75 :             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          65 :       onEndDIE(Unit, Entry);
     171             :     }
     172          26 :     onEndCompileUnit(Unit);
     173             :   }
     174          32 : }
     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