blob: 3567a3839c5d5b8a2a70047e3d3b6181fc506bc9 [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
Stephen Wilsonec2d9782011-04-08 13:36:44 +000010#include <limits.h>
11
Chris Lattner24943d22010-06-08 16:52:24 +000012#include "lldb/API/SBLineEntry.h"
Caroline Tice98f930f2010-09-20 05:20:02 +000013#include "lldb/API/SBStream.h"
Greg Clayton49ce6822010-10-31 03:01:06 +000014#include "lldb/Core/StreamString.h"
Caroline Tice7826c882010-10-26 03:11:13 +000015#include "lldb/Core/Log.h"
Greg Clayton49ce6822010-10-31 03:01:06 +000016#include "lldb/Symbol/LineEntry.h"
Chris Lattner24943d22010-06-08 16:52:24 +000017
18using namespace lldb;
Caroline Tice7826c882010-10-26 03:11:13 +000019using namespace lldb_private;
Chris Lattner24943d22010-06-08 16:52:24 +000020
21
22SBLineEntry::SBLineEntry () :
Greg Clayton63094e02010-06-23 01:19:29 +000023 m_opaque_ap ()
Chris Lattner24943d22010-06-08 16:52:24 +000024{
25}
26
27SBLineEntry::SBLineEntry (const SBLineEntry &rhs) :
Greg Clayton63094e02010-06-23 01:19:29 +000028 m_opaque_ap ()
Chris Lattner24943d22010-06-08 16:52:24 +000029{
30 if (rhs.IsValid())
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}
33
34
35
36SBLineEntry::SBLineEntry (const lldb_private::LineEntry *lldb_object_ptr) :
Greg Clayton63094e02010-06-23 01:19:29 +000037 m_opaque_ap ()
Chris Lattner24943d22010-06-08 16:52:24 +000038{
39 if (lldb_object_ptr)
Greg Clayton63094e02010-06-23 01:19:29 +000040 m_opaque_ap.reset (new lldb_private::LineEntry(*lldb_object_ptr));
Chris Lattner24943d22010-06-08 16:52:24 +000041}
42
43const SBLineEntry &
44SBLineEntry::operator = (const SBLineEntry &rhs)
45{
Greg Clayton49ce6822010-10-31 03:01:06 +000046 if (this != &rhs && rhs.IsValid())
47 m_opaque_ap.reset (new lldb_private::LineEntry(*rhs));
Chris Lattner24943d22010-06-08 16:52:24 +000048 return *this;
49}
50
51void
52SBLineEntry::SetLineEntry (const lldb_private::LineEntry &lldb_object_ref)
53{
Greg Clayton63094e02010-06-23 01:19:29 +000054 if (m_opaque_ap.get())
55 (*m_opaque_ap.get()) = lldb_object_ref;
Chris Lattner24943d22010-06-08 16:52:24 +000056 else
Greg Clayton63094e02010-06-23 01:19:29 +000057 m_opaque_ap.reset (new lldb_private::LineEntry (lldb_object_ref));
Chris Lattner24943d22010-06-08 16:52:24 +000058}
59
60
61SBLineEntry::~SBLineEntry ()
62{
63}
64
65
66SBAddress
67SBLineEntry::GetStartAddress () const
68{
Caroline Tice7826c882010-10-26 03:11:13 +000069
Chris Lattner24943d22010-06-08 16:52:24 +000070 SBAddress sb_address;
Greg Clayton63094e02010-06-23 01:19:29 +000071 if (m_opaque_ap.get())
72 sb_address.SetAddress(&m_opaque_ap->range.GetBaseAddress());
Caroline Tice7826c882010-10-26 03:11:13 +000073
Greg Claytone005f2c2010-11-06 01:53:30 +000074 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +000075 if (log)
76 {
Greg Clayton49ce6822010-10-31 03:01:06 +000077 StreamString sstr;
78 if (sb_address.get())
79 sb_address->Dump (&sstr, NULL, Address::DumpStyleModuleWithFileAddress, Address::DumpStyleInvalid, 4);
80 log->Printf ("SBLineEntry(%p)::GetStartAddress () => SBAddress (%p): %s",
81 m_opaque_ap.get(), sb_address.get(), sstr.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +000082 }
83
Chris Lattner24943d22010-06-08 16:52:24 +000084 return sb_address;
85}
86
87SBAddress
88SBLineEntry::GetEndAddress () const
89{
90 SBAddress sb_address;
Greg Clayton63094e02010-06-23 01:19:29 +000091 if (m_opaque_ap.get())
Chris Lattner24943d22010-06-08 16:52:24 +000092 {
Greg Clayton63094e02010-06-23 01:19:29 +000093 sb_address.SetAddress(&m_opaque_ap->range.GetBaseAddress());
94 sb_address.OffsetAddress(m_opaque_ap->range.GetByteSize());
Chris Lattner24943d22010-06-08 16:52:24 +000095 }
Greg Claytone005f2c2010-11-06 01:53:30 +000096 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +000097 if (log)
98 {
99 StreamString sstr;
100 if (sb_address.get())
101 sb_address->Dump (&sstr, NULL, Address::DumpStyleModuleWithFileAddress, Address::DumpStyleInvalid, 4);
102 log->Printf ("SBLineEntry(%p)::GetEndAddress () => SBAddress (%p): %s",
103 m_opaque_ap.get(), sb_address.get(), sstr.GetData());
104 }
Chris Lattner24943d22010-06-08 16:52:24 +0000105 return sb_address;
106}
107
108bool
109SBLineEntry::IsValid () const
110{
Greg Clayton63094e02010-06-23 01:19:29 +0000111 return m_opaque_ap.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +0000112}
113
114
115SBFileSpec
116SBLineEntry::GetFileSpec () const
117{
Greg Claytone005f2c2010-11-06 01:53:30 +0000118 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000119
Chris Lattner24943d22010-06-08 16:52:24 +0000120 SBFileSpec sb_file_spec;
Greg Clayton63094e02010-06-23 01:19:29 +0000121 if (m_opaque_ap.get() && m_opaque_ap->file)
122 sb_file_spec.SetFileSpec(m_opaque_ap->file);
Caroline Tice7826c882010-10-26 03:11:13 +0000123
124 if (log)
125 {
126 SBStream sstr;
127 sb_file_spec.GetDescription (sstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000128 log->Printf ("SBLineEntry(%p)::GetFileSpec () => SBFileSpec(%p): %s", m_opaque_ap.get(),
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000129 sb_file_spec.get(), sstr.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +0000130 }
131
Chris Lattner24943d22010-06-08 16:52:24 +0000132 return sb_file_spec;
133}
134
135uint32_t
136SBLineEntry::GetLine () const
137{
Greg Claytone005f2c2010-11-06 01:53:30 +0000138 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000139
Caroline Tice7826c882010-10-26 03:11:13 +0000140 uint32_t line = 0;
Greg Clayton63094e02010-06-23 01:19:29 +0000141 if (m_opaque_ap.get())
Caroline Tice7826c882010-10-26 03:11:13 +0000142 line = m_opaque_ap->line;
143
144 if (log)
Greg Clayton49ce6822010-10-31 03:01:06 +0000145 log->Printf ("SBLineEntry(%p)::GetLine () => %u", m_opaque_ap.get(), line);
Caroline Tice7826c882010-10-26 03:11:13 +0000146
147 return line;
Chris Lattner24943d22010-06-08 16:52:24 +0000148}
149
150
151uint32_t
152SBLineEntry::GetColumn () const
153{
Greg Clayton63094e02010-06-23 01:19:29 +0000154 if (m_opaque_ap.get())
155 return m_opaque_ap->column;
Chris Lattner24943d22010-06-08 16:52:24 +0000156 return 0;
157}
158
159bool
160SBLineEntry::operator == (const SBLineEntry &rhs) const
161{
Greg Clayton63094e02010-06-23 01:19:29 +0000162 lldb_private::LineEntry *lhs_ptr = m_opaque_ap.get();
163 lldb_private::LineEntry *rhs_ptr = rhs.m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000164
165 if (lhs_ptr && rhs_ptr)
166 return lldb_private::LineEntry::Compare (*lhs_ptr, *rhs_ptr) == 0;
167
168 return lhs_ptr == rhs_ptr;
169}
170
171bool
172SBLineEntry::operator != (const SBLineEntry &rhs) const
173{
Greg Clayton63094e02010-06-23 01:19:29 +0000174 lldb_private::LineEntry *lhs_ptr = m_opaque_ap.get();
175 lldb_private::LineEntry *rhs_ptr = rhs.m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000176
177 if (lhs_ptr && rhs_ptr)
178 return lldb_private::LineEntry::Compare (*lhs_ptr, *rhs_ptr) != 0;
179
180 return lhs_ptr != rhs_ptr;
181}
182
183const lldb_private::LineEntry *
184SBLineEntry::operator->() const
185{
Greg Clayton63094e02010-06-23 01:19:29 +0000186 return m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000187}
188
189const lldb_private::LineEntry &
190SBLineEntry::operator*() const
191{
Greg Clayton63094e02010-06-23 01:19:29 +0000192 return *m_opaque_ap;
Chris Lattner24943d22010-06-08 16:52:24 +0000193}
194
Caroline Tice98f930f2010-09-20 05:20:02 +0000195bool
196SBLineEntry::GetDescription (SBStream &description)
197{
198 if (m_opaque_ap.get())
199 {
Caroline Tice98f930f2010-09-20 05:20:02 +0000200 char file_path[PATH_MAX*2];
201 m_opaque_ap->file.GetPath (file_path, sizeof (file_path));
Greg Clayton49ce6822010-10-31 03:01:06 +0000202 description.Printf ("%s:%u", file_path, GetLine());
Caroline Tice98f930f2010-09-20 05:20:02 +0000203 if (GetColumn() > 0)
Greg Clayton49ce6822010-10-31 03:01:06 +0000204 description.Printf (":%u", GetColumn());
Caroline Tice98f930f2010-09-20 05:20:02 +0000205 }
206 else
207 description.Printf ("No value");
Chris Lattner24943d22010-06-08 16:52:24 +0000208
Caroline Tice98f930f2010-09-20 05:20:02 +0000209 return true;
210}
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000211
212lldb_private::LineEntry *
213SBLineEntry::get ()
214{
215 return m_opaque_ap.get();
216}