blob: 4e2fc6af460a44ff54945c442a26523e5e565811 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- SBCompileUnit.cpp ---------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/API/SBCompileUnit.h"
11#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"
Zachary Turner6f9e6902017-03-03 20:56:28 +000019#include "lldb/Utility/Log.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020
21using namespace lldb;
22using namespace lldb_private;
23
Kate Stoneb9c1b512016-09-06 20:57:50 +000024SBCompileUnit::SBCompileUnit() : m_opaque_ptr(NULL) {}
Chris Lattner30fdc8d2010-06-08 16:52:24 +000025
Kate Stoneb9c1b512016-09-06 20:57:50 +000026SBCompileUnit::SBCompileUnit(lldb_private::CompileUnit *lldb_object_ptr)
27 : m_opaque_ptr(lldb_object_ptr) {}
28
29SBCompileUnit::SBCompileUnit(const SBCompileUnit &rhs)
30 : m_opaque_ptr(rhs.m_opaque_ptr) {}
31
32const SBCompileUnit &SBCompileUnit::operator=(const SBCompileUnit &rhs) {
33 m_opaque_ptr = rhs.m_opaque_ptr;
34 return *this;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000035}
36
Kate Stoneb9c1b512016-09-06 20:57:50 +000037SBCompileUnit::~SBCompileUnit() { m_opaque_ptr = NULL; }
38
39SBFileSpec SBCompileUnit::GetFileSpec() const {
40 SBFileSpec file_spec;
41 if (m_opaque_ptr)
42 file_spec.SetFileSpec(*m_opaque_ptr);
43 return file_spec;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000044}
45
Kate Stoneb9c1b512016-09-06 20:57:50 +000046uint32_t SBCompileUnit::GetNumLineEntries() const {
47 if (m_opaque_ptr) {
48 LineTable *line_table = m_opaque_ptr->GetLineTable();
49 if (line_table)
50 return line_table->GetSize();
51 }
52 return 0;
Greg Claytonefabb122010-11-05 23:17:00 +000053}
54
Kate Stoneb9c1b512016-09-06 20:57:50 +000055SBLineEntry SBCompileUnit::GetLineEntryAtIndex(uint32_t idx) const {
56 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
Greg Claytonefabb122010-11-05 23:17:00 +000057
Kate Stoneb9c1b512016-09-06 20:57:50 +000058 SBLineEntry sb_line_entry;
59 if (m_opaque_ptr) {
60 LineTable *line_table = m_opaque_ptr->GetLineTable();
61 if (line_table) {
62 LineEntry line_entry;
63 if (line_table->GetLineEntryAtIndex(idx, line_entry))
64 sb_line_entry.SetLineEntry(line_entry);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000065 }
Kate Stoneb9c1b512016-09-06 20:57:50 +000066 }
67
68 if (log) {
69 SBStream sstr;
70 sb_line_entry.GetDescription(sstr);
71 log->Printf("SBCompileUnit(%p)::GetLineEntryAtIndex (idx=%u) => "
72 "SBLineEntry(%p): '%s'",
73 static_cast<void *>(m_opaque_ptr), idx,
74 static_cast<void *>(sb_line_entry.get()), sstr.GetData());
75 }
76
77 return sb_line_entry;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000078}
79
Kate Stoneb9c1b512016-09-06 20:57:50 +000080uint32_t SBCompileUnit::FindLineEntryIndex(uint32_t start_idx, uint32_t line,
81 SBFileSpec *inline_file_spec) const {
82 const bool exact = true;
83 return FindLineEntryIndex(start_idx, line, inline_file_spec, exact);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000084}
85
Kate Stoneb9c1b512016-09-06 20:57:50 +000086uint32_t SBCompileUnit::FindLineEntryIndex(uint32_t start_idx, uint32_t line,
87 SBFileSpec *inline_file_spec,
88 bool exact) const {
89 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
Jim Ingham87df91b2011-09-23 00:54:11 +000090
Kate Stoneb9c1b512016-09-06 20:57:50 +000091 uint32_t index = UINT32_MAX;
92 if (m_opaque_ptr) {
93 FileSpec file_spec;
94 if (inline_file_spec && inline_file_spec->IsValid())
95 file_spec = inline_file_spec->ref();
Caroline Ticedde9cff2010-09-20 05:20:02 +000096 else
Kate Stoneb9c1b512016-09-06 20:57:50 +000097 file_spec = *m_opaque_ptr;
98
99 index = m_opaque_ptr->FindLineEntry(
100 start_idx, line, inline_file_spec ? inline_file_spec->get() : NULL,
101 exact, NULL);
102 }
103
104 if (log) {
105 SBStream sstr;
106 if (index == UINT32_MAX) {
107 log->Printf("SBCompileUnit(%p)::FindLineEntryIndex (start_idx=%u, "
108 "line=%u, SBFileSpec(%p)) => NOT FOUND",
109 static_cast<void *>(m_opaque_ptr), start_idx, line,
110 inline_file_spec
111 ? static_cast<const void *>(inline_file_spec->get())
112 : NULL);
113 } else {
114 log->Printf("SBCompileUnit(%p)::FindLineEntryIndex (start_idx=%u, "
115 "line=%u, SBFileSpec(%p)) => %u",
116 static_cast<void *>(m_opaque_ptr), start_idx, line,
117 inline_file_spec
118 ? static_cast<const void *>(inline_file_spec->get())
119 : NULL,
120 index);
121 }
122 }
123
124 return index;
125}
126
127uint32_t SBCompileUnit::GetNumSupportFiles() const {
128 if (m_opaque_ptr) {
129 FileSpecList &support_files = m_opaque_ptr->GetSupportFiles();
130 return support_files.GetSize();
131 }
132 return 0;
133}
134
135lldb::SBTypeList SBCompileUnit::GetTypes(uint32_t type_mask) {
136 SBTypeList sb_type_list;
137
Zachary Turner117b1fa2018-10-25 20:45:40 +0000138 if (!m_opaque_ptr)
139 return sb_type_list;
140
141 ModuleSP module_sp(m_opaque_ptr->GetModule());
142 if (!module_sp)
143 return sb_type_list;
144
145 SymbolVendor *vendor = module_sp->GetSymbolVendor();
146 if (!vendor)
147 return sb_type_list;
148
149 TypeClass type_class = static_cast<TypeClass>(type_mask);
150 TypeList type_list;
151 vendor->GetTypes(m_opaque_ptr, type_class, type_list);
152 sb_type_list.m_opaque_ap->Append(type_list);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000153 return sb_type_list;
154}
155
156SBFileSpec SBCompileUnit::GetSupportFileAtIndex(uint32_t idx) const {
157 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
158
159 SBFileSpec sb_file_spec;
160 if (m_opaque_ptr) {
161 FileSpecList &support_files = m_opaque_ptr->GetSupportFiles();
162 FileSpec file_spec = support_files.GetFileSpecAtIndex(idx);
163 sb_file_spec.SetFileSpec(file_spec);
164 }
165
166 if (log) {
167 SBStream sstr;
168 sb_file_spec.GetDescription(sstr);
169 log->Printf("SBCompileUnit(%p)::GetGetFileSpecAtIndex (idx=%u) => "
170 "SBFileSpec(%p): '%s'",
171 static_cast<void *>(m_opaque_ptr), idx,
172 static_cast<const void *>(sb_file_spec.get()), sstr.GetData());
173 }
174
175 return sb_file_spec;
176}
177
178uint32_t SBCompileUnit::FindSupportFileIndex(uint32_t start_idx,
179 const SBFileSpec &sb_file,
180 bool full) {
181 if (m_opaque_ptr) {
182 FileSpecList &support_files = m_opaque_ptr->GetSupportFiles();
183 return support_files.FindFileIndex(start_idx, sb_file.ref(), full);
184 }
185 return 0;
186}
187
188lldb::LanguageType SBCompileUnit::GetLanguage() {
189 if (m_opaque_ptr)
190 return m_opaque_ptr->GetLanguage();
191 return lldb::eLanguageTypeUnknown;
192}
193
194bool SBCompileUnit::IsValid() const { return m_opaque_ptr != NULL; }
195
196bool SBCompileUnit::operator==(const SBCompileUnit &rhs) const {
197 return m_opaque_ptr == rhs.m_opaque_ptr;
198}
199
200bool SBCompileUnit::operator!=(const SBCompileUnit &rhs) const {
201 return m_opaque_ptr != rhs.m_opaque_ptr;
202}
203
204const lldb_private::CompileUnit *SBCompileUnit::operator->() const {
205 return m_opaque_ptr;
206}
207
208const lldb_private::CompileUnit &SBCompileUnit::operator*() const {
209 return *m_opaque_ptr;
210}
211
212lldb_private::CompileUnit *SBCompileUnit::get() { return m_opaque_ptr; }
213
214void SBCompileUnit::reset(lldb_private::CompileUnit *lldb_object_ptr) {
215 m_opaque_ptr = lldb_object_ptr;
216}
217
218bool SBCompileUnit::GetDescription(SBStream &description) {
219 Stream &strm = description.ref();
220
221 if (m_opaque_ptr) {
222 m_opaque_ptr->Dump(&strm, false);
223 } else
224 strm.PutCString("No value");
225
226 return true;
Caroline Ticedde9cff2010-09-20 05:20:02 +0000227}