Coverage Report

Created: 2022-01-18 06:27

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- DWARFDebugAbbrev.cpp ----------------------------------------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#include "DWARFDebugAbbrev.h"
10
#include "DWARFDataExtractor.h"
11
#include "lldb/Utility/Stream.h"
12
13
using namespace lldb;
14
using namespace lldb_private;
15
using namespace std;
16
17
// DWARFAbbreviationDeclarationSet::Clear()
18
95.8k
void DWARFAbbreviationDeclarationSet::Clear() {
19
95.8k
  m_idx_offset = 0;
20
95.8k
  m_decls.clear();
21
95.8k
}
22
23
// DWARFAbbreviationDeclarationSet::Extract()
24
llvm::Error
25
DWARFAbbreviationDeclarationSet::extract(const DWARFDataExtractor &data,
26
95.8k
                                         lldb::offset_t *offset_ptr) {
27
95.8k
  const lldb::offset_t begin_offset = *offset_ptr;
28
95.8k
  m_offset = begin_offset;
29
95.8k
  Clear();
30
95.8k
  DWARFAbbreviationDeclaration abbrevDeclaration;
31
95.8k
  dw_uleb128_t prev_abbr_code = 0;
32
381k
  while (true) {
33
381k
    llvm::Expected<DWARFEnumState> es =
34
381k
        abbrevDeclaration.extract(data, offset_ptr);
35
381k
    if (!es)
36
11
      return es.takeError();
37
381k
    if (*es == DWARFEnumState::Complete)
38
95.8k
      break;
39
285k
    m_decls.push_back(abbrevDeclaration);
40
285k
    if (m_idx_offset == 0)
41
12.2k
      m_idx_offset = abbrevDeclaration.Code();
42
273k
    else if (prev_abbr_code + 1 != abbrevDeclaration.Code()) {
43
      // Out of order indexes, we can't do O(1) lookups...
44
18
      m_idx_offset = UINT32_MAX;
45
18
    }
46
285k
    prev_abbr_code = abbrevDeclaration.Code();
47
285k
  }
48
95.8k
  return llvm::ErrorSuccess();
49
95.8k
}
50
51
// DWARFAbbreviationDeclarationSet::GetAbbreviationDeclaration()
52
const DWARFAbbreviationDeclaration *
53
DWARFAbbreviationDeclarationSet::GetAbbreviationDeclaration(
54
7.82M
    dw_uleb128_t abbrCode) const {
55
7.82M
  if (m_idx_offset == UINT32_MAX) {
56
855
    DWARFAbbreviationDeclarationCollConstIter pos;
57
855
    DWARFAbbreviationDeclarationCollConstIter end = m_decls.end();
58
2.86k
    for (pos = m_decls.begin(); pos != end; 
++pos2.01k
) {
59
2.86k
      if (pos->Code() == abbrCode)
60
854
        return &(*pos);
61
2.86k
    }
62
7.82M
  } else {
63
7.82M
    uint32_t idx = abbrCode - m_idx_offset;
64
7.82M
    if (idx < m_decls.size())
65
7.82M
      return &m_decls[idx];
66
7.82M
  }
67
1
  return nullptr;
68
7.82M
}
69
70
71
// DWARFAbbreviationDeclarationSet::GetUnsupportedForms()
72
void DWARFAbbreviationDeclarationSet::GetUnsupportedForms(
73
96.1k
    std::set<dw_form_t> &invalid_forms) const {
74
285k
  for (const auto &abbr_decl : m_decls) {
75
285k
    const size_t num_attrs = abbr_decl.NumAttributes();
76
1.38M
    for (size_t i=0; i<num_attrs; 
++i1.09M
) {
77
1.09M
      dw_form_t form = abbr_decl.GetFormByIndex(i);
78
1.09M
      if (!DWARFFormValue::FormIsSupported(form))
79
0
        invalid_forms.insert(form);
80
1.09M
    }
81
285k
  }
82
96.1k
}
83
84
// Encode
85
//
86
// Encode the abbreviation table onto the end of the buffer provided into a
87
// byte representation as would be found in a ".debug_abbrev" debug information
88
// section.
89
// void
90
// DWARFAbbreviationDeclarationSet::Encode(BinaryStreamBuf& debug_abbrev_buf)
91
// const
92
//{
93
//  DWARFAbbreviationDeclarationCollConstIter pos;
94
//  DWARFAbbreviationDeclarationCollConstIter end = m_decls.end();
95
//  for (pos = m_decls.begin(); pos != end; ++pos)
96
//      pos->Append(debug_abbrev_buf);
97
//  debug_abbrev_buf.Append8(0);
98
//}
99
100
// DWARFDebugAbbrev constructor
101
DWARFDebugAbbrev::DWARFDebugAbbrev()
102
12.2k
    : m_abbrevCollMap(), m_prev_abbr_offset_pos(m_abbrevCollMap.end()) {}
103
104
// DWARFDebugAbbrev::Parse()
105
12.2k
llvm::Error DWARFDebugAbbrev::parse(const DWARFDataExtractor &data) {
106
12.2k
  lldb::offset_t offset = 0;
107
108
108k
  while (data.ValidOffset(offset)) {
109
95.8k
    uint32_t initial_cu_offset = offset;
110
95.8k
    DWARFAbbreviationDeclarationSet abbrevDeclSet;
111
112
95.8k
    llvm::Error error = abbrevDeclSet.extract(data, &offset);
113
95.8k
    if (error)
114
7
      return error;
115
116
95.8k
    m_abbrevCollMap[initial_cu_offset] = abbrevDeclSet;
117
95.8k
  }
118
12.2k
  m_prev_abbr_offset_pos = m_abbrevCollMap.end();
119
12.2k
  return llvm::ErrorSuccess();
120
12.2k
}
121
122
// DWARFDebugAbbrev::GetAbbreviationDeclarationSet()
123
const DWARFAbbreviationDeclarationSet *
124
DWARFDebugAbbrev::GetAbbreviationDeclarationSet(
125
22.4k
    dw_offset_t cu_abbr_offset) const {
126
22.4k
  DWARFAbbreviationDeclarationCollMapConstIter end = m_abbrevCollMap.end();
127
22.4k
  DWARFAbbreviationDeclarationCollMapConstIter pos;
128
22.4k
  if (m_prev_abbr_offset_pos != end &&
129
22.4k
      
m_prev_abbr_offset_pos->first == cu_abbr_offset10.5k
)
130
10.5k
    return &(m_prev_abbr_offset_pos->second);
131
11.9k
  else {
132
11.9k
    pos = m_abbrevCollMap.find(cu_abbr_offset);
133
11.9k
    m_prev_abbr_offset_pos = pos;
134
11.9k
  }
135
136
11.9k
  if (pos != m_abbrevCollMap.end())
137
11.9k
    return &(pos->second);
138
0
  return nullptr;
139
11.9k
}
140
141
// DWARFDebugAbbrev::GetUnsupportedForms()
142
void DWARFDebugAbbrev::GetUnsupportedForms(
143
12.2k
    std::set<dw_form_t> &invalid_forms) const {
144
12.2k
  for (const auto &pair : m_abbrevCollMap)
145
96.1k
    pair.second.GetUnsupportedForms(invalid_forms);
146
12.2k
}