1 //===-- SBWatchpoint.cpp --------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/API/SBWatchpoint.h"
11 #include "lldb/API/SBDefines.h"
12 #include "lldb/API/SBAddress.h"
13 #include "lldb/API/SBDebugger.h"
14 #include "lldb/API/SBEvent.h"
15 #include "lldb/API/SBStream.h"
17 #include "lldb/lldb-types.h"
18 #include "lldb/lldb-defines.h"
19 #include "lldb/Breakpoint/Watchpoint.h"
20 #include "lldb/Breakpoint/WatchpointList.h"
21 #include "lldb/Core/Log.h"
22 #include "lldb/Core/Stream.h"
23 #include "lldb/Core/StreamFile.h"
24 #include "lldb/Target/Target.h"
27 using namespace lldb_private;
30 SBWatchpoint::SBWatchpoint () :
35 SBWatchpoint::SBWatchpoint (const lldb::WatchpointSP &wp_sp) :
38 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
43 GetDescription (sstr, lldb::eDescriptionLevelBrief);
44 log->Printf ("SBWatchpoint::SBWatchpoint (const lldb::WatchpointSP &wp_sp"
45 "=%p) => this.sp = %p (%s)", wp_sp.get(), m_opaque_sp.get(), sstr.GetData());
49 SBWatchpoint::SBWatchpoint(const SBWatchpoint &rhs) :
50 m_opaque_sp (rhs.m_opaque_sp)
55 SBWatchpoint::operator = (const SBWatchpoint &rhs)
58 m_opaque_sp = rhs.m_opaque_sp;
63 SBWatchpoint::~SBWatchpoint ()
68 SBWatchpoint::GetID ()
70 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
72 watch_id_t watch_id = LLDB_INVALID_WATCH_ID;
73 lldb::WatchpointSP watchpoint_sp(GetSP());
75 watch_id = watchpoint_sp->GetID();
79 if (watch_id == LLDB_INVALID_WATCH_ID)
80 log->Printf ("SBWatchpoint(%p)::GetID () => LLDB_INVALID_WATCH_ID", watchpoint_sp.get());
82 log->Printf ("SBWatchpoint(%p)::GetID () => %u", watchpoint_sp.get(), watch_id);
89 SBWatchpoint::IsValid() const
91 return (bool) m_opaque_sp;
95 SBWatchpoint::GetError ()
98 lldb::WatchpointSP watchpoint_sp(GetSP());
101 sb_error.SetError(watchpoint_sp->GetError());
107 SBWatchpoint::GetHardwareIndex ()
109 int32_t hw_index = -1;
111 lldb::WatchpointSP watchpoint_sp(GetSP());
114 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
115 hw_index = watchpoint_sp->GetHardwareIndex();
122 SBWatchpoint::GetWatchAddress ()
124 addr_t ret_addr = LLDB_INVALID_ADDRESS;
126 lldb::WatchpointSP watchpoint_sp(GetSP());
129 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
130 ret_addr = watchpoint_sp->GetLoadAddress();
137 SBWatchpoint::GetWatchSize ()
139 size_t watch_size = 0;
141 lldb::WatchpointSP watchpoint_sp(GetSP());
144 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
145 watch_size = watchpoint_sp->GetByteSize();
152 SBWatchpoint::SetEnabled (bool enabled)
154 lldb::WatchpointSP watchpoint_sp(GetSP());
157 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
158 watchpoint_sp->GetTarget().DisableWatchpointByID(watchpoint_sp->GetID());
163 SBWatchpoint::IsEnabled ()
165 lldb::WatchpointSP watchpoint_sp(GetSP());
168 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
169 return watchpoint_sp->IsEnabled();
176 SBWatchpoint::GetHitCount ()
179 lldb::WatchpointSP watchpoint_sp(GetSP());
182 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
183 count = watchpoint_sp->GetHitCount();
186 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
188 log->Printf ("SBWatchpoint(%p)::GetHitCount () => %u", watchpoint_sp.get(), count);
194 SBWatchpoint::GetIgnoreCount ()
196 lldb::WatchpointSP watchpoint_sp(GetSP());
199 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
200 return watchpoint_sp->GetIgnoreCount();
207 SBWatchpoint::SetIgnoreCount (uint32_t n)
209 lldb::WatchpointSP watchpoint_sp(GetSP());
212 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
213 watchpoint_sp->SetIgnoreCount (n);
218 SBWatchpoint::GetCondition ()
220 lldb::WatchpointSP watchpoint_sp(GetSP());
223 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
224 return watchpoint_sp->GetConditionText ();
230 SBWatchpoint::SetCondition (const char *condition)
232 lldb::WatchpointSP watchpoint_sp(GetSP());
235 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
236 watchpoint_sp->SetCondition (condition);
241 SBWatchpoint::GetDescription (SBStream &description, DescriptionLevel level)
243 Stream &strm = description.ref();
245 lldb::WatchpointSP watchpoint_sp(GetSP());
248 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
249 watchpoint_sp->GetDescription (&strm, level);
253 strm.PutCString ("No value");
259 SBWatchpoint::Clear ()
265 SBWatchpoint::GetSP () const
271 SBWatchpoint::SetSP (const lldb::WatchpointSP &sp)
277 SBWatchpoint::EventIsWatchpointEvent (const lldb::SBEvent &event)
279 return Watchpoint::WatchpointEventData::GetEventDataFromEvent(event.get()) != NULL;
284 SBWatchpoint::GetWatchpointEventTypeFromEvent (const SBEvent& event)
287 return Watchpoint::WatchpointEventData::GetWatchpointEventTypeFromEvent (event.GetSP());
288 return eWatchpointEventTypeInvalidType;
292 SBWatchpoint::GetWatchpointFromEvent (const lldb::SBEvent& event)
294 SBWatchpoint sb_watchpoint;
296 sb_watchpoint.m_opaque_sp = Watchpoint::WatchpointEventData::GetWatchpointFromEvent (event.GetSP());
297 return sb_watchpoint;