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