blob: 1a1a970aaa873dcb1c86d4a887cacfbb28d8dfcd [file] [log] [blame]
Greg Clayton1b282f92011-10-13 18:08:26 +00001//===-- SBWatchpoint.cpp --------------------------------*- C++ -*-===//
Johnny Chen5d043462011-09-26 22:40:50 +00002//
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
Greg Clayton1b282f92011-10-13 18:08:26 +000010#include "lldb/API/SBWatchpoint.h"
Johnny Chen5d043462011-09-26 22:40:50 +000011#include "lldb/API/SBDefines.h"
12#include "lldb/API/SBAddress.h"
13#include "lldb/API/SBDebugger.h"
Jim Ingham1b5792e2012-12-18 02:03:49 +000014#include "lldb/API/SBEvent.h"
Johnny Chen5d043462011-09-26 22:40:50 +000015#include "lldb/API/SBStream.h"
16
17#include "lldb/lldb-types.h"
18#include "lldb/lldb-defines.h"
Johnny Chen01a67862011-10-14 00:42:25 +000019#include "lldb/Breakpoint/Watchpoint.h"
20#include "lldb/Breakpoint/WatchpointList.h"
Johnny Chen5d043462011-09-26 22:40:50 +000021#include "lldb/Core/Log.h"
22#include "lldb/Core/Stream.h"
23#include "lldb/Core/StreamFile.h"
24#include "lldb/Target/Target.h"
25
26using namespace lldb;
27using namespace lldb_private;
28
29
Greg Clayton1b282f92011-10-13 18:08:26 +000030SBWatchpoint::SBWatchpoint () :
Johnny Chen5d043462011-09-26 22:40:50 +000031 m_opaque_sp ()
32{
33}
34
Johnny Chen01a67862011-10-14 00:42:25 +000035SBWatchpoint::SBWatchpoint (const lldb::WatchpointSP &wp_sp) :
36 m_opaque_sp (wp_sp)
Johnny Chen5d043462011-09-26 22:40:50 +000037{
Greg Clayton5160ce52013-03-27 23:08:40 +000038 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen5d043462011-09-26 22:40:50 +000039
40 if (log)
41 {
42 SBStream sstr;
43 GetDescription (sstr, lldb::eDescriptionLevelBrief);
Johnny Chen01a67862011-10-14 00:42:25 +000044 log->Printf ("SBWatchpoint::SBWatchpoint (const lldb::WatchpointSP &wp_sp"
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000045 "=%p) => this.sp = %p (%s)",
46 static_cast<void*>(wp_sp.get()),
47 static_cast<void*>(m_opaque_sp.get()), sstr.GetData());
Johnny Chen5d043462011-09-26 22:40:50 +000048 }
49}
50
Greg Clayton1b282f92011-10-13 18:08:26 +000051SBWatchpoint::SBWatchpoint(const SBWatchpoint &rhs) :
Johnny Chen5d043462011-09-26 22:40:50 +000052 m_opaque_sp (rhs.m_opaque_sp)
53{
54}
55
Greg Clayton1b282f92011-10-13 18:08:26 +000056const SBWatchpoint &
57SBWatchpoint::operator = (const SBWatchpoint &rhs)
Johnny Chen5d043462011-09-26 22:40:50 +000058{
59 if (this != &rhs)
60 m_opaque_sp = rhs.m_opaque_sp;
61 return *this;
62}
63
64
Greg Clayton1b282f92011-10-13 18:08:26 +000065SBWatchpoint::~SBWatchpoint ()
Johnny Chen5d043462011-09-26 22:40:50 +000066{
67}
68
Johnny Chend4dd7992011-09-27 01:19:20 +000069watch_id_t
Greg Clayton1b282f92011-10-13 18:08:26 +000070SBWatchpoint::GetID ()
Johnny Chend4dd7992011-09-27 01:19:20 +000071{
Greg Clayton5160ce52013-03-27 23:08:40 +000072 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chend4dd7992011-09-27 01:19:20 +000073
74 watch_id_t watch_id = LLDB_INVALID_WATCH_ID;
Greg Clayton81e871e2012-02-04 02:27:34 +000075 lldb::WatchpointSP watchpoint_sp(GetSP());
76 if (watchpoint_sp)
77 watch_id = watchpoint_sp->GetID();
Johnny Chend4dd7992011-09-27 01:19:20 +000078
79 if (log)
80 {
81 if (watch_id == LLDB_INVALID_WATCH_ID)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000082 log->Printf ("SBWatchpoint(%p)::GetID () => LLDB_INVALID_WATCH_ID",
83 static_cast<void*>(watchpoint_sp.get()));
Johnny Chend4dd7992011-09-27 01:19:20 +000084 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000085 log->Printf ("SBWatchpoint(%p)::GetID () => %u",
86 static_cast<void*>(watchpoint_sp.get()), watch_id);
Johnny Chend4dd7992011-09-27 01:19:20 +000087 }
88
89 return watch_id;
90}
91
Johnny Chen5d043462011-09-26 22:40:50 +000092bool
Greg Clayton1b282f92011-10-13 18:08:26 +000093SBWatchpoint::IsValid() const
Johnny Chen5d043462011-09-26 22:40:50 +000094{
Jim Inghamf94e1792012-08-11 00:35:26 +000095 return (bool) m_opaque_sp;
Johnny Chen5d043462011-09-26 22:40:50 +000096}
97
Jim Inghamef42a6f2012-06-06 18:46:25 +000098SBError
99SBWatchpoint::GetError ()
100{
101 SBError sb_error;
102 lldb::WatchpointSP watchpoint_sp(GetSP());
103 if (watchpoint_sp)
104 {
105 sb_error.SetError(watchpoint_sp->GetError());
106 }
107 return sb_error;
108}
109
Johnny Chend4dd7992011-09-27 01:19:20 +0000110int32_t
Greg Clayton1b282f92011-10-13 18:08:26 +0000111SBWatchpoint::GetHardwareIndex ()
Johnny Chend4dd7992011-09-27 01:19:20 +0000112{
113 int32_t hw_index = -1;
114
Greg Clayton81e871e2012-02-04 02:27:34 +0000115 lldb::WatchpointSP watchpoint_sp(GetSP());
116 if (watchpoint_sp)
Johnny Chend4dd7992011-09-27 01:19:20 +0000117 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000118 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
119 hw_index = watchpoint_sp->GetHardwareIndex();
Johnny Chend4dd7992011-09-27 01:19:20 +0000120 }
121
122 return hw_index;
123}
124
Johnny Chen5d043462011-09-26 22:40:50 +0000125addr_t
Greg Clayton1b282f92011-10-13 18:08:26 +0000126SBWatchpoint::GetWatchAddress ()
Johnny Chen5d043462011-09-26 22:40:50 +0000127{
128 addr_t ret_addr = LLDB_INVALID_ADDRESS;
129
Greg Clayton81e871e2012-02-04 02:27:34 +0000130 lldb::WatchpointSP watchpoint_sp(GetSP());
131 if (watchpoint_sp)
Johnny Chen5d043462011-09-26 22:40:50 +0000132 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000133 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
134 ret_addr = watchpoint_sp->GetLoadAddress();
Johnny Chen5d043462011-09-26 22:40:50 +0000135 }
136
137 return ret_addr;
138}
139
140size_t
Greg Clayton1b282f92011-10-13 18:08:26 +0000141SBWatchpoint::GetWatchSize ()
Johnny Chen5d043462011-09-26 22:40:50 +0000142{
143 size_t watch_size = 0;
144
Greg Clayton81e871e2012-02-04 02:27:34 +0000145 lldb::WatchpointSP watchpoint_sp(GetSP());
146 if (watchpoint_sp)
Johnny Chen5d043462011-09-26 22:40:50 +0000147 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000148 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
149 watch_size = watchpoint_sp->GetByteSize();
Johnny Chen5d043462011-09-26 22:40:50 +0000150 }
151
152 return watch_size;
153}
154
155void
Greg Clayton1b282f92011-10-13 18:08:26 +0000156SBWatchpoint::SetEnabled (bool enabled)
Johnny Chen5d043462011-09-26 22:40:50 +0000157{
Greg Clayton81e871e2012-02-04 02:27:34 +0000158 lldb::WatchpointSP watchpoint_sp(GetSP());
159 if (watchpoint_sp)
Johnny Chen5d043462011-09-26 22:40:50 +0000160 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000161 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
162 watchpoint_sp->GetTarget().DisableWatchpointByID(watchpoint_sp->GetID());
Johnny Chen5d043462011-09-26 22:40:50 +0000163 }
164}
165
166bool
Greg Clayton1b282f92011-10-13 18:08:26 +0000167SBWatchpoint::IsEnabled ()
Johnny Chen5d043462011-09-26 22:40:50 +0000168{
Greg Clayton81e871e2012-02-04 02:27:34 +0000169 lldb::WatchpointSP watchpoint_sp(GetSP());
170 if (watchpoint_sp)
Johnny Chen5d043462011-09-26 22:40:50 +0000171 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000172 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
173 return watchpoint_sp->IsEnabled();
Johnny Chen5d043462011-09-26 22:40:50 +0000174 }
175 else
176 return false;
177}
178
179uint32_t
Greg Clayton1b282f92011-10-13 18:08:26 +0000180SBWatchpoint::GetHitCount ()
Johnny Chend4dd7992011-09-27 01:19:20 +0000181{
182 uint32_t count = 0;
Greg Clayton81e871e2012-02-04 02:27:34 +0000183 lldb::WatchpointSP watchpoint_sp(GetSP());
184 if (watchpoint_sp)
Johnny Chend4dd7992011-09-27 01:19:20 +0000185 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000186 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
187 count = watchpoint_sp->GetHitCount();
Johnny Chend4dd7992011-09-27 01:19:20 +0000188 }
189
Greg Clayton5160ce52013-03-27 23:08:40 +0000190 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chend4dd7992011-09-27 01:19:20 +0000191 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000192 log->Printf ("SBWatchpoint(%p)::GetHitCount () => %u",
193 static_cast<void*>(watchpoint_sp.get()), count);
Johnny Chend4dd7992011-09-27 01:19:20 +0000194
195 return count;
196}
197
198uint32_t
Greg Clayton1b282f92011-10-13 18:08:26 +0000199SBWatchpoint::GetIgnoreCount ()
Johnny Chen5d043462011-09-26 22:40:50 +0000200{
Greg Clayton81e871e2012-02-04 02:27:34 +0000201 lldb::WatchpointSP watchpoint_sp(GetSP());
202 if (watchpoint_sp)
Johnny Chen5d043462011-09-26 22:40:50 +0000203 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000204 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
205 return watchpoint_sp->GetIgnoreCount();
Johnny Chen5d043462011-09-26 22:40:50 +0000206 }
207 else
208 return 0;
209}
210
211void
Greg Clayton1b282f92011-10-13 18:08:26 +0000212SBWatchpoint::SetIgnoreCount (uint32_t n)
Johnny Chen5d043462011-09-26 22:40:50 +0000213{
Greg Clayton81e871e2012-02-04 02:27:34 +0000214 lldb::WatchpointSP watchpoint_sp(GetSP());
215 if (watchpoint_sp)
Johnny Chen5d043462011-09-26 22:40:50 +0000216 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000217 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
218 watchpoint_sp->SetIgnoreCount (n);
Johnny Chen5d043462011-09-26 22:40:50 +0000219 }
220}
221
Johnny Chen16dcf712011-10-17 18:58:00 +0000222const char *
223SBWatchpoint::GetCondition ()
224{
Greg Clayton81e871e2012-02-04 02:27:34 +0000225 lldb::WatchpointSP watchpoint_sp(GetSP());
226 if (watchpoint_sp)
Johnny Chen16dcf712011-10-17 18:58:00 +0000227 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000228 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
229 return watchpoint_sp->GetConditionText ();
Johnny Chen16dcf712011-10-17 18:58:00 +0000230 }
231 return NULL;
232}
233
234void
235SBWatchpoint::SetCondition (const char *condition)
236{
Greg Clayton81e871e2012-02-04 02:27:34 +0000237 lldb::WatchpointSP watchpoint_sp(GetSP());
238 if (watchpoint_sp)
Johnny Chen16dcf712011-10-17 18:58:00 +0000239 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000240 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
241 watchpoint_sp->SetCondition (condition);
Johnny Chen16dcf712011-10-17 18:58:00 +0000242 }
243}
244
Johnny Chen5d043462011-09-26 22:40:50 +0000245bool
Greg Clayton1b282f92011-10-13 18:08:26 +0000246SBWatchpoint::GetDescription (SBStream &description, DescriptionLevel level)
Johnny Chen5d043462011-09-26 22:40:50 +0000247{
Greg Claytonda7bc7d2011-11-13 06:57:31 +0000248 Stream &strm = description.ref();
249
Greg Clayton81e871e2012-02-04 02:27:34 +0000250 lldb::WatchpointSP watchpoint_sp(GetSP());
251 if (watchpoint_sp)
Johnny Chen5d043462011-09-26 22:40:50 +0000252 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000253 Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex());
254 watchpoint_sp->GetDescription (&strm, level);
Greg Claytonda7bc7d2011-11-13 06:57:31 +0000255 strm.EOL();
Johnny Chen5d043462011-09-26 22:40:50 +0000256 }
257 else
Greg Claytonda7bc7d2011-11-13 06:57:31 +0000258 strm.PutCString ("No value");
Johnny Chen5d043462011-09-26 22:40:50 +0000259
260 return true;
261}
262
Greg Clayton81e871e2012-02-04 02:27:34 +0000263void
264SBWatchpoint::Clear ()
Johnny Chen5d043462011-09-26 22:40:50 +0000265{
Greg Clayton81e871e2012-02-04 02:27:34 +0000266 m_opaque_sp.reset();
Johnny Chen5d043462011-09-26 22:40:50 +0000267}
268
Greg Clayton81e871e2012-02-04 02:27:34 +0000269lldb::WatchpointSP
270SBWatchpoint::GetSP () const
Johnny Chen5d043462011-09-26 22:40:50 +0000271{
272 return m_opaque_sp;
273}
Greg Clayton81e871e2012-02-04 02:27:34 +0000274
275void
276SBWatchpoint::SetSP (const lldb::WatchpointSP &sp)
277{
278 m_opaque_sp = sp;
279}
Jim Ingham1b5792e2012-12-18 02:03:49 +0000280
281bool
282SBWatchpoint::EventIsWatchpointEvent (const lldb::SBEvent &event)
283{
284 return Watchpoint::WatchpointEventData::GetEventDataFromEvent(event.get()) != NULL;
285
286}
287
288WatchpointEventType
289SBWatchpoint::GetWatchpointEventTypeFromEvent (const SBEvent& event)
290{
291 if (event.IsValid())
292 return Watchpoint::WatchpointEventData::GetWatchpointEventTypeFromEvent (event.GetSP());
293 return eWatchpointEventTypeInvalidType;
294}
295
296SBWatchpoint
297SBWatchpoint::GetWatchpointFromEvent (const lldb::SBEvent& event)
298{
299 SBWatchpoint sb_watchpoint;
300 if (event.IsValid())
301 sb_watchpoint.m_opaque_sp = Watchpoint::WatchpointEventData::GetWatchpointFromEvent (event.GetSP());
302 return sb_watchpoint;
303}