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)",
46 static_cast<void*>(wp_sp.get()),
47 static_cast<void*>(m_opaque_sp.get()), sstr.GetData());
51 SBWatchpoint::SBWatchpoint(const SBWatchpoint &rhs) :
52 m_opaque_sp (rhs.m_opaque_sp)
57 SBWatchpoint::operator = (const SBWatchpoint &rhs)
60 m_opaque_sp = rhs.m_opaque_sp;
65 SBWatchpoint::~SBWatchpoint ()
70 SBWatchpoint::GetID ()
72 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
74 watch_id_t watch_id = LLDB_INVALID_WATCH_ID;
75 lldb::WatchpointSP watchpoint_sp(GetSP());
77 watch_id = watchpoint_sp->GetID();
81 if (watch_id == LLDB_INVALID_WATCH_ID)
82 log->Printf ("SBWatchpoint(%p)::GetID () => LLDB_INVALID_WATCH_ID",
83 static_cast<void*>(watchpoint_sp.get()));
85 log->Printf ("SBWatchpoint(%p)::GetID () => %u",
86 static_cast<void*>(watchpoint_sp.get()), watch_id);
93 SBWatchpoint::IsValid() const
95 return (bool) m_opaque_sp;
99 SBWatchpoint::GetError ()
102 lldb::WatchpointSP watchpoint_sp(GetSP());
105 sb_error.SetError(watchpoint_sp->GetError());
111 SBWatchpoint::GetHardwareIndex ()
113 int32_t hw_index = -1;
115 lldb::WatchpointSP watchpoint_sp(GetSP());
118 std::lock_guard<std::recursive_mutex> guard(watchpoint_sp->GetTarget().GetAPIMutex());
119 hw_index = watchpoint_sp->GetHardwareIndex();
126 SBWatchpoint::GetWatchAddress ()
128 addr_t ret_addr = LLDB_INVALID_ADDRESS;
130 lldb::WatchpointSP watchpoint_sp(GetSP());
133 std::lock_guard<std::recursive_mutex> guard(watchpoint_sp->GetTarget().GetAPIMutex());
134 ret_addr = watchpoint_sp->GetLoadAddress();
141 SBWatchpoint::GetWatchSize ()
143 size_t watch_size = 0;
145 lldb::WatchpointSP watchpoint_sp(GetSP());
148 std::lock_guard<std::recursive_mutex> guard(watchpoint_sp->GetTarget().GetAPIMutex());
149 watch_size = watchpoint_sp->GetByteSize();
156 SBWatchpoint::SetEnabled (bool enabled)
158 lldb::WatchpointSP watchpoint_sp(GetSP());
161 std::lock_guard<std::recursive_mutex> guard(watchpoint_sp->GetTarget().GetAPIMutex());
162 watchpoint_sp->GetTarget().DisableWatchpointByID(watchpoint_sp->GetID());
167 SBWatchpoint::IsEnabled ()
169 lldb::WatchpointSP watchpoint_sp(GetSP());
172 std::lock_guard<std::recursive_mutex> guard(watchpoint_sp->GetTarget().GetAPIMutex());
173 return watchpoint_sp->IsEnabled();
180 SBWatchpoint::GetHitCount ()
183 lldb::WatchpointSP watchpoint_sp(GetSP());
186 std::lock_guard<std::recursive_mutex> guard(watchpoint_sp->GetTarget().GetAPIMutex());
187 count = watchpoint_sp->GetHitCount();
190 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
192 log->Printf ("SBWatchpoint(%p)::GetHitCount () => %u",
193 static_cast<void*>(watchpoint_sp.get()), count);
199 SBWatchpoint::GetIgnoreCount ()
201 lldb::WatchpointSP watchpoint_sp(GetSP());
204 std::lock_guard<std::recursive_mutex> guard(watchpoint_sp->GetTarget().GetAPIMutex());
205 return watchpoint_sp->GetIgnoreCount();
212 SBWatchpoint::SetIgnoreCount (uint32_t n)
214 lldb::WatchpointSP watchpoint_sp(GetSP());
217 std::lock_guard<std::recursive_mutex> guard(watchpoint_sp->GetTarget().GetAPIMutex());
218 watchpoint_sp->SetIgnoreCount (n);
223 SBWatchpoint::GetCondition ()
225 lldb::WatchpointSP watchpoint_sp(GetSP());
228 std::lock_guard<std::recursive_mutex> guard(watchpoint_sp->GetTarget().GetAPIMutex());
229 return watchpoint_sp->GetConditionText ();
235 SBWatchpoint::SetCondition (const char *condition)
237 lldb::WatchpointSP watchpoint_sp(GetSP());
240 std::lock_guard<std::recursive_mutex> guard(watchpoint_sp->GetTarget().GetAPIMutex());
241 watchpoint_sp->SetCondition (condition);
246 SBWatchpoint::GetDescription (SBStream &description, DescriptionLevel level)
248 Stream &strm = description.ref();
250 lldb::WatchpointSP watchpoint_sp(GetSP());
253 std::lock_guard<std::recursive_mutex> guard(watchpoint_sp->GetTarget().GetAPIMutex());
254 watchpoint_sp->GetDescription (&strm, level);
258 strm.PutCString ("No value");
264 SBWatchpoint::Clear ()
270 SBWatchpoint::GetSP () const
276 SBWatchpoint::SetSP (const lldb::WatchpointSP &sp)
282 SBWatchpoint::EventIsWatchpointEvent (const lldb::SBEvent &event)
284 return Watchpoint::WatchpointEventData::GetEventDataFromEvent(event.get()) != NULL;
289 SBWatchpoint::GetWatchpointEventTypeFromEvent (const SBEvent& event)
292 return Watchpoint::WatchpointEventData::GetWatchpointEventTypeFromEvent (event.GetSP());
293 return eWatchpointEventTypeInvalidType;
297 SBWatchpoint::GetWatchpointFromEvent (const lldb::SBEvent& event)
299 SBWatchpoint sb_watchpoint;
301 sb_watchpoint.m_opaque_sp = Watchpoint::WatchpointEventData::GetWatchpointFromEvent (event.GetSP());
302 return sb_watchpoint;