blob: 9693dc9a687c47c7fedc6b3973d2b80fd1d1f16c [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
Jonas Devliegherebaf56642019-03-06 00:06:00 +000023SBCompileUnit::SBCompileUnit() : m_opaque_ptr(NULL) {
24 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;
41 return *this;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000042}
43
Kate Stoneb9c1b512016-09-06 20:57:50 +000044SBCompileUnit::~SBCompileUnit() { m_opaque_ptr = NULL; }
45
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(
111 start_idx, line, inline_file_spec ? inline_file_spec->get() : NULL,
112 exact, NULL);
113 }
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
Kate Stoneb9c1b512016-09-06 20:57:50 +0000121 if (m_opaque_ptr) {
122 FileSpecList &support_files = m_opaque_ptr->GetSupportFiles();
123 return support_files.GetSize();
124 }
125 return 0;
126}
127
128lldb::SBTypeList SBCompileUnit::GetTypes(uint32_t type_mask) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000129 LLDB_RECORD_METHOD(lldb::SBTypeList, SBCompileUnit, GetTypes, (uint32_t),
130 type_mask);
131
Kate Stoneb9c1b512016-09-06 20:57:50 +0000132 SBTypeList sb_type_list;
133
Zachary Turner117b1fa2018-10-25 20:45:40 +0000134 if (!m_opaque_ptr)
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000135 return LLDB_RECORD_RESULT(sb_type_list);
Zachary Turner117b1fa2018-10-25 20:45:40 +0000136
137 ModuleSP module_sp(m_opaque_ptr->GetModule());
138 if (!module_sp)
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000139 return LLDB_RECORD_RESULT(sb_type_list);
Zachary Turner117b1fa2018-10-25 20:45:40 +0000140
141 SymbolVendor *vendor = module_sp->GetSymbolVendor();
142 if (!vendor)
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000143 return LLDB_RECORD_RESULT(sb_type_list);
Zachary Turner117b1fa2018-10-25 20:45:40 +0000144
145 TypeClass type_class = static_cast<TypeClass>(type_mask);
146 TypeList type_list;
147 vendor->GetTypes(m_opaque_ptr, type_class, type_list);
Jonas Devlieghered5b44032019-02-13 06:25:41 +0000148 sb_type_list.m_opaque_up->Append(type_list);
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000149 return LLDB_RECORD_RESULT(sb_type_list);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000150}
151
152SBFileSpec SBCompileUnit::GetSupportFileAtIndex(uint32_t idx) const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000153 LLDB_RECORD_METHOD_CONST(lldb::SBFileSpec, SBCompileUnit,
154 GetSupportFileAtIndex, (uint32_t), idx);
155
Kate Stoneb9c1b512016-09-06 20:57:50 +0000156 SBFileSpec sb_file_spec;
157 if (m_opaque_ptr) {
158 FileSpecList &support_files = m_opaque_ptr->GetSupportFiles();
159 FileSpec file_spec = support_files.GetFileSpecAtIndex(idx);
160 sb_file_spec.SetFileSpec(file_spec);
161 }
162
Kate Stoneb9c1b512016-09-06 20:57:50 +0000163
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000164 return LLDB_RECORD_RESULT(sb_file_spec);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000165}
166
167uint32_t SBCompileUnit::FindSupportFileIndex(uint32_t start_idx,
168 const SBFileSpec &sb_file,
169 bool full) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000170 LLDB_RECORD_METHOD(uint32_t, SBCompileUnit, FindSupportFileIndex,
171 (uint32_t, const lldb::SBFileSpec &, bool), start_idx,
172 sb_file, full);
173
Kate Stoneb9c1b512016-09-06 20:57:50 +0000174 if (m_opaque_ptr) {
175 FileSpecList &support_files = m_opaque_ptr->GetSupportFiles();
176 return support_files.FindFileIndex(start_idx, sb_file.ref(), full);
177 }
178 return 0;
179}
180
181lldb::LanguageType SBCompileUnit::GetLanguage() {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000182 LLDB_RECORD_METHOD_NO_ARGS(lldb::LanguageType, SBCompileUnit, GetLanguage);
183
Kate Stoneb9c1b512016-09-06 20:57:50 +0000184 if (m_opaque_ptr)
185 return m_opaque_ptr->GetLanguage();
186 return lldb::eLanguageTypeUnknown;
187}
188
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000189bool SBCompileUnit::IsValid() const {
190 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCompileUnit, IsValid);
Pavel Labath7f5237b2019-03-11 13:58:46 +0000191 return this->operator bool();
192}
193SBCompileUnit::operator bool() const {
194 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCompileUnit, operator bool);
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000195
196 return m_opaque_ptr != NULL;
197}
Kate Stoneb9c1b512016-09-06 20:57:50 +0000198
199bool SBCompileUnit::operator==(const SBCompileUnit &rhs) const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000200 LLDB_RECORD_METHOD_CONST(
201 bool, SBCompileUnit, operator==,(const lldb::SBCompileUnit &), rhs);
202
Kate Stoneb9c1b512016-09-06 20:57:50 +0000203 return m_opaque_ptr == rhs.m_opaque_ptr;
204}
205
206bool SBCompileUnit::operator!=(const SBCompileUnit &rhs) const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000207 LLDB_RECORD_METHOD_CONST(
208 bool, SBCompileUnit, operator!=,(const lldb::SBCompileUnit &), rhs);
209
Kate Stoneb9c1b512016-09-06 20:57:50 +0000210 return m_opaque_ptr != rhs.m_opaque_ptr;
211}
212
213const lldb_private::CompileUnit *SBCompileUnit::operator->() const {
214 return m_opaque_ptr;
215}
216
217const lldb_private::CompileUnit &SBCompileUnit::operator*() const {
218 return *m_opaque_ptr;
219}
220
221lldb_private::CompileUnit *SBCompileUnit::get() { return m_opaque_ptr; }
222
223void SBCompileUnit::reset(lldb_private::CompileUnit *lldb_object_ptr) {
224 m_opaque_ptr = lldb_object_ptr;
225}
226
227bool SBCompileUnit::GetDescription(SBStream &description) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000228 LLDB_RECORD_METHOD(bool, SBCompileUnit, GetDescription, (lldb::SBStream &),
229 description);
230
Kate Stoneb9c1b512016-09-06 20:57:50 +0000231 Stream &strm = description.ref();
232
233 if (m_opaque_ptr) {
234 m_opaque_ptr->Dump(&strm, false);
235 } else
236 strm.PutCString("No value");
237
238 return true;
Caroline Ticedde9cff2010-09-20 05:20:02 +0000239}
Michal Gornyae211ec2019-03-19 17:13:13 +0000240
241namespace lldb_private {
242namespace repro {
243
244template <>
245void RegisterMethods<SBCompileUnit>(Registry &R) {
246 LLDB_REGISTER_CONSTRUCTOR(SBCompileUnit, ());
247 LLDB_REGISTER_CONSTRUCTOR(SBCompileUnit, (const lldb::SBCompileUnit &));
248 LLDB_REGISTER_METHOD(
249 const lldb::SBCompileUnit &,
250 SBCompileUnit, operator=,(const lldb::SBCompileUnit &));
251 LLDB_REGISTER_METHOD_CONST(lldb::SBFileSpec, SBCompileUnit, GetFileSpec,
252 ());
253 LLDB_REGISTER_METHOD_CONST(uint32_t, SBCompileUnit, GetNumLineEntries, ());
254 LLDB_REGISTER_METHOD_CONST(lldb::SBLineEntry, SBCompileUnit,
255 GetLineEntryAtIndex, (uint32_t));
256 LLDB_REGISTER_METHOD_CONST(uint32_t, SBCompileUnit, FindLineEntryIndex,
257 (uint32_t, uint32_t, lldb::SBFileSpec *));
258 LLDB_REGISTER_METHOD_CONST(uint32_t, SBCompileUnit, FindLineEntryIndex,
259 (uint32_t, uint32_t, lldb::SBFileSpec *, bool));
260 LLDB_REGISTER_METHOD_CONST(uint32_t, SBCompileUnit, GetNumSupportFiles, ());
261 LLDB_REGISTER_METHOD(lldb::SBTypeList, SBCompileUnit, GetTypes, (uint32_t));
262 LLDB_REGISTER_METHOD_CONST(lldb::SBFileSpec, SBCompileUnit,
263 GetSupportFileAtIndex, (uint32_t));
264 LLDB_REGISTER_METHOD(uint32_t, SBCompileUnit, FindSupportFileIndex,
265 (uint32_t, const lldb::SBFileSpec &, bool));
266 LLDB_REGISTER_METHOD(lldb::LanguageType, SBCompileUnit, GetLanguage, ());
267 LLDB_REGISTER_METHOD_CONST(bool, SBCompileUnit, IsValid, ());
268 LLDB_REGISTER_METHOD_CONST(bool, SBCompileUnit, operator bool, ());
269 LLDB_REGISTER_METHOD_CONST(
270 bool, SBCompileUnit, operator==,(const lldb::SBCompileUnit &));
271 LLDB_REGISTER_METHOD_CONST(
272 bool, SBCompileUnit, operator!=,(const lldb::SBCompileUnit &));
273 LLDB_REGISTER_METHOD(bool, SBCompileUnit, GetDescription,
274 (lldb::SBStream &));
275}
276
277}
278}