1 //===-- 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"
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/SymbolVendor.h"
18 #include "lldb/Symbol/Type.h"
19 #include "lldb/Utility/Log.h"
20
21 using namespace lldb;
22 using namespace lldb_private;
23
SBCompileUnit()24 SBCompileUnit::SBCompileUnit() : m_opaque_ptr(NULL) {}
25
SBCompileUnit(lldb_private::CompileUnit * lldb_object_ptr)26 SBCompileUnit::SBCompileUnit(lldb_private::CompileUnit *lldb_object_ptr)
27 : m_opaque_ptr(lldb_object_ptr) {}
28
SBCompileUnit(const SBCompileUnit & rhs)29 SBCompileUnit::SBCompileUnit(const SBCompileUnit &rhs)
30 : m_opaque_ptr(rhs.m_opaque_ptr) {}
31
operator =(const SBCompileUnit & rhs)32 const SBCompileUnit &SBCompileUnit::operator=(const SBCompileUnit &rhs) {
33 m_opaque_ptr = rhs.m_opaque_ptr;
34 return *this;
35 }
36
~SBCompileUnit()37 SBCompileUnit::~SBCompileUnit() { m_opaque_ptr = NULL; }
38
GetFileSpec() const39 SBFileSpec SBCompileUnit::GetFileSpec() const {
40 SBFileSpec file_spec;
41 if (m_opaque_ptr)
42 file_spec.SetFileSpec(*m_opaque_ptr);
43 return file_spec;
44 }
45
GetNumLineEntries() const46 uint32_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;
53 }
54
GetLineEntryAtIndex(uint32_t idx) const55 SBLineEntry SBCompileUnit::GetLineEntryAtIndex(uint32_t idx) const {
56 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
57
58 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);
65 }
66 }
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;
78 }
79
FindLineEntryIndex(uint32_t start_idx,uint32_t line,SBFileSpec * inline_file_spec) const80 uint32_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);
84 }
85
FindLineEntryIndex(uint32_t start_idx,uint32_t line,SBFileSpec * inline_file_spec,bool exact) const86 uint32_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));
90
91 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();
96 else
97 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
GetNumSupportFiles() const127 uint32_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
GetTypes(uint32_t type_mask)135 lldb::SBTypeList SBCompileUnit::GetTypes(uint32_t type_mask) {
136 SBTypeList sb_type_list;
137
138 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);
153 return sb_type_list;
154 }
155
GetSupportFileAtIndex(uint32_t idx) const156 SBFileSpec 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
FindSupportFileIndex(uint32_t start_idx,const SBFileSpec & sb_file,bool full)178 uint32_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
GetLanguage()188 lldb::LanguageType SBCompileUnit::GetLanguage() {
189 if (m_opaque_ptr)
190 return m_opaque_ptr->GetLanguage();
191 return lldb::eLanguageTypeUnknown;
192 }
193
IsValid() const194 bool SBCompileUnit::IsValid() const { return m_opaque_ptr != NULL; }
195
operator ==(const SBCompileUnit & rhs) const196 bool SBCompileUnit::operator==(const SBCompileUnit &rhs) const {
197 return m_opaque_ptr == rhs.m_opaque_ptr;
198 }
199
operator !=(const SBCompileUnit & rhs) const200 bool SBCompileUnit::operator!=(const SBCompileUnit &rhs) const {
201 return m_opaque_ptr != rhs.m_opaque_ptr;
202 }
203
operator ->() const204 const lldb_private::CompileUnit *SBCompileUnit::operator->() const {
205 return m_opaque_ptr;
206 }
207
operator *() const208 const lldb_private::CompileUnit &SBCompileUnit::operator*() const {
209 return *m_opaque_ptr;
210 }
211
get()212 lldb_private::CompileUnit *SBCompileUnit::get() { return m_opaque_ptr; }
213
reset(lldb_private::CompileUnit * lldb_object_ptr)214 void SBCompileUnit::reset(lldb_private::CompileUnit *lldb_object_ptr) {
215 m_opaque_ptr = lldb_object_ptr;
216 }
217
GetDescription(SBStream & description)218 bool 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;
227 }
228