blob: b4b9441c910c373509426e912ca4717f0ef98db3 [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),
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 Chen10b12b32011-09-16 21:41:42 +000053void
54WatchpointLocation::SetDeclInfo (std::string &str)
55{
56 m_decl_str = str;
57 return;
58}
59
Chris Lattner24943d22010-06-08 16:52:24 +000060
61// RETURNS - true if we should stop at this breakpoint, false if we
62// should continue.
63
64bool
65WatchpointLocation::BreakpointWasHit (StoppointCallbackContext *context)
66{
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;
76 return m_callback(m_callback_baton, context, GetID(), access);
77 }
78 return false;
79}
80
81void
Johnny Chen34bbf852011-09-12 23:38:44 +000082WatchpointLocation::GetDescription (Stream *s, lldb::DescriptionLevel level)
83{
Johnny Chen95f41b82011-09-13 01:13:20 +000084 s->Printf(" ");
Johnny Chen10b12b32011-09-16 21:41:42 +000085 DumpWithLevel(s, level);
Johnny Chen34bbf852011-09-12 23:38:44 +000086 return;
87}
88
89void
Chris Lattner24943d22010-06-08 16:52:24 +000090WatchpointLocation::Dump(Stream *s) const
91{
Johnny Chen10b12b32011-09-16 21:41:42 +000092 DumpWithLevel(s, lldb::eDescriptionLevelBrief);
93}
94
95void
96WatchpointLocation::DumpWithLevel(Stream *s, lldb::DescriptionLevel description_level) const
97{
Chris Lattner24943d22010-06-08 16:52:24 +000098 if (s == NULL)
99 return;
100
Johnny Chen10b12b32011-09-16 21:41:42 +0000101 assert(description_level >= lldb::eDescriptionLevelBrief &&
102 description_level <= lldb::eDescriptionLevelVerbose);
103
104 s->Printf("WatchpointLocation %u: addr = 0x%8.8llx size = %zu state = %s type = %s%s",
105 GetID(),
106 (uint64_t)m_addr,
107 m_byte_size,
108 m_enabled ? "enabled" : "disabled",
109 m_watch_read ? "r" : "",
110 m_watch_write ? "w" : "");
111
112 if (description_level >= lldb::eDescriptionLevelFull)
113 s->Printf("\n declare @ '%s'", m_decl_str.c_str());
114
115 if (description_level >= lldb::eDescriptionLevelVerbose)
116 s->Printf("\n hit_count = %-4u ignore_count = %-4u callback = %8p baton = %8p",
117 GetHitCount(),
118 GetIgnoreCount(),
119 m_callback,
120 m_callback_baton);
Chris Lattner24943d22010-06-08 16:52:24 +0000121}
122
123bool
124WatchpointLocation::IsEnabled() const
125{
126 return m_enabled;
127}
128
129void
Johnny Chen21900fb2011-09-06 22:38:36 +0000130WatchpointLocation::SetEnabled(bool enabled)
Chris Lattner24943d22010-06-08 16:52:24 +0000131{
132 if (!enabled)
133 SetHardwareIndex(LLDB_INVALID_INDEX32);
134 m_enabled = enabled;
135}
136
137void
138WatchpointLocation::SetWatchpointType (uint32_t type)
139{
140 m_watch_read = (type & LLDB_WATCH_TYPE_READ) != 0;
141 m_watch_write = (type & LLDB_WATCH_TYPE_WRITE) != 0;
142}
143
144bool
145WatchpointLocation::WatchpointRead () const
146{
147 return m_watch_read != 0;
148}
149bool
150WatchpointLocation::WatchpointWrite () const
151{
152 return m_watch_write != 0;
153}
Greg Clayton54e7afa2010-07-09 20:39:50 +0000154uint32_t
Chris Lattner24943d22010-06-08 16:52:24 +0000155WatchpointLocation::GetIgnoreCount () const
156{
157 return m_ignore_count;
158}
159
160void
Greg Clayton54e7afa2010-07-09 20:39:50 +0000161WatchpointLocation::SetIgnoreCount (uint32_t n)
Chris Lattner24943d22010-06-08 16:52:24 +0000162{
163 m_ignore_count = n;
164}