blob: b79761fac8b14ef464ec759b13400b456ea9bc93 [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{
22}
23
24SBLineEntry::SBLineEntry (const SBLineEntry &rhs) :
Greg Clayton63094e02010-06-23 01:19:29 +000025 m_opaque_ap ()
Chris Lattner24943d22010-06-08 16:52:24 +000026{
Caroline Tice61ba7ec2010-10-26 23:49:36 +000027 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Tice7826c882010-10-26 03:11:13 +000028
Chris Lattner24943d22010-06-08 16:52:24 +000029 if (rhs.IsValid())
30 {
Greg Clayton63094e02010-06-23 01:19:29 +000031 m_opaque_ap.reset (new lldb_private::LineEntry (*rhs));
Chris Lattner24943d22010-06-08 16:52:24 +000032 }
Caroline Tice7826c882010-10-26 03:11:13 +000033
34 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +000035 log->Printf ("SBLineEntry::SBLineEntry (rhs.ap=%p) => this.ap = %p ",
36 (rhs.IsValid() ? rhs.m_opaque_ap.get() : NULL), m_opaque_ap.get());
Caroline Tice7826c882010-10-26 03:11:13 +000037
Chris Lattner24943d22010-06-08 16:52:24 +000038}
39
40
41
42SBLineEntry::SBLineEntry (const lldb_private::LineEntry *lldb_object_ptr) :
Greg Clayton63094e02010-06-23 01:19:29 +000043 m_opaque_ap ()
Chris Lattner24943d22010-06-08 16:52:24 +000044{
Caroline Tice61ba7ec2010-10-26 23:49:36 +000045 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Tice7826c882010-10-26 03:11:13 +000046
Chris Lattner24943d22010-06-08 16:52:24 +000047 if (lldb_object_ptr)
Greg Clayton63094e02010-06-23 01:19:29 +000048 m_opaque_ap.reset (new lldb_private::LineEntry(*lldb_object_ptr));
Caroline Tice7826c882010-10-26 03:11:13 +000049
50 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +000051 log->Printf ("SBLineEntry::SBLineEntry (lldb_object_ptr=%p) => this.ap = %p",
52 lldb_object_ptr, m_opaque_ap.get());
Chris Lattner24943d22010-06-08 16:52:24 +000053}
54
55const SBLineEntry &
56SBLineEntry::operator = (const SBLineEntry &rhs)
57{
58 if (this != &rhs)
59 {
60 if (rhs.IsValid())
Greg Clayton63094e02010-06-23 01:19:29 +000061 m_opaque_ap.reset (new lldb_private::LineEntry(*rhs));
Chris Lattner24943d22010-06-08 16:52:24 +000062 }
63 return *this;
64}
65
66void
67SBLineEntry::SetLineEntry (const lldb_private::LineEntry &lldb_object_ref)
68{
Greg Clayton63094e02010-06-23 01:19:29 +000069 if (m_opaque_ap.get())
70 (*m_opaque_ap.get()) = lldb_object_ref;
Chris Lattner24943d22010-06-08 16:52:24 +000071 else
Greg Clayton63094e02010-06-23 01:19:29 +000072 m_opaque_ap.reset (new lldb_private::LineEntry (lldb_object_ref));
Chris Lattner24943d22010-06-08 16:52:24 +000073}
74
75
76SBLineEntry::~SBLineEntry ()
77{
78}
79
80
81SBAddress
82SBLineEntry::GetStartAddress () const
83{
Caroline Tice7826c882010-10-26 03:11:13 +000084 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
85
Caroline Tice61ba7ec2010-10-26 23:49:36 +000086 //if (log)
87 // log->Printf ("SBLineEntry::GetStartAddress ()");
Caroline Tice7826c882010-10-26 03:11:13 +000088
Chris Lattner24943d22010-06-08 16:52:24 +000089 SBAddress sb_address;
Greg Clayton63094e02010-06-23 01:19:29 +000090 if (m_opaque_ap.get())
91 sb_address.SetAddress(&m_opaque_ap->range.GetBaseAddress());
Caroline Tice7826c882010-10-26 03:11:13 +000092
93 if (log)
94 {
95 SBStream sstr;
96 sb_address.GetDescription (sstr);
Caroline Tice61ba7ec2010-10-26 23:49:36 +000097 log->Printf ("SBLineEntry::GetStartAddress (this.ap=%p) => SBAddress (this.ap = %p, (%s)", m_opaque_ap.get(),
98 sb_address.get(), sstr.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +000099 }
100
Chris Lattner24943d22010-06-08 16:52:24 +0000101 return sb_address;
102}
103
104SBAddress
105SBLineEntry::GetEndAddress () const
106{
107 SBAddress sb_address;
Greg Clayton63094e02010-06-23 01:19:29 +0000108 if (m_opaque_ap.get())
Chris Lattner24943d22010-06-08 16:52:24 +0000109 {
Greg Clayton63094e02010-06-23 01:19:29 +0000110 sb_address.SetAddress(&m_opaque_ap->range.GetBaseAddress());
111 sb_address.OffsetAddress(m_opaque_ap->range.GetByteSize());
Chris Lattner24943d22010-06-08 16:52:24 +0000112 }
113 return sb_address;
114}
115
116bool
117SBLineEntry::IsValid () const
118{
Greg Clayton63094e02010-06-23 01:19:29 +0000119 return m_opaque_ap.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +0000120}
121
122
123SBFileSpec
124SBLineEntry::GetFileSpec () const
125{
Caroline Tice7826c882010-10-26 03:11:13 +0000126 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
127
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000128 //if (log)
129 // log->Printf ("SBLineEntry::GetFileSpec ()");
Caroline Tice7826c882010-10-26 03:11:13 +0000130
Chris Lattner24943d22010-06-08 16:52:24 +0000131 SBFileSpec sb_file_spec;
Greg Clayton63094e02010-06-23 01:19:29 +0000132 if (m_opaque_ap.get() && m_opaque_ap->file)
133 sb_file_spec.SetFileSpec(m_opaque_ap->file);
Caroline Tice7826c882010-10-26 03:11:13 +0000134
135 if (log)
136 {
137 SBStream sstr;
138 sb_file_spec.GetDescription (sstr);
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000139 log->Printf ("SBLineEntry::GetFileSpec (this.ap=%p) => SBFileSpec : this.ap = %p, '%s'", m_opaque_ap.get(),
140 sb_file_spec.get(), sstr.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +0000141 }
142
Chris Lattner24943d22010-06-08 16:52:24 +0000143 return sb_file_spec;
144}
145
146uint32_t
147SBLineEntry::GetLine () const
148{
Caroline Tice7826c882010-10-26 03:11:13 +0000149 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
150
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000151 //if (log)
152 // log->Printf ("SBLineEntry::GetLine ()");
Caroline Tice7826c882010-10-26 03:11:13 +0000153
154 uint32_t line = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000155 if (m_opaque_ap.get())
Caroline Tice7826c882010-10-26 03:11:13 +0000156 line = m_opaque_ap->line;
157
158 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000159 log->Printf ("SBLineEntry::GetLine (this.ap=%p) => %d", m_opaque_ap.get(), line);
Caroline Tice7826c882010-10-26 03:11:13 +0000160
161 return line;
Chris Lattner24943d22010-06-08 16:52:24 +0000162}
163
164
165uint32_t
166SBLineEntry::GetColumn () const
167{
Greg Clayton63094e02010-06-23 01:19:29 +0000168 if (m_opaque_ap.get())
169 return m_opaque_ap->column;
Chris Lattner24943d22010-06-08 16:52:24 +0000170 return 0;
171}
172
173bool
174SBLineEntry::operator == (const SBLineEntry &rhs) const
175{
Greg Clayton63094e02010-06-23 01:19:29 +0000176 lldb_private::LineEntry *lhs_ptr = m_opaque_ap.get();
177 lldb_private::LineEntry *rhs_ptr = rhs.m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000178
179 if (lhs_ptr && rhs_ptr)
180 return lldb_private::LineEntry::Compare (*lhs_ptr, *rhs_ptr) == 0;
181
182 return lhs_ptr == rhs_ptr;
183}
184
185bool
186SBLineEntry::operator != (const SBLineEntry &rhs) const
187{
Greg Clayton63094e02010-06-23 01:19:29 +0000188 lldb_private::LineEntry *lhs_ptr = m_opaque_ap.get();
189 lldb_private::LineEntry *rhs_ptr = rhs.m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000190
191 if (lhs_ptr && rhs_ptr)
192 return lldb_private::LineEntry::Compare (*lhs_ptr, *rhs_ptr) != 0;
193
194 return lhs_ptr != rhs_ptr;
195}
196
197const lldb_private::LineEntry *
198SBLineEntry::operator->() const
199{
Greg Clayton63094e02010-06-23 01:19:29 +0000200 return m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000201}
202
203const lldb_private::LineEntry &
204SBLineEntry::operator*() const
205{
Greg Clayton63094e02010-06-23 01:19:29 +0000206 return *m_opaque_ap;
Chris Lattner24943d22010-06-08 16:52:24 +0000207}
208
Caroline Tice98f930f2010-09-20 05:20:02 +0000209bool
210SBLineEntry::GetDescription (SBStream &description)
211{
212 if (m_opaque_ap.get())
213 {
214 // Line entry: File, line x {, column y}: Addresses: <start_addr> - <end_addr>
215 char file_path[PATH_MAX*2];
216 m_opaque_ap->file.GetPath (file_path, sizeof (file_path));
217 description.Printf ("Line entry: %s, line %d", file_path, GetLine());
218 if (GetColumn() > 0)
219 description.Printf (", column %d", GetColumn());
220 description.Printf (": Addresses: 0x%p - 0x%p", GetStartAddress().GetFileAddress() ,
221 GetEndAddress().GetFileAddress());
222 }
223 else
224 description.Printf ("No value");
Chris Lattner24943d22010-06-08 16:52:24 +0000225
Caroline Tice98f930f2010-09-20 05:20:02 +0000226 return true;
227}
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000228
229lldb_private::LineEntry *
230SBLineEntry::get ()
231{
232 return m_opaque_ap.get();
233}