Coverage Report

Created: 2023-11-11 10:31

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/API/SBCompileUnit.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- SBCompileUnit.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 "lldb/API/SBCompileUnit.h"
10
#include "lldb/API/SBLineEntry.h"
11
#include "lldb/API/SBStream.h"
12
#include "lldb/Core/Module.h"
13
#include "lldb/Symbol/CompileUnit.h"
14
#include "lldb/Symbol/LineEntry.h"
15
#include "lldb/Symbol/LineTable.h"
16
#include "lldb/Symbol/SymbolFile.h"
17
#include "lldb/Symbol/Type.h"
18
#include "lldb/Symbol/TypeList.h"
19
#include "lldb/Utility/Instrumentation.h"
20
21
using namespace lldb;
22
using namespace lldb_private;
23
24
439
SBCompileUnit::SBCompileUnit() { LLDB_INSTRUMENT_VA(this); }
25
26
SBCompileUnit::SBCompileUnit(lldb_private::CompileUnit *lldb_object_ptr)
27
362
    : m_opaque_ptr(lldb_object_ptr) {}
28
29
SBCompileUnit::SBCompileUnit(const SBCompileUnit &rhs)
30
398
    : m_opaque_ptr(rhs.m_opaque_ptr) {
31
398
  LLDB_INSTRUMENT_VA(this, rhs);
32
398
}
33
34
398
const SBCompileUnit &SBCompileUnit::operator=(const SBCompileUnit &rhs) {
35
398
  LLDB_INSTRUMENT_VA(this, rhs);
36
37
398
  m_opaque_ptr = rhs.m_opaque_ptr;
38
398
  return *this;
39
398
}
40
41
1.19k
SBCompileUnit::~SBCompileUnit() { m_opaque_ptr = nullptr; }
42
43
37
SBFileSpec SBCompileUnit::GetFileSpec() const {
44
37
  LLDB_INSTRUMENT_VA(this);
45
46
37
  SBFileSpec file_spec;
47
37
  if (m_opaque_ptr)
48
36
    file_spec.SetFileSpec(m_opaque_ptr->GetPrimaryFile());
49
37
  return file_spec;
50
37
}
51
52
9
uint32_t SBCompileUnit::GetNumLineEntries() const {
53
9
  LLDB_INSTRUMENT_VA(this);
54
55
9
  if (m_opaque_ptr) {
56
6
    LineTable *line_table = m_opaque_ptr->GetLineTable();
57
6
    if (line_table) {
58
6
      return line_table->GetSize();
59
6
    }
60
6
  }
61
3
  return 0;
62
9
}
63
64
171
SBLineEntry SBCompileUnit::GetLineEntryAtIndex(uint32_t idx) const {
65
171
  LLDB_INSTRUMENT_VA(this, idx);
66
67
171
  SBLineEntry sb_line_entry;
68
171
  if (m_opaque_ptr) {
69
170
    LineTable *line_table = m_opaque_ptr->GetLineTable();
70
170
    if (line_table) {
71
170
      LineEntry line_entry;
72
170
      if (line_table->GetLineEntryAtIndex(idx, line_entry))
73
170
        sb_line_entry.SetLineEntry(line_entry);
74
170
    }
75
170
  }
76
77
171
  return sb_line_entry;
78
171
}
79
80
uint32_t SBCompileUnit::FindLineEntryIndex(lldb::SBLineEntry &line_entry,
81
2
                                           bool exact) const {
82
2
  LLDB_INSTRUMENT_VA(this, line_entry, exact);
83
84
2
  if (!m_opaque_ptr || !line_entry.IsValid())
85
0
    return UINT32_MAX;
86
87
2
  LineEntry found_line_entry;
88
89
2
  return m_opaque_ptr->FindLineEntry(0, line_entry.GetLine(),
90
2
                                     line_entry.GetFileSpec().get(), exact,
91
2
                                     &line_entry.ref());
92
2
}
93
94
uint32_t SBCompileUnit::FindLineEntryIndex(uint32_t start_idx, uint32_t line,
95
5
                                           SBFileSpec *inline_file_spec) const {
96
5
  LLDB_INSTRUMENT_VA(this, start_idx, line, inline_file_spec);
97
98
5
  const bool exact = true;
99
5
  return FindLineEntryIndex(start_idx, line, inline_file_spec, exact);
100
5
}
101
102
uint32_t SBCompileUnit::FindLineEntryIndex(uint32_t start_idx, uint32_t line,
103
                                           SBFileSpec *inline_file_spec,
104
7
                                           bool exact) const {
105
7
  LLDB_INSTRUMENT_VA(this, start_idx, line, inline_file_spec, exact);
106
107
7
  uint32_t index = UINT32_MAX;
108
7
  if (m_opaque_ptr) {
109
6
    FileSpec file_spec;
110
6
    if (inline_file_spec && inline_file_spec->IsValid())
111
6
      file_spec = inline_file_spec->ref();
112
0
    else
113
0
      file_spec = m_opaque_ptr->GetPrimaryFile();
114
115
6
    LineEntry line_entry;
116
6
    index = m_opaque_ptr->FindLineEntry(
117
6
        start_idx, line, inline_file_spec ? inline_file_spec->get() : 
nullptr0
,
118
6
        exact, &line_entry);
119
6
  }
120
121
7
  return index;
122
7
}
123
124
0
uint32_t SBCompileUnit::GetNumSupportFiles() const {
125
0
  LLDB_INSTRUMENT_VA(this);
126
127
0
  if (m_opaque_ptr)
128
0
    return m_opaque_ptr->GetSupportFiles().GetSize();
129
130
0
  return 0;
131
0
}
132
133
4
lldb::SBTypeList SBCompileUnit::GetTypes(uint32_t type_mask) {
134
4
  LLDB_INSTRUMENT_VA(this, type_mask);
135
136
4
  SBTypeList sb_type_list;
137
138
4
  if (!m_opaque_ptr)
139
0
    return sb_type_list;
140
141
4
  ModuleSP module_sp(m_opaque_ptr->GetModule());
142
4
  if (!module_sp)
143
0
    return sb_type_list;
144
145
4
  SymbolFile *symfile = module_sp->GetSymbolFile();
146
4
  if (!symfile)
147
0
    return sb_type_list;
148
149
4
  TypeClass type_class = static_cast<TypeClass>(type_mask);
150
4
  TypeList type_list;
151
4
  symfile->GetTypes(m_opaque_ptr, type_class, type_list);
152
4
  sb_type_list.m_opaque_up->Append(type_list);
153
4
  return sb_type_list;
154
4
}
155
156
0
SBFileSpec SBCompileUnit::GetSupportFileAtIndex(uint32_t idx) const {
157
0
  LLDB_INSTRUMENT_VA(this, idx);
158
159
0
  SBFileSpec sb_file_spec;
160
0
  if (m_opaque_ptr) {
161
0
    FileSpec spec = m_opaque_ptr->GetSupportFiles().GetFileSpecAtIndex(idx);
162
0
    sb_file_spec.SetFileSpec(spec);
163
0
  }
164
165
0
  return sb_file_spec;
166
0
}
167
168
uint32_t SBCompileUnit::FindSupportFileIndex(uint32_t start_idx,
169
                                             const SBFileSpec &sb_file,
170
0
                                             bool full) {
171
0
  LLDB_INSTRUMENT_VA(this, start_idx, sb_file, full);
172
173
0
  if (m_opaque_ptr) {
174
0
    const FileSpecList &support_files = m_opaque_ptr->GetSupportFiles();
175
0
    return support_files.FindFileIndex(start_idx, sb_file.ref(), full);
176
0
  }
177
0
  return 0;
178
0
}
179
180
0
lldb::LanguageType SBCompileUnit::GetLanguage() {
181
0
  LLDB_INSTRUMENT_VA(this);
182
183
0
  if (m_opaque_ptr)
184
0
    return m_opaque_ptr->GetLanguage();
185
0
  return lldb::eLanguageTypeUnknown;
186
0
}
187
188
347
bool SBCompileUnit::IsValid() const {
189
347
  LLDB_INSTRUMENT_VA(this);
190
347
  return this->operator bool();
191
347
}
192
350
SBCompileUnit::operator bool() const {
193
350
  LLDB_INSTRUMENT_VA(this);
194
195
350
  return m_opaque_ptr != nullptr;
196
350
}
197
198
0
bool SBCompileUnit::operator==(const SBCompileUnit &rhs) const {
199
0
  LLDB_INSTRUMENT_VA(this, rhs);
200
201
0
  return m_opaque_ptr == rhs.m_opaque_ptr;
202
0
}
203
204
0
bool SBCompileUnit::operator!=(const SBCompileUnit &rhs) const {
205
0
  LLDB_INSTRUMENT_VA(this, rhs);
206
207
0
  return m_opaque_ptr != rhs.m_opaque_ptr;
208
0
}
209
210
0
const lldb_private::CompileUnit *SBCompileUnit::operator->() const {
211
0
  return m_opaque_ptr;
212
0
}
213
214
0
const lldb_private::CompileUnit &SBCompileUnit::operator*() const {
215
0
  return *m_opaque_ptr;
216
0
}
217
218
0
lldb_private::CompileUnit *SBCompileUnit::get() { return m_opaque_ptr; }
219
220
35
void SBCompileUnit::reset(lldb_private::CompileUnit *lldb_object_ptr) {
221
35
  m_opaque_ptr = lldb_object_ptr;
222
35
}
223
224
10
bool SBCompileUnit::GetDescription(SBStream &description) {
225
10
  LLDB_INSTRUMENT_VA(this, description);
226
227
10
  Stream &strm = description.ref();
228
229
10
  if (m_opaque_ptr) {
230
8
    m_opaque_ptr->Dump(&strm, false);
231
8
  } else
232
2
    strm.PutCString("No value");
233
234
10
  return true;
235
10
}