blob: e0c14edfff295bc4a12231a25c18c7c1e6c3727b [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- WatchpointLocation.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/Breakpoint/WatchpointLocation.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
16#include "lldb/Core/Stream.h"
17
18using namespace lldb;
19using namespace lldb_private;
20
Johnny Chen8ed0ef92011-09-06 02:52:28 +000021WatchpointLocation::WatchpointLocation (lldb::addr_t addr, size_t size, bool hardware) :
22 StoppointLocation (GetNextID(), addr, size, hardware),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000023 m_enabled(0),
24 m_watch_read(0),
25 m_watch_write(0),
26 m_watch_was_read(0),
27 m_watch_was_written(0),
28 m_ignore_count(0),
29 m_callback(NULL),
30 m_callback_baton(NULL)
31{
32}
33
34WatchpointLocation::~WatchpointLocation()
35{
36}
37
38break_id_t
39WatchpointLocation::GetNextID()
40{
41 static break_id_t g_next_ID = 0;
42 return ++g_next_ID;
43}
44
45bool
46WatchpointLocation::SetCallback (WatchpointHitCallback callback, void *callback_baton)
47{
48 m_callback = callback;
49 m_callback_baton = callback_baton;
50 return true;
51}
52
Johnny Chende6bd242011-09-16 21:41:42 +000053void
54WatchpointLocation::SetDeclInfo (std::string &str)
55{
56 m_decl_str = str;
57 return;
58}
59
Chris Lattner30fdc8d2010-06-08 16:52:24 +000060
61// RETURNS - true if we should stop at this breakpoint, false if we
62// should continue.
63
64bool
Johnny Chenfd158f42011-09-21 22:47:15 +000065WatchpointLocation::ShouldStop (StoppointCallbackContext *context)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000066{
67 m_hit_count++;
68
69 if (m_hit_count > m_ignore_count)
70 {
71 uint32_t access = 0;
72 if (m_watch_was_read)
73 access |= LLDB_WATCH_TYPE_READ;
74 if (m_watch_was_written)
75 access |= LLDB_WATCH_TYPE_WRITE;
Johnny Chenfd158f42011-09-21 22:47:15 +000076
77 if (m_callback)
78 return m_callback(m_callback_baton, context, GetID(), access);
79 else
80 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000081 }
82 return false;
83}
84
85void
Johnny Chen887062a2011-09-12 23:38:44 +000086WatchpointLocation::GetDescription (Stream *s, lldb::DescriptionLevel level)
87{
Johnny Chen02ae3412011-09-13 01:13:20 +000088 s->Printf(" ");
Johnny Chende6bd242011-09-16 21:41:42 +000089 DumpWithLevel(s, level);
Johnny Chen887062a2011-09-12 23:38:44 +000090 return;
91}
92
93void
Chris Lattner30fdc8d2010-06-08 16:52:24 +000094WatchpointLocation::Dump(Stream *s) const
95{
Johnny Chende6bd242011-09-16 21:41:42 +000096 DumpWithLevel(s, lldb::eDescriptionLevelBrief);
97}
98
99void
100WatchpointLocation::DumpWithLevel(Stream *s, lldb::DescriptionLevel description_level) const
101{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000102 if (s == NULL)
103 return;
104
Johnny Chende6bd242011-09-16 21:41:42 +0000105 assert(description_level >= lldb::eDescriptionLevelBrief &&
106 description_level <= lldb::eDescriptionLevelVerbose);
107
108 s->Printf("WatchpointLocation %u: addr = 0x%8.8llx size = %zu state = %s type = %s%s",
109 GetID(),
110 (uint64_t)m_addr,
111 m_byte_size,
112 m_enabled ? "enabled" : "disabled",
113 m_watch_read ? "r" : "",
114 m_watch_write ? "w" : "");
115
116 if (description_level >= lldb::eDescriptionLevelFull)
117 s->Printf("\n declare @ '%s'", m_decl_str.c_str());
118
119 if (description_level >= lldb::eDescriptionLevelVerbose)
Johnny Chen86364b42011-09-20 23:28:55 +0000120 s->Printf("\n hw_index = %i hit_count = %-4u ignore_count = %-4u callback = %8p baton = %8p",
121 GetHardwareIndex(),
Johnny Chende6bd242011-09-16 21:41:42 +0000122 GetHitCount(),
123 GetIgnoreCount(),
124 m_callback,
125 m_callback_baton);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000126}
127
128bool
129WatchpointLocation::IsEnabled() const
130{
131 return m_enabled;
132}
133
134void
Johnny Chen11309a32011-09-06 22:38:36 +0000135WatchpointLocation::SetEnabled(bool enabled)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000136{
137 if (!enabled)
138 SetHardwareIndex(LLDB_INVALID_INDEX32);
139 m_enabled = enabled;
140}
141
142void
143WatchpointLocation::SetWatchpointType (uint32_t type)
144{
145 m_watch_read = (type & LLDB_WATCH_TYPE_READ) != 0;
146 m_watch_write = (type & LLDB_WATCH_TYPE_WRITE) != 0;
147}
148
149bool
150WatchpointLocation::WatchpointRead () const
151{
152 return m_watch_read != 0;
153}
154bool
155WatchpointLocation::WatchpointWrite () const
156{
157 return m_watch_write != 0;
158}
Greg Claytonc982c762010-07-09 20:39:50 +0000159uint32_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000160WatchpointLocation::GetIgnoreCount () const
161{
162 return m_ignore_count;
163}
164
165void
Greg Claytonc982c762010-07-09 20:39:50 +0000166WatchpointLocation::SetIgnoreCount (uint32_t n)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000167{
168 m_ignore_count = n;
169}