blob: 6b2785a22b33a43bbe30e18367a386f44b87a5f7 [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),
Johnny Chen096c2932011-09-26 22:40:50 +000023 m_target(NULL),
Chris Lattner24943d22010-06-08 16:52:24 +000024 m_enabled(0),
Johnny Chen01acfa72011-09-22 18:04:58 +000025 m_is_hardware(hardware),
Chris Lattner24943d22010-06-08 16:52:24 +000026 m_watch_read(0),
27 m_watch_write(0),
28 m_watch_was_read(0),
29 m_watch_was_written(0),
30 m_ignore_count(0),
31 m_callback(NULL),
32 m_callback_baton(NULL)
33{
34}
35
36WatchpointLocation::~WatchpointLocation()
37{
38}
39
40break_id_t
41WatchpointLocation::GetNextID()
42{
43 static break_id_t g_next_ID = 0;
44 return ++g_next_ID;
45}
46
47bool
48WatchpointLocation::SetCallback (WatchpointHitCallback callback, void *callback_baton)
49{
50 m_callback = callback;
51 m_callback_baton = callback_baton;
52 return true;
53}
54
Johnny Chen10b12b32011-09-16 21:41:42 +000055void
56WatchpointLocation::SetDeclInfo (std::string &str)
57{
58 m_decl_str = str;
59 return;
60}
61
Chris Lattner24943d22010-06-08 16:52:24 +000062
Johnny Chen01acfa72011-09-22 18:04:58 +000063bool
64WatchpointLocation::IsHardware () const
65{
66 return m_is_hardware;
67}
68
Chris Lattner24943d22010-06-08 16:52:24 +000069// RETURNS - true if we should stop at this breakpoint, false if we
70// should continue.
71
72bool
Johnny Chen043f8c22011-09-21 22:47:15 +000073WatchpointLocation::ShouldStop (StoppointCallbackContext *context)
Chris Lattner24943d22010-06-08 16:52:24 +000074{
Johnny Chen01acfa72011-09-22 18:04:58 +000075 ++m_hit_count;
Chris Lattner24943d22010-06-08 16:52:24 +000076
Johnny Chen01acfa72011-09-22 18:04:58 +000077 if (!IsEnabled())
78 return false;
Johnny Chen043f8c22011-09-21 22:47:15 +000079
Johnny Chen01acfa72011-09-22 18:04:58 +000080 if (m_hit_count <= GetIgnoreCount())
81 return false;
82
83 uint32_t access = 0;
84 if (m_watch_was_read)
85 access |= LLDB_WATCH_TYPE_READ;
86 if (m_watch_was_written)
87 access |= LLDB_WATCH_TYPE_WRITE;
88
89 if (m_callback)
90 return m_callback(m_callback_baton, context, GetID(), access);
91 else
92 return true;
Chris Lattner24943d22010-06-08 16:52:24 +000093}
94
95void
Johnny Chen34bbf852011-09-12 23:38:44 +000096WatchpointLocation::GetDescription (Stream *s, lldb::DescriptionLevel level)
97{
Johnny Chen95f41b82011-09-13 01:13:20 +000098 s->Printf(" ");
Johnny Chen10b12b32011-09-16 21:41:42 +000099 DumpWithLevel(s, level);
Johnny Chen34bbf852011-09-12 23:38:44 +0000100 return;
101}
102
103void
Chris Lattner24943d22010-06-08 16:52:24 +0000104WatchpointLocation::Dump(Stream *s) const
105{
Johnny Chen10b12b32011-09-16 21:41:42 +0000106 DumpWithLevel(s, lldb::eDescriptionLevelBrief);
107}
108
109void
110WatchpointLocation::DumpWithLevel(Stream *s, lldb::DescriptionLevel description_level) const
111{
Chris Lattner24943d22010-06-08 16:52:24 +0000112 if (s == NULL)
113 return;
114
Johnny Chen10b12b32011-09-16 21:41:42 +0000115 assert(description_level >= lldb::eDescriptionLevelBrief &&
116 description_level <= lldb::eDescriptionLevelVerbose);
117
118 s->Printf("WatchpointLocation %u: addr = 0x%8.8llx size = %zu state = %s type = %s%s",
119 GetID(),
120 (uint64_t)m_addr,
121 m_byte_size,
122 m_enabled ? "enabled" : "disabled",
123 m_watch_read ? "r" : "",
124 m_watch_write ? "w" : "");
125
126 if (description_level >= lldb::eDescriptionLevelFull)
127 s->Printf("\n declare @ '%s'", m_decl_str.c_str());
128
129 if (description_level >= lldb::eDescriptionLevelVerbose)
Johnny Chenda5a8022011-09-20 23:28:55 +0000130 s->Printf("\n hw_index = %i hit_count = %-4u ignore_count = %-4u callback = %8p baton = %8p",
131 GetHardwareIndex(),
Johnny Chen10b12b32011-09-16 21:41:42 +0000132 GetHitCount(),
133 GetIgnoreCount(),
134 m_callback,
135 m_callback_baton);
Chris Lattner24943d22010-06-08 16:52:24 +0000136}
137
138bool
139WatchpointLocation::IsEnabled() const
140{
141 return m_enabled;
142}
143
144void
Johnny Chen21900fb2011-09-06 22:38:36 +0000145WatchpointLocation::SetEnabled(bool enabled)
Chris Lattner24943d22010-06-08 16:52:24 +0000146{
147 if (!enabled)
148 SetHardwareIndex(LLDB_INVALID_INDEX32);
149 m_enabled = enabled;
150}
151
152void
153WatchpointLocation::SetWatchpointType (uint32_t type)
154{
155 m_watch_read = (type & LLDB_WATCH_TYPE_READ) != 0;
156 m_watch_write = (type & LLDB_WATCH_TYPE_WRITE) != 0;
157}
158
159bool
160WatchpointLocation::WatchpointRead () const
161{
162 return m_watch_read != 0;
163}
164bool
165WatchpointLocation::WatchpointWrite () const
166{
167 return m_watch_write != 0;
168}
Greg Clayton54e7afa2010-07-09 20:39:50 +0000169uint32_t
Chris Lattner24943d22010-06-08 16:52:24 +0000170WatchpointLocation::GetIgnoreCount () const
171{
172 return m_ignore_count;
173}
174
175void
Greg Clayton54e7afa2010-07-09 20:39:50 +0000176WatchpointLocation::SetIgnoreCount (uint32_t n)
Chris Lattner24943d22010-06-08 16:52:24 +0000177{
178 m_ignore_count = n;
179}