Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1 | //===-- SBWatchpointLocation.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/SBWatchpointLocation.h" |
| 11 | #include "lldb/API/SBDefines.h" |
| 12 | #include "lldb/API/SBAddress.h" |
| 13 | #include "lldb/API/SBDebugger.h" |
| 14 | #include "lldb/API/SBStream.h" |
| 15 | |
| 16 | #include "lldb/lldb-types.h" |
| 17 | #include "lldb/lldb-defines.h" |
| 18 | #include "lldb/Breakpoint/WatchpointLocation.h" |
| 19 | #include "lldb/Breakpoint/WatchpointLocationList.h" |
| 20 | #include "lldb/Core/Log.h" |
| 21 | #include "lldb/Core/Stream.h" |
| 22 | #include "lldb/Core/StreamFile.h" |
| 23 | #include "lldb/Target/Target.h" |
| 24 | |
| 25 | using namespace lldb; |
| 26 | using namespace lldb_private; |
| 27 | |
| 28 | |
| 29 | SBWatchpointLocation::SBWatchpointLocation () : |
| 30 | m_opaque_sp () |
| 31 | { |
| 32 | } |
| 33 | |
| 34 | SBWatchpointLocation::SBWatchpointLocation (const lldb::WatchpointLocationSP &watch_loc_sp) : |
| 35 | m_opaque_sp (watch_loc_sp) |
| 36 | { |
| 37 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 38 | |
| 39 | if (log) |
| 40 | { |
| 41 | SBStream sstr; |
| 42 | GetDescription (sstr, lldb::eDescriptionLevelBrief); |
| 43 | log->Printf ("SBWatchpointLocation::SBWatchpointLocation (const lldb::WatchpointLocationsSP &watch_loc_sp" |
| 44 | "=%p) => this.sp = %p (%s)", watch_loc_sp.get(), m_opaque_sp.get(), sstr.GetData()); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | SBWatchpointLocation::SBWatchpointLocation(const SBWatchpointLocation &rhs) : |
| 49 | m_opaque_sp (rhs.m_opaque_sp) |
| 50 | { |
| 51 | } |
| 52 | |
| 53 | const SBWatchpointLocation & |
| 54 | SBWatchpointLocation::operator = (const SBWatchpointLocation &rhs) |
| 55 | { |
| 56 | if (this != &rhs) |
| 57 | m_opaque_sp = rhs.m_opaque_sp; |
| 58 | return *this; |
| 59 | } |
| 60 | |
| 61 | |
| 62 | SBWatchpointLocation::~SBWatchpointLocation () |
| 63 | { |
| 64 | } |
| 65 | |
| 66 | bool |
| 67 | SBWatchpointLocation::IsValid() const |
| 68 | { |
| 69 | return m_opaque_sp.get() != NULL; |
| 70 | } |
| 71 | |
| 72 | addr_t |
| 73 | SBWatchpointLocation::GetWatchAddress () const |
| 74 | { |
| 75 | addr_t ret_addr = LLDB_INVALID_ADDRESS; |
| 76 | |
| 77 | if (m_opaque_sp) |
| 78 | { |
| 79 | Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); |
| 80 | ret_addr = m_opaque_sp->GetLoadAddress(); |
| 81 | } |
| 82 | |
| 83 | return ret_addr; |
| 84 | } |
| 85 | |
| 86 | size_t |
| 87 | SBWatchpointLocation::GetWatchSize () const |
| 88 | { |
| 89 | size_t watch_size = 0; |
| 90 | |
| 91 | if (m_opaque_sp) |
| 92 | { |
| 93 | Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); |
| 94 | watch_size = m_opaque_sp->GetByteSize(); |
| 95 | } |
| 96 | |
| 97 | return watch_size; |
| 98 | } |
| 99 | |
| 100 | void |
| 101 | SBWatchpointLocation::SetEnabled (bool enabled) |
| 102 | { |
| 103 | if (m_opaque_sp) |
| 104 | { |
| 105 | Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); |
| 106 | m_opaque_sp->SetEnabled (enabled); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | bool |
| 111 | SBWatchpointLocation::IsEnabled () |
| 112 | { |
| 113 | if (m_opaque_sp) |
| 114 | { |
| 115 | Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); |
| 116 | return m_opaque_sp->IsEnabled(); |
| 117 | } |
| 118 | else |
| 119 | return false; |
| 120 | } |
| 121 | |
| 122 | uint32_t |
| 123 | SBWatchpointLocation::GetIgnoreCount () |
| 124 | { |
| 125 | if (m_opaque_sp) |
| 126 | { |
| 127 | Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); |
| 128 | return m_opaque_sp->GetIgnoreCount(); |
| 129 | } |
| 130 | else |
| 131 | return 0; |
| 132 | } |
| 133 | |
| 134 | void |
| 135 | SBWatchpointLocation::SetIgnoreCount (uint32_t n) |
| 136 | { |
| 137 | if (m_opaque_sp) |
| 138 | { |
| 139 | Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); |
| 140 | m_opaque_sp->SetIgnoreCount (n); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | bool |
| 145 | SBWatchpointLocation::GetDescription (SBStream &description, DescriptionLevel level) |
| 146 | { |
| 147 | if (m_opaque_sp) |
| 148 | { |
| 149 | Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); |
| 150 | description.ref(); |
| 151 | m_opaque_sp->GetDescription (description.get(), level); |
| 152 | description.get()->EOL(); |
| 153 | } |
| 154 | else |
| 155 | description.Printf ("No value"); |
| 156 | |
| 157 | return true; |
| 158 | } |
| 159 | |
| 160 | lldb_private::WatchpointLocation * |
| 161 | SBWatchpointLocation::operator->() const |
| 162 | { |
| 163 | return m_opaque_sp.get(); |
| 164 | } |
| 165 | |
| 166 | lldb_private::WatchpointLocation * |
| 167 | SBWatchpointLocation::get() const |
| 168 | { |
| 169 | return m_opaque_sp.get(); |
| 170 | } |
| 171 | |
| 172 | lldb::WatchpointLocationSP & |
| 173 | SBWatchpointLocation::operator *() |
| 174 | { |
| 175 | return m_opaque_sp; |
| 176 | } |
| 177 | |
| 178 | const lldb::WatchpointLocationSP & |
| 179 | SBWatchpointLocation::operator *() const |
| 180 | { |
| 181 | return m_opaque_sp; |
| 182 | } |
| 183 | |