[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / lldb / source / API / SBCompileUnit.cpp
blobd52040d850a957b4371bb6a461174cbc0e7c6fc8
1 //===-- SBCompileUnit.cpp ---------------------------------------*- C++ -*-===//
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 //===----------------------------------------------------------------------===//
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/SymbolFile.h"
18 #include "lldb/Symbol/Type.h"
19 #include "lldb/Symbol/TypeList.h"
21 using namespace lldb;
22 using namespace lldb_private;
24 SBCompileUnit::SBCompileUnit() : m_opaque_ptr(nullptr) {
25 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBCompileUnit);
28 SBCompileUnit::SBCompileUnit(lldb_private::CompileUnit *lldb_object_ptr)
29 : m_opaque_ptr(lldb_object_ptr) {}
31 SBCompileUnit::SBCompileUnit(const SBCompileUnit &rhs)
32 : m_opaque_ptr(rhs.m_opaque_ptr) {
33 LLDB_RECORD_CONSTRUCTOR(SBCompileUnit, (const lldb::SBCompileUnit &), rhs);
36 const SBCompileUnit &SBCompileUnit::operator=(const SBCompileUnit &rhs) {
37 LLDB_RECORD_METHOD(const lldb::SBCompileUnit &,
38 SBCompileUnit, operator=,(const lldb::SBCompileUnit &),
39 rhs);
41 m_opaque_ptr = rhs.m_opaque_ptr;
42 return LLDB_RECORD_RESULT(*this);
45 SBCompileUnit::~SBCompileUnit() { m_opaque_ptr = nullptr; }
47 SBFileSpec SBCompileUnit::GetFileSpec() const {
48 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBFileSpec, SBCompileUnit,
49 GetFileSpec);
51 SBFileSpec file_spec;
52 if (m_opaque_ptr)
53 file_spec.SetFileSpec(m_opaque_ptr->GetPrimaryFile());
54 return LLDB_RECORD_RESULT(file_spec);
57 uint32_t SBCompileUnit::GetNumLineEntries() const {
58 LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBCompileUnit, GetNumLineEntries);
60 if (m_opaque_ptr) {
61 LineTable *line_table = m_opaque_ptr->GetLineTable();
62 if (line_table) {
63 return line_table->GetSize();
66 return 0;
69 SBLineEntry SBCompileUnit::GetLineEntryAtIndex(uint32_t idx) const {
70 LLDB_RECORD_METHOD_CONST(lldb::SBLineEntry, SBCompileUnit,
71 GetLineEntryAtIndex, (uint32_t), idx);
73 SBLineEntry sb_line_entry;
74 if (m_opaque_ptr) {
75 LineTable *line_table = m_opaque_ptr->GetLineTable();
76 if (line_table) {
77 LineEntry line_entry;
78 if (line_table->GetLineEntryAtIndex(idx, line_entry))
79 sb_line_entry.SetLineEntry(line_entry);
83 return LLDB_RECORD_RESULT(sb_line_entry);
86 uint32_t SBCompileUnit::FindLineEntryIndex(uint32_t start_idx, uint32_t line,
87 SBFileSpec *inline_file_spec) const {
88 LLDB_RECORD_METHOD_CONST(uint32_t, SBCompileUnit, FindLineEntryIndex,
89 (uint32_t, uint32_t, lldb::SBFileSpec *), start_idx,
90 line, inline_file_spec);
92 const bool exact = true;
93 return FindLineEntryIndex(start_idx, line, inline_file_spec, exact);
96 uint32_t SBCompileUnit::FindLineEntryIndex(uint32_t start_idx, uint32_t line,
97 SBFileSpec *inline_file_spec,
98 bool exact) const {
99 LLDB_RECORD_METHOD_CONST(uint32_t, SBCompileUnit, FindLineEntryIndex,
100 (uint32_t, uint32_t, lldb::SBFileSpec *, bool),
101 start_idx, line, inline_file_spec, exact);
103 uint32_t index = UINT32_MAX;
104 if (m_opaque_ptr) {
105 FileSpec file_spec;
106 if (inline_file_spec && inline_file_spec->IsValid())
107 file_spec = inline_file_spec->ref();
108 else
109 file_spec = m_opaque_ptr->GetPrimaryFile();
111 index = m_opaque_ptr->FindLineEntry(
112 start_idx, line, inline_file_spec ? inline_file_spec->get() : nullptr,
113 exact, nullptr);
116 return index;
119 uint32_t SBCompileUnit::GetNumSupportFiles() const {
120 LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBCompileUnit, GetNumSupportFiles);
122 if (m_opaque_ptr)
123 return m_opaque_ptr->GetSupportFiles().GetSize();
125 return 0;
128 lldb::SBTypeList SBCompileUnit::GetTypes(uint32_t type_mask) {
129 LLDB_RECORD_METHOD(lldb::SBTypeList, SBCompileUnit, GetTypes, (uint32_t),
130 type_mask);
132 SBTypeList sb_type_list;
134 if (!m_opaque_ptr)
135 return LLDB_RECORD_RESULT(sb_type_list);
137 ModuleSP module_sp(m_opaque_ptr->GetModule());
138 if (!module_sp)
139 return LLDB_RECORD_RESULT(sb_type_list);
141 SymbolFile *symfile = module_sp->GetSymbolFile();
142 if (!symfile)
143 return LLDB_RECORD_RESULT(sb_type_list);
145 TypeClass type_class = static_cast<TypeClass>(type_mask);
146 TypeList type_list;
147 symfile->GetTypes(m_opaque_ptr, type_class, type_list);
148 sb_type_list.m_opaque_up->Append(type_list);
149 return LLDB_RECORD_RESULT(sb_type_list);
152 SBFileSpec SBCompileUnit::GetSupportFileAtIndex(uint32_t idx) const {
153 LLDB_RECORD_METHOD_CONST(lldb::SBFileSpec, SBCompileUnit,
154 GetSupportFileAtIndex, (uint32_t), idx);
156 SBFileSpec sb_file_spec;
157 if (m_opaque_ptr) {
158 FileSpec spec = m_opaque_ptr->GetSupportFiles().GetFileSpecAtIndex(idx);
159 sb_file_spec.SetFileSpec(spec);
163 return LLDB_RECORD_RESULT(sb_file_spec);
166 uint32_t SBCompileUnit::FindSupportFileIndex(uint32_t start_idx,
167 const SBFileSpec &sb_file,
168 bool full) {
169 LLDB_RECORD_METHOD(uint32_t, SBCompileUnit, FindSupportFileIndex,
170 (uint32_t, const lldb::SBFileSpec &, bool), start_idx,
171 sb_file, full);
173 if (m_opaque_ptr) {
174 const FileSpecList &support_files = m_opaque_ptr->GetSupportFiles();
175 return support_files.FindFileIndex(start_idx, sb_file.ref(), full);
177 return 0;
180 lldb::LanguageType SBCompileUnit::GetLanguage() {
181 LLDB_RECORD_METHOD_NO_ARGS(lldb::LanguageType, SBCompileUnit, GetLanguage);
183 if (m_opaque_ptr)
184 return m_opaque_ptr->GetLanguage();
185 return lldb::eLanguageTypeUnknown;
188 bool SBCompileUnit::IsValid() const {
189 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCompileUnit, IsValid);
190 return this->operator bool();
192 SBCompileUnit::operator bool() const {
193 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCompileUnit, operator bool);
195 return m_opaque_ptr != nullptr;
198 bool SBCompileUnit::operator==(const SBCompileUnit &rhs) const {
199 LLDB_RECORD_METHOD_CONST(
200 bool, SBCompileUnit, operator==,(const lldb::SBCompileUnit &), rhs);
202 return m_opaque_ptr == rhs.m_opaque_ptr;
205 bool SBCompileUnit::operator!=(const SBCompileUnit &rhs) const {
206 LLDB_RECORD_METHOD_CONST(
207 bool, SBCompileUnit, operator!=,(const lldb::SBCompileUnit &), rhs);
209 return m_opaque_ptr != rhs.m_opaque_ptr;
212 const lldb_private::CompileUnit *SBCompileUnit::operator->() const {
213 return m_opaque_ptr;
216 const lldb_private::CompileUnit &SBCompileUnit::operator*() const {
217 return *m_opaque_ptr;
220 lldb_private::CompileUnit *SBCompileUnit::get() { return m_opaque_ptr; }
222 void SBCompileUnit::reset(lldb_private::CompileUnit *lldb_object_ptr) {
223 m_opaque_ptr = lldb_object_ptr;
226 bool SBCompileUnit::GetDescription(SBStream &description) {
227 LLDB_RECORD_METHOD(bool, SBCompileUnit, GetDescription, (lldb::SBStream &),
228 description);
230 Stream &strm = description.ref();
232 if (m_opaque_ptr) {
233 m_opaque_ptr->Dump(&strm, false);
234 } else
235 strm.PutCString("No value");
237 return true;
240 namespace lldb_private {
241 namespace repro {
243 template <>
244 void RegisterMethods<SBCompileUnit>(Registry &R) {
245 LLDB_REGISTER_CONSTRUCTOR(SBCompileUnit, ());
246 LLDB_REGISTER_CONSTRUCTOR(SBCompileUnit, (const lldb::SBCompileUnit &));
247 LLDB_REGISTER_METHOD(
248 const lldb::SBCompileUnit &,
249 SBCompileUnit, operator=,(const lldb::SBCompileUnit &));
250 LLDB_REGISTER_METHOD_CONST(lldb::SBFileSpec, SBCompileUnit, GetFileSpec,
251 ());
252 LLDB_REGISTER_METHOD_CONST(uint32_t, SBCompileUnit, GetNumLineEntries, ());
253 LLDB_REGISTER_METHOD_CONST(lldb::SBLineEntry, SBCompileUnit,
254 GetLineEntryAtIndex, (uint32_t));
255 LLDB_REGISTER_METHOD_CONST(uint32_t, SBCompileUnit, FindLineEntryIndex,
256 (uint32_t, uint32_t, lldb::SBFileSpec *));
257 LLDB_REGISTER_METHOD_CONST(uint32_t, SBCompileUnit, FindLineEntryIndex,
258 (uint32_t, uint32_t, lldb::SBFileSpec *, bool));
259 LLDB_REGISTER_METHOD_CONST(uint32_t, SBCompileUnit, GetNumSupportFiles, ());
260 LLDB_REGISTER_METHOD(lldb::SBTypeList, SBCompileUnit, GetTypes, (uint32_t));
261 LLDB_REGISTER_METHOD_CONST(lldb::SBFileSpec, SBCompileUnit,
262 GetSupportFileAtIndex, (uint32_t));
263 LLDB_REGISTER_METHOD(uint32_t, SBCompileUnit, FindSupportFileIndex,
264 (uint32_t, const lldb::SBFileSpec &, bool));
265 LLDB_REGISTER_METHOD(lldb::LanguageType, SBCompileUnit, GetLanguage, ());
266 LLDB_REGISTER_METHOD_CONST(bool, SBCompileUnit, IsValid, ());
267 LLDB_REGISTER_METHOD_CONST(bool, SBCompileUnit, operator bool, ());
268 LLDB_REGISTER_METHOD_CONST(
269 bool, SBCompileUnit, operator==,(const lldb::SBCompileUnit &));
270 LLDB_REGISTER_METHOD_CONST(
271 bool, SBCompileUnit, operator!=,(const lldb::SBCompileUnit &));
272 LLDB_REGISTER_METHOD(bool, SBCompileUnit, GetDescription,
273 (lldb::SBStream &));