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 17 using namespace lldb; 18 using namespace lldb_private; 19 20 21 SBCompileUnit::SBCompileUnit () : 22 m_opaque_ptr (NULL) 23 { 24 } 25 26 SBCompileUnit::SBCompileUnit (lldb_private::CompileUnit *lldb_object_ptr) : 27 m_opaque_ptr (lldb_object_ptr) 28 { 29 } 30 31 SBCompileUnit::~SBCompileUnit () 32 { 33 m_opaque_ptr = NULL; 34 } 35 36 SBFileSpec 37 SBCompileUnit::GetFileSpec () const 38 { 39 SBFileSpec file_spec; 40 if (m_opaque_ptr) 41 file_spec.SetFileSpec(*m_opaque_ptr); 42 return file_spec; 43 } 44 45 uint32_t 46 SBCompileUnit::GetNumLineEntries () const 47 { 48 if (m_opaque_ptr) 49 { 50 LineTable *line_table = m_opaque_ptr->GetLineTable (); 51 if (line_table) 52 return line_table->GetSize(); 53 } 54 return 0; 55 } 56 57 SBLineEntry 58 SBCompileUnit::GetLineEntryAtIndex (uint32_t idx) const 59 { 60 SBLineEntry sb_line_entry; 61 if (m_opaque_ptr) 62 { 63 LineTable *line_table = m_opaque_ptr->GetLineTable (); 64 if (line_table) 65 { 66 LineEntry line_entry; 67 if (line_table->GetLineEntryAtIndex(idx, line_entry)) 68 sb_line_entry.SetLineEntry(line_entry); 69 } 70 } 71 return sb_line_entry; 72 } 73 74 uint32_t 75 SBCompileUnit::FindLineEntryIndex (uint32_t start_idx, uint32_t line, SBFileSpec *inline_file_spec) const 76 { 77 if (m_opaque_ptr) 78 { 79 FileSpec file_spec; 80 if (inline_file_spec && inline_file_spec->IsValid()) 81 file_spec = inline_file_spec->ref(); 82 else 83 file_spec = *m_opaque_ptr; 84 85 return m_opaque_ptr->FindLineEntry (start_idx, 86 line, 87 inline_file_spec ? inline_file_spec->get() : NULL, 88 NULL); 89 } 90 return UINT32_MAX; 91 } 92 93 bool 94 SBCompileUnit::IsValid () const 95 { 96 return m_opaque_ptr != NULL; 97 } 98 99 bool 100 SBCompileUnit::operator == (const SBCompileUnit &rhs) const 101 { 102 return m_opaque_ptr == rhs.m_opaque_ptr; 103 } 104 105 bool 106 SBCompileUnit::operator != (const SBCompileUnit &rhs) const 107 { 108 return m_opaque_ptr != rhs.m_opaque_ptr; 109 } 110 111 const lldb_private::CompileUnit * 112 SBCompileUnit::operator->() const 113 { 114 return m_opaque_ptr; 115 } 116 117 const lldb_private::CompileUnit & 118 SBCompileUnit::operator*() const 119 { 120 return *m_opaque_ptr; 121 } 122 123 bool 124 SBCompileUnit::GetDescription (SBStream &description) 125 { 126 if (m_opaque_ptr) 127 { 128 description.ref(); 129 m_opaque_ptr->Dump (description.get(), false); 130 } 131 else 132 description.Printf ("No Value"); 133 134 return true; 135 } 136