Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 1 | //===-- StopInfo.cpp --------------------------------------------*- C++ -*-===// |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +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 | |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 10 | // C Includes |
| 11 | // C++ Includes |
| 12 | #include <string> |
| 13 | |
| 14 | // Other libraries and framework includes |
| 15 | // Project includes |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 16 | #include "lldb/Target/StopInfo.h" |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 17 | #include "lldb/Core/Log.h" |
Greg Clayton | 4e78f60 | 2010-11-18 18:52:36 +0000 | [diff] [blame] | 18 | #include "lldb/Breakpoint/Breakpoint.h" |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 19 | #include "lldb/Breakpoint/BreakpointLocation.h" |
| 20 | #include "lldb/Breakpoint/StoppointCallbackContext.h" |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 21 | #include "lldb/Breakpoint/Watchpoint.h" |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 22 | #include "lldb/Core/Debugger.h" |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 23 | #include "lldb/Core/StreamString.h" |
Zachary Turner | a78bd7f | 2015-03-03 23:11:11 +0000 | [diff] [blame] | 24 | #include "lldb/Core/ValueObject.h" |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 25 | #include "lldb/Expression/UserExpression.h" |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 26 | #include "lldb/Target/Target.h" |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 27 | #include "lldb/Target/Thread.h" |
| 28 | #include "lldb/Target/ThreadPlan.h" |
| 29 | #include "lldb/Target/Process.h" |
| 30 | #include "lldb/Target/UnixSignals.h" |
| 31 | |
| 32 | using namespace lldb; |
| 33 | using namespace lldb_private; |
| 34 | |
| 35 | StopInfo::StopInfo (Thread &thread, uint64_t value) : |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 36 | m_thread_wp (thread.shared_from_this()), |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 37 | m_stop_id (thread.GetProcess()->GetStopID()), |
| 38 | m_resume_id (thread.GetProcess()->GetResumeID()), |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 39 | m_value (value), |
Jason Molenda | 0453be9 | 2015-05-15 00:19:28 +0000 | [diff] [blame] | 40 | m_description (), |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 41 | m_override_should_notify (eLazyBoolCalculate), |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 42 | m_override_should_stop (eLazyBoolCalculate), |
| 43 | m_extended_info() |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 44 | { |
| 45 | } |
| 46 | |
| 47 | bool |
| 48 | StopInfo::IsValid () const |
| 49 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 50 | ThreadSP thread_sp (m_thread_wp.lock()); |
| 51 | if (thread_sp) |
| 52 | return thread_sp->GetProcess()->GetStopID() == m_stop_id; |
| 53 | return false; |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 54 | } |
| 55 | |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 56 | void |
| 57 | StopInfo::MakeStopInfoValid () |
| 58 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 59 | ThreadSP thread_sp (m_thread_wp.lock()); |
| 60 | if (thread_sp) |
| 61 | { |
| 62 | m_stop_id = thread_sp->GetProcess()->GetStopID(); |
| 63 | m_resume_id = thread_sp->GetProcess()->GetResumeID(); |
| 64 | } |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Jim Ingham | 0faa43f | 2011-11-08 03:00:11 +0000 | [diff] [blame] | 67 | bool |
| 68 | StopInfo::HasTargetRunSinceMe () |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 69 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 70 | ThreadSP thread_sp (m_thread_wp.lock()); |
| 71 | |
| 72 | if (thread_sp) |
Jim Ingham | 0faa43f | 2011-11-08 03:00:11 +0000 | [diff] [blame] | 73 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 74 | lldb::StateType ret_type = thread_sp->GetProcess()->GetPrivateState(); |
| 75 | if (ret_type == eStateRunning) |
Jim Ingham | 0faa43f | 2011-11-08 03:00:11 +0000 | [diff] [blame] | 76 | { |
| 77 | return true; |
| 78 | } |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 79 | else if (ret_type == eStateStopped) |
| 80 | { |
| 81 | // This is a little tricky. We want to count "run and stopped again before you could |
| 82 | // ask this question as a "TRUE" answer to HasTargetRunSinceMe. But we don't want to |
| 83 | // include any running of the target done for expressions. So we track both resumes, |
| 84 | // and resumes caused by expressions, and check if there are any resumes NOT caused |
| 85 | // by expressions. |
| 86 | |
| 87 | uint32_t curr_resume_id = thread_sp->GetProcess()->GetResumeID(); |
| 88 | uint32_t last_user_expression_id = thread_sp->GetProcess()->GetLastUserExpressionResumeID (); |
| 89 | if (curr_resume_id == m_resume_id) |
| 90 | { |
| 91 | return false; |
| 92 | } |
| 93 | else if (curr_resume_id > last_user_expression_id) |
| 94 | { |
| 95 | return true; |
| 96 | } |
| 97 | } |
Jim Ingham | 0faa43f | 2011-11-08 03:00:11 +0000 | [diff] [blame] | 98 | } |
| 99 | return false; |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 100 | } |
| 101 | |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 102 | //---------------------------------------------------------------------- |
| 103 | // StopInfoBreakpoint |
| 104 | //---------------------------------------------------------------------- |
| 105 | |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 106 | namespace lldb_private |
| 107 | { |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 108 | class StopInfoBreakpoint : public StopInfo |
| 109 | { |
| 110 | public: |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 111 | StopInfoBreakpoint (Thread &thread, break_id_t break_id) : |
| 112 | StopInfo (thread, break_id), |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 113 | m_should_stop (false), |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 114 | m_should_stop_is_valid (false), |
Jim Ingham | 52c7d20 | 2011-10-28 01:12:19 +0000 | [diff] [blame] | 115 | m_should_perform_action (true), |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 116 | m_address (LLDB_INVALID_ADDRESS), |
| 117 | m_break_id(LLDB_INVALID_BREAK_ID), |
| 118 | m_was_one_shot (false) |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 119 | { |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 120 | StoreBPInfo(); |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 121 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 122 | |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 123 | StopInfoBreakpoint (Thread &thread, break_id_t break_id, bool should_stop) : |
| 124 | StopInfo (thread, break_id), |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 125 | m_should_stop (should_stop), |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 126 | m_should_stop_is_valid (true), |
Jim Ingham | 52c7d20 | 2011-10-28 01:12:19 +0000 | [diff] [blame] | 127 | m_should_perform_action (true), |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 128 | m_address (LLDB_INVALID_ADDRESS), |
| 129 | m_break_id(LLDB_INVALID_BREAK_ID), |
| 130 | m_was_one_shot (false) |
| 131 | { |
| 132 | StoreBPInfo(); |
| 133 | } |
| 134 | |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 135 | ~StopInfoBreakpoint() override = default; |
| 136 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 137 | void |
| 138 | StoreBPInfo () |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 139 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 140 | ThreadSP thread_sp (m_thread_wp.lock()); |
| 141 | if (thread_sp) |
Jim Ingham | 52c7d20 | 2011-10-28 01:12:19 +0000 | [diff] [blame] | 142 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 143 | BreakpointSiteSP bp_site_sp (thread_sp->GetProcess()->GetBreakpointSiteList().FindByID (m_value)); |
| 144 | if (bp_site_sp) |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 145 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 146 | if (bp_site_sp->GetNumberOfOwners() == 1) |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 147 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 148 | BreakpointLocationSP bp_loc_sp = bp_site_sp->GetOwnerAtIndex(0); |
| 149 | if (bp_loc_sp) |
| 150 | { |
| 151 | m_break_id = bp_loc_sp->GetBreakpoint().GetID(); |
| 152 | m_was_one_shot = bp_loc_sp->GetBreakpoint().IsOneShot(); |
| 153 | } |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 154 | } |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 155 | m_address = bp_site_sp->GetLoadAddress(); |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 156 | } |
Jim Ingham | 52c7d20 | 2011-10-28 01:12:19 +0000 | [diff] [blame] | 157 | } |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 158 | } |
| 159 | |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 160 | bool |
| 161 | IsValidForOperatingSystemThread(Thread &thread) override |
Greg Clayton | ab745c2 | 2015-04-07 22:17:41 +0000 | [diff] [blame] | 162 | { |
| 163 | ProcessSP process_sp (thread.GetProcess()); |
| 164 | if (process_sp) |
| 165 | { |
| 166 | BreakpointSiteSP bp_site_sp (process_sp->GetBreakpointSiteList().FindByID (m_value)); |
| 167 | if (bp_site_sp) |
| 168 | return bp_site_sp->ValidForThisThread (&thread); |
| 169 | } |
| 170 | return false; |
| 171 | } |
| 172 | |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 173 | StopReason |
| 174 | GetStopReason() const override |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 175 | { |
| 176 | return eStopReasonBreakpoint; |
| 177 | } |
| 178 | |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 179 | bool |
| 180 | ShouldStopSynchronous(Event *event_ptr) override |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 181 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 182 | ThreadSP thread_sp (m_thread_wp.lock()); |
| 183 | if (thread_sp) |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 184 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 185 | if (!m_should_stop_is_valid) |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 186 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 187 | // Only check once if we should stop at a breakpoint |
| 188 | BreakpointSiteSP bp_site_sp (thread_sp->GetProcess()->GetBreakpointSiteList().FindByID (m_value)); |
| 189 | if (bp_site_sp) |
| 190 | { |
| 191 | ExecutionContext exe_ctx (thread_sp->GetStackFrameAtIndex(0)); |
| 192 | StoppointCallbackContext context (event_ptr, exe_ctx, true); |
Jim Ingham | a672ece | 2014-10-22 01:54:17 +0000 | [diff] [blame] | 193 | bp_site_sp->BumpHitCounts(); |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 194 | m_should_stop = bp_site_sp->ShouldStop (&context); |
| 195 | } |
| 196 | else |
| 197 | { |
| 198 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 199 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 200 | if (log) |
| 201 | log->Printf ("Process::%s could not find breakpoint site id: %" PRId64 "...", __FUNCTION__, m_value); |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 202 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 203 | m_should_stop = true; |
| 204 | } |
| 205 | m_should_stop_is_valid = true; |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 206 | } |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 207 | return m_should_stop; |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 208 | } |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 209 | return false; |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 210 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 211 | |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 212 | bool |
| 213 | DoShouldNotify(Event *event_ptr) override |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 214 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 215 | ThreadSP thread_sp (m_thread_wp.lock()); |
| 216 | if (thread_sp) |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 217 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 218 | BreakpointSiteSP bp_site_sp (thread_sp->GetProcess()->GetBreakpointSiteList().FindByID (m_value)); |
| 219 | if (bp_site_sp) |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 220 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 221 | bool all_internal = true; |
| 222 | |
| 223 | for (uint32_t i = 0; i < bp_site_sp->GetNumberOfOwners(); i++) |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 224 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 225 | if (!bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint().IsInternal()) |
| 226 | { |
| 227 | all_internal = false; |
| 228 | break; |
| 229 | } |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 230 | } |
Eugene Zelenko | d70a6e7 | 2016-02-18 18:52:47 +0000 | [diff] [blame] | 231 | return !all_internal; |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 232 | } |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 233 | } |
| 234 | return true; |
| 235 | } |
| 236 | |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 237 | const char * |
| 238 | GetDescription() override |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 239 | { |
| 240 | if (m_description.empty()) |
| 241 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 242 | ThreadSP thread_sp (m_thread_wp.lock()); |
| 243 | if (thread_sp) |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 244 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 245 | BreakpointSiteSP bp_site_sp (thread_sp->GetProcess()->GetBreakpointSiteList().FindByID (m_value)); |
| 246 | if (bp_site_sp) |
Jim Ingham | 2995077 | 2013-01-26 02:19:28 +0000 | [diff] [blame] | 247 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 248 | StreamString strm; |
| 249 | // If we have just hit an internal breakpoint, and it has a kind description, print that instead of the |
| 250 | // full breakpoint printing: |
| 251 | if (bp_site_sp->IsInternal()) |
Jim Ingham | 2995077 | 2013-01-26 02:19:28 +0000 | [diff] [blame] | 252 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 253 | size_t num_owners = bp_site_sp->GetNumberOfOwners(); |
| 254 | for (size_t idx = 0; idx < num_owners; idx++) |
Jim Ingham | 2995077 | 2013-01-26 02:19:28 +0000 | [diff] [blame] | 255 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 256 | const char *kind = bp_site_sp->GetOwnerAtIndex(idx)->GetBreakpoint().GetBreakpointKind(); |
Eugene Zelenko | d70a6e7 | 2016-02-18 18:52:47 +0000 | [diff] [blame] | 257 | if (kind != nullptr) |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 258 | { |
| 259 | m_description.assign (kind); |
| 260 | return kind; |
| 261 | } |
Jim Ingham | 2995077 | 2013-01-26 02:19:28 +0000 | [diff] [blame] | 262 | } |
| 263 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 264 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 265 | strm.Printf("breakpoint "); |
| 266 | bp_site_sp->GetDescription(&strm, eDescriptionLevelBrief); |
| 267 | m_description.swap (strm.GetString()); |
Jim Ingham | 2995077 | 2013-01-26 02:19:28 +0000 | [diff] [blame] | 268 | } |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 269 | else |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 270 | { |
| 271 | StreamString strm; |
| 272 | if (m_break_id != LLDB_INVALID_BREAK_ID) |
| 273 | { |
| 274 | BreakpointSP break_sp = thread_sp->GetProcess()->GetTarget().GetBreakpointByID(m_break_id); |
| 275 | if (break_sp) |
| 276 | { |
| 277 | if (break_sp->IsInternal()) |
| 278 | { |
| 279 | const char *kind = break_sp->GetBreakpointKind(); |
| 280 | if (kind) |
| 281 | strm.Printf ("internal %s breakpoint(%d).", kind, m_break_id); |
| 282 | else |
| 283 | strm.Printf ("internal breakpoint(%d).", m_break_id); |
| 284 | } |
| 285 | else |
| 286 | { |
| 287 | strm.Printf ("breakpoint %d.", m_break_id); |
| 288 | } |
| 289 | } |
| 290 | else |
| 291 | { |
| 292 | if (m_was_one_shot) |
| 293 | strm.Printf ("one-shot breakpoint %d", m_break_id); |
| 294 | else |
| 295 | strm.Printf ("breakpoint %d which has been deleted.", m_break_id); |
| 296 | } |
| 297 | } |
| 298 | else if (m_address == LLDB_INVALID_ADDRESS) |
| 299 | strm.Printf("breakpoint site %" PRIi64 " which has been deleted - unknown address", m_value); |
| 300 | else |
| 301 | strm.Printf("breakpoint site %" PRIi64 " which has been deleted - was at 0x%" PRIx64, m_value, m_address); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 302 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 303 | m_description.swap (strm.GetString()); |
| 304 | } |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 305 | } |
| 306 | } |
| 307 | return m_description.c_str(); |
| 308 | } |
| 309 | |
| 310 | protected: |
Jim Ingham | 6d66ce6 | 2012-04-20 21:16:56 +0000 | [diff] [blame] | 311 | bool |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 312 | ShouldStop(Event *event_ptr) override |
Jim Ingham | 6d66ce6 | 2012-04-20 21:16:56 +0000 | [diff] [blame] | 313 | { |
| 314 | // This just reports the work done by PerformAction or the synchronous stop. It should |
| 315 | // only ever get called after they have had a chance to run. |
| 316 | assert (m_should_stop_is_valid); |
| 317 | return m_should_stop; |
| 318 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 319 | |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 320 | void |
| 321 | PerformAction(Event *event_ptr) override |
Jim Ingham | 3ebcf7f | 2010-08-10 00:59:59 +0000 | [diff] [blame] | 322 | { |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 323 | if (!m_should_perform_action) |
| 324 | return; |
| 325 | m_should_perform_action = false; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 326 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 327 | ThreadSP thread_sp (m_thread_wp.lock()); |
| 328 | |
| 329 | if (thread_sp) |
Jim Ingham | 5cb9a18 | 2013-03-28 00:13:30 +0000 | [diff] [blame] | 330 | { |
Jim Ingham | cca8995 | 2014-08-05 01:58:14 +0000 | [diff] [blame] | 331 | Log *log = lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_BREAKPOINTS | LIBLLDB_LOG_STEP); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 332 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 333 | if (!thread_sp->IsValid()) |
Jim Ingham | 3ebcf7f | 2010-08-10 00:59:59 +0000 | [diff] [blame] | 334 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 335 | // This shouldn't ever happen, but just in case, don't do more harm. |
Jason Molenda | 3f032ff | 2013-08-06 23:08:59 +0000 | [diff] [blame] | 336 | if (log) |
| 337 | { |
| 338 | log->Printf ("PerformAction got called with an invalid thread."); |
| 339 | } |
Jim Ingham | 79ea1d8 | 2011-12-09 04:17:31 +0000 | [diff] [blame] | 340 | m_should_stop = true; |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 341 | m_should_stop_is_valid = true; |
| 342 | return; |
Jim Ingham | 79ea1d8 | 2011-12-09 04:17:31 +0000 | [diff] [blame] | 343 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 344 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 345 | BreakpointSiteSP bp_site_sp (thread_sp->GetProcess()->GetBreakpointSiteList().FindByID (m_value)); |
Jim Ingham | 46e9f9d | 2015-04-23 00:28:25 +0000 | [diff] [blame] | 346 | std::unordered_set<break_id_t> precondition_breakpoints; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 347 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 348 | if (bp_site_sp) |
Jim Ingham | 79ea1d8 | 2011-12-09 04:17:31 +0000 | [diff] [blame] | 349 | { |
Jim Ingham | 9d1ccda | 2015-07-29 17:51:36 +0000 | [diff] [blame] | 350 | // Let's copy the owners list out of the site and store them in a local list. That way if |
| 351 | // one of the breakpoint actions changes the site, then we won't be operating on a bad list. |
| 352 | BreakpointLocationCollection site_locations; |
| 353 | size_t num_owners = bp_site_sp->CopyOwnersList(site_locations); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 354 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 355 | if (num_owners == 0) |
| 356 | { |
| 357 | m_should_stop = true; |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 358 | } |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 359 | else |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 360 | { |
Jim Ingham | 46e9f9d | 2015-04-23 00:28:25 +0000 | [diff] [blame] | 361 | // We go through each location, and test first its precondition - this overrides everything. Note, |
| 362 | // we only do this once per breakpoint - not once per location... |
| 363 | // Then check the condition. If the condition says to stop, |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 364 | // then we run the callback for that location. If that callback says to stop as well, then |
| 365 | // we set m_should_stop to true; we are going to stop. |
| 366 | // But we still want to give all the breakpoints whose conditions say we are going to stop a |
| 367 | // chance to run their callbacks. |
| 368 | // Of course if any callback restarts the target by putting "continue" in the callback, then |
| 369 | // we're going to restart, without running the rest of the callbacks. And in this case we will |
| 370 | // end up not stopping even if another location said we should stop. But that's better than not |
| 371 | // running all the callbacks. |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 372 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 373 | m_should_stop = false; |
Jim Ingham | 8d94ba0 | 2016-03-12 02:45:34 +0000 | [diff] [blame] | 374 | |
| 375 | // We don't select threads as we go through them testing breakpoint conditions and running commands. |
| 376 | // So we need to set the thread for expression evaluation here: |
| 377 | ThreadList::ExpressionExecutionThreadPusher thread_pusher(thread_sp); |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 378 | |
| 379 | ExecutionContext exe_ctx (thread_sp->GetStackFrameAtIndex(0)); |
| 380 | Process *process = exe_ctx.GetProcessPtr(); |
| 381 | if (process->GetModIDRef().IsLastResumeForUserExpression()) |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 382 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 383 | // If we are in the middle of evaluating an expression, don't run asynchronous breakpoint commands or |
| 384 | // expressions. That could lead to infinite recursion if the command or condition re-calls the function |
| 385 | // with this breakpoint. |
| 386 | // TODO: We can keep a list of the breakpoints we've seen while running expressions in the nested |
| 387 | // PerformAction calls that can arise when the action runs a function that hits another breakpoint, |
| 388 | // and only stop running commands when we see the same breakpoint hit a second time. |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 389 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 390 | m_should_stop_is_valid = true; |
| 391 | if (log) |
| 392 | log->Printf ("StopInfoBreakpoint::PerformAction - Hit a breakpoint while running an expression," |
| 393 | " not running commands to avoid recursion."); |
| 394 | bool ignoring_breakpoints = process->GetIgnoreBreakpointsInExpressions(); |
| 395 | if (ignoring_breakpoints) |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 396 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 397 | m_should_stop = false; |
| 398 | // Internal breakpoints will always stop. |
| 399 | for (size_t j = 0; j < num_owners; j++) |
| 400 | { |
| 401 | lldb::BreakpointLocationSP bp_loc_sp = bp_site_sp->GetOwnerAtIndex(j); |
| 402 | if (bp_loc_sp->GetBreakpoint().IsInternal()) |
| 403 | { |
| 404 | m_should_stop = true; |
| 405 | break; |
| 406 | } |
| 407 | } |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 408 | } |
Sean Callanan | 3dbf346 | 2013-04-19 07:09:15 +0000 | [diff] [blame] | 409 | else |
| 410 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 411 | m_should_stop = true; |
| 412 | } |
| 413 | if (log) |
| 414 | log->Printf ("StopInfoBreakpoint::PerformAction - in expression, continuing: %s.", |
| 415 | m_should_stop ? "true" : "false"); |
| 416 | process->GetTarget().GetDebugger().GetAsyncOutputStream()->Printf("Warning: hit breakpoint while " |
| 417 | "running function, skipping commands and conditions to prevent recursion."); |
| 418 | return; |
| 419 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 420 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 421 | StoppointCallbackContext context (event_ptr, exe_ctx, false); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 422 | |
Jim Ingham | a672ece | 2014-10-22 01:54:17 +0000 | [diff] [blame] | 423 | // For safety's sake let's also grab an extra reference to the breakpoint owners of the locations we're |
| 424 | // going to examine, since the locations are going to have to get back to their breakpoints, and the |
| 425 | // locations don't keep their owners alive. I'm just sticking the BreakpointSP's in a vector since |
Jim Ingham | 9d1ccda | 2015-07-29 17:51:36 +0000 | [diff] [blame] | 426 | // I'm only using it to locally increment their retain counts. |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 427 | |
Jim Ingham | a672ece | 2014-10-22 01:54:17 +0000 | [diff] [blame] | 428 | std::vector<lldb::BreakpointSP> location_owners; |
| 429 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 430 | for (size_t j = 0; j < num_owners; j++) |
Jim Ingham | a672ece | 2014-10-22 01:54:17 +0000 | [diff] [blame] | 431 | { |
Jim Ingham | 9d1ccda | 2015-07-29 17:51:36 +0000 | [diff] [blame] | 432 | BreakpointLocationSP loc(site_locations.GetByIndex(j)); |
Jim Ingham | a672ece | 2014-10-22 01:54:17 +0000 | [diff] [blame] | 433 | location_owners.push_back(loc->GetBreakpoint().shared_from_this()); |
| 434 | |
| 435 | } |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 436 | |
| 437 | for (size_t j = 0; j < num_owners; j++) |
| 438 | { |
| 439 | lldb::BreakpointLocationSP bp_loc_sp = site_locations.GetByIndex(j); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 440 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 441 | // If another action disabled this breakpoint or its location, then don't run the actions. |
| 442 | if (!bp_loc_sp->IsEnabled() || !bp_loc_sp->GetBreakpoint().IsEnabled()) |
| 443 | continue; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 444 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 445 | // The breakpoint site may have many locations associated with it, not all of them valid for |
| 446 | // this thread. Skip the ones that aren't: |
| 447 | if (!bp_loc_sp->ValidForThisThread(thread_sp.get())) |
Jim Ingham | a8b99ca | 2014-01-15 03:30:04 +0000 | [diff] [blame] | 448 | { |
| 449 | if (log) |
| 450 | { |
| 451 | StreamString s; |
| 452 | bp_loc_sp->GetDescription(&s, eDescriptionLevelBrief); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 453 | log->Printf ("Breakpoint %s hit on thread 0x%llx but it was not for this thread, continuing.", |
| 454 | s.GetData(), |
| 455 | static_cast<unsigned long long>(thread_sp->GetID())); |
Jim Ingham | a8b99ca | 2014-01-15 03:30:04 +0000 | [diff] [blame] | 456 | } |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 457 | continue; |
Jim Ingham | a8b99ca | 2014-01-15 03:30:04 +0000 | [diff] [blame] | 458 | } |
Jim Ingham | 46e9f9d | 2015-04-23 00:28:25 +0000 | [diff] [blame] | 459 | |
| 460 | // First run the precondition, but since the precondition is per breakpoint, only run it once |
| 461 | // per breakpoint. |
| 462 | std::pair<std::unordered_set<break_id_t>::iterator, bool> result |
| 463 | = precondition_breakpoints.insert(bp_loc_sp->GetBreakpoint().GetID()); |
| 464 | if (!result.second) |
| 465 | continue; |
| 466 | |
| 467 | bool precondition_result = bp_loc_sp->GetBreakpoint().EvaluatePrecondition(context); |
| 468 | if (!precondition_result) |
| 469 | continue; |
| 470 | |
| 471 | // Next run the condition for the breakpoint. If that says we should stop, then we'll run |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 472 | // the callback for the breakpoint. If the callback says we shouldn't stop that will win. |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 473 | |
Eugene Zelenko | d70a6e7 | 2016-02-18 18:52:47 +0000 | [diff] [blame] | 474 | if (bp_loc_sp->GetConditionText() != nullptr) |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 475 | { |
| 476 | Error condition_error; |
| 477 | bool condition_says_stop = bp_loc_sp->ConditionSaysStop(exe_ctx, condition_error); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 478 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 479 | if (!condition_error.Success()) |
| 480 | { |
| 481 | Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger(); |
| 482 | StreamSP error_sp = debugger.GetAsyncErrorStream (); |
| 483 | error_sp->Printf ("Stopped due to an error evaluating condition of breakpoint "); |
| 484 | bp_loc_sp->GetDescription (error_sp.get(), eDescriptionLevelBrief); |
| 485 | error_sp->Printf (": \"%s\"", |
| 486 | bp_loc_sp->GetConditionText()); |
| 487 | error_sp->EOL(); |
| 488 | const char *err_str = condition_error.AsCString("<Unknown Error>"); |
| 489 | if (log) |
| 490 | log->Printf("Error evaluating condition: \"%s\"\n", err_str); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 491 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 492 | error_sp->PutCString (err_str); |
| 493 | error_sp->EOL(); |
| 494 | error_sp->Flush(); |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 495 | } |
| 496 | else |
| 497 | { |
Jim Ingham | a8b99ca | 2014-01-15 03:30:04 +0000 | [diff] [blame] | 498 | if (log) |
| 499 | { |
| 500 | StreamString s; |
| 501 | bp_loc_sp->GetDescription(&s, eDescriptionLevelBrief); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 502 | log->Printf ("Condition evaluated for breakpoint %s on thread 0x%llx conditon_says_stop: %i.", |
| 503 | s.GetData(), |
| 504 | static_cast<unsigned long long>(thread_sp->GetID()), |
| 505 | condition_says_stop); |
Jim Ingham | a8b99ca | 2014-01-15 03:30:04 +0000 | [diff] [blame] | 506 | } |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 507 | if (!condition_says_stop) |
Jim Ingham | d762df8 | 2015-01-15 01:41:04 +0000 | [diff] [blame] | 508 | { |
| 509 | // We don't want to increment the hit count of breakpoints if the condition fails. |
| 510 | // We've already bumped it by the time we get here, so undo the bump: |
| 511 | bp_loc_sp->UndoBumpHitCount(); |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 512 | continue; |
Jim Ingham | d762df8 | 2015-01-15 01:41:04 +0000 | [diff] [blame] | 513 | } |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 514 | } |
| 515 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 516 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 517 | bool callback_says_stop; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 518 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 519 | // FIXME: For now the callbacks have to run in async mode - the first time we restart we need |
| 520 | // to get out of there. So set it here. |
| 521 | // When we figure out how to nest breakpoint hits then this will change. |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 522 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 523 | Debugger &debugger = thread_sp->CalculateTarget()->GetDebugger(); |
| 524 | bool old_async = debugger.GetAsyncExecution(); |
| 525 | debugger.SetAsyncExecution (true); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 526 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 527 | callback_says_stop = bp_loc_sp->InvokeCallback (&context); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 528 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 529 | debugger.SetAsyncExecution (old_async); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 530 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 531 | if (callback_says_stop) |
| 532 | m_should_stop = true; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 533 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 534 | // If we are going to stop for this breakpoint, then remove the breakpoint. |
| 535 | if (callback_says_stop && bp_loc_sp && bp_loc_sp->GetBreakpoint().IsOneShot()) |
| 536 | { |
| 537 | thread_sp->GetProcess()->GetTarget().RemoveBreakpointByID (bp_loc_sp->GetBreakpoint().GetID()); |
| 538 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 539 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 540 | // Also make sure that the callback hasn't continued the target. |
| 541 | // If it did, when we'll set m_should_start to false and get out of here. |
| 542 | if (HasTargetRunSinceMe ()) |
| 543 | { |
| 544 | m_should_stop = false; |
| 545 | break; |
Sean Callanan | 3dbf346 | 2013-04-19 07:09:15 +0000 | [diff] [blame] | 546 | } |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 547 | } |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 548 | } |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 549 | // We've figured out what this stop wants to do, so mark it as valid so we don't compute it again. |
| 550 | m_should_stop_is_valid = true; |
Jim Ingham | 3ebcf7f | 2010-08-10 00:59:59 +0000 | [diff] [blame] | 551 | } |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 552 | else |
| 553 | { |
| 554 | m_should_stop = true; |
| 555 | m_should_stop_is_valid = true; |
| 556 | Log * log_process(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Jim Ingham | 79ea1d8 | 2011-12-09 04:17:31 +0000 | [diff] [blame] | 557 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 558 | if (log_process) |
| 559 | log_process->Printf ("Process::%s could not find breakpoint site id: %" PRId64 "...", __FUNCTION__, m_value); |
| 560 | } |
| 561 | if (log) |
| 562 | log->Printf ("Process::%s returning from action with m_should_stop: %d.", __FUNCTION__, m_should_stop); |
Jim Ingham | 3ebcf7f | 2010-08-10 00:59:59 +0000 | [diff] [blame] | 563 | } |
Jim Ingham | 3ebcf7f | 2010-08-10 00:59:59 +0000 | [diff] [blame] | 564 | } |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 565 | |
| 566 | private: |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 567 | bool m_should_stop; |
| 568 | bool m_should_stop_is_valid; |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 569 | bool m_should_perform_action; // Since we are trying to preserve the "state" of the system even if we run functions |
| 570 | // etc. behind the users backs, we need to make sure we only REALLY perform the action once. |
Jim Ingham | 52c7d20 | 2011-10-28 01:12:19 +0000 | [diff] [blame] | 571 | lldb::addr_t m_address; // We use this to capture the breakpoint site address when we create the StopInfo, |
| 572 | // in case somebody deletes it between the time the StopInfo is made and the |
| 573 | // description is asked for. |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 574 | lldb::break_id_t m_break_id; |
| 575 | bool m_was_one_shot; |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 576 | }; |
| 577 | |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 578 | //---------------------------------------------------------------------- |
| 579 | // StopInfoWatchpoint |
| 580 | //---------------------------------------------------------------------- |
| 581 | |
| 582 | class StopInfoWatchpoint : public StopInfo |
| 583 | { |
| 584 | public: |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 585 | // Make sure watchpoint is properly disabled and subsequently enabled while performing watchpoint actions. |
| 586 | class WatchpointSentry { |
| 587 | public: |
| 588 | WatchpointSentry(Process *p, Watchpoint *w): |
| 589 | process(p), |
| 590 | watchpoint(w) |
| 591 | { |
| 592 | if (process && watchpoint) |
| 593 | { |
Jim Ingham | 1b5792e | 2012-12-18 02:03:49 +0000 | [diff] [blame] | 594 | const bool notify = false; |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 595 | watchpoint->TurnOnEphemeralMode(); |
Jim Ingham | 1b5792e | 2012-12-18 02:03:49 +0000 | [diff] [blame] | 596 | process->DisableWatchpoint(watchpoint, notify); |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 597 | } |
| 598 | } |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 599 | |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 600 | ~WatchpointSentry() |
| 601 | { |
| 602 | if (process && watchpoint) |
| 603 | { |
| 604 | if (!watchpoint->IsDisabledDuringEphemeralMode()) |
Jim Ingham | 1b5792e | 2012-12-18 02:03:49 +0000 | [diff] [blame] | 605 | { |
| 606 | const bool notify = false; |
| 607 | process->EnableWatchpoint(watchpoint, notify); |
| 608 | } |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 609 | watchpoint->TurnOffEphemeralMode(); |
| 610 | } |
| 611 | } |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 612 | |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 613 | private: |
| 614 | Process *process; |
| 615 | Watchpoint *watchpoint; |
| 616 | }; |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 617 | |
Jaydeep Patil | 8314350 | 2015-08-13 03:44:09 +0000 | [diff] [blame] | 618 | StopInfoWatchpoint (Thread &thread, break_id_t watch_id, lldb::addr_t watch_hit_addr) : |
Johnny Chen | fd158f4 | 2011-09-21 22:47:15 +0000 | [diff] [blame] | 619 | StopInfo(thread, watch_id), |
Johnny Chen | fd158f4 | 2011-09-21 22:47:15 +0000 | [diff] [blame] | 620 | m_should_stop(false), |
Jaydeep Patil | 8314350 | 2015-08-13 03:44:09 +0000 | [diff] [blame] | 621 | m_should_stop_is_valid(false), |
| 622 | m_watch_hit_addr(watch_hit_addr) |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 623 | { |
| 624 | } |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 625 | |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 626 | ~StopInfoWatchpoint() override = default; |
| 627 | |
| 628 | StopReason |
| 629 | GetStopReason() const override |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 630 | { |
| 631 | return eStopReasonWatchpoint; |
| 632 | } |
| 633 | |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 634 | const char * |
| 635 | GetDescription() override |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 636 | { |
| 637 | if (m_description.empty()) |
| 638 | { |
| 639 | StreamString strm; |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 640 | strm.Printf("watchpoint %" PRIi64, m_value); |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 641 | m_description.swap (strm.GetString()); |
| 642 | } |
| 643 | return m_description.c_str(); |
| 644 | } |
| 645 | |
| 646 | protected: |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 647 | bool |
| 648 | ShouldStopSynchronous(Event *event_ptr) override |
Johnny Chen | fd158f4 | 2011-09-21 22:47:15 +0000 | [diff] [blame] | 649 | { |
| 650 | // ShouldStop() method is idempotent and should not affect hit count. |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 651 | // See Process::RunPrivateStateThread()->Process()->HandlePrivateEvent() |
| 652 | // -->Process()::ShouldBroadcastEvent()->ThreadList::ShouldStop()-> |
| 653 | // Thread::ShouldStop()->ThreadPlanBase::ShouldStop()-> |
| 654 | // StopInfoWatchpoint::ShouldStop() and |
| 655 | // Event::DoOnRemoval()->Process::ProcessEventData::DoOnRemoval()-> |
| 656 | // StopInfoWatchpoint::PerformAction(). |
Johnny Chen | fd158f4 | 2011-09-21 22:47:15 +0000 | [diff] [blame] | 657 | if (m_should_stop_is_valid) |
| 658 | return m_should_stop; |
| 659 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 660 | ThreadSP thread_sp (m_thread_wp.lock()); |
| 661 | if (thread_sp) |
Johnny Chen | fd158f4 | 2011-09-21 22:47:15 +0000 | [diff] [blame] | 662 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 663 | WatchpointSP wp_sp (thread_sp->CalculateTarget()->GetWatchpointList().FindByID(GetValue())); |
| 664 | if (wp_sp) |
| 665 | { |
| 666 | // Check if we should stop at a watchpoint. |
| 667 | ExecutionContext exe_ctx (thread_sp->GetStackFrameAtIndex(0)); |
| 668 | StoppointCallbackContext context (event_ptr, exe_ctx, true); |
| 669 | m_should_stop = wp_sp->ShouldStop (&context); |
| 670 | } |
| 671 | else |
| 672 | { |
| 673 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Johnny Chen | fd158f4 | 2011-09-21 22:47:15 +0000 | [diff] [blame] | 674 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 675 | if (log) |
| 676 | log->Printf ("Process::%s could not find watchpoint location id: %" PRId64 "...", |
| 677 | __FUNCTION__, GetValue()); |
Johnny Chen | fd158f4 | 2011-09-21 22:47:15 +0000 | [diff] [blame] | 678 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 679 | m_should_stop = true; |
| 680 | } |
Johnny Chen | fd158f4 | 2011-09-21 22:47:15 +0000 | [diff] [blame] | 681 | } |
| 682 | m_should_stop_is_valid = true; |
| 683 | return m_should_stop; |
| 684 | } |
| 685 | |
Jim Ingham | 9b620f3 | 2013-02-22 21:23:43 +0000 | [diff] [blame] | 686 | bool |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 687 | ShouldStop(Event *event_ptr) override |
Jim Ingham | 9b620f3 | 2013-02-22 21:23:43 +0000 | [diff] [blame] | 688 | { |
| 689 | // This just reports the work done by PerformAction or the synchronous stop. It should |
| 690 | // only ever get called after they have had a chance to run. |
| 691 | assert (m_should_stop_is_valid); |
| 692 | return m_should_stop; |
| 693 | } |
| 694 | |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 695 | void |
| 696 | PerformAction(Event *event_ptr) override |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 697 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 698 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS); |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 699 | // We're going to calculate if we should stop or not in some way during the course of |
| 700 | // this code. Also by default we're going to stop, so set that here. |
| 701 | m_should_stop = true; |
| 702 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 703 | ThreadSP thread_sp (m_thread_wp.lock()); |
| 704 | if (thread_sp) |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 705 | { |
Johnny Chen | 0f7ad8d | 2012-08-21 22:06:34 +0000 | [diff] [blame] | 706 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 707 | WatchpointSP wp_sp (thread_sp->CalculateTarget()->GetWatchpointList().FindByID(GetValue())); |
| 708 | if (wp_sp) |
Enrico Granata | f04a219 | 2012-07-13 23:18:48 +0000 | [diff] [blame] | 709 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 710 | ExecutionContext exe_ctx (thread_sp->GetStackFrameAtIndex(0)); |
| 711 | Process* process = exe_ctx.GetProcessPtr(); |
| 712 | |
| 713 | // This sentry object makes sure the current watchpoint is disabled while performing watchpoint actions, |
| 714 | // and it is then enabled after we are finished. |
| 715 | WatchpointSentry sentry(process, wp_sp.get()); |
| 716 | |
Enrico Granata | f04a219 | 2012-07-13 23:18:48 +0000 | [diff] [blame] | 717 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 718 | // check if this process is running on an architecture where watchpoints trigger |
| 719 | // before the associated instruction runs. if so, disable the WP, single-step and then |
| 720 | // re-enable the watchpoint |
| 721 | if (process) |
Enrico Granata | f04a219 | 2012-07-13 23:18:48 +0000 | [diff] [blame] | 722 | { |
Jason Molenda | fe80690 | 2013-05-04 00:39:52 +0000 | [diff] [blame] | 723 | uint32_t num; |
| 724 | bool wp_triggers_after; |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 725 | if (process->GetWatchpointSupportInfo(num, wp_triggers_after).Success()) |
Enrico Granata | f04a219 | 2012-07-13 23:18:48 +0000 | [diff] [blame] | 726 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 727 | if (!wp_triggers_after) |
| 728 | { |
Jim Ingham | 363ddd7 | 2013-07-02 21:12:44 +0000 | [diff] [blame] | 729 | StopInfoSP stored_stop_info_sp = thread_sp->GetStopInfo(); |
| 730 | assert (stored_stop_info_sp.get() == this); |
| 731 | |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 732 | ThreadPlanSP new_plan_sp(thread_sp->QueueThreadPlanForStepSingleInstruction(false, // step-over |
Greg Clayton | dc6224e | 2014-10-21 01:00:42 +0000 | [diff] [blame] | 733 | false, // abort_other_plans |
| 734 | true)); // stop_other_threads |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 735 | new_plan_sp->SetIsMasterPlan (true); |
| 736 | new_plan_sp->SetOkayToDiscard (false); |
| 737 | new_plan_sp->SetPrivate (true); |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 738 | process->GetThreadList().SetSelectedThreadByID (thread_sp->GetID()); |
Eugene Zelenko | d70a6e7 | 2016-02-18 18:52:47 +0000 | [diff] [blame] | 739 | process->ResumeSynchronous(nullptr); |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 740 | process->GetThreadList().SetSelectedThreadByID (thread_sp->GetID()); |
Jim Ingham | 363ddd7 | 2013-07-02 21:12:44 +0000 | [diff] [blame] | 741 | thread_sp->SetStopInfo(stored_stop_info_sp); |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 742 | } |
Enrico Granata | f04a219 | 2012-07-13 23:18:48 +0000 | [diff] [blame] | 743 | } |
| 744 | } |
| 745 | } |
Johnny Chen | 209bd65 | 2012-08-13 21:09:54 +0000 | [diff] [blame] | 746 | |
Jaydeep Patil | 8314350 | 2015-08-13 03:44:09 +0000 | [diff] [blame] | 747 | /* |
| 748 | * MIPS: Last 3bits of the watchpoint address are masked by the kernel. For example: |
| 749 | * 'n' is at 0x120010d00 and 'm' is 0x120010d04. When a watchpoint is set at 'm', then |
| 750 | * watch exception is generated even when 'n' is read/written. To handle this case, |
| 751 | * server emulates the instruction at PC and finds the base address of the load/store |
| 752 | * instruction and appends it in the description of the stop-info packet. If watchpoint |
| 753 | * is not set on this address by user then this do not stop. |
| 754 | */ |
| 755 | if (m_watch_hit_addr != LLDB_INVALID_ADDRESS) |
| 756 | { |
| 757 | WatchpointSP wp_hit_sp = thread_sp->CalculateTarget()->GetWatchpointList().FindByAddress(m_watch_hit_addr); |
| 758 | if (!wp_hit_sp) |
Mohit K. Bhakkad | acdff16 | 2015-10-06 05:25:17 +0000 | [diff] [blame] | 759 | { |
Jaydeep Patil | 8314350 | 2015-08-13 03:44:09 +0000 | [diff] [blame] | 760 | m_should_stop = false; |
Mohit K. Bhakkad | acdff16 | 2015-10-06 05:25:17 +0000 | [diff] [blame] | 761 | wp_sp->IncrementFalseAlarmsAndReviseHitCount(); |
| 762 | } |
Jaydeep Patil | 8314350 | 2015-08-13 03:44:09 +0000 | [diff] [blame] | 763 | } |
Mohit K. Bhakkad | acdff16 | 2015-10-06 05:25:17 +0000 | [diff] [blame] | 764 | |
Mohit K. Bhakkad | 13763c3 | 2015-11-03 09:04:33 +0000 | [diff] [blame] | 765 | // TODO: This condition should be checked in the synchronous part of the watchpoint code |
| 766 | // (Watchpoint::ShouldStop), so that we avoid pulling an event even if the watchpoint fails |
| 767 | // the ignore count condition. It is moved here temporarily, because for archs with |
| 768 | // watchpoint_exceptions_received=before, the code in the previous lines takes care of moving |
| 769 | // the inferior to next PC. We have to check the ignore count condition after this is done, |
| 770 | // otherwise we will hit same watchpoint multiple times until we pass ignore condition, but we |
| 771 | // won't actually be ignoring them. |
| 772 | if (wp_sp->GetHitCount() <= wp_sp->GetIgnoreCount()) |
| 773 | m_should_stop = false; |
| 774 | |
Eugene Zelenko | d70a6e7 | 2016-02-18 18:52:47 +0000 | [diff] [blame] | 775 | if (m_should_stop && wp_sp->GetConditionText() != nullptr) |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 776 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 777 | // We need to make sure the user sees any parse errors in their condition, so we'll hook the |
| 778 | // constructor errors up to the debugger's Async I/O. |
Jim Ingham | 1624a2d | 2014-05-05 02:26:40 +0000 | [diff] [blame] | 779 | ExpressionResults result_code; |
Greg Clayton | 62afb9f | 2013-11-04 19:35:17 +0000 | [diff] [blame] | 780 | EvaluateExpressionOptions expr_options; |
| 781 | expr_options.SetUnwindOnError(true); |
| 782 | expr_options.SetIgnoreBreakpoints(true); |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 783 | ValueObjectSP result_value_sp; |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 784 | Error error; |
Eugene Zelenko | d70a6e7 | 2016-02-18 18:52:47 +0000 | [diff] [blame] | 785 | result_code = UserExpression::Evaluate(exe_ctx, |
| 786 | expr_options, |
| 787 | wp_sp->GetConditionText(), |
| 788 | nullptr, |
| 789 | result_value_sp, |
| 790 | error); |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 791 | |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 792 | if (result_code == eExpressionCompleted) |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 793 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 794 | if (result_value_sp) |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 795 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 796 | Scalar scalar_value; |
| 797 | if (result_value_sp->ResolveValue (scalar_value)) |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 798 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 799 | if (scalar_value.ULongLong(1) == 0) |
| 800 | { |
| 801 | // We have been vetoed. This takes precedence over querying |
| 802 | // the watchpoint whether it should stop (aka ignore count and |
| 803 | // friends). See also StopInfoWatchpoint::ShouldStop() as well |
| 804 | // as Process::ProcessEventData::DoOnRemoval(). |
| 805 | m_should_stop = false; |
| 806 | } |
| 807 | else |
| 808 | m_should_stop = true; |
| 809 | if (log) |
| 810 | log->Printf("Condition successfully evaluated, result is %s.\n", |
| 811 | m_should_stop ? "true" : "false"); |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 812 | } |
| 813 | else |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 814 | { |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 815 | m_should_stop = true; |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 816 | if (log) |
| 817 | log->Printf("Failed to get an integer result from the expression."); |
| 818 | } |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 819 | } |
| 820 | } |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 821 | else |
| 822 | { |
| 823 | Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger(); |
| 824 | StreamSP error_sp = debugger.GetAsyncErrorStream (); |
| 825 | error_sp->Printf ("Stopped due to an error evaluating condition of watchpoint "); |
| 826 | wp_sp->GetDescription (error_sp.get(), eDescriptionLevelBrief); |
| 827 | error_sp->Printf (": \"%s\"", |
| 828 | wp_sp->GetConditionText()); |
| 829 | error_sp->EOL(); |
| 830 | const char *err_str = error.AsCString("<Unknown Error>"); |
| 831 | if (log) |
| 832 | log->Printf("Error evaluating condition: \"%s\"\n", err_str); |
| 833 | |
| 834 | error_sp->PutCString (err_str); |
| 835 | error_sp->EOL(); |
| 836 | error_sp->Flush(); |
| 837 | // If the condition fails to be parsed or run, we should stop. |
| 838 | m_should_stop = true; |
| 839 | } |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 840 | } |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 841 | |
| 842 | // If the condition says to stop, we run the callback to further decide whether to stop. |
| 843 | if (m_should_stop) |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 844 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 845 | StoppointCallbackContext context (event_ptr, exe_ctx, false); |
| 846 | bool stop_requested = wp_sp->InvokeCallback (&context); |
| 847 | // Also make sure that the callback hasn't continued the target. |
| 848 | // If it did, when we'll set m_should_stop to false and get out of here. |
| 849 | if (HasTargetRunSinceMe ()) |
| 850 | m_should_stop = false; |
| 851 | |
| 852 | if (m_should_stop && !stop_requested) |
| 853 | { |
| 854 | // We have been vetoed by the callback mechanism. |
| 855 | m_should_stop = false; |
| 856 | } |
| 857 | } |
| 858 | // Finally, if we are going to stop, print out the new & old values: |
| 859 | if (m_should_stop) |
| 860 | { |
| 861 | wp_sp->CaptureWatchedValue(exe_ctx); |
| 862 | |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 863 | Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger(); |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 864 | StreamSP output_sp = debugger.GetAsyncOutputStream (); |
| 865 | wp_sp->DumpSnapshots(output_sp.get()); |
| 866 | output_sp->EOL(); |
| 867 | output_sp->Flush(); |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 868 | } |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 869 | |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 870 | } |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 871 | else |
| 872 | { |
| 873 | Log * log_process(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Johnny Chen | 1320641 | 2012-08-09 23:10:57 +0000 | [diff] [blame] | 874 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 875 | if (log_process) |
| 876 | log_process->Printf ("Process::%s could not find watchpoint id: %" PRId64 "...", __FUNCTION__, m_value); |
Johnny Chen | 1320641 | 2012-08-09 23:10:57 +0000 | [diff] [blame] | 877 | } |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 878 | if (log) |
| 879 | log->Printf ("Process::%s returning from action with m_should_stop: %d.", __FUNCTION__, m_should_stop); |
Jim Ingham | a7dfb66 | 2012-10-23 07:20:06 +0000 | [diff] [blame] | 880 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 881 | m_should_stop_is_valid = true; |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 882 | } |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 883 | } |
| 884 | |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 885 | private: |
Johnny Chen | fd158f4 | 2011-09-21 22:47:15 +0000 | [diff] [blame] | 886 | bool m_should_stop; |
| 887 | bool m_should_stop_is_valid; |
Jaydeep Patil | 8314350 | 2015-08-13 03:44:09 +0000 | [diff] [blame] | 888 | lldb::addr_t m_watch_hit_addr; |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 889 | }; |
| 890 | |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 891 | //---------------------------------------------------------------------- |
| 892 | // StopInfoUnixSignal |
| 893 | //---------------------------------------------------------------------- |
| 894 | |
| 895 | class StopInfoUnixSignal : public StopInfo |
| 896 | { |
| 897 | public: |
Pavel Labath | c4e25c9 | 2015-05-29 10:13:03 +0000 | [diff] [blame] | 898 | StopInfoUnixSignal (Thread &thread, int signo, const char *description) : |
Greg Clayton | a658fd2 | 2011-06-04 01:26:29 +0000 | [diff] [blame] | 899 | StopInfo (thread, signo) |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 900 | { |
Pavel Labath | c4e25c9 | 2015-05-29 10:13:03 +0000 | [diff] [blame] | 901 | SetDescription (description); |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 902 | } |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 903 | |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 904 | ~StopInfoUnixSignal() override = default; |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 905 | |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 906 | StopReason |
| 907 | GetStopReason() const override |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 908 | { |
| 909 | return eStopReasonSignal; |
| 910 | } |
| 911 | |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 912 | bool |
| 913 | ShouldStopSynchronous(Event *event_ptr) override |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 914 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 915 | ThreadSP thread_sp (m_thread_wp.lock()); |
| 916 | if (thread_sp) |
Chaoren Lin | 98d0a4b | 2015-07-14 01:09:28 +0000 | [diff] [blame] | 917 | return thread_sp->GetProcess()->GetUnixSignals()->GetShouldStop(m_value); |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 918 | return false; |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 919 | } |
| 920 | |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 921 | bool |
| 922 | ShouldStop(Event *event_ptr) override |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 923 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 924 | ThreadSP thread_sp (m_thread_wp.lock()); |
| 925 | if (thread_sp) |
Chaoren Lin | 98d0a4b | 2015-07-14 01:09:28 +0000 | [diff] [blame] | 926 | return thread_sp->GetProcess()->GetUnixSignals()->GetShouldStop(m_value); |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 927 | return false; |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 928 | } |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 929 | |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 930 | // If should stop returns false, check if we should notify of this event |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 931 | bool |
| 932 | DoShouldNotify(Event *event_ptr) override |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 933 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 934 | ThreadSP thread_sp (m_thread_wp.lock()); |
| 935 | if (thread_sp) |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 936 | { |
Chaoren Lin | 98d0a4b | 2015-07-14 01:09:28 +0000 | [diff] [blame] | 937 | bool should_notify = thread_sp->GetProcess()->GetUnixSignals()->GetShouldNotify(m_value); |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 938 | if (should_notify) |
| 939 | { |
| 940 | StreamString strm; |
| 941 | strm.Printf ("thread %d received signal: %s", |
| 942 | thread_sp->GetIndexID(), |
Chaoren Lin | 98d0a4b | 2015-07-14 01:09:28 +0000 | [diff] [blame] | 943 | thread_sp->GetProcess()->GetUnixSignals()->GetSignalAsCString(m_value)); |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 944 | Process::ProcessEventData::AddRestartedReason(event_ptr, strm.GetData()); |
| 945 | } |
| 946 | return should_notify; |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 947 | } |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 948 | return true; |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 949 | } |
| 950 | |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 951 | void |
| 952 | WillResume(lldb::StateType resume_state) override |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 953 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 954 | ThreadSP thread_sp (m_thread_wp.lock()); |
| 955 | if (thread_sp) |
| 956 | { |
Eugene Zelenko | d70a6e7 | 2016-02-18 18:52:47 +0000 | [diff] [blame] | 957 | if (!thread_sp->GetProcess()->GetUnixSignals()->GetShouldSuppress(m_value)) |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 958 | thread_sp->SetResumeSignal(m_value); |
| 959 | } |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 960 | } |
| 961 | |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 962 | const char * |
| 963 | GetDescription() override |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 964 | { |
| 965 | if (m_description.empty()) |
| 966 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 967 | ThreadSP thread_sp (m_thread_wp.lock()); |
| 968 | if (thread_sp) |
| 969 | { |
| 970 | StreamString strm; |
Chaoren Lin | 98d0a4b | 2015-07-14 01:09:28 +0000 | [diff] [blame] | 971 | const char *signal_name = thread_sp->GetProcess()->GetUnixSignals()->GetSignalAsCString(m_value); |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 972 | if (signal_name) |
| 973 | strm.Printf("signal %s", signal_name); |
| 974 | else |
| 975 | strm.Printf("signal %" PRIi64, m_value); |
| 976 | m_description.swap (strm.GetString()); |
| 977 | } |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 978 | } |
| 979 | return m_description.c_str(); |
| 980 | } |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 981 | }; |
| 982 | |
| 983 | //---------------------------------------------------------------------- |
| 984 | // StopInfoTrace |
| 985 | //---------------------------------------------------------------------- |
| 986 | |
| 987 | class StopInfoTrace : public StopInfo |
| 988 | { |
| 989 | public: |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 990 | StopInfoTrace (Thread &thread) : |
| 991 | StopInfo (thread, LLDB_INVALID_UID) |
| 992 | { |
| 993 | } |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 994 | |
| 995 | ~StopInfoTrace() override = default; |
| 996 | |
| 997 | StopReason |
| 998 | GetStopReason() const override |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 999 | { |
| 1000 | return eStopReasonTrace; |
| 1001 | } |
| 1002 | |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 1003 | const char * |
| 1004 | GetDescription() override |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 1005 | { |
Greg Clayton | a658fd2 | 2011-06-04 01:26:29 +0000 | [diff] [blame] | 1006 | if (m_description.empty()) |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 1007 | return "trace"; |
Greg Clayton | a658fd2 | 2011-06-04 01:26:29 +0000 | [diff] [blame] | 1008 | else |
| 1009 | return m_description.c_str(); |
| 1010 | } |
| 1011 | }; |
| 1012 | |
Greg Clayton | a658fd2 | 2011-06-04 01:26:29 +0000 | [diff] [blame] | 1013 | //---------------------------------------------------------------------- |
| 1014 | // StopInfoException |
| 1015 | //---------------------------------------------------------------------- |
| 1016 | |
| 1017 | class StopInfoException : public StopInfo |
| 1018 | { |
| 1019 | public: |
Greg Clayton | a658fd2 | 2011-06-04 01:26:29 +0000 | [diff] [blame] | 1020 | StopInfoException (Thread &thread, const char *description) : |
| 1021 | StopInfo (thread, LLDB_INVALID_UID) |
| 1022 | { |
| 1023 | if (description) |
| 1024 | SetDescription (description); |
| 1025 | } |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 1026 | |
| 1027 | ~StopInfoException() override = default; |
| 1028 | |
| 1029 | StopReason |
| 1030 | GetStopReason() const override |
Greg Clayton | a658fd2 | 2011-06-04 01:26:29 +0000 | [diff] [blame] | 1031 | { |
| 1032 | return eStopReasonException; |
| 1033 | } |
| 1034 | |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 1035 | const char * |
| 1036 | GetDescription() override |
Greg Clayton | a658fd2 | 2011-06-04 01:26:29 +0000 | [diff] [blame] | 1037 | { |
| 1038 | if (m_description.empty()) |
| 1039 | return "exception"; |
| 1040 | else |
| 1041 | return m_description.c_str(); |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 1042 | } |
| 1043 | }; |
| 1044 | |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 1045 | //---------------------------------------------------------------------- |
| 1046 | // StopInfoThreadPlan |
| 1047 | //---------------------------------------------------------------------- |
| 1048 | |
| 1049 | class StopInfoThreadPlan : public StopInfo |
| 1050 | { |
| 1051 | public: |
Sean Callanan | bc8ac34 | 2015-09-04 20:49:51 +0000 | [diff] [blame] | 1052 | StopInfoThreadPlan (ThreadPlanSP &plan_sp, ValueObjectSP &return_valobj_sp, ExpressionVariableSP &expression_variable_sp) : |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 1053 | StopInfo (plan_sp->GetThread(), LLDB_INVALID_UID), |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 1054 | m_plan_sp (plan_sp), |
Jim Ingham | 30fadaf | 2014-07-08 01:07:32 +0000 | [diff] [blame] | 1055 | m_return_valobj_sp (return_valobj_sp), |
| 1056 | m_expression_variable_sp (expression_variable_sp) |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 1057 | { |
| 1058 | } |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 1059 | |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 1060 | ~StopInfoThreadPlan() override = default; |
| 1061 | |
| 1062 | StopReason |
| 1063 | GetStopReason() const override |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 1064 | { |
| 1065 | return eStopReasonPlanComplete; |
| 1066 | } |
| 1067 | |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 1068 | const char * |
| 1069 | GetDescription() override |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 1070 | { |
| 1071 | if (m_description.empty()) |
| 1072 | { |
| 1073 | StreamString strm; |
| 1074 | m_plan_sp->GetDescription (&strm, eDescriptionLevelBrief); |
| 1075 | m_description.swap (strm.GetString()); |
| 1076 | } |
| 1077 | return m_description.c_str(); |
| 1078 | } |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 1079 | |
| 1080 | ValueObjectSP |
| 1081 | GetReturnValueObject() |
| 1082 | { |
| 1083 | return m_return_valobj_sp; |
| 1084 | } |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 1085 | |
Sean Callanan | bc8ac34 | 2015-09-04 20:49:51 +0000 | [diff] [blame] | 1086 | ExpressionVariableSP |
Jim Ingham | 30fadaf | 2014-07-08 01:07:32 +0000 | [diff] [blame] | 1087 | GetExpressionVariable() |
| 1088 | { |
| 1089 | return m_expression_variable_sp; |
| 1090 | } |
| 1091 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 1092 | protected: |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 1093 | bool |
| 1094 | ShouldStop(Event *event_ptr) override |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 1095 | { |
| 1096 | if (m_plan_sp) |
| 1097 | return m_plan_sp->ShouldStop(event_ptr); |
| 1098 | else |
| 1099 | return StopInfo::ShouldStop(event_ptr); |
| 1100 | } |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 1101 | |
| 1102 | private: |
| 1103 | ThreadPlanSP m_plan_sp; |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 1104 | ValueObjectSP m_return_valobj_sp; |
Sean Callanan | bc8ac34 | 2015-09-04 20:49:51 +0000 | [diff] [blame] | 1105 | ExpressionVariableSP m_expression_variable_sp; |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 1106 | }; |
Greg Clayton | 90ba811 | 2012-12-05 00:16:59 +0000 | [diff] [blame] | 1107 | |
| 1108 | class StopInfoExec : public StopInfo |
| 1109 | { |
| 1110 | public: |
Greg Clayton | 90ba811 | 2012-12-05 00:16:59 +0000 | [diff] [blame] | 1111 | StopInfoExec (Thread &thread) : |
| 1112 | StopInfo (thread, LLDB_INVALID_UID), |
| 1113 | m_performed_action (false) |
| 1114 | { |
| 1115 | } |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 1116 | |
| 1117 | ~StopInfoExec() override = default; |
| 1118 | |
| 1119 | StopReason |
| 1120 | GetStopReason() const override |
Greg Clayton | 90ba811 | 2012-12-05 00:16:59 +0000 | [diff] [blame] | 1121 | { |
| 1122 | return eStopReasonExec; |
| 1123 | } |
| 1124 | |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 1125 | const char * |
| 1126 | GetDescription() override |
Greg Clayton | 90ba811 | 2012-12-05 00:16:59 +0000 | [diff] [blame] | 1127 | { |
| 1128 | return "exec"; |
| 1129 | } |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 1130 | |
Greg Clayton | 90ba811 | 2012-12-05 00:16:59 +0000 | [diff] [blame] | 1131 | protected: |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 1132 | void |
| 1133 | PerformAction(Event *event_ptr) override |
Greg Clayton | 90ba811 | 2012-12-05 00:16:59 +0000 | [diff] [blame] | 1134 | { |
| 1135 | // Only perform the action once |
| 1136 | if (m_performed_action) |
| 1137 | return; |
| 1138 | m_performed_action = true; |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 1139 | ThreadSP thread_sp (m_thread_wp.lock()); |
| 1140 | if (thread_sp) |
| 1141 | thread_sp->GetProcess()->DidExec(); |
Greg Clayton | 90ba811 | 2012-12-05 00:16:59 +0000 | [diff] [blame] | 1142 | } |
| 1143 | |
| 1144 | bool m_performed_action; |
| 1145 | }; |
| 1146 | |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 1147 | } // namespace lldb_private |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 1148 | |
| 1149 | StopInfoSP |
| 1150 | StopInfo::CreateStopReasonWithBreakpointSiteID (Thread &thread, break_id_t break_id) |
| 1151 | { |
| 1152 | return StopInfoSP (new StopInfoBreakpoint (thread, break_id)); |
| 1153 | } |
| 1154 | |
| 1155 | StopInfoSP |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 1156 | StopInfo::CreateStopReasonWithBreakpointSiteID (Thread &thread, break_id_t break_id, bool should_stop) |
| 1157 | { |
| 1158 | return StopInfoSP (new StopInfoBreakpoint (thread, break_id, should_stop)); |
| 1159 | } |
| 1160 | |
| 1161 | StopInfoSP |
Jaydeep Patil | 8314350 | 2015-08-13 03:44:09 +0000 | [diff] [blame] | 1162 | StopInfo::CreateStopReasonWithWatchpointID (Thread &thread, break_id_t watch_id, lldb::addr_t watch_hit_addr) |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 1163 | { |
Jaydeep Patil | 8314350 | 2015-08-13 03:44:09 +0000 | [diff] [blame] | 1164 | return StopInfoSP (new StopInfoWatchpoint (thread, watch_id, watch_hit_addr)); |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 1165 | } |
| 1166 | |
| 1167 | StopInfoSP |
Pavel Labath | c4e25c9 | 2015-05-29 10:13:03 +0000 | [diff] [blame] | 1168 | StopInfo::CreateStopReasonWithSignal (Thread &thread, int signo, const char *description) |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 1169 | { |
Pavel Labath | c4e25c9 | 2015-05-29 10:13:03 +0000 | [diff] [blame] | 1170 | return StopInfoSP (new StopInfoUnixSignal (thread, signo, description)); |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 1171 | } |
| 1172 | |
| 1173 | StopInfoSP |
| 1174 | StopInfo::CreateStopReasonToTrace (Thread &thread) |
| 1175 | { |
| 1176 | return StopInfoSP (new StopInfoTrace (thread)); |
| 1177 | } |
| 1178 | |
| 1179 | StopInfoSP |
Jim Ingham | 30fadaf | 2014-07-08 01:07:32 +0000 | [diff] [blame] | 1180 | StopInfo::CreateStopReasonWithPlan (ThreadPlanSP &plan_sp, |
| 1181 | ValueObjectSP return_valobj_sp, |
Sean Callanan | bc8ac34 | 2015-09-04 20:49:51 +0000 | [diff] [blame] | 1182 | ExpressionVariableSP expression_variable_sp) |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 1183 | { |
Jim Ingham | 30fadaf | 2014-07-08 01:07:32 +0000 | [diff] [blame] | 1184 | return StopInfoSP (new StopInfoThreadPlan (plan_sp, return_valobj_sp, expression_variable_sp)); |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 1185 | } |
Greg Clayton | a658fd2 | 2011-06-04 01:26:29 +0000 | [diff] [blame] | 1186 | |
| 1187 | StopInfoSP |
| 1188 | StopInfo::CreateStopReasonWithException (Thread &thread, const char *description) |
| 1189 | { |
| 1190 | return StopInfoSP (new StopInfoException (thread, description)); |
| 1191 | } |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 1192 | |
Greg Clayton | 90ba811 | 2012-12-05 00:16:59 +0000 | [diff] [blame] | 1193 | StopInfoSP |
| 1194 | StopInfo::CreateStopReasonWithExec (Thread &thread) |
| 1195 | { |
| 1196 | return StopInfoSP (new StopInfoExec (thread)); |
| 1197 | } |
| 1198 | |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 1199 | ValueObjectSP |
| 1200 | StopInfo::GetReturnValueObject(StopInfoSP &stop_info_sp) |
| 1201 | { |
| 1202 | if (stop_info_sp && stop_info_sp->GetStopReason() == eStopReasonPlanComplete) |
| 1203 | { |
| 1204 | StopInfoThreadPlan *plan_stop_info = static_cast<StopInfoThreadPlan *>(stop_info_sp.get()); |
| 1205 | return plan_stop_info->GetReturnValueObject(); |
| 1206 | } |
| 1207 | else |
| 1208 | return ValueObjectSP(); |
| 1209 | } |
Jim Ingham | 30fadaf | 2014-07-08 01:07:32 +0000 | [diff] [blame] | 1210 | |
Sean Callanan | bc8ac34 | 2015-09-04 20:49:51 +0000 | [diff] [blame] | 1211 | ExpressionVariableSP |
Jim Ingham | 30fadaf | 2014-07-08 01:07:32 +0000 | [diff] [blame] | 1212 | StopInfo::GetExpressionVariable(StopInfoSP &stop_info_sp) |
| 1213 | { |
| 1214 | if (stop_info_sp && stop_info_sp->GetStopReason() == eStopReasonPlanComplete) |
| 1215 | { |
| 1216 | StopInfoThreadPlan *plan_stop_info = static_cast<StopInfoThreadPlan *>(stop_info_sp.get()); |
| 1217 | return plan_stop_info->GetExpressionVariable(); |
| 1218 | } |
| 1219 | else |
Sean Callanan | bc8ac34 | 2015-09-04 20:49:51 +0000 | [diff] [blame] | 1220 | return ExpressionVariableSP(); |
Jim Ingham | 30fadaf | 2014-07-08 01:07:32 +0000 | [diff] [blame] | 1221 | } |