Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- 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 | |
| 18 | using namespace lldb; |
| 19 | using namespace lldb_private; |
| 20 | |
Johnny Chen | edda23f | 2011-09-06 02:52:28 +0000 | [diff] [blame] | 21 | WatchpointLocation::WatchpointLocation (lldb::addr_t addr, size_t size, bool hardware) : |
| 22 | StoppointLocation (GetNextID(), addr, size, hardware), |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 23 | m_target(NULL), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 24 | m_enabled(0), |
Johnny Chen | 01acfa7 | 2011-09-22 18:04:58 +0000 | [diff] [blame] | 25 | m_is_hardware(hardware), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 26 | 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 | |
| 36 | WatchpointLocation::~WatchpointLocation() |
| 37 | { |
| 38 | } |
| 39 | |
| 40 | break_id_t |
| 41 | WatchpointLocation::GetNextID() |
| 42 | { |
| 43 | static break_id_t g_next_ID = 0; |
| 44 | return ++g_next_ID; |
| 45 | } |
| 46 | |
| 47 | bool |
| 48 | WatchpointLocation::SetCallback (WatchpointHitCallback callback, void *callback_baton) |
| 49 | { |
| 50 | m_callback = callback; |
| 51 | m_callback_baton = callback_baton; |
| 52 | return true; |
| 53 | } |
| 54 | |
Johnny Chen | 10b12b3 | 2011-09-16 21:41:42 +0000 | [diff] [blame] | 55 | void |
| 56 | WatchpointLocation::SetDeclInfo (std::string &str) |
| 57 | { |
| 58 | m_decl_str = str; |
| 59 | return; |
| 60 | } |
| 61 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 62 | |
Johnny Chen | 01acfa7 | 2011-09-22 18:04:58 +0000 | [diff] [blame] | 63 | bool |
| 64 | WatchpointLocation::IsHardware () const |
| 65 | { |
| 66 | return m_is_hardware; |
| 67 | } |
| 68 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 69 | // RETURNS - true if we should stop at this breakpoint, false if we |
| 70 | // should continue. |
| 71 | |
| 72 | bool |
Johnny Chen | 043f8c2 | 2011-09-21 22:47:15 +0000 | [diff] [blame] | 73 | WatchpointLocation::ShouldStop (StoppointCallbackContext *context) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 74 | { |
Johnny Chen | 01acfa7 | 2011-09-22 18:04:58 +0000 | [diff] [blame] | 75 | ++m_hit_count; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 76 | |
Johnny Chen | 01acfa7 | 2011-09-22 18:04:58 +0000 | [diff] [blame] | 77 | if (!IsEnabled()) |
| 78 | return false; |
Johnny Chen | 043f8c2 | 2011-09-21 22:47:15 +0000 | [diff] [blame] | 79 | |
Johnny Chen | 01acfa7 | 2011-09-22 18:04:58 +0000 | [diff] [blame] | 80 | 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 Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | void |
Johnny Chen | 34bbf85 | 2011-09-12 23:38:44 +0000 | [diff] [blame] | 96 | WatchpointLocation::GetDescription (Stream *s, lldb::DescriptionLevel level) |
| 97 | { |
Johnny Chen | 10b12b3 | 2011-09-16 21:41:42 +0000 | [diff] [blame] | 98 | DumpWithLevel(s, level); |
Johnny Chen | 34bbf85 | 2011-09-12 23:38:44 +0000 | [diff] [blame] | 99 | return; |
| 100 | } |
| 101 | |
| 102 | void |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 103 | WatchpointLocation::Dump(Stream *s) const |
| 104 | { |
Johnny Chen | 10b12b3 | 2011-09-16 21:41:42 +0000 | [diff] [blame] | 105 | DumpWithLevel(s, lldb::eDescriptionLevelBrief); |
| 106 | } |
| 107 | |
| 108 | void |
| 109 | WatchpointLocation::DumpWithLevel(Stream *s, lldb::DescriptionLevel description_level) const |
| 110 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 111 | if (s == NULL) |
| 112 | return; |
| 113 | |
Johnny Chen | 10b12b3 | 2011-09-16 21:41:42 +0000 | [diff] [blame] | 114 | 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 Chen | da5a802 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 129 | s->Printf("\n hw_index = %i hit_count = %-4u ignore_count = %-4u callback = %8p baton = %8p", |
| 130 | GetHardwareIndex(), |
Johnny Chen | 10b12b3 | 2011-09-16 21:41:42 +0000 | [diff] [blame] | 131 | GetHitCount(), |
| 132 | GetIgnoreCount(), |
| 133 | m_callback, |
| 134 | m_callback_baton); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | bool |
| 138 | WatchpointLocation::IsEnabled() const |
| 139 | { |
| 140 | return m_enabled; |
| 141 | } |
| 142 | |
| 143 | void |
Johnny Chen | 21900fb | 2011-09-06 22:38:36 +0000 | [diff] [blame] | 144 | WatchpointLocation::SetEnabled(bool enabled) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 145 | { |
| 146 | if (!enabled) |
| 147 | SetHardwareIndex(LLDB_INVALID_INDEX32); |
| 148 | m_enabled = enabled; |
| 149 | } |
| 150 | |
| 151 | void |
| 152 | WatchpointLocation::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 | |
| 158 | bool |
| 159 | WatchpointLocation::WatchpointRead () const |
| 160 | { |
| 161 | return m_watch_read != 0; |
| 162 | } |
| 163 | bool |
| 164 | WatchpointLocation::WatchpointWrite () const |
| 165 | { |
| 166 | return m_watch_write != 0; |
| 167 | } |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 168 | uint32_t |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 169 | WatchpointLocation::GetIgnoreCount () const |
| 170 | { |
| 171 | return m_ignore_count; |
| 172 | } |
| 173 | |
| 174 | void |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 175 | WatchpointLocation::SetIgnoreCount (uint32_t n) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 176 | { |
| 177 | m_ignore_count = n; |
| 178 | } |