1 //===-- SBAddress.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/SBAddress.h"
11 #include "lldb/API/SBProcess.h"
12 #include "lldb/API/SBStream.h"
13 #include "lldb/Core/Address.h"
14 
15 using namespace lldb;
16 
17 
18 SBAddress::SBAddress () :
19     m_opaque_ap ()
20 {
21 }
22 
23 SBAddress::SBAddress (const lldb_private::Address *lldb_object_ptr) :
24     m_opaque_ap ()
25 {
26     if (lldb_object_ptr)
27         m_opaque_ap.reset (new lldb_private::Address(*lldb_object_ptr));
28 }
29 
30 SBAddress::SBAddress (const SBAddress &rhs) :
31     m_opaque_ap ()
32 {
33     if (rhs.IsValid())
34         m_opaque_ap.reset (new lldb_private::Address(*rhs.m_opaque_ap.get()));
35 }
36 
37 SBAddress::~SBAddress ()
38 {
39 }
40 
41 const SBAddress &
42 SBAddress::operator = (const SBAddress &rhs)
43 {
44     if (this != &rhs)
45     {
46         if (rhs.IsValid())
47             m_opaque_ap.reset (new lldb_private::Address(*rhs.m_opaque_ap.get()));
48     }
49     return *this;
50 }
51 
52 bool
53 SBAddress::IsValid () const
54 {
55     return m_opaque_ap.get() != NULL && m_opaque_ap->IsValid();
56 }
57 
58 void
59 SBAddress::Clear ()
60 {
61     m_opaque_ap.reset();
62 }
63 
64 void
65 SBAddress::SetAddress (const lldb_private::Address *lldb_object_ptr)
66 {
67     if (lldb_object_ptr)
68     {
69         if (m_opaque_ap.get())
70             *m_opaque_ap = *lldb_object_ptr;
71         else
72             m_opaque_ap.reset (new lldb_private::Address(*lldb_object_ptr));
73         return;
74     }
75     if (m_opaque_ap.get())
76         m_opaque_ap->Clear();
77 }
78 
79 lldb::addr_t
80 SBAddress::GetFileAddress () const
81 {
82     if (m_opaque_ap.get())
83         return m_opaque_ap->GetFileAddress();
84     else
85         return LLDB_INVALID_ADDRESS;
86 }
87 
88 lldb::addr_t
89 SBAddress::GetLoadAddress (const SBTarget &target) const
90 {
91     if (m_opaque_ap.get())
92         return m_opaque_ap->GetLoadAddress(target.get());
93     else
94         return LLDB_INVALID_ADDRESS;
95 }
96 
97 bool
98 SBAddress::OffsetAddress (addr_t offset)
99 {
100     if (m_opaque_ap.get())
101     {
102         addr_t addr_offset = m_opaque_ap->GetOffset();
103         if (addr_offset != LLDB_INVALID_ADDRESS)
104         {
105             m_opaque_ap->SetOffset(addr_offset + offset);
106             return true;
107         }
108     }
109     return false;
110 }
111 
112 lldb_private::Address *
113 SBAddress::operator->()
114 {
115     return m_opaque_ap.get();
116 }
117 
118 const lldb_private::Address *
119 SBAddress::operator->() const
120 {
121     return m_opaque_ap.get();
122 }
123 
124 lldb_private::Address &
125 SBAddress::operator*()
126 {
127     if (m_opaque_ap.get() == NULL)
128         m_opaque_ap.reset (new lldb_private::Address);
129     return *m_opaque_ap;
130 }
131 
132 const lldb_private::Address &
133 SBAddress::operator*() const
134 {
135     assert (m_opaque_ap.get());
136     return *m_opaque_ap;
137 }
138 
139 
140 bool
141 SBAddress::GetDescription (SBStream &description)
142 {
143     description.ref();
144     if (m_opaque_ap.get())
145     {
146         m_opaque_ap->DumpDebug (description.get());
147     }
148     else
149         description.Printf ("No value");
150 
151     return true;
152 }
153