• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
SBLineEntry()22 SBLineEntry::SBLineEntry () :
23     m_opaque_ap ()
24 {
25 }
26 
SBLineEntry(const SBLineEntry & rhs)27 SBLineEntry::SBLineEntry (const SBLineEntry &rhs) :
28     m_opaque_ap ()
29 {
30     if (rhs.IsValid())
31         ref() = rhs.ref();
32 }
33 
SBLineEntry(const lldb_private::LineEntry * lldb_object_ptr)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 &
operator =(const SBLineEntry & rhs)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
SetLineEntry(const lldb_private::LineEntry & lldb_object_ref)55 SBLineEntry::SetLineEntry (const lldb_private::LineEntry &lldb_object_ref)
56 {
57     ref() = lldb_object_ref;
58 }
59 
60 
~SBLineEntry()61 SBLineEntry::~SBLineEntry ()
62 {
63 }
64 
65 
66 SBAddress
GetStartAddress() const67 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     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
75     if (log)
76     {
77         StreamString sstr;
78         const Address *addr = sb_address.get();
79         if (addr)
80             addr->Dump (&sstr, NULL, Address::DumpStyleModuleWithFileAddress, Address::DumpStyleInvalid, 4);
81         log->Printf ("SBLineEntry(%p)::GetStartAddress () => SBAddress (%p): %s",
82                      m_opaque_ap.get(), sb_address.get(), sstr.GetData());
83     }
84 
85     return sb_address;
86 }
87 
88 SBAddress
GetEndAddress() const89 SBLineEntry::GetEndAddress () const
90 {
91     SBAddress sb_address;
92     if (m_opaque_ap.get())
93     {
94         sb_address.SetAddress(&m_opaque_ap->range.GetBaseAddress());
95         sb_address.OffsetAddress(m_opaque_ap->range.GetByteSize());
96     }
97     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
98     if (log)
99     {
100         StreamString sstr;
101         const Address *addr = sb_address.get();
102         if (addr)
103             addr->Dump (&sstr, NULL, Address::DumpStyleModuleWithFileAddress, Address::DumpStyleInvalid, 4);
104         log->Printf ("SBLineEntry(%p)::GetEndAddress () => SBAddress (%p): %s",
105                      m_opaque_ap.get(), sb_address.get(), sstr.GetData());
106     }
107     return sb_address;
108 }
109 
110 bool
IsValid() const111 SBLineEntry::IsValid () const
112 {
113     return m_opaque_ap.get() && m_opaque_ap->IsValid();
114 }
115 
116 
117 SBFileSpec
GetFileSpec() const118 SBLineEntry::GetFileSpec () const
119 {
120     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
121 
122     SBFileSpec sb_file_spec;
123     if (m_opaque_ap.get() && m_opaque_ap->file)
124         sb_file_spec.SetFileSpec(m_opaque_ap->file);
125 
126     if (log)
127     {
128         SBStream sstr;
129         sb_file_spec.GetDescription (sstr);
130         log->Printf ("SBLineEntry(%p)::GetFileSpec () => SBFileSpec(%p): %s", m_opaque_ap.get(),
131                      sb_file_spec.get(), sstr.GetData());
132     }
133 
134     return sb_file_spec;
135 }
136 
137 uint32_t
GetLine() const138 SBLineEntry::GetLine () const
139 {
140     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
141 
142     uint32_t line = 0;
143     if (m_opaque_ap.get())
144         line = m_opaque_ap->line;
145 
146     if (log)
147         log->Printf ("SBLineEntry(%p)::GetLine () => %u", m_opaque_ap.get(), line);
148 
149     return line;
150 }
151 
152 
153 uint32_t
GetColumn() const154 SBLineEntry::GetColumn () const
155 {
156     if (m_opaque_ap.get())
157         return m_opaque_ap->column;
158     return 0;
159 }
160 
161 void
SetFileSpec(lldb::SBFileSpec filespec)162 SBLineEntry::SetFileSpec (lldb::SBFileSpec filespec)
163 {
164     if (filespec.IsValid())
165         ref().file = filespec.ref();
166     else
167         ref().file.Clear();
168 }
169 void
SetLine(uint32_t line)170 SBLineEntry::SetLine (uint32_t line)
171 {
172     ref().line = line;
173 }
174 
175 void
SetColumn(uint32_t column)176 SBLineEntry::SetColumn (uint32_t column)
177 {
178     ref().line = column;
179 }
180 
181 
182 
183 bool
operator ==(const SBLineEntry & rhs) const184 SBLineEntry::operator == (const SBLineEntry &rhs) const
185 {
186     lldb_private::LineEntry *lhs_ptr = m_opaque_ap.get();
187     lldb_private::LineEntry *rhs_ptr = rhs.m_opaque_ap.get();
188 
189     if (lhs_ptr && rhs_ptr)
190         return lldb_private::LineEntry::Compare (*lhs_ptr, *rhs_ptr) == 0;
191 
192     return lhs_ptr == rhs_ptr;
193 }
194 
195 bool
operator !=(const SBLineEntry & rhs) const196 SBLineEntry::operator != (const SBLineEntry &rhs) const
197 {
198     lldb_private::LineEntry *lhs_ptr = m_opaque_ap.get();
199     lldb_private::LineEntry *rhs_ptr = rhs.m_opaque_ap.get();
200 
201     if (lhs_ptr && rhs_ptr)
202         return lldb_private::LineEntry::Compare (*lhs_ptr, *rhs_ptr) != 0;
203 
204     return lhs_ptr != rhs_ptr;
205 }
206 
207 const lldb_private::LineEntry *
operator ->() const208 SBLineEntry::operator->() const
209 {
210     return m_opaque_ap.get();
211 }
212 
213 lldb_private::LineEntry &
ref()214 SBLineEntry::ref()
215 {
216     if (m_opaque_ap.get() == NULL)
217         m_opaque_ap.reset (new lldb_private::LineEntry ());
218     return *m_opaque_ap;
219 }
220 
221 const lldb_private::LineEntry &
ref() const222 SBLineEntry::ref() const
223 {
224     return *m_opaque_ap;
225 }
226 
227 bool
GetDescription(SBStream & description)228 SBLineEntry::GetDescription (SBStream &description)
229 {
230     Stream &strm = description.ref();
231 
232     if (m_opaque_ap.get())
233     {
234         char file_path[PATH_MAX*2];
235         m_opaque_ap->file.GetPath (file_path, sizeof (file_path));
236         strm.Printf ("%s:%u", file_path, GetLine());
237         if (GetColumn() > 0)
238             strm.Printf (":%u", GetColumn());
239     }
240     else
241         strm.PutCString ("No value");
242 
243     return true;
244 }
245 
246 lldb_private::LineEntry *
get()247 SBLineEntry::get ()
248 {
249     return m_opaque_ap.get();
250 }
251