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