blob: 7341d3603dfe3802f066e826b40250fdb4b2dce8 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- 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
Stephen Wilson8acdbb82011-04-08 13:36:44 +000010#include <limits.h>
11
Chris Lattner30fdc8d2010-06-08 16:52:24 +000012#include "lldb/API/SBLineEntry.h"
Caroline Ticedde9cff2010-09-20 05:20:02 +000013#include "lldb/API/SBStream.h"
Zachary Turner8d48cd62017-03-22 17:33:23 +000014#include "lldb/Host/PosixApi.h"
Greg Claytoncfd1ace2010-10-31 03:01:06 +000015#include "lldb/Symbol/LineEntry.h"
Zachary Turner6f9e6902017-03-03 20:56:28 +000016#include "lldb/Utility/Log.h"
Zachary Turnerbf9a7732017-02-02 21:39:50 +000017#include "lldb/Utility/StreamString.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000018
19using namespace lldb;
Caroline Ticeceb6b132010-10-26 03:11:13 +000020using namespace lldb_private;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000021
Kate Stoneb9c1b512016-09-06 20:57:50 +000022SBLineEntry::SBLineEntry() : m_opaque_ap() {}
Chris Lattner30fdc8d2010-06-08 16:52:24 +000023
Kate Stoneb9c1b512016-09-06 20:57:50 +000024SBLineEntry::SBLineEntry(const SBLineEntry &rhs) : m_opaque_ap() {
25 if (rhs.IsValid())
26 ref() = rhs.ref();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027}
28
Kate Stoneb9c1b512016-09-06 20:57:50 +000029SBLineEntry::SBLineEntry(const lldb_private::LineEntry *lldb_object_ptr)
30 : m_opaque_ap() {
31 if (lldb_object_ptr)
32 ref() = *lldb_object_ptr;
33}
34
35const SBLineEntry &SBLineEntry::operator=(const SBLineEntry &rhs) {
36 if (this != &rhs) {
Chris Lattner30fdc8d2010-06-08 16:52:24 +000037 if (rhs.IsValid())
Kate Stoneb9c1b512016-09-06 20:57:50 +000038 ref() = rhs.ref();
Greg Clayton8f7180b2011-09-26 07:11:27 +000039 else
Kate Stoneb9c1b512016-09-06 20:57:50 +000040 m_opaque_ap.reset();
41 }
42 return *this;
Greg Clayton8f7180b2011-09-26 07:11:27 +000043}
44
Kate Stoneb9c1b512016-09-06 20:57:50 +000045void SBLineEntry::SetLineEntry(const lldb_private::LineEntry &lldb_object_ref) {
46 ref() = lldb_object_ref;
Greg Clayton8f7180b2011-09-26 07:11:27 +000047}
48
Kate Stoneb9c1b512016-09-06 20:57:50 +000049SBLineEntry::~SBLineEntry() {}
Greg Clayton8f7180b2011-09-26 07:11:27 +000050
Kate Stoneb9c1b512016-09-06 20:57:50 +000051SBAddress SBLineEntry::GetStartAddress() const {
52 SBAddress sb_address;
53 if (m_opaque_ap.get())
54 sb_address.SetAddress(&m_opaque_ap->range.GetBaseAddress());
Greg Clayton8f7180b2011-09-26 07:11:27 +000055
Kate Stoneb9c1b512016-09-06 20:57:50 +000056 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 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000067
Kate Stoneb9c1b512016-09-06 20:57:50 +000068 return sb_address;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000069}
70
Kate Stoneb9c1b512016-09-06 20:57:50 +000071SBAddress 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;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000089}
90
Kate Stoneb9c1b512016-09-06 20:57:50 +000091bool SBLineEntry::IsValid() const {
92 return m_opaque_ap.get() && m_opaque_ap->IsValid();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000093}
94
Kate Stoneb9c1b512016-09-06 20:57:50 +000095SBFileSpec 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;
Greg Clayton8f7180b2011-09-26 07:11:27 +0000111}
112
Kate Stoneb9c1b512016-09-06 20:57:50 +0000113uint32_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;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000125}
126
Kate Stoneb9c1b512016-09-06 20:57:50 +0000127uint32_t SBLineEntry::GetColumn() const {
128 if (m_opaque_ap.get())
129 return m_opaque_ap->column;
130 return 0;
Caroline Ticedde9cff2010-09-20 05:20:02 +0000131}
Caroline Tice750cd172010-10-26 23:49:36 +0000132
Kate Stoneb9c1b512016-09-06 20:57:50 +0000133void SBLineEntry::SetFileSpec(lldb::SBFileSpec filespec) {
134 if (filespec.IsValid())
135 ref().file = filespec.ref();
136 else
137 ref().file.Clear();
Caroline Tice750cd172010-10-26 23:49:36 +0000138}
Kate Stoneb9c1b512016-09-06 20:57:50 +0000139void SBLineEntry::SetLine(uint32_t line) { ref().line = line; }
140
141void SBLineEntry::SetColumn(uint32_t column) { ref().line = column; }
142
143bool 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
153bool 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
163const lldb_private::LineEntry *SBLineEntry::operator->() const {
164 return m_opaque_ap.get();
165}
166
167lldb_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
173const lldb_private::LineEntry &SBLineEntry::ref() const { return *m_opaque_ap; }
174
175bool 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
190lldb_private::LineEntry *SBLineEntry::get() { return m_opaque_ap.get(); }