blob: b3b705f58a6d48e1df3fa584165269c9b41ba3a1 [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);
191
192 return m_opaque_ptr != NULL;
193}
Kate Stoneb9c1b512016-09-06 20:57:50 +0000194
195bool SBCompileUnit::operator==(const SBCompileUnit &rhs) const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000196 LLDB_RECORD_METHOD_CONST(
197 bool, SBCompileUnit, operator==,(const lldb::SBCompileUnit &), rhs);
198
Kate Stoneb9c1b512016-09-06 20:57:50 +0000199 return m_opaque_ptr == rhs.m_opaque_ptr;
200}
201
202bool SBCompileUnit::operator!=(const SBCompileUnit &rhs) const {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000203 LLDB_RECORD_METHOD_CONST(
204 bool, SBCompileUnit, operator!=,(const lldb::SBCompileUnit &), rhs);
205
Kate Stoneb9c1b512016-09-06 20:57:50 +0000206 return m_opaque_ptr != rhs.m_opaque_ptr;
207}
208
209const lldb_private::CompileUnit *SBCompileUnit::operator->() const {
210 return m_opaque_ptr;
211}
212
213const lldb_private::CompileUnit &SBCompileUnit::operator*() const {
214 return *m_opaque_ptr;
215}
216
217lldb_private::CompileUnit *SBCompileUnit::get() { return m_opaque_ptr; }
218
219void SBCompileUnit::reset(lldb_private::CompileUnit *lldb_object_ptr) {
220 m_opaque_ptr = lldb_object_ptr;
221}
222
223bool SBCompileUnit::GetDescription(SBStream &description) {
Jonas Devliegherebaf56642019-03-06 00:06:00 +0000224 LLDB_RECORD_METHOD(bool, SBCompileUnit, GetDescription, (lldb::SBStream &),
225 description);
226
Kate Stoneb9c1b512016-09-06 20:57:50 +0000227 Stream &strm = description.ref();
228
229 if (m_opaque_ptr) {
230 m_opaque_ptr->Dump(&strm, false);
231 } else
232 strm.PutCString("No value");
233
234 return true;
Caroline Ticedde9cff2010-09-20 05:20:02 +0000235}