blob: c9ca70645d958f5c8f449ba16188e36019ea0280 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- SBCompileUnit.cpp ---------------------------------------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006//
7//===----------------------------------------------------------------------===//
8
9#include "lldb/API/SBCompileUnit.h"
Jonas Devliegherebaf56642019-03-06 00:06:00 +000010#include "SBReproducerPrivate.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000011#include "lldb/API/SBLineEntry.h"
Caroline Ticedde9cff2010-09-20 05:20:02 +000012#include "lldb/API/SBStream.h"
Greg Claytonf02500c2013-06-18 22:51:05 +000013#include "lldb/Core/Module.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000014#include "lldb/Symbol/CompileUnit.h"
15#include "lldb/Symbol/LineEntry.h"
16#include "lldb/Symbol/LineTable.h"
Greg Claytonf02500c2013-06-18 22:51:05 +000017#include "lldb/Symbol/SymbolVendor.h"
18#include "lldb/Symbol/Type.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019
20using namespace lldb;
21using namespace lldb_private;
22
Konrad Kleine248a1302019-05-23 11:14:47 +000023SBCompileUnit::SBCompileUnit() : m_opaque_ptr(nullptr) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +000024 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBCompileUnit);
25}
Chris Lattner30fdc8d2010-06-08 16:52:24 +000026
Kate Stoneb9c1b512016-09-06 20:57:50 +000027SBCompileUnit::SBCompileUnit(lldb_private::CompileUnit *lldb_object_ptr)
28 : m_opaque_ptr(lldb_object_ptr) {}
29
30SBCompileUnit::SBCompileUnit(const SBCompileUnit &rhs)
Jonas Devliegherebaf56642019-03-06 00:06:00 +000031 : m_opaque_ptr(rhs.m_opaque_ptr) {
32 LLDB_RECORD_CONSTRUCTOR(SBCompileUnit, (const lldb::SBCompileUnit &), rhs);
33}
Kate Stoneb9c1b512016-09-06 20:57:50 +000034
35const SBCompileUnit &SBCompileUnit::operator=(const SBCompileUnit &rhs) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +000036 LLDB_RECORD_METHOD(const lldb::SBCompileUnit &,
37 SBCompileUnit, operator=,(const lldb::SBCompileUnit &),
38 rhs);
39
Kate Stoneb9c1b512016-09-06 20:57:50 +000040 m_opaque_ptr = rhs.m_opaque_ptr;
Jonas Devlieghere306809f2019-04-03 21:31:22 +000041 return LLDB_RECORD_RESULT(*this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000042}
43
Konrad Kleine248a1302019-05-23 11:14:47 +000044SBCompileUnit::~SBCompileUnit() { m_opaque_ptr = nullptr; }
Kate Stoneb9c1b512016-09-06 20:57:50 +000045
46SBFileSpec SBCompileUnit::GetFileSpec() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +000047 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBFileSpec, SBCompileUnit,
48 GetFileSpec);
49
Kate Stoneb9c1b512016-09-06 20:57:50 +000050 SBFileSpec file_spec;
51 if (m_opaque_ptr)
52 file_spec.SetFileSpec(*m_opaque_ptr);
Jonas Devliegherebaf56642019-03-06 00:06:00 +000053 return LLDB_RECORD_RESULT(file_spec);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000054}
55
Kate Stoneb9c1b512016-09-06 20:57:50 +000056uint32_t SBCompileUnit::GetNumLineEntries() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +000057 LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBCompileUnit, GetNumLineEntries);
58
Kate Stoneb9c1b512016-09-06 20:57:50 +000059 if (m_opaque_ptr) {
60 LineTable *line_table = m_opaque_ptr->GetLineTable();
Jason Molendab459f182019-03-06 02:32:45 +000061 if (line_table) {
Kate Stoneb9c1b512016-09-06 20:57:50 +000062 return line_table->GetSize();
Jason Molendab459f182019-03-06 02:32:45 +000063 }
Kate Stoneb9c1b512016-09-06 20:57:50 +000064 }
65 return 0;
Greg Claytonefabb122010-11-05 23:17:00 +000066}
67
Kate Stoneb9c1b512016-09-06 20:57:50 +000068SBLineEntry SBCompileUnit::GetLineEntryAtIndex(uint32_t idx) const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +000069 LLDB_RECORD_METHOD_CONST(lldb::SBLineEntry, SBCompileUnit,
70 GetLineEntryAtIndex, (uint32_t), idx);
71
Kate Stoneb9c1b512016-09-06 20:57:50 +000072 SBLineEntry sb_line_entry;
73 if (m_opaque_ptr) {
74 LineTable *line_table = m_opaque_ptr->GetLineTable();
75 if (line_table) {
76 LineEntry line_entry;
77 if (line_table->GetLineEntryAtIndex(idx, line_entry))
78 sb_line_entry.SetLineEntry(line_entry);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000079 }
Kate Stoneb9c1b512016-09-06 20:57:50 +000080 }
81
Jonas Devliegherebaf56642019-03-06 00:06:00 +000082 return LLDB_RECORD_RESULT(sb_line_entry);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000083}
84
Kate Stoneb9c1b512016-09-06 20:57:50 +000085uint32_t SBCompileUnit::FindLineEntryIndex(uint32_t start_idx, uint32_t line,
86 SBFileSpec *inline_file_spec) const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +000087 LLDB_RECORD_METHOD_CONST(uint32_t, SBCompileUnit, FindLineEntryIndex,
88 (uint32_t, uint32_t, lldb::SBFileSpec *), start_idx,
89 line, inline_file_spec);
90
Kate Stoneb9c1b512016-09-06 20:57:50 +000091 const bool exact = true;
92 return FindLineEntryIndex(start_idx, line, inline_file_spec, exact);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000093}
94
Kate Stoneb9c1b512016-09-06 20:57:50 +000095uint32_t SBCompileUnit::FindLineEntryIndex(uint32_t start_idx, uint32_t line,
96 SBFileSpec *inline_file_spec,
97 bool exact) const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +000098 LLDB_RECORD_METHOD_CONST(uint32_t, SBCompileUnit, FindLineEntryIndex,
99 (uint32_t, uint32_t, lldb::SBFileSpec *, bool),
100 start_idx, line, inline_file_spec, exact);
101
Kate Stoneb9c1b512016-09-06 20:57:50 +0000102 uint32_t index = UINT32_MAX;
103 if (m_opaque_ptr) {
104 FileSpec file_spec;
105 if (inline_file_spec && inline_file_spec->IsValid())
106 file_spec = inline_file_spec->ref();
Caroline Ticedde9cff2010-09-20 05:20:02 +0000107 else
Kate Stoneb9c1b512016-09-06 20:57:50 +0000108 file_spec = *m_opaque_ptr;
109
110 index = m_opaque_ptr->FindLineEntry(
Konrad Kleine248a1302019-05-23 11:14:47 +0000111 start_idx, line, inline_file_spec ? inline_file_spec->get() : nullptr,
112 exact, nullptr);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000113 }
114
Kate Stoneb9c1b512016-09-06 20:57:50 +0000115 return index;
116}
117
118uint32_t SBCompileUnit::GetNumSupportFiles() const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000119 LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBCompileUnit, GetNumSupportFiles);
120
Pavel Labath833dba02019-05-30 08:21:25 +0000121 if (m_opaque_ptr)
122 return m_opaque_ptr->GetSupportFiles().GetSize();
123
Kate Stoneb9c1b512016-09-06 20:57:50 +0000124 return 0;
125}
126
127lldb::SBTypeList SBCompileUnit::GetTypes(uint32_t type_mask) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000128 LLDB_RECORD_METHOD(lldb::SBTypeList, SBCompileUnit, GetTypes, (uint32_t),
129 type_mask);
130
Kate Stoneb9c1b512016-09-06 20:57:50 +0000131 SBTypeList sb_type_list;
132
Zachary Turner117b1fa2018-10-25 20:45:40 +0000133 if (!m_opaque_ptr)
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000134 return LLDB_RECORD_RESULT(sb_type_list);
Zachary Turner117b1fa2018-10-25 20:45:40 +0000135
136 ModuleSP module_sp(m_opaque_ptr->GetModule());
137 if (!module_sp)
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000138 return LLDB_RECORD_RESULT(sb_type_list);
Zachary Turner117b1fa2018-10-25 20:45:40 +0000139
140 SymbolVendor *vendor = module_sp->GetSymbolVendor();
141 if (!vendor)
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000142 return LLDB_RECORD_RESULT(sb_type_list);
Zachary Turner117b1fa2018-10-25 20:45:40 +0000143
144 TypeClass type_class = static_cast<TypeClass>(type_mask);
145 TypeList type_list;
146 vendor->GetTypes(m_opaque_ptr, type_class, type_list);
Jonas Devlieghered5b44032019-02-13 06:25:41 +0000147 sb_type_list.m_opaque_up->Append(type_list);
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000148 return LLDB_RECORD_RESULT(sb_type_list);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000149}
150
151SBFileSpec SBCompileUnit::GetSupportFileAtIndex(uint32_t idx) const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000152 LLDB_RECORD_METHOD_CONST(lldb::SBFileSpec, SBCompileUnit,
153 GetSupportFileAtIndex, (uint32_t), idx);
154
Kate Stoneb9c1b512016-09-06 20:57:50 +0000155 SBFileSpec sb_file_spec;
156 if (m_opaque_ptr) {
Pavel Labath833dba02019-05-30 08:21:25 +0000157 FileSpec spec = m_opaque_ptr->GetSupportFiles().GetFileSpecAtIndex(idx);
158 sb_file_spec.SetFileSpec(spec);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000159 }
160
Kate Stoneb9c1b512016-09-06 20:57:50 +0000161
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000162 return LLDB_RECORD_RESULT(sb_file_spec);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000163}
164
165uint32_t SBCompileUnit::FindSupportFileIndex(uint32_t start_idx,
166 const SBFileSpec &sb_file,
167 bool full) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000168 LLDB_RECORD_METHOD(uint32_t, SBCompileUnit, FindSupportFileIndex,
169 (uint32_t, const lldb::SBFileSpec &, bool), start_idx,
170 sb_file, full);
171
Kate Stoneb9c1b512016-09-06 20:57:50 +0000172 if (m_opaque_ptr) {
Pavel Labath833dba02019-05-30 08:21:25 +0000173 const FileSpecList &support_files = m_opaque_ptr->GetSupportFiles();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000174 return support_files.FindFileIndex(start_idx, sb_file.ref(), full);
175 }
176 return 0;
177}
178
179lldb::LanguageType SBCompileUnit::GetLanguage() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000180 LLDB_RECORD_METHOD_NO_ARGS(lldb::LanguageType, SBCompileUnit, GetLanguage);
181
Kate Stoneb9c1b512016-09-06 20:57:50 +0000182 if (m_opaque_ptr)
183 return m_opaque_ptr->GetLanguage();
184 return lldb::eLanguageTypeUnknown;
185}
186
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000187bool SBCompileUnit::IsValid() const {
188 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCompileUnit, IsValid);
Pavel Labath7f5237b2019-03-11 13:58:46 +0000189 return this->operator bool();
190}
191SBCompileUnit::operator bool() const {
192 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCompileUnit, operator bool);
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000193
Konrad Kleine248a1302019-05-23 11:14:47 +0000194 return m_opaque_ptr != nullptr;
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000195}
Kate Stoneb9c1b512016-09-06 20:57:50 +0000196
197bool SBCompileUnit::operator==(const SBCompileUnit &rhs) const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000198 LLDB_RECORD_METHOD_CONST(
199 bool, SBCompileUnit, operator==,(const lldb::SBCompileUnit &), rhs);
200
Kate Stoneb9c1b512016-09-06 20:57:50 +0000201 return m_opaque_ptr == rhs.m_opaque_ptr;
202}
203
204bool SBCompileUnit::operator!=(const SBCompileUnit &rhs) const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000205 LLDB_RECORD_METHOD_CONST(
206 bool, SBCompileUnit, operator!=,(const lldb::SBCompileUnit &), rhs);
207
Kate Stoneb9c1b512016-09-06 20:57:50 +0000208 return m_opaque_ptr != rhs.m_opaque_ptr;
209}
210
211const lldb_private::CompileUnit *SBCompileUnit::operator->() const {
212 return m_opaque_ptr;
213}
214
215const lldb_private::CompileUnit &SBCompileUnit::operator*() const {
216 return *m_opaque_ptr;
217}
218
219lldb_private::CompileUnit *SBCompileUnit::get() { return m_opaque_ptr; }
220
221void SBCompileUnit::reset(lldb_private::CompileUnit *lldb_object_ptr) {
222 m_opaque_ptr = lldb_object_ptr;
223}
224
225bool SBCompileUnit::GetDescription(SBStream &description) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000226 LLDB_RECORD_METHOD(bool, SBCompileUnit, GetDescription, (lldb::SBStream &),
227 description);
228
Kate Stoneb9c1b512016-09-06 20:57:50 +0000229 Stream &strm = description.ref();
230
231 if (m_opaque_ptr) {
232 m_opaque_ptr->Dump(&strm, false);
233 } else
234 strm.PutCString("No value");
235
236 return true;
Caroline Ticedde9cff2010-09-20 05:20:02 +0000237}
Michal Gornyae211ec2019-03-19 17:13:13 +0000238
239namespace lldb_private {
240namespace repro {
241
242template <>
243void 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,
250 ());
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,
272 (lldb::SBStream &));
273}
274
275}
276}