blob: a0bbc037d5c97ab5393ae85493fe15724fb121bf [file] [log] [blame]
Chris Lattner24943d22010-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 Chenedda23f2011-09-06 02:52:28 +000021WatchpointLocation::WatchpointLocation (lldb::addr_t addr, size_t size, bool hardware) :
22 StoppointLocation (GetNextID(), addr, size, hardware),
Chris Lattner24943d22010-06-08 16:52:24 +000023 m_enabled(0),
Johnny Chen01acfa72011-09-22 18:04:58 +000024 m_is_hardware(hardware),
Chris Lattner24943d22010-06-08 16:52:24 +000025 m_watch_read(0),
26 m_watch_write(0),
27 m_watch_was_read(0),
28 m_watch_was_written(0),
29 m_ignore_count(0),
30 m_callback(NULL),
31 m_callback_baton(NULL)
32{
33}
34
35WatchpointLocation::~WatchpointLocation()
36{
37}
38
39break_id_t
40WatchpointLocation::GetNextID()
41{
42 static break_id_t g_next_ID = 0;
43 return ++g_next_ID;
44}
45
46bool
47WatchpointLocation::SetCallback (WatchpointHitCallback callback, void *callback_baton)
48{
49 m_callback = callback;
50 m_callback_baton = callback_baton;
51 return true;
52}
53
Johnny Chen10b12b32011-09-16 21:41:42 +000054void
55WatchpointLocation::SetDeclInfo (std::string &str)
56{
57 m_decl_str = str;
58 return;
59}
60
Chris Lattner24943d22010-06-08 16:52:24 +000061
Johnny Chen01acfa72011-09-22 18:04:58 +000062bool
63WatchpointLocation::IsHardware () const
64{
65 return m_is_hardware;
66}
67
Chris Lattner24943d22010-06-08 16:52:24 +000068// RETURNS - true if we should stop at this breakpoint, false if we
69// should continue.
70
71bool
Johnny Chen043f8c22011-09-21 22:47:15 +000072WatchpointLocation::ShouldStop (StoppointCallbackContext *context)
Chris Lattner24943d22010-06-08 16:52:24 +000073{
Johnny Chen01acfa72011-09-22 18:04:58 +000074 ++m_hit_count;
Chris Lattner24943d22010-06-08 16:52:24 +000075
Johnny Chen01acfa72011-09-22 18:04:58 +000076 if (!IsEnabled())
77 return false;
Johnny Chen043f8c22011-09-21 22:47:15 +000078
Johnny Chen01acfa72011-09-22 18:04:58 +000079 if (m_hit_count <= GetIgnoreCount())
80 return false;
81
82 uint32_t access = 0;
83 if (m_watch_was_read)
84 access |= LLDB_WATCH_TYPE_READ;
85 if (m_watch_was_written)
86 access |= LLDB_WATCH_TYPE_WRITE;
87
88 if (m_callback)
89 return m_callback(m_callback_baton, context, GetID(), access);
90 else
91 return true;
Chris Lattner24943d22010-06-08 16:52:24 +000092}
93
94void
Johnny Chen34bbf852011-09-12 23:38:44 +000095WatchpointLocation::GetDescription (Stream *s, lldb::DescriptionLevel level)
96{
Johnny Chen95f41b82011-09-13 01:13:20 +000097 s->Printf(" ");
Johnny Chen10b12b32011-09-16 21:41:42 +000098 DumpWithLevel(s, level);
Johnny Chen34bbf852011-09-12 23:38:44 +000099 return;
100}
101
102void
Chris Lattner24943d22010-06-08 16:52:24 +0000103WatchpointLocation::Dump(Stream *s) const
104{
Johnny Chen10b12b32011-09-16 21:41:42 +0000105 DumpWithLevel(s, lldb::eDescriptionLevelBrief);
106}
107
108void
109WatchpointLocation::DumpWithLevel(Stream *s, lldb::DescriptionLevel description_level) const
110{
Chris Lattner24943d22010-06-08 16:52:24 +0000111 if (s == NULL)
112 return;
113
Johnny Chen10b12b32011-09-16 21:41:42 +0000114 assert(description_level >= lldb::eDescriptionLevelBrief &&
115 description_level <= lldb::eDescriptionLevelVerbose);
116
117 s->Printf("WatchpointLocation %u: addr = 0x%8.8llx size = %zu state = %s type = %s%s",
118 GetID(),
119 (uint64_t)m_addr,
120 m_byte_size,
121 m_enabled ? "enabled" : "disabled",
122 m_watch_read ? "r" : "",
123 m_watch_write ? "w" : "");
124
125 if (description_level >= lldb::eDescriptionLevelFull)
126 s->Printf("\n declare @ '%s'", m_decl_str.c_str());
127
128 if (description_level >= lldb::eDescriptionLevelVerbose)
Johnny Chenda5a8022011-09-20 23:28:55 +0000129 s->Printf("\n hw_index = %i hit_count = %-4u ignore_count = %-4u callback = %8p baton = %8p",
130 GetHardwareIndex(),
Johnny Chen10b12b32011-09-16 21:41:42 +0000131 GetHitCount(),
132 GetIgnoreCount(),
133 m_callback,
134 m_callback_baton);
Chris Lattner24943d22010-06-08 16:52:24 +0000135}
136
137bool
138WatchpointLocation::IsEnabled() const
139{
140 return m_enabled;
141}
142
143void
Johnny Chen21900fb2011-09-06 22:38:36 +0000144WatchpointLocation::SetEnabled(bool enabled)
Chris Lattner24943d22010-06-08 16:52:24 +0000145{
146 if (!enabled)
147 SetHardwareIndex(LLDB_INVALID_INDEX32);
148 m_enabled = enabled;
149}
150
151void
152WatchpointLocation::SetWatchpointType (uint32_t type)
153{
154 m_watch_read = (type & LLDB_WATCH_TYPE_READ) != 0;
155 m_watch_write = (type & LLDB_WATCH_TYPE_WRITE) != 0;
156}
157
158bool
159WatchpointLocation::WatchpointRead () const
160{
161 return m_watch_read != 0;
162}
163bool
164WatchpointLocation::WatchpointWrite () const
165{
166 return m_watch_write != 0;
167}
Greg Clayton54e7afa2010-07-09 20:39:50 +0000168uint32_t
Chris Lattner24943d22010-06-08 16:52:24 +0000169WatchpointLocation::GetIgnoreCount () const
170{
171 return m_ignore_count;
172}
173
174void
Greg Clayton54e7afa2010-07-09 20:39:50 +0000175WatchpointLocation::SetIgnoreCount (uint32_t n)
Chris Lattner24943d22010-06-08 16:52:24 +0000176{
177 m_ignore_count = n;
178}