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 | |
| 21 | WatchpointLocation::WatchpointLocation (lldb::addr_t addr, lldb::tid_t tid, bool hardware) : |
| 22 | StoppointLocation (GetNextID(), addr, tid, hardware), |
| 23 | 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 | |
| 34 | WatchpointLocation::~WatchpointLocation() |
| 35 | { |
| 36 | } |
| 37 | |
| 38 | break_id_t |
| 39 | WatchpointLocation::GetNextID() |
| 40 | { |
| 41 | static break_id_t g_next_ID = 0; |
| 42 | return ++g_next_ID; |
| 43 | } |
| 44 | |
| 45 | bool |
| 46 | WatchpointLocation::SetCallback (WatchpointHitCallback callback, void *callback_baton) |
| 47 | { |
| 48 | m_callback = callback; |
| 49 | m_callback_baton = callback_baton; |
| 50 | return true; |
| 51 | } |
| 52 | |
| 53 | |
| 54 | // RETURNS - true if we should stop at this breakpoint, false if we |
| 55 | // should continue. |
| 56 | |
| 57 | bool |
| 58 | WatchpointLocation::BreakpointWasHit (StoppointCallbackContext *context) |
| 59 | { |
| 60 | m_hit_count++; |
| 61 | |
| 62 | if (m_hit_count > m_ignore_count) |
| 63 | { |
| 64 | uint32_t access = 0; |
| 65 | if (m_watch_was_read) |
| 66 | access |= LLDB_WATCH_TYPE_READ; |
| 67 | if (m_watch_was_written) |
| 68 | access |= LLDB_WATCH_TYPE_WRITE; |
| 69 | return m_callback(m_callback_baton, context, GetID(), access); |
| 70 | } |
| 71 | return false; |
| 72 | } |
| 73 | |
| 74 | void |
| 75 | WatchpointLocation::Dump(Stream *s) const |
| 76 | { |
| 77 | if (s == NULL) |
| 78 | return; |
| 79 | |
| 80 | s->Printf("WatchpointLocation %u: tid = %4.4x addr = 0x%8.8llx size = %zu state = %s type = %s watchpoint (%s%s) hw_index = %i hit_count = %-4u ignore_count = %-4u callback = %8p baton = %8p", |
| 81 | GetID(), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 82 | (uint64_t)m_addr, |
| 83 | m_byte_size, |
| 84 | m_enabled ? "enabled " : "disabled", |
| 85 | IsHardware() ? "hardware" : "software", |
| 86 | m_watch_read ? "r" : "", |
| 87 | m_watch_write ? "w" : "", |
| 88 | GetHardwareIndex(), |
| 89 | GetHitCount(), |
| 90 | GetIgnoreCount(), |
| 91 | m_callback, |
| 92 | m_callback_baton); |
| 93 | } |
| 94 | |
| 95 | bool |
| 96 | WatchpointLocation::IsEnabled() const |
| 97 | { |
| 98 | return m_enabled; |
| 99 | } |
| 100 | |
| 101 | void |
| 102 | WatchpointLocation::SetEnabled(uint32_t enabled) |
| 103 | { |
| 104 | if (!enabled) |
| 105 | SetHardwareIndex(LLDB_INVALID_INDEX32); |
| 106 | m_enabled = enabled; |
| 107 | } |
| 108 | |
| 109 | void |
| 110 | WatchpointLocation::SetWatchpointType (uint32_t type) |
| 111 | { |
| 112 | m_watch_read = (type & LLDB_WATCH_TYPE_READ) != 0; |
| 113 | m_watch_write = (type & LLDB_WATCH_TYPE_WRITE) != 0; |
| 114 | } |
| 115 | |
| 116 | bool |
| 117 | WatchpointLocation::WatchpointRead () const |
| 118 | { |
| 119 | return m_watch_read != 0; |
| 120 | } |
| 121 | bool |
| 122 | WatchpointLocation::WatchpointWrite () const |
| 123 | { |
| 124 | return m_watch_write != 0; |
| 125 | } |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 126 | uint32_t |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 127 | WatchpointLocation::GetIgnoreCount () const |
| 128 | { |
| 129 | return m_ignore_count; |
| 130 | } |
| 131 | |
| 132 | void |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 133 | WatchpointLocation::SetIgnoreCount (uint32_t n) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 134 | { |
| 135 | m_ignore_count = n; |
| 136 | } |