1ac7ddfbfSEd Maste //===-- SBCompileUnit.cpp ---------------------------------------*- C++ -*-===//
2ac7ddfbfSEd Maste //
3ac7ddfbfSEd Maste // The LLVM Compiler Infrastructure
4ac7ddfbfSEd Maste //
5ac7ddfbfSEd Maste // This file is distributed under the University of Illinois Open Source
6ac7ddfbfSEd Maste // License. See LICENSE.TXT for details.
7ac7ddfbfSEd Maste //
8ac7ddfbfSEd Maste //===----------------------------------------------------------------------===//
9ac7ddfbfSEd Maste
10ac7ddfbfSEd Maste #include "lldb/API/SBCompileUnit.h"
11ac7ddfbfSEd Maste #include "lldb/API/SBLineEntry.h"
12ac7ddfbfSEd Maste #include "lldb/API/SBStream.h"
13ac7ddfbfSEd Maste #include "lldb/Core/Module.h"
14ac7ddfbfSEd Maste #include "lldb/Symbol/CompileUnit.h"
15ac7ddfbfSEd Maste #include "lldb/Symbol/LineEntry.h"
16ac7ddfbfSEd Maste #include "lldb/Symbol/LineTable.h"
17ac7ddfbfSEd Maste #include "lldb/Symbol/SymbolVendor.h"
18ac7ddfbfSEd Maste #include "lldb/Symbol/Type.h"
19f678e45dSDimitry Andric #include "lldb/Utility/Log.h"
20ac7ddfbfSEd Maste
21ac7ddfbfSEd Maste using namespace lldb;
22ac7ddfbfSEd Maste using namespace lldb_private;
23ac7ddfbfSEd Maste
SBCompileUnit()24435933ddSDimitry Andric SBCompileUnit::SBCompileUnit() : m_opaque_ptr(NULL) {}
25ac7ddfbfSEd Maste
SBCompileUnit(lldb_private::CompileUnit * lldb_object_ptr)26435933ddSDimitry Andric SBCompileUnit::SBCompileUnit(lldb_private::CompileUnit *lldb_object_ptr)
27435933ddSDimitry Andric : m_opaque_ptr(lldb_object_ptr) {}
28ac7ddfbfSEd Maste
SBCompileUnit(const SBCompileUnit & rhs)29435933ddSDimitry Andric SBCompileUnit::SBCompileUnit(const SBCompileUnit &rhs)
30435933ddSDimitry Andric : m_opaque_ptr(rhs.m_opaque_ptr) {}
31ac7ddfbfSEd Maste
operator =(const SBCompileUnit & rhs)32435933ddSDimitry Andric const SBCompileUnit &SBCompileUnit::operator=(const SBCompileUnit &rhs) {
33ac7ddfbfSEd Maste m_opaque_ptr = rhs.m_opaque_ptr;
34ac7ddfbfSEd Maste return *this;
35ac7ddfbfSEd Maste }
36ac7ddfbfSEd Maste
~SBCompileUnit()37435933ddSDimitry Andric SBCompileUnit::~SBCompileUnit() { m_opaque_ptr = NULL; }
38ac7ddfbfSEd Maste
GetFileSpec() const39435933ddSDimitry Andric SBFileSpec SBCompileUnit::GetFileSpec() const {
40ac7ddfbfSEd Maste SBFileSpec file_spec;
41ac7ddfbfSEd Maste if (m_opaque_ptr)
42ac7ddfbfSEd Maste file_spec.SetFileSpec(*m_opaque_ptr);
43ac7ddfbfSEd Maste return file_spec;
44ac7ddfbfSEd Maste }
45ac7ddfbfSEd Maste
GetNumLineEntries() const46435933ddSDimitry Andric uint32_t SBCompileUnit::GetNumLineEntries() const {
47435933ddSDimitry Andric if (m_opaque_ptr) {
48ac7ddfbfSEd Maste LineTable *line_table = m_opaque_ptr->GetLineTable();
49ac7ddfbfSEd Maste if (line_table)
50ac7ddfbfSEd Maste return line_table->GetSize();
51ac7ddfbfSEd Maste }
52ac7ddfbfSEd Maste return 0;
53ac7ddfbfSEd Maste }
54ac7ddfbfSEd Maste
GetLineEntryAtIndex(uint32_t idx) const55435933ddSDimitry Andric SBLineEntry SBCompileUnit::GetLineEntryAtIndex(uint32_t idx) const {
56ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
57ac7ddfbfSEd Maste
58ac7ddfbfSEd Maste SBLineEntry sb_line_entry;
59435933ddSDimitry Andric if (m_opaque_ptr) {
60ac7ddfbfSEd Maste LineTable *line_table = m_opaque_ptr->GetLineTable();
61435933ddSDimitry Andric if (line_table) {
62ac7ddfbfSEd Maste LineEntry line_entry;
63ac7ddfbfSEd Maste if (line_table->GetLineEntryAtIndex(idx, line_entry))
64ac7ddfbfSEd Maste sb_line_entry.SetLineEntry(line_entry);
65ac7ddfbfSEd Maste }
66ac7ddfbfSEd Maste }
67ac7ddfbfSEd Maste
68435933ddSDimitry Andric if (log) {
69ac7ddfbfSEd Maste SBStream sstr;
70ac7ddfbfSEd Maste sb_line_entry.GetDescription(sstr);
71435933ddSDimitry Andric log->Printf("SBCompileUnit(%p)::GetLineEntryAtIndex (idx=%u) => "
72435933ddSDimitry Andric "SBLineEntry(%p): '%s'",
730127ef0fSEd Maste static_cast<void *>(m_opaque_ptr), idx,
740127ef0fSEd Maste static_cast<void *>(sb_line_entry.get()), sstr.GetData());
75ac7ddfbfSEd Maste }
76ac7ddfbfSEd Maste
77ac7ddfbfSEd Maste return sb_line_entry;
78ac7ddfbfSEd Maste }
79ac7ddfbfSEd Maste
FindLineEntryIndex(uint32_t start_idx,uint32_t line,SBFileSpec * inline_file_spec) const80435933ddSDimitry Andric uint32_t SBCompileUnit::FindLineEntryIndex(uint32_t start_idx, uint32_t line,
81435933ddSDimitry Andric SBFileSpec *inline_file_spec) const {
82ac7ddfbfSEd Maste const bool exact = true;
83ac7ddfbfSEd Maste return FindLineEntryIndex(start_idx, line, inline_file_spec, exact);
84ac7ddfbfSEd Maste }
85ac7ddfbfSEd Maste
FindLineEntryIndex(uint32_t start_idx,uint32_t line,SBFileSpec * inline_file_spec,bool exact) const86435933ddSDimitry Andric uint32_t SBCompileUnit::FindLineEntryIndex(uint32_t start_idx, uint32_t line,
87435933ddSDimitry Andric SBFileSpec *inline_file_spec,
88435933ddSDimitry Andric bool exact) const {
89ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
90ac7ddfbfSEd Maste
91ac7ddfbfSEd Maste uint32_t index = UINT32_MAX;
92435933ddSDimitry Andric if (m_opaque_ptr) {
93ac7ddfbfSEd Maste FileSpec file_spec;
94ac7ddfbfSEd Maste if (inline_file_spec && inline_file_spec->IsValid())
95ac7ddfbfSEd Maste file_spec = inline_file_spec->ref();
96ac7ddfbfSEd Maste else
97ac7ddfbfSEd Maste file_spec = *m_opaque_ptr;
98ac7ddfbfSEd Maste
99435933ddSDimitry Andric index = m_opaque_ptr->FindLineEntry(
100435933ddSDimitry Andric start_idx, line, inline_file_spec ? inline_file_spec->get() : NULL,
101435933ddSDimitry Andric exact, NULL);
102ac7ddfbfSEd Maste }
103ac7ddfbfSEd Maste
104435933ddSDimitry Andric if (log) {
105ac7ddfbfSEd Maste SBStream sstr;
106435933ddSDimitry Andric if (index == UINT32_MAX) {
107435933ddSDimitry Andric log->Printf("SBCompileUnit(%p)::FindLineEntryIndex (start_idx=%u, "
108435933ddSDimitry Andric "line=%u, SBFileSpec(%p)) => NOT FOUND",
1090127ef0fSEd Maste static_cast<void *>(m_opaque_ptr), start_idx, line,
1100127ef0fSEd Maste inline_file_spec
1110127ef0fSEd Maste ? static_cast<const void *>(inline_file_spec->get())
1120127ef0fSEd Maste : NULL);
113435933ddSDimitry Andric } else {
114435933ddSDimitry Andric log->Printf("SBCompileUnit(%p)::FindLineEntryIndex (start_idx=%u, "
115435933ddSDimitry Andric "line=%u, SBFileSpec(%p)) => %u",
1160127ef0fSEd Maste static_cast<void *>(m_opaque_ptr), start_idx, line,
1170127ef0fSEd Maste inline_file_spec
1180127ef0fSEd Maste ? static_cast<const void *>(inline_file_spec->get())
1190127ef0fSEd Maste : NULL,
1200127ef0fSEd Maste index);
121ac7ddfbfSEd Maste }
122ac7ddfbfSEd Maste }
123ac7ddfbfSEd Maste
124ac7ddfbfSEd Maste return index;
125ac7ddfbfSEd Maste }
126ac7ddfbfSEd Maste
GetNumSupportFiles() const127435933ddSDimitry Andric uint32_t SBCompileUnit::GetNumSupportFiles() const {
128435933ddSDimitry Andric if (m_opaque_ptr) {
129ac7ddfbfSEd Maste FileSpecList &support_files = m_opaque_ptr->GetSupportFiles();
130ac7ddfbfSEd Maste return support_files.GetSize();
131ac7ddfbfSEd Maste }
132ac7ddfbfSEd Maste return 0;
133ac7ddfbfSEd Maste }
134ac7ddfbfSEd Maste
GetTypes(uint32_t type_mask)135435933ddSDimitry Andric lldb::SBTypeList SBCompileUnit::GetTypes(uint32_t type_mask) {
136ac7ddfbfSEd Maste SBTypeList sb_type_list;
137ac7ddfbfSEd Maste
138*b5893f02SDimitry Andric if (!m_opaque_ptr)
139*b5893f02SDimitry Andric return sb_type_list;
140*b5893f02SDimitry Andric
141ac7ddfbfSEd Maste ModuleSP module_sp(m_opaque_ptr->GetModule());
142*b5893f02SDimitry Andric if (!module_sp)
143*b5893f02SDimitry Andric return sb_type_list;
144*b5893f02SDimitry Andric
145ac7ddfbfSEd Maste SymbolVendor *vendor = module_sp->GetSymbolVendor();
146*b5893f02SDimitry Andric if (!vendor)
147*b5893f02SDimitry Andric return sb_type_list;
148*b5893f02SDimitry Andric
149*b5893f02SDimitry Andric TypeClass type_class = static_cast<TypeClass>(type_mask);
150ac7ddfbfSEd Maste TypeList type_list;
151*b5893f02SDimitry Andric vendor->GetTypes(m_opaque_ptr, type_class, type_list);
152ac7ddfbfSEd Maste sb_type_list.m_opaque_ap->Append(type_list);
153ac7ddfbfSEd Maste return sb_type_list;
154ac7ddfbfSEd Maste }
155ac7ddfbfSEd Maste
GetSupportFileAtIndex(uint32_t idx) const156435933ddSDimitry Andric SBFileSpec SBCompileUnit::GetSupportFileAtIndex(uint32_t idx) const {
157ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
158ac7ddfbfSEd Maste
159ac7ddfbfSEd Maste SBFileSpec sb_file_spec;
160435933ddSDimitry Andric if (m_opaque_ptr) {
161ac7ddfbfSEd Maste FileSpecList &support_files = m_opaque_ptr->GetSupportFiles();
162ac7ddfbfSEd Maste FileSpec file_spec = support_files.GetFileSpecAtIndex(idx);
163ac7ddfbfSEd Maste sb_file_spec.SetFileSpec(file_spec);
164ac7ddfbfSEd Maste }
165ac7ddfbfSEd Maste
166435933ddSDimitry Andric if (log) {
167ac7ddfbfSEd Maste SBStream sstr;
168ac7ddfbfSEd Maste sb_file_spec.GetDescription(sstr);
169435933ddSDimitry Andric log->Printf("SBCompileUnit(%p)::GetGetFileSpecAtIndex (idx=%u) => "
170435933ddSDimitry Andric "SBFileSpec(%p): '%s'",
1710127ef0fSEd Maste static_cast<void *>(m_opaque_ptr), idx,
172435933ddSDimitry Andric static_cast<const void *>(sb_file_spec.get()), sstr.GetData());
173ac7ddfbfSEd Maste }
174ac7ddfbfSEd Maste
175ac7ddfbfSEd Maste return sb_file_spec;
176ac7ddfbfSEd Maste }
177ac7ddfbfSEd Maste
FindSupportFileIndex(uint32_t start_idx,const SBFileSpec & sb_file,bool full)178435933ddSDimitry Andric uint32_t SBCompileUnit::FindSupportFileIndex(uint32_t start_idx,
179435933ddSDimitry Andric const SBFileSpec &sb_file,
180435933ddSDimitry Andric bool full) {
181435933ddSDimitry Andric if (m_opaque_ptr) {
182ac7ddfbfSEd Maste FileSpecList &support_files = m_opaque_ptr->GetSupportFiles();
183ac7ddfbfSEd Maste return support_files.FindFileIndex(start_idx, sb_file.ref(), full);
184ac7ddfbfSEd Maste }
185ac7ddfbfSEd Maste return 0;
186ac7ddfbfSEd Maste }
187ac7ddfbfSEd Maste
GetLanguage()188435933ddSDimitry Andric lldb::LanguageType SBCompileUnit::GetLanguage() {
1897aa51b79SEd Maste if (m_opaque_ptr)
1907aa51b79SEd Maste return m_opaque_ptr->GetLanguage();
1917aa51b79SEd Maste return lldb::eLanguageTypeUnknown;
1927aa51b79SEd Maste }
1937aa51b79SEd Maste
IsValid() const194435933ddSDimitry Andric bool SBCompileUnit::IsValid() const { return m_opaque_ptr != NULL; }
195ac7ddfbfSEd Maste
operator ==(const SBCompileUnit & rhs) const196435933ddSDimitry Andric bool SBCompileUnit::operator==(const SBCompileUnit &rhs) const {
197ac7ddfbfSEd Maste return m_opaque_ptr == rhs.m_opaque_ptr;
198ac7ddfbfSEd Maste }
199ac7ddfbfSEd Maste
operator !=(const SBCompileUnit & rhs) const200435933ddSDimitry Andric bool SBCompileUnit::operator!=(const SBCompileUnit &rhs) const {
201ac7ddfbfSEd Maste return m_opaque_ptr != rhs.m_opaque_ptr;
202ac7ddfbfSEd Maste }
203ac7ddfbfSEd Maste
operator ->() const204435933ddSDimitry Andric const lldb_private::CompileUnit *SBCompileUnit::operator->() const {
205ac7ddfbfSEd Maste return m_opaque_ptr;
206ac7ddfbfSEd Maste }
207ac7ddfbfSEd Maste
operator *() const208435933ddSDimitry Andric const lldb_private::CompileUnit &SBCompileUnit::operator*() const {
209ac7ddfbfSEd Maste return *m_opaque_ptr;
210ac7ddfbfSEd Maste }
211ac7ddfbfSEd Maste
get()212435933ddSDimitry Andric lldb_private::CompileUnit *SBCompileUnit::get() { return m_opaque_ptr; }
213ac7ddfbfSEd Maste
reset(lldb_private::CompileUnit * lldb_object_ptr)214435933ddSDimitry Andric void SBCompileUnit::reset(lldb_private::CompileUnit *lldb_object_ptr) {
215ac7ddfbfSEd Maste m_opaque_ptr = lldb_object_ptr;
216ac7ddfbfSEd Maste }
217ac7ddfbfSEd Maste
GetDescription(SBStream & description)218435933ddSDimitry Andric bool SBCompileUnit::GetDescription(SBStream &description) {
219ac7ddfbfSEd Maste Stream &strm = description.ref();
220ac7ddfbfSEd Maste
221435933ddSDimitry Andric if (m_opaque_ptr) {
222ac7ddfbfSEd Maste m_opaque_ptr->Dump(&strm, false);
223435933ddSDimitry Andric } else
224ac7ddfbfSEd Maste strm.PutCString("No value");
225ac7ddfbfSEd Maste
226ac7ddfbfSEd Maste return true;
227ac7ddfbfSEd Maste }
228