blob: 8ade4c54f1f244ec67055b130bd134b32af0c8a4 [file] [log] [blame]
Chris Lattner24943d22010-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
10#include "lldb/API/SBLineEntry.h"
Caroline Tice98f930f2010-09-20 05:20:02 +000011#include "lldb/API/SBStream.h"
Chris Lattner24943d22010-06-08 16:52:24 +000012#include "lldb/Symbol/LineEntry.h"
Caroline Tice7826c882010-10-26 03:11:13 +000013#include "lldb/Core/Log.h"
Chris Lattner24943d22010-06-08 16:52:24 +000014
15using namespace lldb;
Caroline Tice7826c882010-10-26 03:11:13 +000016using namespace lldb_private;
Chris Lattner24943d22010-06-08 16:52:24 +000017
18
19SBLineEntry::SBLineEntry () :
Greg Clayton63094e02010-06-23 01:19:29 +000020 m_opaque_ap ()
Chris Lattner24943d22010-06-08 16:52:24 +000021{
Caroline Tice7826c882010-10-26 03:11:13 +000022 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API | LIBLLDB_LOG_VERBOSE);
23
24 if (log)
25 log->Printf ("SBLineEntry::SBLineEntry () ==> this = %p", this);
Chris Lattner24943d22010-06-08 16:52:24 +000026}
27
28SBLineEntry::SBLineEntry (const SBLineEntry &rhs) :
Greg Clayton63094e02010-06-23 01:19:29 +000029 m_opaque_ap ()
Chris Lattner24943d22010-06-08 16:52:24 +000030{
Caroline Tice7826c882010-10-26 03:11:13 +000031 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API | LIBLLDB_LOG_VERBOSE);
32
Chris Lattner24943d22010-06-08 16:52:24 +000033 if (rhs.IsValid())
34 {
Greg Clayton63094e02010-06-23 01:19:29 +000035 m_opaque_ap.reset (new lldb_private::LineEntry (*rhs));
Chris Lattner24943d22010-06-08 16:52:24 +000036 }
Caroline Tice7826c882010-10-26 03:11:13 +000037
38 if (log)
39 log->Printf ("SBLineEntry::SBLineEntry (const SBLineEntry &rhs) rhs.m_opaque_ap.get() = %p ==> this = %p ",
40 (rhs.IsValid() ? rhs.m_opaque_ap.get() : NULL), this);
41
Chris Lattner24943d22010-06-08 16:52:24 +000042}
43
44
45
46SBLineEntry::SBLineEntry (const lldb_private::LineEntry *lldb_object_ptr) :
Greg Clayton63094e02010-06-23 01:19:29 +000047 m_opaque_ap ()
Chris Lattner24943d22010-06-08 16:52:24 +000048{
Caroline Tice7826c882010-10-26 03:11:13 +000049 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API | LIBLLDB_LOG_VERBOSE);
50
Chris Lattner24943d22010-06-08 16:52:24 +000051 if (lldb_object_ptr)
Greg Clayton63094e02010-06-23 01:19:29 +000052 m_opaque_ap.reset (new lldb_private::LineEntry(*lldb_object_ptr));
Caroline Tice7826c882010-10-26 03:11:13 +000053
54 if (log)
55 log->Printf ("SBLineEntry::SBLineEntry (const lldb_private::LineEntry *lldb_object_ptr) lldb_object_ptr = %p"
56 " ==> this = %p (m_opaque_ap.get() = %p)", lldb_object_ptr, this, m_opaque_ap.get());
Chris Lattner24943d22010-06-08 16:52:24 +000057}
58
59const SBLineEntry &
60SBLineEntry::operator = (const SBLineEntry &rhs)
61{
62 if (this != &rhs)
63 {
64 if (rhs.IsValid())
Greg Clayton63094e02010-06-23 01:19:29 +000065 m_opaque_ap.reset (new lldb_private::LineEntry(*rhs));
Chris Lattner24943d22010-06-08 16:52:24 +000066 }
67 return *this;
68}
69
70void
71SBLineEntry::SetLineEntry (const lldb_private::LineEntry &lldb_object_ref)
72{
Greg Clayton63094e02010-06-23 01:19:29 +000073 if (m_opaque_ap.get())
74 (*m_opaque_ap.get()) = lldb_object_ref;
Chris Lattner24943d22010-06-08 16:52:24 +000075 else
Greg Clayton63094e02010-06-23 01:19:29 +000076 m_opaque_ap.reset (new lldb_private::LineEntry (lldb_object_ref));
Chris Lattner24943d22010-06-08 16:52:24 +000077}
78
79
80SBLineEntry::~SBLineEntry ()
81{
82}
83
84
85SBAddress
86SBLineEntry::GetStartAddress () const
87{
Caroline Tice7826c882010-10-26 03:11:13 +000088 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
89
90 if (log)
91 log->Printf ("SBLineEntry::GetStartAddress ()");
92
Chris Lattner24943d22010-06-08 16:52:24 +000093 SBAddress sb_address;
Greg Clayton63094e02010-06-23 01:19:29 +000094 if (m_opaque_ap.get())
95 sb_address.SetAddress(&m_opaque_ap->range.GetBaseAddress());
Caroline Tice7826c882010-10-26 03:11:13 +000096
97 if (log)
98 {
99 SBStream sstr;
100 sb_address.GetDescription (sstr);
101 log->Printf ("SBLineEntry::GetStartAddress ==> SBAddress (this = %p, (%s)", &sb_address, sstr.GetData());
102 }
103
Chris Lattner24943d22010-06-08 16:52:24 +0000104 return sb_address;
105}
106
107SBAddress
108SBLineEntry::GetEndAddress () const
109{
110 SBAddress sb_address;
Greg Clayton63094e02010-06-23 01:19:29 +0000111 if (m_opaque_ap.get())
Chris Lattner24943d22010-06-08 16:52:24 +0000112 {
Greg Clayton63094e02010-06-23 01:19:29 +0000113 sb_address.SetAddress(&m_opaque_ap->range.GetBaseAddress());
114 sb_address.OffsetAddress(m_opaque_ap->range.GetByteSize());
Chris Lattner24943d22010-06-08 16:52:24 +0000115 }
116 return sb_address;
117}
118
119bool
120SBLineEntry::IsValid () const
121{
Greg Clayton63094e02010-06-23 01:19:29 +0000122 return m_opaque_ap.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +0000123}
124
125
126SBFileSpec
127SBLineEntry::GetFileSpec () const
128{
Caroline Tice7826c882010-10-26 03:11:13 +0000129 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
130
131 if (log)
132 log->Printf ("SBLineEntry::GetFileSpec ()");
133
Chris Lattner24943d22010-06-08 16:52:24 +0000134 SBFileSpec sb_file_spec;
Greg Clayton63094e02010-06-23 01:19:29 +0000135 if (m_opaque_ap.get() && m_opaque_ap->file)
136 sb_file_spec.SetFileSpec(m_opaque_ap->file);
Caroline Tice7826c882010-10-26 03:11:13 +0000137
138 if (log)
139 {
140 SBStream sstr;
141 sb_file_spec.GetDescription (sstr);
142 log->Printf ("SBLineEntry::GetFileSpec ==> SBFileSpec (this = %p, '%s'", &sb_file_spec, sstr.GetData());
143 }
144
Chris Lattner24943d22010-06-08 16:52:24 +0000145 return sb_file_spec;
146}
147
148uint32_t
149SBLineEntry::GetLine () const
150{
Caroline Tice7826c882010-10-26 03:11:13 +0000151 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
152
153 if (log)
154 log->Printf ("SBLineEntry::GetLine ()");
155
156 uint32_t line = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000157 if (m_opaque_ap.get())
Caroline Tice7826c882010-10-26 03:11:13 +0000158 line = m_opaque_ap->line;
159
160 if (log)
161 log->Printf ("SBLineEntry::GetLine ==> %d", line);
162
163 return line;
Chris Lattner24943d22010-06-08 16:52:24 +0000164}
165
166
167uint32_t
168SBLineEntry::GetColumn () const
169{
Greg Clayton63094e02010-06-23 01:19:29 +0000170 if (m_opaque_ap.get())
171 return m_opaque_ap->column;
Chris Lattner24943d22010-06-08 16:52:24 +0000172 return 0;
173}
174
175bool
176SBLineEntry::operator == (const SBLineEntry &rhs) const
177{
Greg Clayton63094e02010-06-23 01:19:29 +0000178 lldb_private::LineEntry *lhs_ptr = m_opaque_ap.get();
179 lldb_private::LineEntry *rhs_ptr = rhs.m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000180
181 if (lhs_ptr && rhs_ptr)
182 return lldb_private::LineEntry::Compare (*lhs_ptr, *rhs_ptr) == 0;
183
184 return lhs_ptr == rhs_ptr;
185}
186
187bool
188SBLineEntry::operator != (const SBLineEntry &rhs) const
189{
Greg Clayton63094e02010-06-23 01:19:29 +0000190 lldb_private::LineEntry *lhs_ptr = m_opaque_ap.get();
191 lldb_private::LineEntry *rhs_ptr = rhs.m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000192
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
199const lldb_private::LineEntry *
200SBLineEntry::operator->() const
201{
Greg Clayton63094e02010-06-23 01:19:29 +0000202 return m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000203}
204
205const lldb_private::LineEntry &
206SBLineEntry::operator*() const
207{
Greg Clayton63094e02010-06-23 01:19:29 +0000208 return *m_opaque_ap;
Chris Lattner24943d22010-06-08 16:52:24 +0000209}
210
Caroline Tice98f930f2010-09-20 05:20:02 +0000211bool
212SBLineEntry::GetDescription (SBStream &description)
213{
214 if (m_opaque_ap.get())
215 {
216 // Line entry: File, line x {, column y}: Addresses: <start_addr> - <end_addr>
217 char file_path[PATH_MAX*2];
218 m_opaque_ap->file.GetPath (file_path, sizeof (file_path));
219 description.Printf ("Line entry: %s, line %d", file_path, GetLine());
220 if (GetColumn() > 0)
221 description.Printf (", column %d", GetColumn());
222 description.Printf (": Addresses: 0x%p - 0x%p", GetStartAddress().GetFileAddress() ,
223 GetEndAddress().GetFileAddress());
224 }
225 else
226 description.Printf ("No value");
Chris Lattner24943d22010-06-08 16:52:24 +0000227
Caroline Tice98f930f2010-09-20 05:20:02 +0000228 return true;
229}