LCOV - code coverage report
Current view: top level - lib/DebugInfo/DWARF - DWARFDebugAbbrev.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 60 63 95.2 %
Date: 2017-09-14 15:23:50 Functions: 10 10 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- DWARFDebugAbbrev.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/DWARFDebugAbbrev.h"
      11             : #include "llvm/Support/Format.h"
      12             : #include "llvm/Support/raw_ostream.h"
      13             : #include <algorithm>
      14             : #include <cinttypes>
      15             : #include <cstdint>
      16             : 
      17             : using namespace llvm;
      18             : 
      19       57198 : DWARFAbbreviationDeclarationSet::DWARFAbbreviationDeclarationSet() {
      20       28599 :   clear();
      21       28599 : }
      22             : 
      23       56185 : void DWARFAbbreviationDeclarationSet::clear() {
      24       56185 :   Offset = 0;
      25       56185 :   FirstAbbrCode = 0;
      26       56185 :   Decls.clear();
      27       56185 : }
      28             : 
      29       27586 : bool DWARFAbbreviationDeclarationSet::extract(DataExtractor Data,
      30             :                                               uint32_t *OffsetPtr) {
      31       27586 :   clear();
      32       27586 :   const uint32_t BeginOffset = *OffsetPtr;
      33       27586 :   Offset = BeginOffset;
      34       55172 :   DWARFAbbreviationDeclaration AbbrDecl;
      35       27586 :   uint32_t PrevAbbrCode = 0;
      36     8218607 :   while (AbbrDecl.extract(Data, OffsetPtr)) {
      37     8191021 :     if (FirstAbbrCode == 0) {
      38       27296 :       FirstAbbrCode = AbbrDecl.getCode();
      39             :     } else {
      40     8163725 :       if (PrevAbbrCode + 1 != AbbrDecl.getCode()) {
      41             :         // Codes are not consecutive, can't do O(1) lookups.
      42           0 :         FirstAbbrCode = UINT32_MAX;
      43             :       }
      44             :     }
      45     8191021 :     PrevAbbrCode = AbbrDecl.getCode();
      46     8191021 :     Decls.push_back(std::move(AbbrDecl));
      47             :   }
      48       55172 :   return BeginOffset != *OffsetPtr;
      49             : }
      50             : 
      51         188 : void DWARFAbbreviationDeclarationSet::dump(raw_ostream &OS) const {
      52        2046 :   for (const auto &Decl : Decls)
      53        1294 :     Decl.dump(OS);
      54         188 : }
      55             : 
      56             : const DWARFAbbreviationDeclaration *
      57    14115051 : DWARFAbbreviationDeclarationSet::getAbbreviationDeclaration(
      58             :     uint32_t AbbrCode) const {
      59    14115051 :   if (FirstAbbrCode == UINT32_MAX) {
      60           0 :     for (const auto &Decl : Decls) {
      61           0 :       if (Decl.getCode() == AbbrCode)
      62             :         return &Decl;
      63             :     }
      64             :     return nullptr;
      65             :   }
      66    28230102 :   if (AbbrCode < FirstAbbrCode || AbbrCode >= FirstAbbrCode + Decls.size())
      67             :     return nullptr;
      68    28230102 :   return &Decls[AbbrCode - FirstAbbrCode];
      69             : }
      70             : 
      71        3039 : DWARFDebugAbbrev::DWARFDebugAbbrev() {
      72        1013 :   clear();
      73        1013 : }
      74             : 
      75        2026 : void DWARFDebugAbbrev::clear() {
      76        4052 :   AbbrDeclSets.clear();
      77        4052 :   PrevAbbrOffsetPos = AbbrDeclSets.end();
      78        2026 : }
      79             : 
      80        1013 : void DWARFDebugAbbrev::extract(DataExtractor Data) {
      81        1013 :   clear();
      82             : 
      83        1013 :   uint32_t Offset = 0;
      84        2026 :   DWARFAbbreviationDeclarationSet AbbrDecls;
      85       84784 :   while (Data.isValidOffset(Offset)) {
      86       27586 :     uint32_t CUAbbrOffset = Offset;
      87       27586 :     if (!AbbrDecls.extract(Data, &Offset))
      88             :       break;
      89       55172 :     AbbrDeclSets[CUAbbrOffset] = std::move(AbbrDecls);
      90             :   }
      91        1013 : }
      92             : 
      93         336 : void DWARFDebugAbbrev::dump(raw_ostream &OS) const {
      94         672 :   if (AbbrDeclSets.empty()) {
      95         159 :     OS << "< EMPTY >\n";
      96         159 :     return;
      97             :   }
      98             : 
      99         719 :   for (const auto &I : AbbrDeclSets) {
     100         376 :     OS << format("Abbrev table for offset: 0x%8.8" PRIx64 "\n", I.first);
     101         188 :     I.second.dump(OS);
     102             :   }
     103             : }
     104             : 
     105             : const DWARFAbbreviationDeclarationSet*
     106       27547 : DWARFDebugAbbrev::getAbbreviationDeclarationSet(uint64_t CUAbbrOffset) const {
     107       55094 :   const auto End = AbbrDeclSets.end();
     108       81882 :   if (PrevAbbrOffsetPos != End && PrevAbbrOffsetPos->first == CUAbbrOffset) {
     109         518 :     return &(PrevAbbrOffsetPos->second);
     110             :   }
     111             : 
     112       54576 :   const auto Pos = AbbrDeclSets.find(CUAbbrOffset);
     113       27288 :   if (Pos != End) {
     114       27287 :     PrevAbbrOffsetPos = Pos;
     115       27287 :     return &(Pos->second);
     116             :   }
     117             : 
     118             :   return nullptr;
     119             : }

Generated by: LCOV version 1.13