1 //===-- SBLineEntry.cpp -----------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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"
20 using namespace lldb_private;
22 SBLineEntry::SBLineEntry() : m_opaque_ap() {}
24 SBLineEntry::SBLineEntry(const SBLineEntry &rhs) : m_opaque_ap() {
29 SBLineEntry::SBLineEntry(const lldb_private::LineEntry *lldb_object_ptr)
32 ref() = *lldb_object_ptr;
35 const SBLineEntry &SBLineEntry::operator=(const SBLineEntry &rhs) {
45 void SBLineEntry::SetLineEntry(const lldb_private::LineEntry &lldb_object_ref) {
46 ref() = lldb_object_ref;
49 SBLineEntry::~SBLineEntry() {}
51 SBAddress SBLineEntry::GetStartAddress() const {
54 sb_address.SetAddress(&m_opaque_ap->range.GetBaseAddress());
56 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
59 const Address *addr = sb_address.get();
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());
71 SBAddress SBLineEntry::GetEndAddress() const {
74 sb_address.SetAddress(&m_opaque_ap->range.GetBaseAddress());
75 sb_address.OffsetAddress(m_opaque_ap->range.GetByteSize());
77 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
80 const Address *addr = sb_address.get();
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());
91 bool SBLineEntry::IsValid() const {
92 return m_opaque_ap.get() && m_opaque_ap->IsValid();
95 SBFileSpec SBLineEntry::GetFileSpec() const {
96 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
98 SBFileSpec sb_file_spec;
99 if (m_opaque_ap.get() && m_opaque_ap->file)
100 sb_file_spec.SetFileSpec(m_opaque_ap->file);
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());
113 uint32_t SBLineEntry::GetLine() const {
114 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
118 line = m_opaque_ap->line;
121 log->Printf("SBLineEntry(%p)::GetLine () => %u",
122 static_cast<void *>(m_opaque_ap.get()), line);
127 uint32_t SBLineEntry::GetColumn() const {
129 return m_opaque_ap->column;
133 void SBLineEntry::SetFileSpec(lldb::SBFileSpec filespec) {
134 if (filespec.IsValid())
135 ref().file = filespec.ref();
139 void SBLineEntry::SetLine(uint32_t line) { ref().line = line; }
141 void SBLineEntry::SetColumn(uint32_t column) { ref().line = column; }
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();
147 if (lhs_ptr && rhs_ptr)
148 return lldb_private::LineEntry::Compare(*lhs_ptr, *rhs_ptr) == 0;
150 return lhs_ptr == rhs_ptr;
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();
157 if (lhs_ptr && rhs_ptr)
158 return lldb_private::LineEntry::Compare(*lhs_ptr, *rhs_ptr) != 0;
160 return lhs_ptr != rhs_ptr;
163 const lldb_private::LineEntry *SBLineEntry::operator->() const {
164 return m_opaque_ap.get();
167 lldb_private::LineEntry &SBLineEntry::ref() {
168 if (m_opaque_ap == NULL)
169 m_opaque_ap.reset(new lldb_private::LineEntry());
173 const lldb_private::LineEntry &SBLineEntry::ref() const { return *m_opaque_ap; }
175 bool SBLineEntry::GetDescription(SBStream &description) {
176 Stream &strm = description.ref();
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());
183 strm.Printf(":%u", GetColumn());
185 strm.PutCString("No value");
190 lldb_private::LineEntry *SBLineEntry::get() { return m_opaque_ap.get(); }