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 25 SBCompileUnit::SBCompileUnit () : 26 m_opaque_ptr (NULL) 27 { 28 } 29 30 SBCompileUnit::SBCompileUnit (lldb_private::CompileUnit *lldb_object_ptr) : 31 m_opaque_ptr (lldb_object_ptr) 32 { 33 } 34 35 SBCompileUnit::SBCompileUnit(const SBCompileUnit &rhs) : 36 m_opaque_ptr (rhs.m_opaque_ptr) 37 { 38 } 39 40 const SBCompileUnit & 41 SBCompileUnit::operator = (const SBCompileUnit &rhs) 42 { 43 m_opaque_ptr = rhs.m_opaque_ptr; 44 return *this; 45 } 46 47 48 SBCompileUnit::~SBCompileUnit () 49 { 50 m_opaque_ptr = NULL; 51 } 52 53 SBFileSpec 54 SBCompileUnit::GetFileSpec () const 55 { 56 SBFileSpec file_spec; 57 if (m_opaque_ptr) 58 file_spec.SetFileSpec(*m_opaque_ptr); 59 return file_spec; 60 } 61 62 uint32_t 63 SBCompileUnit::GetNumLineEntries () const 64 { 65 if (m_opaque_ptr) 66 { 67 LineTable *line_table = m_opaque_ptr->GetLineTable (); 68 if (line_table) 69 return line_table->GetSize(); 70 } 71 return 0; 72 } 73 74 SBLineEntry 75 SBCompileUnit::GetLineEntryAtIndex (uint32_t idx) const 76 { 77 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 78 79 SBLineEntry sb_line_entry; 80 if (m_opaque_ptr) 81 { 82 LineTable *line_table = m_opaque_ptr->GetLineTable (); 83 if (line_table) 84 { 85 LineEntry line_entry; 86 if (line_table->GetLineEntryAtIndex(idx, line_entry)) 87 sb_line_entry.SetLineEntry(line_entry); 88 } 89 } 90 91 if (log) 92 { 93 SBStream sstr; 94 sb_line_entry.GetDescription (sstr); 95 log->Printf ("SBCompileUnit(%p)::GetLineEntryAtIndex (idx=%u) => SBLineEntry(%p): '%s'", 96 static_cast<void*>(m_opaque_ptr), idx, 97 static_cast<void*>(sb_line_entry.get()), sstr.GetData()); 98 } 99 100 return sb_line_entry; 101 } 102 103 uint32_t 104 SBCompileUnit::FindLineEntryIndex (uint32_t start_idx, uint32_t line, SBFileSpec *inline_file_spec) const 105 { 106 const bool exact = true; 107 return FindLineEntryIndex (start_idx, line, inline_file_spec, exact); 108 } 109 110 uint32_t 111 SBCompileUnit::FindLineEntryIndex (uint32_t start_idx, uint32_t line, SBFileSpec *inline_file_spec, bool exact) const 112 { 113 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 114 115 uint32_t index = UINT32_MAX; 116 if (m_opaque_ptr) 117 { 118 FileSpec file_spec; 119 if (inline_file_spec && inline_file_spec->IsValid()) 120 file_spec = inline_file_spec->ref(); 121 else 122 file_spec = *m_opaque_ptr; 123 124 index = m_opaque_ptr->FindLineEntry (start_idx, 125 line, 126 inline_file_spec ? inline_file_spec->get() : NULL, 127 exact, 128 NULL); 129 } 130 131 if (log) 132 { 133 SBStream sstr; 134 if (index == UINT32_MAX) 135 { 136 log->Printf ("SBCompileUnit(%p)::FindLineEntryIndex (start_idx=%u, line=%u, SBFileSpec(%p)) => NOT FOUND", 137 static_cast<void*>(m_opaque_ptr), start_idx, line, 138 inline_file_spec 139 ? static_cast<const void*>(inline_file_spec->get()) 140 : NULL); 141 } 142 else 143 { 144 log->Printf ("SBCompileUnit(%p)::FindLineEntryIndex (start_idx=%u, line=%u, SBFileSpec(%p)) => %u", 145 static_cast<void*>(m_opaque_ptr), start_idx, line, 146 inline_file_spec 147 ? static_cast<const void*>(inline_file_spec->get()) 148 : NULL, 149 index); 150 } 151 } 152 153 return index; 154 } 155 156 uint32_t 157 SBCompileUnit::GetNumSupportFiles () const 158 { 159 if (m_opaque_ptr) 160 { 161 FileSpecList& support_files = m_opaque_ptr->GetSupportFiles (); 162 return support_files.GetSize(); 163 } 164 return 0; 165 } 166 167 168 169 lldb::SBTypeList 170 SBCompileUnit::GetTypes (uint32_t type_mask) 171 { 172 SBTypeList sb_type_list; 173 174 if (m_opaque_ptr) 175 { 176 ModuleSP module_sp (m_opaque_ptr->GetModule()); 177 if (module_sp) 178 { 179 SymbolVendor* vendor = module_sp->GetSymbolVendor(); 180 if (vendor) 181 { 182 TypeList type_list; 183 vendor->GetTypes (m_opaque_ptr, type_mask, type_list); 184 sb_type_list.m_opaque_ap->Append(type_list); 185 } 186 } 187 } 188 return sb_type_list; 189 } 190 191 192 193 194 SBFileSpec 195 SBCompileUnit::GetSupportFileAtIndex (uint32_t idx) const 196 { 197 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 198 199 SBFileSpec sb_file_spec; 200 if (m_opaque_ptr) 201 { 202 FileSpecList &support_files = m_opaque_ptr->GetSupportFiles (); 203 FileSpec file_spec = support_files.GetFileSpecAtIndex(idx); 204 sb_file_spec.SetFileSpec(file_spec); 205 } 206 207 if (log) 208 { 209 SBStream sstr; 210 sb_file_spec.GetDescription (sstr); 211 log->Printf ("SBCompileUnit(%p)::GetGetFileSpecAtIndex (idx=%u) => SBFileSpec(%p): '%s'", 212 static_cast<void*>(m_opaque_ptr), idx, 213 static_cast<const void*>(sb_file_spec.get()), 214 sstr.GetData()); 215 } 216 217 return sb_file_spec; 218 } 219 220 uint32_t 221 SBCompileUnit::FindSupportFileIndex (uint32_t start_idx, const SBFileSpec &sb_file, bool full) 222 { 223 if (m_opaque_ptr) 224 { 225 FileSpecList &support_files = m_opaque_ptr->GetSupportFiles (); 226 return support_files.FindFileIndex(start_idx, sb_file.ref(), full); 227 } 228 return 0; 229 } 230 231 bool 232 SBCompileUnit::IsValid () const 233 { 234 return m_opaque_ptr != NULL; 235 } 236 237 bool 238 SBCompileUnit::operator == (const SBCompileUnit &rhs) const 239 { 240 return m_opaque_ptr == rhs.m_opaque_ptr; 241 } 242 243 bool 244 SBCompileUnit::operator != (const SBCompileUnit &rhs) const 245 { 246 return m_opaque_ptr != rhs.m_opaque_ptr; 247 } 248 249 const lldb_private::CompileUnit * 250 SBCompileUnit::operator->() const 251 { 252 return m_opaque_ptr; 253 } 254 255 const lldb_private::CompileUnit & 256 SBCompileUnit::operator*() const 257 { 258 return *m_opaque_ptr; 259 } 260 261 lldb_private::CompileUnit * 262 SBCompileUnit::get () 263 { 264 return m_opaque_ptr; 265 } 266 267 void 268 SBCompileUnit::reset (lldb_private::CompileUnit *lldb_object_ptr) 269 { 270 m_opaque_ptr = lldb_object_ptr; 271 } 272 273 274 bool 275 SBCompileUnit::GetDescription (SBStream &description) 276 { 277 Stream &strm = description.ref(); 278 279 if (m_opaque_ptr) 280 { 281 m_opaque_ptr->Dump (&strm, false); 282 } 283 else 284 strm.PutCString ("No value"); 285 286 return true; 287 } 288