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), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 23 | m_enabled(0), |
Johnny Chen | 01acfa7 | 2011-09-22 18:04:58 +0000 | [diff] [blame] | 24 | m_is_hardware(hardware), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 25 | 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 | |
| 35 | WatchpointLocation::~WatchpointLocation() |
| 36 | { |
| 37 | } |
| 38 | |
| 39 | break_id_t |
| 40 | WatchpointLocation::GetNextID() |
| 41 | { |
| 42 | static break_id_t g_next_ID = 0; |
| 43 | return ++g_next_ID; |
| 44 | } |
| 45 | |
| 46 | bool |
| 47 | WatchpointLocation::SetCallback (WatchpointHitCallback callback, void *callback_baton) |
| 48 | { |
| 49 | m_callback = callback; |
| 50 | m_callback_baton = callback_baton; |
| 51 | return true; |
| 52 | } |
| 53 | |
Johnny Chen | 10b12b3 | 2011-09-16 21:41:42 +0000 | [diff] [blame] | 54 | void |
| 55 | WatchpointLocation::SetDeclInfo (std::string &str) |
| 56 | { |
| 57 | m_decl_str = str; |
| 58 | return; |
| 59 | } |
| 60 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 61 | |
Johnny Chen | 01acfa7 | 2011-09-22 18:04:58 +0000 | [diff] [blame] | 62 | bool |
| 63 | WatchpointLocation::IsHardware () const |
| 64 | { |
| 65 | return m_is_hardware; |
| 66 | } |
| 67 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 68 | // RETURNS - true if we should stop at this breakpoint, false if we |
| 69 | // should continue. |
| 70 | |
| 71 | bool |
Johnny Chen | 043f8c2 | 2011-09-21 22:47:15 +0000 | [diff] [blame] | 72 | WatchpointLocation::ShouldStop (StoppointCallbackContext *context) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 73 | { |
Johnny Chen | 01acfa7 | 2011-09-22 18:04:58 +0000 | [diff] [blame] | 74 | ++m_hit_count; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 75 | |
Johnny Chen | 01acfa7 | 2011-09-22 18:04:58 +0000 | [diff] [blame] | 76 | if (!IsEnabled()) |
| 77 | return false; |
Johnny Chen | 043f8c2 | 2011-09-21 22:47:15 +0000 | [diff] [blame] | 78 | |
Johnny Chen | 01acfa7 | 2011-09-22 18:04:58 +0000 | [diff] [blame] | 79 | 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 Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | void |
Johnny Chen | 34bbf85 | 2011-09-12 23:38:44 +0000 | [diff] [blame] | 95 | WatchpointLocation::GetDescription (Stream *s, lldb::DescriptionLevel level) |
| 96 | { |
Johnny Chen | 95f41b8 | 2011-09-13 01:13:20 +0000 | [diff] [blame] | 97 | s->Printf(" "); |
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 | } |