blob: 482ecec1ce699fbd88188f1963d78289ed6ba8e2 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- 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/Core/Address.h"
13
14using namespace lldb;
15
16
17SBAddress::SBAddress () :
18 m_lldb_object_ap ()
19{
20}
21
22SBAddress::SBAddress (const lldb_private::Address *lldb_object_ptr) :
23 m_lldb_object_ap ()
24{
25 if (lldb_object_ptr)
26 m_lldb_object_ap.reset (new lldb_private::Address(*lldb_object_ptr));
27}
28
29SBAddress::SBAddress (const SBAddress &rhs) :
30 m_lldb_object_ap ()
31{
32 if (rhs.IsValid())
33 m_lldb_object_ap.reset (new lldb_private::Address(*rhs.m_lldb_object_ap.get()));
34}
35
36SBAddress::~SBAddress ()
37{
38}
39
40const SBAddress &
41SBAddress::operator = (const SBAddress &rhs)
42{
43 if (this != &rhs)
44 {
45 if (rhs.IsValid())
46 m_lldb_object_ap.reset (new lldb_private::Address(*rhs.m_lldb_object_ap.get()));
47 }
48 return *this;
49}
50
51bool
52SBAddress::IsValid () const
53{
54 return m_lldb_object_ap.get() != NULL && m_lldb_object_ap->IsValid();
55}
56
57void
58SBAddress::SetAddress (const lldb_private::Address *lldb_object_ptr)
59{
60 if (lldb_object_ptr)
61 {
62 if (m_lldb_object_ap.get())
63 *m_lldb_object_ap = *lldb_object_ptr;
64 else
65 m_lldb_object_ap.reset (new lldb_private::Address(*lldb_object_ptr));
66 return;
67 }
68 if (m_lldb_object_ap.get())
69 m_lldb_object_ap->Clear();
70}
71
72lldb::addr_t
73SBAddress::GetFileAddress () const
74{
75 if (m_lldb_object_ap.get())
76 return m_lldb_object_ap->GetFileAddress();
77 else
78 return LLDB_INVALID_ADDRESS;
79}
80
81lldb::addr_t
82SBAddress::GetLoadAddress (const SBProcess &process) const
83{
84 if (m_lldb_object_ap.get())
85 return m_lldb_object_ap->GetLoadAddress(process.get());
86 else
87 return LLDB_INVALID_ADDRESS;
88}
89
90bool
91SBAddress::OffsetAddress (addr_t offset)
92{
93 if (m_lldb_object_ap.get())
94 {
95 addr_t addr_offset = m_lldb_object_ap->GetOffset();
96 if (addr_offset != LLDB_INVALID_ADDRESS)
97 {
98 m_lldb_object_ap->SetOffset(addr_offset + offset);
99 return true;
100 }
101 }
102 return false;
103}
104
105
106const lldb_private::Address *
107SBAddress::operator->() const
108{
109 return m_lldb_object_ap.get();
110}
111
112const lldb_private::Address &
113SBAddress::operator*() const
114{
115 return *m_lldb_object_ap;
116}
117
118