blob: 023afb94aad8cb3bb4c3f667829762f8cda927b5 [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"
13
14using namespace lldb;
15
16
17SBLineEntry::SBLineEntry () :
Greg Clayton63094e02010-06-23 01:19:29 +000018 m_opaque_ap ()
Chris Lattner24943d22010-06-08 16:52:24 +000019{
20}
21
22SBLineEntry::SBLineEntry (const SBLineEntry &rhs) :
Greg Clayton63094e02010-06-23 01:19:29 +000023 m_opaque_ap ()
Chris Lattner24943d22010-06-08 16:52:24 +000024{
25 if (rhs.IsValid())
26 {
Greg Clayton63094e02010-06-23 01:19:29 +000027 m_opaque_ap.reset (new lldb_private::LineEntry (*rhs));
Chris Lattner24943d22010-06-08 16:52:24 +000028 }
29}
30
31
32
33SBLineEntry::SBLineEntry (const lldb_private::LineEntry *lldb_object_ptr) :
Greg Clayton63094e02010-06-23 01:19:29 +000034 m_opaque_ap ()
Chris Lattner24943d22010-06-08 16:52:24 +000035{
36 if (lldb_object_ptr)
Greg Clayton63094e02010-06-23 01:19:29 +000037 m_opaque_ap.reset (new lldb_private::LineEntry(*lldb_object_ptr));
Chris Lattner24943d22010-06-08 16:52:24 +000038}
39
40const SBLineEntry &
41SBLineEntry::operator = (const SBLineEntry &rhs)
42{
43 if (this != &rhs)
44 {
45 if (rhs.IsValid())
Greg Clayton63094e02010-06-23 01:19:29 +000046 m_opaque_ap.reset (new lldb_private::LineEntry(*rhs));
Chris Lattner24943d22010-06-08 16:52:24 +000047 }
48 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{
69 SBAddress sb_address;
Greg Clayton63094e02010-06-23 01:19:29 +000070 if (m_opaque_ap.get())
71 sb_address.SetAddress(&m_opaque_ap->range.GetBaseAddress());
Chris Lattner24943d22010-06-08 16:52:24 +000072 return sb_address;
73}
74
75SBAddress
76SBLineEntry::GetEndAddress () const
77{
78 SBAddress sb_address;
Greg Clayton63094e02010-06-23 01:19:29 +000079 if (m_opaque_ap.get())
Chris Lattner24943d22010-06-08 16:52:24 +000080 {
Greg Clayton63094e02010-06-23 01:19:29 +000081 sb_address.SetAddress(&m_opaque_ap->range.GetBaseAddress());
82 sb_address.OffsetAddress(m_opaque_ap->range.GetByteSize());
Chris Lattner24943d22010-06-08 16:52:24 +000083 }
84 return sb_address;
85}
86
87bool
88SBLineEntry::IsValid () const
89{
Greg Clayton63094e02010-06-23 01:19:29 +000090 return m_opaque_ap.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000091}
92
93
94SBFileSpec
95SBLineEntry::GetFileSpec () const
96{
97 SBFileSpec sb_file_spec;
Greg Clayton63094e02010-06-23 01:19:29 +000098 if (m_opaque_ap.get() && m_opaque_ap->file)
99 sb_file_spec.SetFileSpec(m_opaque_ap->file);
Chris Lattner24943d22010-06-08 16:52:24 +0000100 return sb_file_spec;
101}
102
103uint32_t
104SBLineEntry::GetLine () const
105{
Greg Clayton63094e02010-06-23 01:19:29 +0000106 if (m_opaque_ap.get())
107 return m_opaque_ap->line;
Chris Lattner24943d22010-06-08 16:52:24 +0000108 return 0;
109}
110
111
112uint32_t
113SBLineEntry::GetColumn () const
114{
Greg Clayton63094e02010-06-23 01:19:29 +0000115 if (m_opaque_ap.get())
116 return m_opaque_ap->column;
Chris Lattner24943d22010-06-08 16:52:24 +0000117 return 0;
118}
119
120bool
121SBLineEntry::operator == (const SBLineEntry &rhs) const
122{
Greg Clayton63094e02010-06-23 01:19:29 +0000123 lldb_private::LineEntry *lhs_ptr = m_opaque_ap.get();
124 lldb_private::LineEntry *rhs_ptr = rhs.m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000125
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
132bool
133SBLineEntry::operator != (const SBLineEntry &rhs) const
134{
Greg Clayton63094e02010-06-23 01:19:29 +0000135 lldb_private::LineEntry *lhs_ptr = m_opaque_ap.get();
136 lldb_private::LineEntry *rhs_ptr = rhs.m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000137
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
144const lldb_private::LineEntry *
145SBLineEntry::operator->() const
146{
Greg Clayton63094e02010-06-23 01:19:29 +0000147 return m_opaque_ap.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000148}
149
150const lldb_private::LineEntry &
151SBLineEntry::operator*() const
152{
Greg Clayton63094e02010-06-23 01:19:29 +0000153 return *m_opaque_ap;
Chris Lattner24943d22010-06-08 16:52:24 +0000154}
155
Caroline Tice98f930f2010-09-20 05:20:02 +0000156bool
157SBLineEntry::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");
Chris Lattner24943d22010-06-08 16:52:24 +0000172
Caroline Tice98f930f2010-09-20 05:20:02 +0000173 return true;
174}