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 "lldb/API/SBLineEntry.h"
11 #include "lldb/API/SBStream.h"
12 #include "lldb/Symbol/LineEntry.h"
13 
14 using namespace lldb;
15 
16 
17 SBLineEntry::SBLineEntry () :
18     m_opaque_ap ()
19 {
20 }
21 
22 SBLineEntry::SBLineEntry (const SBLineEntry &rhs) :
23     m_opaque_ap ()
24 {
25     if (rhs.IsValid())
26     {
27         m_opaque_ap.reset (new lldb_private::LineEntry (*rhs));
28     }
29 }
30 
31 
32 
33 SBLineEntry::SBLineEntry (const lldb_private::LineEntry *lldb_object_ptr) :
34     m_opaque_ap ()
35 {
36     if (lldb_object_ptr)
37         m_opaque_ap.reset (new lldb_private::LineEntry(*lldb_object_ptr));
38 }
39 
40 const SBLineEntry &
41 SBLineEntry::operator = (const SBLineEntry &rhs)
42 {
43     if (this != &rhs)
44     {
45         if (rhs.IsValid())
46             m_opaque_ap.reset (new lldb_private::LineEntry(*rhs));
47     }
48     return *this;
49 }
50 
51 void
52 SBLineEntry::SetLineEntry (const lldb_private::LineEntry &lldb_object_ref)
53 {
54     if (m_opaque_ap.get())
55         (*m_opaque_ap.get()) = lldb_object_ref;
56     else
57         m_opaque_ap.reset (new lldb_private::LineEntry (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     return sb_address;
73 }
74 
75 SBAddress
76 SBLineEntry::GetEndAddress () const
77 {
78     SBAddress sb_address;
79     if (m_opaque_ap.get())
80     {
81         sb_address.SetAddress(&m_opaque_ap->range.GetBaseAddress());
82         sb_address.OffsetAddress(m_opaque_ap->range.GetByteSize());
83     }
84     return sb_address;
85 }
86 
87 bool
88 SBLineEntry::IsValid () const
89 {
90     return m_opaque_ap.get() != NULL;
91 }
92 
93 
94 SBFileSpec
95 SBLineEntry::GetFileSpec () const
96 {
97     SBFileSpec sb_file_spec;
98     if (m_opaque_ap.get() && m_opaque_ap->file)
99         sb_file_spec.SetFileSpec(m_opaque_ap->file);
100     return sb_file_spec;
101 }
102 
103 uint32_t
104 SBLineEntry::GetLine () const
105 {
106     if (m_opaque_ap.get())
107         return m_opaque_ap->line;
108     return 0;
109 }
110 
111 
112 uint32_t
113 SBLineEntry::GetColumn () const
114 {
115     if (m_opaque_ap.get())
116         return m_opaque_ap->column;
117     return 0;
118 }
119 
120 bool
121 SBLineEntry::operator == (const SBLineEntry &rhs) const
122 {
123     lldb_private::LineEntry *lhs_ptr = m_opaque_ap.get();
124     lldb_private::LineEntry *rhs_ptr = rhs.m_opaque_ap.get();
125 
126     if (lhs_ptr && rhs_ptr)
127         return lldb_private::LineEntry::Compare (*lhs_ptr, *rhs_ptr) == 0;
128 
129     return lhs_ptr == rhs_ptr;
130 }
131 
132 bool
133 SBLineEntry::operator != (const SBLineEntry &rhs) const
134 {
135     lldb_private::LineEntry *lhs_ptr = m_opaque_ap.get();
136     lldb_private::LineEntry *rhs_ptr = rhs.m_opaque_ap.get();
137 
138     if (lhs_ptr && rhs_ptr)
139         return lldb_private::LineEntry::Compare (*lhs_ptr, *rhs_ptr) != 0;
140 
141     return lhs_ptr != rhs_ptr;
142 }
143 
144 const lldb_private::LineEntry *
145 SBLineEntry::operator->() const
146 {
147     return m_opaque_ap.get();
148 }
149 
150 const lldb_private::LineEntry &
151 SBLineEntry::operator*() const
152 {
153     return *m_opaque_ap;
154 }
155 
156 bool
157 SBLineEntry::GetDescription (SBStream &description)
158 {
159     if (m_opaque_ap.get())
160     {
161         // Line entry:  File, line x {, column y}:  Addresses: <start_addr> - <end_addr>
162         char file_path[PATH_MAX*2];
163         m_opaque_ap->file.GetPath (file_path, sizeof (file_path));
164         description.Printf ("Line entry: %s, line %d", file_path, GetLine());
165         if (GetColumn() > 0)
166             description.Printf (", column %d", GetColumn());
167         description.Printf (":  Addresses:  0x%p - 0x%p", GetStartAddress().GetFileAddress() ,
168                             GetEndAddress().GetFileAddress());
169     }
170     else
171         description.Printf ("No value");
172 
173     return true;
174 }
175