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