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 m_opaque_ap.reset (new lldb_private::LineEntry (*rhs)); 32 } 33 34 35 36 SBLineEntry::SBLineEntry (const lldb_private::LineEntry *lldb_object_ptr) : 37 m_opaque_ap () 38 { 39 if (lldb_object_ptr) 40 m_opaque_ap.reset (new lldb_private::LineEntry(*lldb_object_ptr)); 41 } 42 43 const SBLineEntry & 44 SBLineEntry::operator = (const SBLineEntry &rhs) 45 { 46 if (this != &rhs && rhs.IsValid()) 47 m_opaque_ap.reset (new lldb_private::LineEntry(*rhs)); 48 return *this; 49 } 50 51 void 52 SBLineEntry::SetLineEntry (const lldb_private::LineEntry &lldb_object_ref) 53 { 54 if (m_opaque_ap.get()) 55 (*m_opaque_ap.get()) = lldb_object_ref; 56 else 57 m_opaque_ap.reset (new lldb_private::LineEntry (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 bool 160 SBLineEntry::operator == (const SBLineEntry &rhs) const 161 { 162 lldb_private::LineEntry *lhs_ptr = m_opaque_ap.get(); 163 lldb_private::LineEntry *rhs_ptr = rhs.m_opaque_ap.get(); 164 165 if (lhs_ptr && rhs_ptr) 166 return lldb_private::LineEntry::Compare (*lhs_ptr, *rhs_ptr) == 0; 167 168 return lhs_ptr == rhs_ptr; 169 } 170 171 bool 172 SBLineEntry::operator != (const SBLineEntry &rhs) const 173 { 174 lldb_private::LineEntry *lhs_ptr = m_opaque_ap.get(); 175 lldb_private::LineEntry *rhs_ptr = rhs.m_opaque_ap.get(); 176 177 if (lhs_ptr && rhs_ptr) 178 return lldb_private::LineEntry::Compare (*lhs_ptr, *rhs_ptr) != 0; 179 180 return lhs_ptr != rhs_ptr; 181 } 182 183 const lldb_private::LineEntry * 184 SBLineEntry::operator->() const 185 { 186 return m_opaque_ap.get(); 187 } 188 189 const lldb_private::LineEntry & 190 SBLineEntry::operator*() const 191 { 192 return *m_opaque_ap; 193 } 194 195 bool 196 SBLineEntry::GetDescription (SBStream &description) 197 { 198 if (m_opaque_ap.get()) 199 { 200 char file_path[PATH_MAX*2]; 201 m_opaque_ap->file.GetPath (file_path, sizeof (file_path)); 202 description.Printf ("%s:%u", file_path, GetLine()); 203 if (GetColumn() > 0) 204 description.Printf (":%u", GetColumn()); 205 } 206 else 207 description.Printf ("No value"); 208 209 return true; 210 } 211 212 lldb_private::LineEntry * 213 SBLineEntry::get () 214 { 215 return m_opaque_ap.get(); 216 } 217