Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 1 | //===-- Watchpoint.cpp ------------------------------------------*- C++ -*-===// |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 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 | |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 10 | #include "lldb/Breakpoint/Watchpoint.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 11 | |
| 12 | // C Includes |
| 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
| 15 | // Project includes |
Johnny Chen | 712a628 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 16 | #include "lldb/Breakpoint/StoppointCallbackContext.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 17 | #include "lldb/Core/Stream.h" |
Jim Ingham | 9e37662 | 2012-10-23 07:20:06 +0000 | [diff] [blame] | 18 | #include "lldb/Core/Value.h" |
| 19 | #include "lldb/Core/ValueObject.h" |
| 20 | #include "lldb/Core/ValueObjectMemory.h" |
| 21 | #include "lldb/Symbol/ClangASTContext.h" |
Johnny Chen | 712a628 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 22 | #include "lldb/Target/Process.h" |
| 23 | #include "lldb/Target/Target.h" |
| 24 | #include "lldb/Target/ThreadSpec.h" |
Jim Ingham | 14f17cf | 2012-05-02 00:30:53 +0000 | [diff] [blame] | 25 | #include "lldb/Expression/ClangUserExpression.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 26 | |
| 27 | using namespace lldb; |
| 28 | using namespace lldb_private; |
| 29 | |
Jim Ingham | 9e37662 | 2012-10-23 07:20:06 +0000 | [diff] [blame] | 30 | Watchpoint::Watchpoint (Target& target, lldb::addr_t addr, size_t size, const ClangASTType *type, bool hardware) : |
Johnny Chen | 116a5cd | 2012-02-25 06:44:30 +0000 | [diff] [blame] | 31 | StoppointLocation (0, addr, size, hardware), |
Jim Ingham | 9e37662 | 2012-10-23 07:20:06 +0000 | [diff] [blame] | 32 | m_target(target), |
Johnny Chen | 116a5cd | 2012-02-25 06:44:30 +0000 | [diff] [blame] | 33 | m_enabled(false), |
Johnny Chen | 01acfa7 | 2011-09-22 18:04:58 +0000 | [diff] [blame] | 34 | m_is_hardware(hardware), |
Johnny Chen | 9e98559 | 2012-08-13 21:09:54 +0000 | [diff] [blame] | 35 | m_is_watch_variable(false), |
Johnny Chen | f84e566 | 2012-08-21 23:17:04 +0000 | [diff] [blame] | 36 | m_is_ephemeral(false), |
Johnny Chen | 258db3a | 2012-08-23 22:28:26 +0000 | [diff] [blame] | 37 | m_disabled_count(0), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 38 | m_watch_read(0), |
| 39 | m_watch_write(0), |
| 40 | m_watch_was_read(0), |
| 41 | m_watch_was_written(0), |
| 42 | m_ignore_count(0), |
Johnny Chen | 0b09366 | 2012-08-14 20:56:37 +0000 | [diff] [blame] | 43 | m_false_alarms(0), |
Johnny Chen | 41a55ef | 2011-10-14 19:15:48 +0000 | [diff] [blame] | 44 | m_decl_str(), |
Johnny Chen | 116a5cd | 2012-02-25 06:44:30 +0000 | [diff] [blame] | 45 | m_watch_spec_str(), |
Jim Ingham | 9e37662 | 2012-10-23 07:20:06 +0000 | [diff] [blame] | 46 | m_type(), |
Johnny Chen | f3ec461 | 2012-08-09 23:09:42 +0000 | [diff] [blame] | 47 | m_error(), |
| 48 | m_options () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 49 | { |
Jim Ingham | 9e37662 | 2012-10-23 07:20:06 +0000 | [diff] [blame] | 50 | if (type && type->IsValid()) |
| 51 | m_type = *type; |
| 52 | else |
| 53 | { |
| 54 | // If we don't have a known type, then we force it to unsigned int of the right size. |
| 55 | ClangASTContext *ast_context = target.GetScratchClangASTContext(); |
Jim Ingham | ed2b62a | 2012-10-23 21:09:09 +0000 | [diff] [blame] | 56 | clang_type_t clang_type = ast_context->GetBuiltinTypeForEncodingAndBitSize(eEncodingUint, 8 * size); |
Jim Ingham | 9e37662 | 2012-10-23 07:20:06 +0000 | [diff] [blame] | 57 | m_type.SetClangType(ast_context->getASTContext(), clang_type); |
| 58 | } |
| 59 | |
| 60 | // Set the initial value of the watched variable: |
| 61 | if (m_target.GetProcessSP()) |
| 62 | { |
| 63 | ExecutionContext exe_ctx; |
| 64 | m_target.GetProcessSP()->CalculateExecutionContext(exe_ctx); |
| 65 | CaptureWatchedValue (exe_ctx); |
| 66 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 67 | } |
| 68 | |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 69 | Watchpoint::~Watchpoint() |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 70 | { |
| 71 | } |
| 72 | |
Johnny Chen | f3ec461 | 2012-08-09 23:09:42 +0000 | [diff] [blame] | 73 | // This function is used when "baton" doesn't need to be freed |
| 74 | void |
| 75 | Watchpoint::SetCallback (WatchpointHitCallback callback, void *baton, bool is_synchronous) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 76 | { |
Johnny Chen | f3ec461 | 2012-08-09 23:09:42 +0000 | [diff] [blame] | 77 | // The default "Baton" class will keep a copy of "baton" and won't free |
| 78 | // or delete it when it goes goes out of scope. |
| 79 | m_options.SetCallback(callback, BatonSP (new Baton(baton)), is_synchronous); |
| 80 | |
| 81 | //SendWatchpointChangedEvent (eWatchpointEventTypeCommandChanged); |
| 82 | } |
| 83 | |
| 84 | // This function is used when a baton needs to be freed and therefore is |
| 85 | // contained in a "Baton" subclass. |
| 86 | void |
| 87 | Watchpoint::SetCallback (WatchpointHitCallback callback, const BatonSP &callback_baton_sp, bool is_synchronous) |
| 88 | { |
| 89 | m_options.SetCallback(callback, callback_baton_sp, is_synchronous); |
| 90 | } |
| 91 | |
| 92 | void |
| 93 | Watchpoint::ClearCallback () |
| 94 | { |
| 95 | m_options.ClearCallback (); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Johnny Chen | 10b12b3 | 2011-09-16 21:41:42 +0000 | [diff] [blame] | 98 | void |
Johnny Chen | 9e98559 | 2012-08-13 21:09:54 +0000 | [diff] [blame] | 99 | Watchpoint::SetDeclInfo (const std::string &str) |
Johnny Chen | 10b12b3 | 2011-09-16 21:41:42 +0000 | [diff] [blame] | 100 | { |
| 101 | m_decl_str = str; |
| 102 | return; |
| 103 | } |
| 104 | |
Johnny Chen | 9e98559 | 2012-08-13 21:09:54 +0000 | [diff] [blame] | 105 | std::string |
| 106 | Watchpoint::GetWatchSpec() |
| 107 | { |
| 108 | return m_watch_spec_str; |
| 109 | } |
| 110 | |
Johnny Chen | 116a5cd | 2012-02-25 06:44:30 +0000 | [diff] [blame] | 111 | void |
Johnny Chen | 9e98559 | 2012-08-13 21:09:54 +0000 | [diff] [blame] | 112 | Watchpoint::SetWatchSpec (const std::string &str) |
Johnny Chen | 116a5cd | 2012-02-25 06:44:30 +0000 | [diff] [blame] | 113 | { |
| 114 | m_watch_spec_str = str; |
| 115 | return; |
| 116 | } |
| 117 | |
Johnny Chen | 51b7c5f | 2012-01-23 23:03:59 +0000 | [diff] [blame] | 118 | // Override default impl of StoppointLocation::IsHardware() since m_is_hardware |
| 119 | // member field is more accurate. |
Johnny Chen | 01acfa7 | 2011-09-22 18:04:58 +0000 | [diff] [blame] | 120 | bool |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 121 | Watchpoint::IsHardware () const |
Johnny Chen | 01acfa7 | 2011-09-22 18:04:58 +0000 | [diff] [blame] | 122 | { |
| 123 | return m_is_hardware; |
| 124 | } |
| 125 | |
Johnny Chen | 9e98559 | 2012-08-13 21:09:54 +0000 | [diff] [blame] | 126 | bool |
| 127 | Watchpoint::IsWatchVariable() const |
| 128 | { |
| 129 | return m_is_watch_variable; |
| 130 | } |
| 131 | |
| 132 | void |
| 133 | Watchpoint::SetWatchVariable(bool val) |
| 134 | { |
| 135 | m_is_watch_variable = val; |
| 136 | } |
| 137 | |
Jim Ingham | 9e37662 | 2012-10-23 07:20:06 +0000 | [diff] [blame] | 138 | bool |
| 139 | Watchpoint::CaptureWatchedValue (const ExecutionContext &exe_ctx) |
| 140 | { |
| 141 | ConstString watch_name("$__lldb__watch_value"); |
| 142 | m_old_value_sp = m_new_value_sp; |
| 143 | Address watch_address(GetLoadAddress()); |
Jim Ingham | ed2b62a | 2012-10-23 21:09:09 +0000 | [diff] [blame] | 144 | if (!m_type.IsValid()) |
| 145 | { |
| 146 | // Don't know how to report new & old values, since we couldn't make a scalar type for this watchpoint. |
| 147 | // This works around an assert in ValueObjectMemory::Create. |
| 148 | // FIXME: This should not happen, but if it does in some case we care about, |
| 149 | // we can go grab the value raw and print it as unsigned. |
| 150 | return false; |
| 151 | } |
Jim Ingham | 9e37662 | 2012-10-23 07:20:06 +0000 | [diff] [blame] | 152 | m_new_value_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(), watch_name.AsCString(), watch_address, m_type); |
| 153 | m_new_value_sp = m_new_value_sp->CreateConstantValue(watch_name); |
| 154 | if (m_new_value_sp && m_new_value_sp->GetError().Success()) |
| 155 | return true; |
| 156 | else |
| 157 | return false; |
| 158 | } |
| 159 | |
Johnny Chen | 0b09366 | 2012-08-14 20:56:37 +0000 | [diff] [blame] | 160 | void |
| 161 | Watchpoint::IncrementFalseAlarmsAndReviseHitCount() |
| 162 | { |
| 163 | ++m_false_alarms; |
| 164 | if (m_false_alarms) |
| 165 | { |
| 166 | if (m_hit_count >= m_false_alarms) |
| 167 | { |
| 168 | m_hit_count -= m_false_alarms; |
| 169 | m_false_alarms = 0; |
| 170 | } |
| 171 | else |
| 172 | { |
| 173 | m_false_alarms -= m_hit_count; |
| 174 | m_hit_count = 0; |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 179 | // RETURNS - true if we should stop at this breakpoint, false if we |
| 180 | // should continue. |
| 181 | |
| 182 | bool |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 183 | Watchpoint::ShouldStop (StoppointCallbackContext *context) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 184 | { |
Johnny Chen | 51b7c5f | 2012-01-23 23:03:59 +0000 | [diff] [blame] | 185 | IncrementHitCount(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 186 | |
Johnny Chen | 01acfa7 | 2011-09-22 18:04:58 +0000 | [diff] [blame] | 187 | if (!IsEnabled()) |
| 188 | return false; |
Johnny Chen | 043f8c2 | 2011-09-21 22:47:15 +0000 | [diff] [blame] | 189 | |
Johnny Chen | 51b7c5f | 2012-01-23 23:03:59 +0000 | [diff] [blame] | 190 | if (GetHitCount() <= GetIgnoreCount()) |
Johnny Chen | 01acfa7 | 2011-09-22 18:04:58 +0000 | [diff] [blame] | 191 | return false; |
| 192 | |
Johnny Chen | 712a628 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 193 | return true; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | void |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 197 | Watchpoint::GetDescription (Stream *s, lldb::DescriptionLevel level) |
Johnny Chen | 34bbf85 | 2011-09-12 23:38:44 +0000 | [diff] [blame] | 198 | { |
Johnny Chen | 10b12b3 | 2011-09-16 21:41:42 +0000 | [diff] [blame] | 199 | DumpWithLevel(s, level); |
Johnny Chen | 34bbf85 | 2011-09-12 23:38:44 +0000 | [diff] [blame] | 200 | return; |
| 201 | } |
| 202 | |
| 203 | void |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 204 | Watchpoint::Dump(Stream *s) const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 205 | { |
Johnny Chen | 10b12b3 | 2011-09-16 21:41:42 +0000 | [diff] [blame] | 206 | DumpWithLevel(s, lldb::eDescriptionLevelBrief); |
| 207 | } |
| 208 | |
Johnny Chen | c9c2a9b | 2012-08-13 23:27:50 +0000 | [diff] [blame] | 209 | // If prefix is NULL, we display the watch id and ignore the prefix altogether. |
Johnny Chen | 10b12b3 | 2011-09-16 21:41:42 +0000 | [diff] [blame] | 210 | void |
Johnny Chen | c9c2a9b | 2012-08-13 23:27:50 +0000 | [diff] [blame] | 211 | Watchpoint::DumpSnapshots(Stream *s, const char *prefix) const |
Johnny Chen | 9e98559 | 2012-08-13 21:09:54 +0000 | [diff] [blame] | 212 | { |
Johnny Chen | c9c2a9b | 2012-08-13 23:27:50 +0000 | [diff] [blame] | 213 | if (!prefix) |
| 214 | { |
| 215 | s->Printf("\nWatchpoint %u hit:", GetID()); |
| 216 | prefix = ""; |
| 217 | } |
Jim Ingham | 9e37662 | 2012-10-23 07:20:06 +0000 | [diff] [blame] | 218 | |
| 219 | if (m_old_value_sp) |
Johnny Chen | 9e98559 | 2012-08-13 21:09:54 +0000 | [diff] [blame] | 220 | { |
Jim Ingham | 9e37662 | 2012-10-23 07:20:06 +0000 | [diff] [blame] | 221 | s->Printf("\n%sold value: %s", prefix, m_old_value_sp->GetValueAsCString()); |
Johnny Chen | 9e98559 | 2012-08-13 21:09:54 +0000 | [diff] [blame] | 222 | } |
Jim Ingham | 9e37662 | 2012-10-23 07:20:06 +0000 | [diff] [blame] | 223 | if (m_new_value_sp) |
Johnny Chen | 9e98559 | 2012-08-13 21:09:54 +0000 | [diff] [blame] | 224 | { |
Jim Ingham | 9e37662 | 2012-10-23 07:20:06 +0000 | [diff] [blame] | 225 | s->Printf("\n%snew value: %s", prefix, m_new_value_sp->GetValueAsCString()); |
Johnny Chen | 9e98559 | 2012-08-13 21:09:54 +0000 | [diff] [blame] | 226 | } |
| 227 | } |
| 228 | |
| 229 | void |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 230 | Watchpoint::DumpWithLevel(Stream *s, lldb::DescriptionLevel description_level) const |
Johnny Chen | 10b12b3 | 2011-09-16 21:41:42 +0000 | [diff] [blame] | 231 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 232 | if (s == NULL) |
| 233 | return; |
| 234 | |
Johnny Chen | 10b12b3 | 2011-09-16 21:41:42 +0000 | [diff] [blame] | 235 | assert(description_level >= lldb::eDescriptionLevelBrief && |
| 236 | description_level <= lldb::eDescriptionLevelVerbose); |
| 237 | |
Daniel Malea | 5f35a4b | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 238 | s->Printf("Watchpoint %u: addr = 0x%8.8" PRIx64 " size = %u state = %s type = %s%s", |
Johnny Chen | 10b12b3 | 2011-09-16 21:41:42 +0000 | [diff] [blame] | 239 | GetID(), |
Johnny Chen | 1c2d941 | 2012-01-24 00:11:02 +0000 | [diff] [blame] | 240 | GetLoadAddress(), |
Johnny Chen | 10b12b3 | 2011-09-16 21:41:42 +0000 | [diff] [blame] | 241 | m_byte_size, |
Johnny Chen | 116a5cd | 2012-02-25 06:44:30 +0000 | [diff] [blame] | 242 | IsEnabled() ? "enabled" : "disabled", |
Johnny Chen | 10b12b3 | 2011-09-16 21:41:42 +0000 | [diff] [blame] | 243 | m_watch_read ? "r" : "", |
| 244 | m_watch_write ? "w" : ""); |
| 245 | |
Johnny Chen | 712a628 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 246 | if (description_level >= lldb::eDescriptionLevelFull) { |
Johnny Chen | 55a2d5a | 2012-01-30 21:46:17 +0000 | [diff] [blame] | 247 | if (!m_decl_str.empty()) |
Johnny Chen | 712a628 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 248 | s->Printf("\n declare @ '%s'", m_decl_str.c_str()); |
Johnny Chen | 116a5cd | 2012-02-25 06:44:30 +0000 | [diff] [blame] | 249 | if (!m_watch_spec_str.empty()) |
Johnny Chen | 9e98559 | 2012-08-13 21:09:54 +0000 | [diff] [blame] | 250 | s->Printf("\n watchpoint spec = '%s'", m_watch_spec_str.c_str()); |
| 251 | |
| 252 | // Dump the snapshots we have taken. |
Johnny Chen | c9c2a9b | 2012-08-13 23:27:50 +0000 | [diff] [blame] | 253 | DumpSnapshots(s, " "); |
Johnny Chen | 9e98559 | 2012-08-13 21:09:54 +0000 | [diff] [blame] | 254 | |
Johnny Chen | 712a628 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 255 | if (GetConditionText()) |
| 256 | s->Printf("\n condition = '%s'", GetConditionText()); |
Johnny Chen | f3ec461 | 2012-08-09 23:09:42 +0000 | [diff] [blame] | 257 | m_options.GetCallbackDescription(s, description_level); |
Johnny Chen | 712a628 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 258 | } |
Johnny Chen | 10b12b3 | 2011-09-16 21:41:42 +0000 | [diff] [blame] | 259 | |
| 260 | if (description_level >= lldb::eDescriptionLevelVerbose) |
Jason Molenda | a4a1587 | 2012-02-23 22:32:13 +0000 | [diff] [blame] | 261 | { |
Johnny Chen | f3ec461 | 2012-08-09 23:09:42 +0000 | [diff] [blame] | 262 | s->Printf("\n hw_index = %i hit_count = %-4u ignore_count = %-4u", |
| 263 | GetHardwareIndex(), |
| 264 | GetHitCount(), |
| 265 | GetIgnoreCount()); |
Jason Molenda | a4a1587 | 2012-02-23 22:32:13 +0000 | [diff] [blame] | 266 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | bool |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 270 | Watchpoint::IsEnabled() const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 271 | { |
| 272 | return m_enabled; |
| 273 | } |
| 274 | |
Johnny Chen | f84e566 | 2012-08-21 23:17:04 +0000 | [diff] [blame] | 275 | // Within StopInfo.cpp, we purposely turn on the ephemeral mode right before temporarily disable the watchpoint |
| 276 | // in order to perform possible watchpoint actions without triggering further watchpoint events. |
| 277 | // After the temporary disabled watchpoint is enabled, we then turn off the ephemeral mode. |
| 278 | |
| 279 | void |
| 280 | Watchpoint::TurnOnEphemeralMode() |
| 281 | { |
| 282 | m_is_ephemeral = true; |
| 283 | } |
| 284 | |
| 285 | void |
| 286 | Watchpoint::TurnOffEphemeralMode() |
| 287 | { |
| 288 | m_is_ephemeral = false; |
Johnny Chen | 258db3a | 2012-08-23 22:28:26 +0000 | [diff] [blame] | 289 | // Leaving ephemeral mode, reset the m_disabled_count! |
| 290 | m_disabled_count = 0; |
| 291 | } |
| 292 | |
| 293 | bool |
| 294 | Watchpoint::IsDisabledDuringEphemeralMode() |
| 295 | { |
| 296 | return m_disabled_count > 1; |
Johnny Chen | f84e566 | 2012-08-21 23:17:04 +0000 | [diff] [blame] | 297 | } |
| 298 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 299 | void |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 300 | Watchpoint::SetEnabled(bool enabled) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 301 | { |
| 302 | if (!enabled) |
Johnny Chen | c9c2a9b | 2012-08-13 23:27:50 +0000 | [diff] [blame] | 303 | { |
Johnny Chen | f84e566 | 2012-08-21 23:17:04 +0000 | [diff] [blame] | 304 | if (!m_is_ephemeral) |
| 305 | SetHardwareIndex(LLDB_INVALID_INDEX32); |
Johnny Chen | 258db3a | 2012-08-23 22:28:26 +0000 | [diff] [blame] | 306 | else |
| 307 | ++m_disabled_count; |
| 308 | |
Johnny Chen | bd446f1 | 2012-08-21 22:06:34 +0000 | [diff] [blame] | 309 | // Don't clear the snapshots for now. |
| 310 | // Within StopInfo.cpp, we purposely do disable/enable watchpoint while performing watchpoint actions. |
Johnny Chen | c9c2a9b | 2012-08-13 23:27:50 +0000 | [diff] [blame] | 311 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 312 | m_enabled = enabled; |
| 313 | } |
| 314 | |
| 315 | void |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 316 | Watchpoint::SetWatchpointType (uint32_t type) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 317 | { |
| 318 | m_watch_read = (type & LLDB_WATCH_TYPE_READ) != 0; |
| 319 | m_watch_write = (type & LLDB_WATCH_TYPE_WRITE) != 0; |
| 320 | } |
| 321 | |
| 322 | bool |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 323 | Watchpoint::WatchpointRead () const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 324 | { |
| 325 | return m_watch_read != 0; |
| 326 | } |
| 327 | bool |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 328 | Watchpoint::WatchpointWrite () const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 329 | { |
| 330 | return m_watch_write != 0; |
| 331 | } |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 332 | uint32_t |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 333 | Watchpoint::GetIgnoreCount () const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 334 | { |
| 335 | return m_ignore_count; |
| 336 | } |
| 337 | |
| 338 | void |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 339 | Watchpoint::SetIgnoreCount (uint32_t n) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 340 | { |
| 341 | m_ignore_count = n; |
| 342 | } |
Johnny Chen | 712a628 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 343 | |
| 344 | bool |
| 345 | Watchpoint::InvokeCallback (StoppointCallbackContext *context) |
| 346 | { |
Johnny Chen | f3ec461 | 2012-08-09 23:09:42 +0000 | [diff] [blame] | 347 | return m_options.InvokeCallback (context, GetID()); |
Johnny Chen | 712a628 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | void |
| 351 | Watchpoint::SetCondition (const char *condition) |
| 352 | { |
| 353 | if (condition == NULL || condition[0] == '\0') |
| 354 | { |
| 355 | if (m_condition_ap.get()) |
| 356 | m_condition_ap.reset(); |
| 357 | } |
| 358 | else |
| 359 | { |
| 360 | // Pass NULL for expr_prefix (no translation-unit level definitions). |
Sean Callanan | daa6efe | 2011-12-21 22:22:58 +0000 | [diff] [blame] | 361 | m_condition_ap.reset(new ClangUserExpression (condition, NULL, lldb::eLanguageTypeUnknown, ClangUserExpression::eResultTypeAny)); |
Johnny Chen | 712a628 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 362 | } |
| 363 | } |
| 364 | |
| 365 | const char * |
| 366 | Watchpoint::GetConditionText () const |
| 367 | { |
| 368 | if (m_condition_ap.get()) |
| 369 | return m_condition_ap->GetUserText(); |
| 370 | else |
| 371 | return NULL; |
| 372 | } |
| 373 | |