]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/API/SBLineEntry.cpp
Merge ^/head r306906 through r307382.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / API / SBLineEntry.cpp
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         ref() = rhs.ref();
32 }
33
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 &
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
55 SBLineEntry::SetLineEntry (const lldb_private::LineEntry &lldb_object_ref)
56 {
57     ref() = lldb_object_ref;
58 }
59
60
61 SBLineEntry::~SBLineEntry ()
62 {
63 }
64
65
66 SBAddress
67 SBLineEntry::GetStartAddress () const
68 {
69     SBAddress sb_address;
70     if (m_opaque_ap.get())
71         sb_address.SetAddress(&m_opaque_ap->range.GetBaseAddress());
72
73     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
74     if (log)
75     {
76         StreamString sstr;
77         const Address *addr = sb_address.get();
78         if (addr)
79             addr->Dump (&sstr, NULL, Address::DumpStyleModuleWithFileAddress, Address::DumpStyleInvalid, 4);
80         log->Printf ("SBLineEntry(%p)::GetStartAddress () => SBAddress (%p): %s",
81                      static_cast<void*>(m_opaque_ap.get()),
82                      static_cast<void*>(sb_address.get()), sstr.GetData());
83     }
84
85     return sb_address;
86 }
87
88 SBAddress
89 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                      static_cast<void*>(m_opaque_ap.get()),
106                      static_cast<void*>(sb_address.get()), sstr.GetData());
107     }
108     return sb_address;
109 }
110
111 bool
112 SBLineEntry::IsValid () const
113 {
114     return m_opaque_ap.get() && m_opaque_ap->IsValid();
115 }
116
117
118 SBFileSpec
119 SBLineEntry::GetFileSpec () const
120 {
121     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
122
123     SBFileSpec sb_file_spec;
124     if (m_opaque_ap.get() && m_opaque_ap->file)
125         sb_file_spec.SetFileSpec(m_opaque_ap->file);
126
127     if (log)
128     {
129         SBStream sstr;
130         sb_file_spec.GetDescription (sstr);
131         log->Printf ("SBLineEntry(%p)::GetFileSpec () => SBFileSpec(%p): %s",
132                      static_cast<void*>(m_opaque_ap.get()),
133                      static_cast<const void*>(sb_file_spec.get()),
134                      sstr.GetData());
135     }
136
137     return sb_file_spec;
138 }
139
140 uint32_t
141 SBLineEntry::GetLine () const
142 {
143     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
144
145     uint32_t line = 0;
146     if (m_opaque_ap.get())
147         line = m_opaque_ap->line;
148
149     if (log)
150         log->Printf ("SBLineEntry(%p)::GetLine () => %u",
151                      static_cast<void*>(m_opaque_ap.get()), line);
152
153     return line;
154 }
155
156
157 uint32_t
158 SBLineEntry::GetColumn () const
159 {
160     if (m_opaque_ap.get())
161         return m_opaque_ap->column;
162     return 0;
163 }
164
165 void
166 SBLineEntry::SetFileSpec (lldb::SBFileSpec filespec)
167 {
168     if (filespec.IsValid())
169         ref().file = filespec.ref();
170     else
171         ref().file.Clear();
172 }
173 void
174 SBLineEntry::SetLine (uint32_t line)
175 {
176     ref().line = line;
177 }
178
179 void
180 SBLineEntry::SetColumn (uint32_t column)
181 {
182     ref().line = column;
183 }
184
185
186
187 bool
188 SBLineEntry::operator == (const SBLineEntry &rhs) const
189 {
190     lldb_private::LineEntry *lhs_ptr = m_opaque_ap.get();
191     lldb_private::LineEntry *rhs_ptr = rhs.m_opaque_ap.get();
192
193     if (lhs_ptr && rhs_ptr)
194         return lldb_private::LineEntry::Compare (*lhs_ptr, *rhs_ptr) == 0;
195
196     return lhs_ptr == rhs_ptr;
197 }
198
199 bool
200 SBLineEntry::operator != (const SBLineEntry &rhs) const
201 {
202     lldb_private::LineEntry *lhs_ptr = m_opaque_ap.get();
203     lldb_private::LineEntry *rhs_ptr = rhs.m_opaque_ap.get();
204
205     if (lhs_ptr && rhs_ptr)
206         return lldb_private::LineEntry::Compare (*lhs_ptr, *rhs_ptr) != 0;
207
208     return lhs_ptr != rhs_ptr;
209 }
210
211 const lldb_private::LineEntry *
212 SBLineEntry::operator->() const
213 {
214     return m_opaque_ap.get();
215 }
216
217 lldb_private::LineEntry &
218 SBLineEntry::ref()
219 {
220     if (m_opaque_ap.get() == NULL)
221         m_opaque_ap.reset (new lldb_private::LineEntry ());
222     return *m_opaque_ap;
223 }
224
225 const lldb_private::LineEntry &
226 SBLineEntry::ref() const
227 {
228     return *m_opaque_ap;
229 }
230
231 bool
232 SBLineEntry::GetDescription (SBStream &description)
233 {
234     Stream &strm = description.ref();
235
236     if (m_opaque_ap.get())
237     {
238         char file_path[PATH_MAX*2];
239         m_opaque_ap->file.GetPath (file_path, sizeof (file_path));
240         strm.Printf ("%s:%u", file_path, GetLine());
241         if (GetColumn() > 0)
242             strm.Printf (":%u", GetColumn());
243     }
244     else
245         strm.PutCString ("No value");
246
247     return true;
248 }
249
250 lldb_private::LineEntry *
251 SBLineEntry::get ()
252 {
253     return m_opaque_ap.get();
254 }