blob: 5187d584b7dcb9d43e50ca2e70bdc1de91962a79 [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"
Greg Clayton49ce6822010-10-31 03:01:06 +000012#include "lldb/Core/StreamString.h"
Caroline Tice7826c882010-10-26 03:11:13 +000013#include "lldb/Core/Log.h"
Greg Clayton49ce6822010-10-31 03:01:06 +000014#include "lldb/Symbol/LineEntry.h"
Chris Lattner24943d22010-06-08 16:52:24 +000015
16using namespace lldb;
Caroline Tice7826c882010-10-26 03:11:13 +000017using namespace lldb_private;
Chris Lattner24943d22010-06-08 16:52:24 +000018
19
20SBLineEntry::SBLineEntry () :
Greg Clayton63094e02010-06-23 01:19:29 +000021 m_opaque_ap ()
Chris Lattner24943d22010-06-08 16:52:24 +000022{
23}
24
25SBLineEntry::SBLineEntry (const SBLineEntry &rhs) :
Greg Clayton63094e02010-06-23 01:19:29 +000026 m_opaque_ap ()
Chris Lattner24943d22010-06-08 16:52:24 +000027{
28 if (rhs.IsValid())
Greg Clayton63094e02010-06-23 01:19:29 +000029 m_opaque_ap.reset (new lldb_private::LineEntry (*rhs));
Chris Lattner24943d22010-06-08 16:52:24 +000030}
31
32
33
34SBLineEntry::SBLineEntry (const lldb_private::LineEntry *lldb_object_ptr) :
Greg Clayton63094e02010-06-23 01:19:29 +000035 m_opaque_ap ()
Chris Lattner24943d22010-06-08 16:52:24 +000036{
37 if (lldb_object_ptr)
Greg Clayton63094e02010-06-23 01:19:29 +000038 m_opaque_ap.reset (new lldb_private::LineEntry(*lldb_object_ptr));
Chris Lattner24943d22010-06-08 16:52:24 +000039}
40
41const SBLineEntry &
42SBLineEntry::operator = (const SBLineEntry &rhs)
43{
Greg Clayton49ce6822010-10-31 03:01:06 +000044 if (this != &rhs && rhs.IsValid())
45 m_opaque_ap.reset (new lldb_private::LineEntry(*rhs));
Chris Lattner24943d22010-06-08 16:52:24 +000046 return *this;
47}
48
49void
50SBLineEntry::SetLineEntry (const lldb_private::LineEntry &lldb_object_ref)
51{
Greg Clayton63094e02010-06-23 01:19:29 +000052 if (m_opaque_ap.get())
53 (*m_opaque_ap.get()) = lldb_object_ref;
Chris Lattner24943d22010-06-08 16:52:24 +000054 else
Greg Clayton63094e02010-06-23 01:19:29 +000055 m_opaque_ap.reset (new lldb_private::LineEntry (lldb_object_ref));
Chris Lattner24943d22010-06-08 16:52:24 +000056}
57
58
59SBLineEntry::~SBLineEntry ()
60{
61}
62
63
64SBAddress
65SBLineEntry::GetStartAddress () const
66{
Caroline Tice7826c882010-10-26 03:11:13 +000067
Chris Lattner24943d22010-06-08 16:52:24 +000068 SBAddress sb_address;
Greg Clayton63094e02010-06-23 01:19:29 +000069 if (m_opaque_ap.get())
70 sb_address.SetAddress(&m_opaque_ap->range.GetBaseAddress());
Caroline Tice7826c882010-10-26 03:11:13 +000071
Greg Claytone005f2c2010-11-06 01:53:30 +000072 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +000073 if (log)
74 {
Greg Clayton49ce6822010-10-31 03:01:06 +000075 StreamString sstr;
76 if (sb_address.get())
77 sb_address->Dump (&sstr, NULL, Address::DumpStyleModuleWithFileAddress, Address::DumpStyleInvalid, 4);
78 log->Printf ("SBLineEntry(%p)::GetStartAddress () => SBAddress (%p): %s",
79 m_opaque_ap.get(), sb_address.get(), sstr.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +000080 }
81
Chris Lattner24943d22010-06-08 16:52:24 +000082 return sb_address;
83}
84
85SBAddress
86SBLineEntry::GetEndAddress () const
87{
88 SBAddress sb_address;
Greg Clayton63094e02010-06-23 01:19:29 +000089 if (m_opaque_ap.get())
Chris Lattner24943d22010-06-08 16:52:24 +000090 {
Greg Clayton63094e02010-06-23 01:19:29 +000091 sb_address.SetAddress(&m_opaque_ap->range.GetBaseAddress());
92 sb_address.OffsetAddress(m_opaque_ap->range.GetByteSize());
Chris Lattner24943d22010-06-08 16:52:24 +000093 }
Greg Claytone005f2c2010-11-06 01:53:30 +000094 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +000095 if (log)
96 {
97 StreamString sstr;
98 if (sb_address.get())
99 sb_address->Dump (&sstr, NULL, Address::DumpStyleModuleWithFileAddress, Address::DumpStyleInvalid, 4);
100 log->Printf ("SBLineEntry(%p)::GetEndAddress () => SBAddress (%p): %s",
101 m_opaque_ap.get(), sb_address.get(), sstr.GetData());
102 }
Chris Lattner24943d22010-06-08 16:52:24 +0000103 return sb_address;
104}
105
106bool
107SBLineEntry::IsValid () const
108{
Greg Clayton63094e02010-06-23 01:19:29 +0000109 return m_opaque_ap.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +0000110}
111
112
113SBFileSpec
114SBLineEntry::GetFileSpec () const
115{
Greg Claytone005f2c2010-11-06 01:53:30 +0000116 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000117
Chris Lattner24943d22010-06-08 16:52:24 +0000118 SBFileSpec sb_file_spec;
Greg Clayton63094e02010-06-23 01:19:29 +0000119 if (m_opaque_ap.get() && m_opaque_ap->file)
120 sb_file_spec.SetFileSpec(m_opaque_ap->file);
Caroline Tice7826c882010-10-26 03:11:13 +0000121
122 if (log)
123 {
124 SBStream sstr;
125 sb_file_spec.GetDescription (sstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000126 log->Printf ("SBLineEntry(%p)::GetFileSpec () => SBFileSpec(%p): %s", m_opaque_ap.get(),
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000127 sb_file_spec.get(), sstr.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +0000128 }
129
Chris Lattner24943d22010-06-08 16:52:24 +0000130 return sb_file_spec;
131}
132
133uint32_t
134SBLineEntry::GetLine () const
135{
Greg Claytone005f2c2010-11-06 01:53:30 +0000136 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000137
Caroline Tice7826c882010-10-26 03:11:13 +0000138 uint32_t line = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000139 if (m_opaque_ap.get())
Caroline Tice7826c882010-10-26 03:11:13 +0000140 line = m_opaque_ap->line;
141
142 if (log)
Greg Clayton49ce6822010-10-31 03:01:06 +0000143 log->Printf ("SBLineEntry(%p)::GetLine () => %u", m_opaque_ap.get(), line);
Caroline Tice7826c882010-10-26 03:11:13 +0000144
145 return line;
Chris Lattner24943d22010-06-08 16:52:24 +0000146}
147
148
149uint32_t
150SBLineEntry::GetColumn () const
151{
Greg Clayton63094e02010-06-23 01:19:29 +0000152 if (m_opaque_ap.get())
153 return m_opaque_ap->column;
Chris Lattner24943d22010-06-08 16:52:24 +0000154 return 0;
155}
156
157bool
158SBLineEntry::operator == (const SBLineEntry &rhs) const
159{
Greg Clayton63094e02010-06-23 01:19:29 +0000160 lldb_private::LineEntry *lhs_ptr = m_opaque_ap.get();
161 lldb_private::LineEntry *rhs_ptr = rhs.m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000162
163 if (lhs_ptr && rhs_ptr)
164 return lldb_private::LineEntry::Compare (*lhs_ptr, *rhs_ptr) == 0;
165
166 return lhs_ptr == rhs_ptr;
167}
168
169bool
170SBLineEntry::operator != (const SBLineEntry &rhs) const
171{
Greg Clayton63094e02010-06-23 01:19:29 +0000172 lldb_private::LineEntry *lhs_ptr = m_opaque_ap.get();
173 lldb_private::LineEntry *rhs_ptr = rhs.m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000174
175 if (lhs_ptr && rhs_ptr)
176 return lldb_private::LineEntry::Compare (*lhs_ptr, *rhs_ptr) != 0;
177
178 return lhs_ptr != rhs_ptr;
179}
180
181const lldb_private::LineEntry *
182SBLineEntry::operator->() const
183{
Greg Clayton63094e02010-06-23 01:19:29 +0000184 return m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000185}
186
187const lldb_private::LineEntry &
188SBLineEntry::operator*() const
189{
Greg Clayton63094e02010-06-23 01:19:29 +0000190 return *m_opaque_ap;
Chris Lattner24943d22010-06-08 16:52:24 +0000191}
192
Caroline Tice98f930f2010-09-20 05:20:02 +0000193bool
194SBLineEntry::GetDescription (SBStream &description)
195{
196 if (m_opaque_ap.get())
197 {
Caroline Tice98f930f2010-09-20 05:20:02 +0000198 char file_path[PATH_MAX*2];
199 m_opaque_ap->file.GetPath (file_path, sizeof (file_path));
Greg Clayton49ce6822010-10-31 03:01:06 +0000200 description.Printf ("%s:%u", file_path, GetLine());
Caroline Tice98f930f2010-09-20 05:20:02 +0000201 if (GetColumn() > 0)
Greg Clayton49ce6822010-10-31 03:01:06 +0000202 description.Printf (":%u", GetColumn());
Caroline Tice98f930f2010-09-20 05:20:02 +0000203 }
204 else
205 description.Printf ("No value");
Chris Lattner24943d22010-06-08 16:52:24 +0000206
Caroline Tice98f930f2010-09-20 05:20:02 +0000207 return true;
208}
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000209
210lldb_private::LineEntry *
211SBLineEntry::get ()
212{
213 return m_opaque_ap.get();
214}