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/Log.h" 14 #include "lldb/Core/Module.h" 15 #include "lldb/Symbol/CompileUnit.h" 16 #include "lldb/Symbol/LineEntry.h" 17 #include "lldb/Symbol/LineTable.h" 18 #include "lldb/Symbol/SymbolVendor.h" 19 #include "lldb/Symbol/Type.h" 20 21 using namespace lldb; 22 using namespace lldb_private; 23 24 SBCompileUnit::SBCompileUnit() : m_opaque_ptr(NULL) {} 25 26 SBCompileUnit::SBCompileUnit(lldb_private::CompileUnit *lldb_object_ptr) 27 : m_opaque_ptr(lldb_object_ptr) {} 28 29 SBCompileUnit::SBCompileUnit(const SBCompileUnit &rhs) 30 : m_opaque_ptr(rhs.m_opaque_ptr) {} 31 32 const SBCompileUnit &SBCompileUnit::operator=(const SBCompileUnit &rhs) { 33 m_opaque_ptr = rhs.m_opaque_ptr; 34 return *this; 35 } 36 37 SBCompileUnit::~SBCompileUnit() { m_opaque_ptr = NULL; } 38 39 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 46 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 55 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 80 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 86 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 127 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 135 lldb::SBTypeList SBCompileUnit::GetTypes(uint32_t type_mask) { 136 SBTypeList sb_type_list; 137 138 if (m_opaque_ptr) { 139 ModuleSP module_sp(m_opaque_ptr->GetModule()); 140 if (module_sp) { 141 SymbolVendor *vendor = module_sp->GetSymbolVendor(); 142 if (vendor) { 143 TypeList type_list; 144 vendor->GetTypes(m_opaque_ptr, type_mask, type_list); 145 sb_type_list.m_opaque_ap->Append(type_list); 146 } 147 } 148 } 149 return sb_type_list; 150 } 151 152 SBFileSpec SBCompileUnit::GetSupportFileAtIndex(uint32_t idx) const { 153 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 154 155 SBFileSpec sb_file_spec; 156 if (m_opaque_ptr) { 157 FileSpecList &support_files = m_opaque_ptr->GetSupportFiles(); 158 FileSpec file_spec = support_files.GetFileSpecAtIndex(idx); 159 sb_file_spec.SetFileSpec(file_spec); 160 } 161 162 if (log) { 163 SBStream sstr; 164 sb_file_spec.GetDescription(sstr); 165 log->Printf("SBCompileUnit(%p)::GetGetFileSpecAtIndex (idx=%u) => " 166 "SBFileSpec(%p): '%s'", 167 static_cast<void *>(m_opaque_ptr), idx, 168 static_cast<const void *>(sb_file_spec.get()), sstr.GetData()); 169 } 170 171 return sb_file_spec; 172 } 173 174 uint32_t SBCompileUnit::FindSupportFileIndex(uint32_t start_idx, 175 const SBFileSpec &sb_file, 176 bool full) { 177 if (m_opaque_ptr) { 178 FileSpecList &support_files = m_opaque_ptr->GetSupportFiles(); 179 return support_files.FindFileIndex(start_idx, sb_file.ref(), full); 180 } 181 return 0; 182 } 183 184 lldb::LanguageType SBCompileUnit::GetLanguage() { 185 if (m_opaque_ptr) 186 return m_opaque_ptr->GetLanguage(); 187 return lldb::eLanguageTypeUnknown; 188 } 189 190 bool SBCompileUnit::IsValid() const { return m_opaque_ptr != NULL; } 191 192 bool SBCompileUnit::operator==(const SBCompileUnit &rhs) const { 193 return m_opaque_ptr == rhs.m_opaque_ptr; 194 } 195 196 bool SBCompileUnit::operator!=(const SBCompileUnit &rhs) const { 197 return m_opaque_ptr != rhs.m_opaque_ptr; 198 } 199 200 const lldb_private::CompileUnit *SBCompileUnit::operator->() const { 201 return m_opaque_ptr; 202 } 203 204 const lldb_private::CompileUnit &SBCompileUnit::operator*() const { 205 return *m_opaque_ptr; 206 } 207 208 lldb_private::CompileUnit *SBCompileUnit::get() { return m_opaque_ptr; } 209 210 void SBCompileUnit::reset(lldb_private::CompileUnit *lldb_object_ptr) { 211 m_opaque_ptr = lldb_object_ptr; 212 } 213 214 bool SBCompileUnit::GetDescription(SBStream &description) { 215 Stream &strm = description.ref(); 216 217 if (m_opaque_ptr) { 218 m_opaque_ptr->Dump(&strm, false); 219 } else 220 strm.PutCString("No value"); 221 222 return true; 223 } 224