1 //===-- SBLineEntry.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/SBLineEntry.h" 11 #include "lldb/API/SBStream.h" 12 #include "lldb/Core/StreamString.h" 13 #include "lldb/Core/Log.h" 14 #include "lldb/Symbol/LineEntry.h" 15 16 using namespace lldb; 17 using namespace lldb_private; 18 19 20 SBLineEntry::SBLineEntry () : 21 m_opaque_ap () 22 { 23 } 24 25 SBLineEntry::SBLineEntry (const SBLineEntry &rhs) : 26 m_opaque_ap () 27 { 28 if (rhs.IsValid()) 29 m_opaque_ap.reset (new lldb_private::LineEntry (*rhs)); 30 } 31 32 33 34 SBLineEntry::SBLineEntry (const lldb_private::LineEntry *lldb_object_ptr) : 35 m_opaque_ap () 36 { 37 if (lldb_object_ptr) 38 m_opaque_ap.reset (new lldb_private::LineEntry(*lldb_object_ptr)); 39 } 40 41 const SBLineEntry & 42 SBLineEntry::operator = (const SBLineEntry &rhs) 43 { 44 if (this != &rhs && rhs.IsValid()) 45 m_opaque_ap.reset (new lldb_private::LineEntry(*rhs)); 46 return *this; 47 } 48 49 void 50 SBLineEntry::SetLineEntry (const lldb_private::LineEntry &lldb_object_ref) 51 { 52 if (m_opaque_ap.get()) 53 (*m_opaque_ap.get()) = lldb_object_ref; 54 else 55 m_opaque_ap.reset (new lldb_private::LineEntry (lldb_object_ref)); 56 } 57 58 59 SBLineEntry::~SBLineEntry () 60 { 61 } 62 63 64 SBAddress 65 SBLineEntry::GetStartAddress () const 66 { 67 68 SBAddress sb_address; 69 if (m_opaque_ap.get()) 70 sb_address.SetAddress(&m_opaque_ap->range.GetBaseAddress()); 71 72 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 73 if (log) 74 { 75 StreamString sstr; 76 if (sb_address.get()) 77 sb_address->Dump (&sstr, NULL, Address::DumpStyleModuleWithFileAddress, Address::DumpStyleInvalid, 4); 78 log->Printf ("SBLineEntry(%p)::GetStartAddress () => SBAddress (%p): %s", 79 m_opaque_ap.get(), sb_address.get(), sstr.GetData()); 80 } 81 82 return sb_address; 83 } 84 85 SBAddress 86 SBLineEntry::GetEndAddress () const 87 { 88 SBAddress sb_address; 89 if (m_opaque_ap.get()) 90 { 91 sb_address.SetAddress(&m_opaque_ap->range.GetBaseAddress()); 92 sb_address.OffsetAddress(m_opaque_ap->range.GetByteSize()); 93 } 94 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 95 if (log) 96 { 97 StreamString sstr; 98 if (sb_address.get()) 99 sb_address->Dump (&sstr, NULL, Address::DumpStyleModuleWithFileAddress, Address::DumpStyleInvalid, 4); 100 log->Printf ("SBLineEntry(%p)::GetEndAddress () => SBAddress (%p): %s", 101 m_opaque_ap.get(), sb_address.get(), sstr.GetData()); 102 } 103 return sb_address; 104 } 105 106 bool 107 SBLineEntry::IsValid () const 108 { 109 return m_opaque_ap.get() != NULL; 110 } 111 112 113 SBFileSpec 114 SBLineEntry::GetFileSpec () const 115 { 116 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 117 118 SBFileSpec sb_file_spec; 119 if (m_opaque_ap.get() && m_opaque_ap->file) 120 sb_file_spec.SetFileSpec(m_opaque_ap->file); 121 122 if (log) 123 { 124 SBStream sstr; 125 sb_file_spec.GetDescription (sstr); 126 log->Printf ("SBLineEntry(%p)::GetFileSpec () => SBFileSpec(%p): %s", m_opaque_ap.get(), 127 sb_file_spec.get(), sstr.GetData()); 128 } 129 130 return sb_file_spec; 131 } 132 133 uint32_t 134 SBLineEntry::GetLine () const 135 { 136 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 137 138 uint32_t line = 0; 139 if (m_opaque_ap.get()) 140 line = m_opaque_ap->line; 141 142 if (log) 143 log->Printf ("SBLineEntry(%p)::GetLine () => %u", m_opaque_ap.get(), line); 144 145 return line; 146 } 147 148 149 uint32_t 150 SBLineEntry::GetColumn () const 151 { 152 if (m_opaque_ap.get()) 153 return m_opaque_ap->column; 154 return 0; 155 } 156 157 bool 158 SBLineEntry::operator == (const SBLineEntry &rhs) const 159 { 160 lldb_private::LineEntry *lhs_ptr = m_opaque_ap.get(); 161 lldb_private::LineEntry *rhs_ptr = rhs.m_opaque_ap.get(); 162 163 if (lhs_ptr && rhs_ptr) 164 return lldb_private::LineEntry::Compare (*lhs_ptr, *rhs_ptr) == 0; 165 166 return lhs_ptr == rhs_ptr; 167 } 168 169 bool 170 SBLineEntry::operator != (const SBLineEntry &rhs) const 171 { 172 lldb_private::LineEntry *lhs_ptr = m_opaque_ap.get(); 173 lldb_private::LineEntry *rhs_ptr = rhs.m_opaque_ap.get(); 174 175 if (lhs_ptr && rhs_ptr) 176 return lldb_private::LineEntry::Compare (*lhs_ptr, *rhs_ptr) != 0; 177 178 return lhs_ptr != rhs_ptr; 179 } 180 181 const lldb_private::LineEntry * 182 SBLineEntry::operator->() const 183 { 184 return m_opaque_ap.get(); 185 } 186 187 const lldb_private::LineEntry & 188 SBLineEntry::operator*() const 189 { 190 return *m_opaque_ap; 191 } 192 193 bool 194 SBLineEntry::GetDescription (SBStream &description) 195 { 196 if (m_opaque_ap.get()) 197 { 198 char file_path[PATH_MAX*2]; 199 m_opaque_ap->file.GetPath (file_path, sizeof (file_path)); 200 description.Printf ("%s:%u", file_path, GetLine()); 201 if (GetColumn() > 0) 202 description.Printf (":%u", GetColumn()); 203 } 204 else 205 description.Printf ("No value"); 206 207 return true; 208 } 209 210 lldb_private::LineEntry * 211 SBLineEntry::get () 212 { 213 return m_opaque_ap.get(); 214 } 215