1 //===-- SBCompileUnit.cpp ---------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/API/SBCompileUnit.h"
10 #include "SBReproducerPrivate.h"
11 #include "lldb/API/SBLineEntry.h"
12 #include "lldb/API/SBStream.h"
13 #include "lldb/Core/Module.h"
14 #include "lldb/Symbol/CompileUnit.h"
15 #include "lldb/Symbol/LineEntry.h"
16 #include "lldb/Symbol/LineTable.h"
17 #include "lldb/Symbol/SymbolVendor.h"
18 #include "lldb/Symbol/Type.h"
21 using namespace lldb_private;
23 SBCompileUnit::SBCompileUnit() : m_opaque_ptr(nullptr) {
24 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBCompileUnit);
27 SBCompileUnit::SBCompileUnit(lldb_private::CompileUnit *lldb_object_ptr)
28 : m_opaque_ptr(lldb_object_ptr) {}
30 SBCompileUnit::SBCompileUnit(const SBCompileUnit &rhs)
31 : m_opaque_ptr(rhs.m_opaque_ptr) {
32 LLDB_RECORD_CONSTRUCTOR(SBCompileUnit, (const lldb::SBCompileUnit &), rhs);
35 const SBCompileUnit &SBCompileUnit::operator=(const SBCompileUnit &rhs) {
36 LLDB_RECORD_METHOD(const lldb::SBCompileUnit &,
37 SBCompileUnit, operator=,(const lldb::SBCompileUnit &),
40 m_opaque_ptr = rhs.m_opaque_ptr;
41 return LLDB_RECORD_RESULT(*this);
44 SBCompileUnit::~SBCompileUnit() { m_opaque_ptr = nullptr; }
46 SBFileSpec SBCompileUnit::GetFileSpec() const {
47 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBFileSpec, SBCompileUnit,
52 file_spec.SetFileSpec(*m_opaque_ptr);
53 return LLDB_RECORD_RESULT(file_spec);
56 uint32_t SBCompileUnit::GetNumLineEntries() const {
57 LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBCompileUnit, GetNumLineEntries);
60 LineTable *line_table = m_opaque_ptr->GetLineTable();
62 return line_table->GetSize();
68 SBLineEntry SBCompileUnit::GetLineEntryAtIndex(uint32_t idx) const {
69 LLDB_RECORD_METHOD_CONST(lldb::SBLineEntry, SBCompileUnit,
70 GetLineEntryAtIndex, (uint32_t), idx);
72 SBLineEntry sb_line_entry;
74 LineTable *line_table = m_opaque_ptr->GetLineTable();
77 if (line_table->GetLineEntryAtIndex(idx, line_entry))
78 sb_line_entry.SetLineEntry(line_entry);
82 return LLDB_RECORD_RESULT(sb_line_entry);
85 uint32_t SBCompileUnit::FindLineEntryIndex(uint32_t start_idx, uint32_t line,
86 SBFileSpec *inline_file_spec) const {
87 LLDB_RECORD_METHOD_CONST(uint32_t, SBCompileUnit, FindLineEntryIndex,
88 (uint32_t, uint32_t, lldb::SBFileSpec *), start_idx,
89 line, inline_file_spec);
91 const bool exact = true;
92 return FindLineEntryIndex(start_idx, line, inline_file_spec, exact);
95 uint32_t SBCompileUnit::FindLineEntryIndex(uint32_t start_idx, uint32_t line,
96 SBFileSpec *inline_file_spec,
98 LLDB_RECORD_METHOD_CONST(uint32_t, SBCompileUnit, FindLineEntryIndex,
99 (uint32_t, uint32_t, lldb::SBFileSpec *, bool),
100 start_idx, line, inline_file_spec, exact);
102 uint32_t index = UINT32_MAX;
105 if (inline_file_spec && inline_file_spec->IsValid())
106 file_spec = inline_file_spec->ref();
108 file_spec = *m_opaque_ptr;
110 index = m_opaque_ptr->FindLineEntry(
111 start_idx, line, inline_file_spec ? inline_file_spec->get() : nullptr,
118 uint32_t SBCompileUnit::GetNumSupportFiles() const {
119 LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBCompileUnit, GetNumSupportFiles);
122 return m_opaque_ptr->GetSupportFiles().GetSize();
127 lldb::SBTypeList SBCompileUnit::GetTypes(uint32_t type_mask) {
128 LLDB_RECORD_METHOD(lldb::SBTypeList, SBCompileUnit, GetTypes, (uint32_t),
131 SBTypeList sb_type_list;
134 return LLDB_RECORD_RESULT(sb_type_list);
136 ModuleSP module_sp(m_opaque_ptr->GetModule());
138 return LLDB_RECORD_RESULT(sb_type_list);
140 SymbolVendor *vendor = module_sp->GetSymbolVendor();
142 return LLDB_RECORD_RESULT(sb_type_list);
144 TypeClass type_class = static_cast<TypeClass>(type_mask);
146 vendor->GetTypes(m_opaque_ptr, type_class, type_list);
147 sb_type_list.m_opaque_up->Append(type_list);
148 return LLDB_RECORD_RESULT(sb_type_list);
151 SBFileSpec SBCompileUnit::GetSupportFileAtIndex(uint32_t idx) const {
152 LLDB_RECORD_METHOD_CONST(lldb::SBFileSpec, SBCompileUnit,
153 GetSupportFileAtIndex, (uint32_t), idx);
155 SBFileSpec sb_file_spec;
157 FileSpec spec = m_opaque_ptr->GetSupportFiles().GetFileSpecAtIndex(idx);
158 sb_file_spec.SetFileSpec(spec);
162 return LLDB_RECORD_RESULT(sb_file_spec);
165 uint32_t SBCompileUnit::FindSupportFileIndex(uint32_t start_idx,
166 const SBFileSpec &sb_file,
168 LLDB_RECORD_METHOD(uint32_t, SBCompileUnit, FindSupportFileIndex,
169 (uint32_t, const lldb::SBFileSpec &, bool), start_idx,
173 const FileSpecList &support_files = m_opaque_ptr->GetSupportFiles();
174 return support_files.FindFileIndex(start_idx, sb_file.ref(), full);
179 lldb::LanguageType SBCompileUnit::GetLanguage() {
180 LLDB_RECORD_METHOD_NO_ARGS(lldb::LanguageType, SBCompileUnit, GetLanguage);
183 return m_opaque_ptr->GetLanguage();
184 return lldb::eLanguageTypeUnknown;
187 bool SBCompileUnit::IsValid() const {
188 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCompileUnit, IsValid);
189 return this->operator bool();
191 SBCompileUnit::operator bool() const {
192 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCompileUnit, operator bool);
194 return m_opaque_ptr != nullptr;
197 bool SBCompileUnit::operator==(const SBCompileUnit &rhs) const {
198 LLDB_RECORD_METHOD_CONST(
199 bool, SBCompileUnit, operator==,(const lldb::SBCompileUnit &), rhs);
201 return m_opaque_ptr == rhs.m_opaque_ptr;
204 bool SBCompileUnit::operator!=(const SBCompileUnit &rhs) const {
205 LLDB_RECORD_METHOD_CONST(
206 bool, SBCompileUnit, operator!=,(const lldb::SBCompileUnit &), rhs);
208 return m_opaque_ptr != rhs.m_opaque_ptr;
211 const lldb_private::CompileUnit *SBCompileUnit::operator->() const {
215 const lldb_private::CompileUnit &SBCompileUnit::operator*() const {
216 return *m_opaque_ptr;
219 lldb_private::CompileUnit *SBCompileUnit::get() { return m_opaque_ptr; }
221 void SBCompileUnit::reset(lldb_private::CompileUnit *lldb_object_ptr) {
222 m_opaque_ptr = lldb_object_ptr;
225 bool SBCompileUnit::GetDescription(SBStream &description) {
226 LLDB_RECORD_METHOD(bool, SBCompileUnit, GetDescription, (lldb::SBStream &),
229 Stream &strm = description.ref();
232 m_opaque_ptr->Dump(&strm, false);
234 strm.PutCString("No value");
239 namespace lldb_private {
243 void RegisterMethods<SBCompileUnit>(Registry &R) {
244 LLDB_REGISTER_CONSTRUCTOR(SBCompileUnit, ());
245 LLDB_REGISTER_CONSTRUCTOR(SBCompileUnit, (const lldb::SBCompileUnit &));
246 LLDB_REGISTER_METHOD(
247 const lldb::SBCompileUnit &,
248 SBCompileUnit, operator=,(const lldb::SBCompileUnit &));
249 LLDB_REGISTER_METHOD_CONST(lldb::SBFileSpec, SBCompileUnit, GetFileSpec,
251 LLDB_REGISTER_METHOD_CONST(uint32_t, SBCompileUnit, GetNumLineEntries, ());
252 LLDB_REGISTER_METHOD_CONST(lldb::SBLineEntry, SBCompileUnit,
253 GetLineEntryAtIndex, (uint32_t));
254 LLDB_REGISTER_METHOD_CONST(uint32_t, SBCompileUnit, FindLineEntryIndex,
255 (uint32_t, uint32_t, lldb::SBFileSpec *));
256 LLDB_REGISTER_METHOD_CONST(uint32_t, SBCompileUnit, FindLineEntryIndex,
257 (uint32_t, uint32_t, lldb::SBFileSpec *, bool));
258 LLDB_REGISTER_METHOD_CONST(uint32_t, SBCompileUnit, GetNumSupportFiles, ());
259 LLDB_REGISTER_METHOD(lldb::SBTypeList, SBCompileUnit, GetTypes, (uint32_t));
260 LLDB_REGISTER_METHOD_CONST(lldb::SBFileSpec, SBCompileUnit,
261 GetSupportFileAtIndex, (uint32_t));
262 LLDB_REGISTER_METHOD(uint32_t, SBCompileUnit, FindSupportFileIndex,
263 (uint32_t, const lldb::SBFileSpec &, bool));
264 LLDB_REGISTER_METHOD(lldb::LanguageType, SBCompileUnit, GetLanguage, ());
265 LLDB_REGISTER_METHOD_CONST(bool, SBCompileUnit, IsValid, ());
266 LLDB_REGISTER_METHOD_CONST(bool, SBCompileUnit, operator bool, ());
267 LLDB_REGISTER_METHOD_CONST(
268 bool, SBCompileUnit, operator==,(const lldb::SBCompileUnit &));
269 LLDB_REGISTER_METHOD_CONST(
270 bool, SBCompileUnit, operator!=,(const lldb::SBCompileUnit &));
271 LLDB_REGISTER_METHOD(bool, SBCompileUnit, GetDescription,