Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 1 | //===-- StopInfo.cpp ---------------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Daniel Malea | 93a6430 | 2012-12-05 00:20:57 +0000 | [diff] [blame] | 10 | #include "lldb/lldb-python.h" |
| 11 | |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 12 | #include "lldb/Target/StopInfo.h" |
| 13 | |
| 14 | // C Includes |
| 15 | // C++ Includes |
| 16 | #include <string> |
| 17 | |
| 18 | // Other libraries and framework includes |
| 19 | // Project includes |
| 20 | #include "lldb/Core/Log.h" |
Greg Clayton | 4e78f60 | 2010-11-18 18:52:36 +0000 | [diff] [blame] | 21 | #include "lldb/Breakpoint/Breakpoint.h" |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 22 | #include "lldb/Breakpoint/BreakpointLocation.h" |
| 23 | #include "lldb/Breakpoint/StoppointCallbackContext.h" |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 24 | #include "lldb/Breakpoint/Watchpoint.h" |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 25 | #include "lldb/Core/Debugger.h" |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 26 | #include "lldb/Core/StreamString.h" |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 27 | #include "lldb/Expression/ClangUserExpression.h" |
| 28 | #include "lldb/Target/Target.h" |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 29 | #include "lldb/Target/Thread.h" |
| 30 | #include "lldb/Target/ThreadPlan.h" |
| 31 | #include "lldb/Target/Process.h" |
| 32 | #include "lldb/Target/UnixSignals.h" |
| 33 | |
| 34 | using namespace lldb; |
| 35 | using namespace lldb_private; |
| 36 | |
| 37 | StopInfo::StopInfo (Thread &thread, uint64_t value) : |
| 38 | m_thread (thread), |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 39 | m_stop_id (thread.GetProcess()->GetStopID()), |
| 40 | m_resume_id (thread.GetProcess()->GetResumeID()), |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 41 | m_value (value) |
| 42 | { |
| 43 | } |
| 44 | |
| 45 | bool |
| 46 | StopInfo::IsValid () const |
| 47 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 48 | return m_thread.GetProcess()->GetStopID() == m_stop_id; |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 49 | } |
| 50 | |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 51 | void |
| 52 | StopInfo::MakeStopInfoValid () |
| 53 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 54 | m_stop_id = m_thread.GetProcess()->GetStopID(); |
| 55 | m_resume_id = m_thread.GetProcess()->GetResumeID(); |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 56 | } |
| 57 | |
Jim Ingham | 0faa43f | 2011-11-08 03:00:11 +0000 | [diff] [blame] | 58 | bool |
| 59 | StopInfo::HasTargetRunSinceMe () |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 60 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 61 | lldb::StateType ret_type = m_thread.GetProcess()->GetPrivateState(); |
Jim Ingham | 0faa43f | 2011-11-08 03:00:11 +0000 | [diff] [blame] | 62 | if (ret_type == eStateRunning) |
| 63 | { |
| 64 | return true; |
| 65 | } |
| 66 | else if (ret_type == eStateStopped) |
| 67 | { |
| 68 | // This is a little tricky. We want to count "run and stopped again before you could |
| 69 | // ask this question as a "TRUE" answer to HasTargetRunSinceMe. But we don't want to |
| 70 | // include any running of the target done for expressions. So we track both resumes, |
| 71 | // and resumes caused by expressions, and check if there are any resumes NOT caused |
| 72 | // by expressions. |
| 73 | |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 74 | uint32_t curr_resume_id = m_thread.GetProcess()->GetResumeID(); |
| 75 | uint32_t last_user_expression_id = m_thread.GetProcess()->GetLastUserExpressionResumeID (); |
Jim Ingham | 0faa43f | 2011-11-08 03:00:11 +0000 | [diff] [blame] | 76 | if (curr_resume_id == m_resume_id) |
| 77 | { |
| 78 | return false; |
| 79 | } |
| 80 | else if (curr_resume_id > last_user_expression_id) |
| 81 | { |
| 82 | return true; |
| 83 | } |
| 84 | } |
| 85 | return false; |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 88 | //---------------------------------------------------------------------- |
| 89 | // StopInfoBreakpoint |
| 90 | //---------------------------------------------------------------------- |
| 91 | |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 92 | namespace lldb_private |
| 93 | { |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 94 | class StopInfoBreakpoint : public StopInfo |
| 95 | { |
| 96 | public: |
| 97 | |
| 98 | StopInfoBreakpoint (Thread &thread, break_id_t break_id) : |
| 99 | StopInfo (thread, break_id), |
| 100 | m_description(), |
| 101 | m_should_stop (false), |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 102 | m_should_stop_is_valid (false), |
Jim Ingham | 52c7d20 | 2011-10-28 01:12:19 +0000 | [diff] [blame] | 103 | m_should_perform_action (true), |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 104 | m_address (LLDB_INVALID_ADDRESS), |
| 105 | m_break_id(LLDB_INVALID_BREAK_ID), |
| 106 | m_was_one_shot (false) |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 107 | { |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 108 | StoreBPInfo(); |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 109 | } |
| 110 | |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 111 | StopInfoBreakpoint (Thread &thread, break_id_t break_id, bool should_stop) : |
| 112 | StopInfo (thread, break_id), |
| 113 | m_description(), |
| 114 | m_should_stop (should_stop), |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 115 | m_should_stop_is_valid (true), |
Jim Ingham | 52c7d20 | 2011-10-28 01:12:19 +0000 | [diff] [blame] | 116 | m_should_perform_action (true), |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 117 | m_address (LLDB_INVALID_ADDRESS), |
| 118 | m_break_id(LLDB_INVALID_BREAK_ID), |
| 119 | m_was_one_shot (false) |
| 120 | { |
| 121 | StoreBPInfo(); |
| 122 | } |
| 123 | |
| 124 | void StoreBPInfo () |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 125 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 126 | BreakpointSiteSP bp_site_sp (m_thread.GetProcess()->GetBreakpointSiteList().FindByID (m_value)); |
Jim Ingham | 52c7d20 | 2011-10-28 01:12:19 +0000 | [diff] [blame] | 127 | if (bp_site_sp) |
| 128 | { |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 129 | if (bp_site_sp->GetNumberOfOwners() == 1) |
| 130 | { |
| 131 | BreakpointLocationSP bp_loc_sp = bp_site_sp->GetOwnerAtIndex(0); |
| 132 | if (bp_loc_sp) |
| 133 | { |
| 134 | m_break_id = bp_loc_sp->GetBreakpoint().GetID(); |
| 135 | m_was_one_shot = bp_loc_sp->GetBreakpoint().IsOneShot(); |
| 136 | } |
| 137 | } |
| 138 | m_address = bp_site_sp->GetLoadAddress(); |
Jim Ingham | 52c7d20 | 2011-10-28 01:12:19 +0000 | [diff] [blame] | 139 | } |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 140 | } |
| 141 | |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 142 | virtual ~StopInfoBreakpoint () |
| 143 | { |
| 144 | } |
| 145 | |
| 146 | virtual StopReason |
| 147 | GetStopReason () const |
| 148 | { |
| 149 | return eStopReasonBreakpoint; |
| 150 | } |
| 151 | |
| 152 | virtual bool |
Jim Ingham | 6d66ce6 | 2012-04-20 21:16:56 +0000 | [diff] [blame] | 153 | ShouldStopSynchronous (Event *event_ptr) |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 154 | { |
| 155 | if (!m_should_stop_is_valid) |
| 156 | { |
| 157 | // Only check once if we should stop at a breakpoint |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 158 | BreakpointSiteSP bp_site_sp (m_thread.GetProcess()->GetBreakpointSiteList().FindByID (m_value)); |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 159 | if (bp_site_sp) |
| 160 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 161 | ExecutionContext exe_ctx (m_thread.GetStackFrameAtIndex(0)); |
| 162 | StoppointCallbackContext context (event_ptr, exe_ctx, true); |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 163 | m_should_stop = bp_site_sp->ShouldStop (&context); |
| 164 | } |
| 165 | else |
| 166 | { |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 167 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 168 | |
| 169 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 170 | 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] | 171 | |
| 172 | m_should_stop = true; |
| 173 | } |
| 174 | m_should_stop_is_valid = true; |
| 175 | } |
| 176 | return m_should_stop; |
| 177 | } |
Jim Ingham | 3ebcf7f | 2010-08-10 00:59:59 +0000 | [diff] [blame] | 178 | |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 179 | virtual bool |
| 180 | ShouldNotify (Event *event_ptr) |
| 181 | { |
| 182 | BreakpointSiteSP bp_site_sp (m_thread.GetProcess()->GetBreakpointSiteList().FindByID (m_value)); |
| 183 | if (bp_site_sp) |
| 184 | { |
| 185 | bool all_internal = true; |
| 186 | |
| 187 | for (uint32_t i = 0; i < bp_site_sp->GetNumberOfOwners(); i++) |
| 188 | { |
| 189 | if (!bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint().IsInternal()) |
| 190 | { |
| 191 | all_internal = false; |
| 192 | break; |
| 193 | } |
| 194 | } |
| 195 | return all_internal == false; |
| 196 | } |
| 197 | return true; |
| 198 | } |
| 199 | |
| 200 | virtual const char * |
| 201 | GetDescription () |
| 202 | { |
| 203 | if (m_description.empty()) |
| 204 | { |
| 205 | BreakpointSiteSP bp_site_sp (m_thread.GetProcess()->GetBreakpointSiteList().FindByID (m_value)); |
| 206 | if (bp_site_sp) |
| 207 | { |
| 208 | StreamString strm; |
| 209 | strm.Printf("breakpoint "); |
| 210 | bp_site_sp->GetDescription(&strm, eDescriptionLevelBrief); |
| 211 | m_description.swap (strm.GetString()); |
| 212 | } |
| 213 | else |
| 214 | { |
| 215 | StreamString strm; |
| 216 | if (m_break_id != LLDB_INVALID_BREAK_ID) |
| 217 | { |
| 218 | if (m_was_one_shot) |
| 219 | strm.Printf ("one-shot breakpoint %d", m_break_id); |
| 220 | else |
| 221 | strm.Printf ("breakpoint %d which has been deleted.", m_break_id); |
| 222 | } |
| 223 | else if (m_address == LLDB_INVALID_ADDRESS) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 224 | strm.Printf("breakpoint site %" PRIi64 " which has been deleted - unknown address", m_value); |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 225 | else |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 226 | strm.Printf("breakpoint site %" PRIi64 " which has been deleted - was at 0x%" PRIx64, m_value, m_address); |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 227 | |
| 228 | m_description.swap (strm.GetString()); |
| 229 | } |
| 230 | } |
| 231 | return m_description.c_str(); |
| 232 | } |
| 233 | |
| 234 | protected: |
Jim Ingham | 6d66ce6 | 2012-04-20 21:16:56 +0000 | [diff] [blame] | 235 | bool |
| 236 | ShouldStop (Event *event_ptr) |
| 237 | { |
| 238 | // This just reports the work done by PerformAction or the synchronous stop. It should |
| 239 | // only ever get called after they have had a chance to run. |
| 240 | assert (m_should_stop_is_valid); |
| 241 | return m_should_stop; |
| 242 | } |
| 243 | |
Jim Ingham | 3ebcf7f | 2010-08-10 00:59:59 +0000 | [diff] [blame] | 244 | virtual void |
| 245 | PerformAction (Event *event_ptr) |
| 246 | { |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 247 | if (!m_should_perform_action) |
| 248 | return; |
| 249 | m_should_perform_action = false; |
| 250 | |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 251 | LogSP log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS); |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 252 | |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 253 | BreakpointSiteSP bp_site_sp (m_thread.GetProcess()->GetBreakpointSiteList().FindByID (m_value)); |
Jim Ingham | 79ea1d8 | 2011-12-09 04:17:31 +0000 | [diff] [blame] | 254 | |
Jim Ingham | 3ebcf7f | 2010-08-10 00:59:59 +0000 | [diff] [blame] | 255 | if (bp_site_sp) |
| 256 | { |
| 257 | size_t num_owners = bp_site_sp->GetNumberOfOwners(); |
Jim Ingham | 79ea1d8 | 2011-12-09 04:17:31 +0000 | [diff] [blame] | 258 | |
| 259 | if (num_owners == 0) |
Jim Ingham | 3ebcf7f | 2010-08-10 00:59:59 +0000 | [diff] [blame] | 260 | { |
Jim Ingham | 79ea1d8 | 2011-12-09 04:17:31 +0000 | [diff] [blame] | 261 | m_should_stop = true; |
| 262 | } |
| 263 | else |
| 264 | { |
| 265 | // We go through each location, and test first its condition. If the condition says to stop, |
| 266 | // then we run the callback for that location. If that callback says to stop as well, then |
| 267 | // we set m_should_stop to true; we are going to stop. |
| 268 | // But we still want to give all the breakpoints whose conditions say we are going to stop a |
| 269 | // chance to run their callbacks. |
| 270 | // Of course if any callback restarts the target by putting "continue" in the callback, then |
| 271 | // we're going to restart, without running the rest of the callbacks. And in this case we will |
| 272 | // end up not stopping even if another location said we should stop. But that's better than not |
| 273 | // running all the callbacks. |
| 274 | |
| 275 | m_should_stop = false; |
| 276 | |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 277 | ExecutionContext exe_ctx (m_thread.GetStackFrameAtIndex(0)); |
| 278 | StoppointCallbackContext context (event_ptr, exe_ctx, false); |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 279 | |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 280 | for (size_t j = 0; j < num_owners; j++) |
| 281 | { |
| 282 | lldb::BreakpointLocationSP bp_loc_sp = bp_site_sp->GetOwnerAtIndex(j); |
Jim Ingham | 79ea1d8 | 2011-12-09 04:17:31 +0000 | [diff] [blame] | 283 | |
| 284 | // First run the condition for the breakpoint. If that says we should stop, then we'll run |
| 285 | // the callback for the breakpoint. If the callback says we shouldn't stop that will win. |
| 286 | |
| 287 | bool condition_says_stop = true; |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 288 | if (bp_loc_sp->GetConditionText() != NULL) |
| 289 | { |
| 290 | // We need to make sure the user sees any parse errors in their condition, so we'll hook the |
| 291 | // constructor errors up to the debugger's Async I/O. |
| 292 | |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 293 | ValueObjectSP result_valobj_sp; |
| 294 | |
| 295 | ExecutionResults result_code; |
| 296 | ValueObjectSP result_value_sp; |
| 297 | const bool discard_on_error = true; |
| 298 | Error error; |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 299 | result_code = ClangUserExpression::EvaluateWithError (exe_ctx, |
Jim Ingham | 6d66ce6 | 2012-04-20 21:16:56 +0000 | [diff] [blame] | 300 | eExecutionPolicyOnlyWhenNeeded, |
Sean Callanan | c7b6506 | 2011-11-07 23:35:40 +0000 | [diff] [blame] | 301 | lldb::eLanguageTypeUnknown, |
Sean Callanan | 20bb3aa | 2011-12-21 22:22:58 +0000 | [diff] [blame] | 302 | ClangUserExpression::eResultTypeAny, |
Sean Callanan | 3bfdaa2 | 2011-09-15 02:13:07 +0000 | [diff] [blame] | 303 | discard_on_error, |
| 304 | bp_loc_sp->GetConditionText(), |
| 305 | NULL, |
| 306 | result_value_sp, |
Greg Clayton | 26ab83d | 2012-10-31 20:49:04 +0000 | [diff] [blame] | 307 | error, |
| 308 | true, |
| 309 | ClangUserExpression::kDefaultTimeout); |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 310 | if (result_code == eExecutionCompleted) |
| 311 | { |
| 312 | if (result_value_sp) |
| 313 | { |
| 314 | Scalar scalar_value; |
| 315 | if (result_value_sp->ResolveValue (scalar_value)) |
| 316 | { |
| 317 | if (scalar_value.ULongLong(1) == 0) |
Jim Ingham | 79ea1d8 | 2011-12-09 04:17:31 +0000 | [diff] [blame] | 318 | condition_says_stop = false; |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 319 | else |
Jim Ingham | 79ea1d8 | 2011-12-09 04:17:31 +0000 | [diff] [blame] | 320 | condition_says_stop = true; |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 321 | if (log) |
| 322 | log->Printf("Condition successfully evaluated, result is %s.\n", |
| 323 | m_should_stop ? "true" : "false"); |
| 324 | } |
| 325 | else |
| 326 | { |
Jim Ingham | 79ea1d8 | 2011-12-09 04:17:31 +0000 | [diff] [blame] | 327 | condition_says_stop = true; |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 328 | if (log) |
| 329 | log->Printf("Failed to get an integer result from the expression."); |
| 330 | } |
| 331 | } |
| 332 | } |
| 333 | else |
| 334 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 335 | Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger(); |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 336 | StreamSP error_sp = debugger.GetAsyncErrorStream (); |
| 337 | error_sp->Printf ("Stopped due to an error evaluating condition of breakpoint "); |
| 338 | bp_loc_sp->GetDescription (error_sp.get(), eDescriptionLevelBrief); |
| 339 | error_sp->Printf (": \"%s\"", |
| 340 | bp_loc_sp->GetConditionText()); |
| 341 | error_sp->EOL(); |
| 342 | const char *err_str = error.AsCString("<Unknown Error>"); |
| 343 | if (log) |
| 344 | log->Printf("Error evaluating condition: \"%s\"\n", err_str); |
| 345 | |
| 346 | error_sp->PutCString (err_str); |
| 347 | error_sp->EOL(); |
| 348 | error_sp->Flush(); |
| 349 | // If the condition fails to be parsed or run, we should stop. |
Jim Ingham | 79ea1d8 | 2011-12-09 04:17:31 +0000 | [diff] [blame] | 350 | condition_says_stop = true; |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 351 | } |
| 352 | } |
| 353 | |
Jim Ingham | 79ea1d8 | 2011-12-09 04:17:31 +0000 | [diff] [blame] | 354 | // If this location's condition says we should aren't going to stop, |
| 355 | // then don't run the callback for this location. |
| 356 | if (!condition_says_stop) |
| 357 | continue; |
| 358 | |
| 359 | bool callback_says_stop; |
| 360 | |
| 361 | // FIXME: For now the callbacks have to run in async mode - the first time we restart we need |
| 362 | // to get out of there. So set it here. |
| 363 | // When we figure out how to nest breakpoint hits then this will change. |
| 364 | |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 365 | Debugger &debugger = m_thread.CalculateTarget()->GetDebugger(); |
Jim Ingham | 79ea1d8 | 2011-12-09 04:17:31 +0000 | [diff] [blame] | 366 | bool old_async = debugger.GetAsyncExecution(); |
| 367 | debugger.SetAsyncExecution (true); |
| 368 | |
| 369 | callback_says_stop = bp_loc_sp->InvokeCallback (&context); |
| 370 | |
| 371 | debugger.SetAsyncExecution (old_async); |
| 372 | |
| 373 | if (callback_says_stop) |
| 374 | m_should_stop = true; |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 375 | |
| 376 | // If we are going to stop for this breakpoint, then remove the breakpoint. |
| 377 | if (callback_says_stop && bp_loc_sp && bp_loc_sp->GetBreakpoint().IsOneShot()) |
| 378 | { |
| 379 | m_thread.GetProcess()->GetTarget().RemoveBreakpointByID (bp_loc_sp->GetBreakpoint().GetID()); |
| 380 | } |
Jim Ingham | 79ea1d8 | 2011-12-09 04:17:31 +0000 | [diff] [blame] | 381 | |
| 382 | // Also make sure that the callback hasn't continued the target. |
| 383 | // If it did, when we'll set m_should_start to false and get out of here. |
| 384 | if (HasTargetRunSinceMe ()) |
| 385 | { |
| 386 | m_should_stop = false; |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 387 | break; |
Jim Ingham | 79ea1d8 | 2011-12-09 04:17:31 +0000 | [diff] [blame] | 388 | } |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 389 | } |
Jim Ingham | 3ebcf7f | 2010-08-10 00:59:59 +0000 | [diff] [blame] | 390 | } |
Jim Ingham | 79ea1d8 | 2011-12-09 04:17:31 +0000 | [diff] [blame] | 391 | // We've figured out what this stop wants to do, so mark it as valid so we don't compute it again. |
| 392 | m_should_stop_is_valid = true; |
| 393 | |
Jim Ingham | 3ebcf7f | 2010-08-10 00:59:59 +0000 | [diff] [blame] | 394 | } |
| 395 | else |
| 396 | { |
Jim Ingham | 79ea1d8 | 2011-12-09 04:17:31 +0000 | [diff] [blame] | 397 | m_should_stop = true; |
| 398 | m_should_stop_is_valid = true; |
Jason Molenda | ccd41e5 | 2012-10-04 22:47:07 +0000 | [diff] [blame] | 399 | LogSP log_process(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Jim Ingham | 3ebcf7f | 2010-08-10 00:59:59 +0000 | [diff] [blame] | 400 | |
Jason Molenda | ccd41e5 | 2012-10-04 22:47:07 +0000 | [diff] [blame] | 401 | if (log_process) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 402 | log_process->Printf ("Process::%s could not find breakpoint site id: %" PRId64 "...", __FUNCTION__, m_value); |
Jim Ingham | 3ebcf7f | 2010-08-10 00:59:59 +0000 | [diff] [blame] | 403 | } |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 404 | if (log) |
| 405 | 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] | 406 | } |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 407 | |
| 408 | private: |
| 409 | std::string m_description; |
| 410 | bool m_should_stop; |
| 411 | bool m_should_stop_is_valid; |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 412 | bool m_should_perform_action; // Since we are trying to preserve the "state" of the system even if we run functions |
| 413 | // 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] | 414 | lldb::addr_t m_address; // We use this to capture the breakpoint site address when we create the StopInfo, |
| 415 | // in case somebody deletes it between the time the StopInfo is made and the |
| 416 | // description is asked for. |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 417 | lldb::break_id_t m_break_id; |
| 418 | bool m_was_one_shot; |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 419 | }; |
| 420 | |
| 421 | |
| 422 | //---------------------------------------------------------------------- |
| 423 | // StopInfoWatchpoint |
| 424 | //---------------------------------------------------------------------- |
| 425 | |
| 426 | class StopInfoWatchpoint : public StopInfo |
| 427 | { |
| 428 | public: |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 429 | // Make sure watchpoint is properly disabled and subsequently enabled while performing watchpoint actions. |
| 430 | class WatchpointSentry { |
| 431 | public: |
| 432 | WatchpointSentry(Process *p, Watchpoint *w): |
| 433 | process(p), |
| 434 | watchpoint(w) |
| 435 | { |
| 436 | if (process && watchpoint) |
| 437 | { |
| 438 | watchpoint->TurnOnEphemeralMode(); |
| 439 | process->DisableWatchpoint(watchpoint); |
| 440 | } |
| 441 | } |
| 442 | ~WatchpointSentry() |
| 443 | { |
| 444 | if (process && watchpoint) |
| 445 | { |
| 446 | if (!watchpoint->IsDisabledDuringEphemeralMode()) |
| 447 | process->EnableWatchpoint(watchpoint); |
| 448 | watchpoint->TurnOffEphemeralMode(); |
| 449 | } |
| 450 | } |
| 451 | private: |
| 452 | Process *process; |
| 453 | Watchpoint *watchpoint; |
| 454 | }; |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 455 | |
| 456 | StopInfoWatchpoint (Thread &thread, break_id_t watch_id) : |
Johnny Chen | fd158f4 | 2011-09-21 22:47:15 +0000 | [diff] [blame] | 457 | StopInfo(thread, watch_id), |
| 458 | m_description(), |
| 459 | m_should_stop(false), |
| 460 | m_should_stop_is_valid(false) |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 461 | { |
| 462 | } |
| 463 | |
| 464 | virtual ~StopInfoWatchpoint () |
| 465 | { |
| 466 | } |
| 467 | |
| 468 | virtual StopReason |
| 469 | GetStopReason () const |
| 470 | { |
| 471 | return eStopReasonWatchpoint; |
| 472 | } |
| 473 | |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 474 | virtual const char * |
| 475 | GetDescription () |
| 476 | { |
| 477 | if (m_description.empty()) |
| 478 | { |
| 479 | StreamString strm; |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 480 | strm.Printf("watchpoint %" PRIi64, m_value); |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 481 | m_description.swap (strm.GetString()); |
| 482 | } |
| 483 | return m_description.c_str(); |
| 484 | } |
| 485 | |
| 486 | protected: |
Johnny Chen | fd158f4 | 2011-09-21 22:47:15 +0000 | [diff] [blame] | 487 | virtual bool |
| 488 | ShouldStop (Event *event_ptr) |
| 489 | { |
| 490 | // ShouldStop() method is idempotent and should not affect hit count. |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 491 | // See Process::RunPrivateStateThread()->Process()->HandlePrivateEvent() |
| 492 | // -->Process()::ShouldBroadcastEvent()->ThreadList::ShouldStop()-> |
| 493 | // Thread::ShouldStop()->ThreadPlanBase::ShouldStop()-> |
| 494 | // StopInfoWatchpoint::ShouldStop() and |
| 495 | // Event::DoOnRemoval()->Process::ProcessEventData::DoOnRemoval()-> |
| 496 | // StopInfoWatchpoint::PerformAction(). |
Johnny Chen | fd158f4 | 2011-09-21 22:47:15 +0000 | [diff] [blame] | 497 | if (m_should_stop_is_valid) |
| 498 | return m_should_stop; |
| 499 | |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 500 | WatchpointSP wp_sp = |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 501 | m_thread.CalculateTarget()->GetWatchpointList().FindByID(GetValue()); |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 502 | if (wp_sp) |
Johnny Chen | fd158f4 | 2011-09-21 22:47:15 +0000 | [diff] [blame] | 503 | { |
| 504 | // Check if we should stop at a watchpoint. |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 505 | ExecutionContext exe_ctx (m_thread.GetStackFrameAtIndex(0)); |
| 506 | StoppointCallbackContext context (event_ptr, exe_ctx, true); |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 507 | m_should_stop = wp_sp->ShouldStop (&context); |
Johnny Chen | fd158f4 | 2011-09-21 22:47:15 +0000 | [diff] [blame] | 508 | } |
| 509 | else |
| 510 | { |
| 511 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
| 512 | |
| 513 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 514 | log->Printf ("Process::%s could not find watchpoint location id: %" PRId64 "...", |
Johnny Chen | fd158f4 | 2011-09-21 22:47:15 +0000 | [diff] [blame] | 515 | __FUNCTION__, GetValue()); |
| 516 | |
| 517 | m_should_stop = true; |
| 518 | } |
| 519 | m_should_stop_is_valid = true; |
| 520 | return m_should_stop; |
| 521 | } |
| 522 | |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 523 | virtual void |
| 524 | PerformAction (Event *event_ptr) |
| 525 | { |
Johnny Chen | 209bd65 | 2012-08-13 21:09:54 +0000 | [diff] [blame] | 526 | LogSP log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS); |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 527 | // We're going to calculate if we should stop or not in some way during the course of |
| 528 | // this code. Also by default we're going to stop, so set that here. |
| 529 | m_should_stop = true; |
| 530 | |
| 531 | WatchpointSP wp_sp = |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 532 | m_thread.CalculateTarget()->GetWatchpointList().FindByID(GetValue()); |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 533 | if (wp_sp) |
| 534 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 535 | ExecutionContext exe_ctx (m_thread.GetStackFrameAtIndex(0)); |
Johnny Chen | 209bd65 | 2012-08-13 21:09:54 +0000 | [diff] [blame] | 536 | Process* process = exe_ctx.GetProcessPtr(); |
Johnny Chen | 0f7ad8d | 2012-08-21 22:06:34 +0000 | [diff] [blame] | 537 | |
Johnny Chen | 66535a3 | 2012-08-21 22:15:58 +0000 | [diff] [blame] | 538 | // This sentry object makes sure the current watchpoint is disabled while performing watchpoint actions, |
| 539 | // and it is then enabled after we are finished. |
Johnny Chen | 0f7ad8d | 2012-08-21 22:06:34 +0000 | [diff] [blame] | 540 | WatchpointSentry sentry(process, wp_sp.get()); |
| 541 | |
Enrico Granata | f04a219 | 2012-07-13 23:18:48 +0000 | [diff] [blame] | 542 | { |
| 543 | // check if this process is running on an architecture where watchpoints trigger |
| 544 | // before the associated instruction runs. if so, disable the WP, single-step and then |
| 545 | // re-enable the watchpoint |
Enrico Granata | f04a219 | 2012-07-13 23:18:48 +0000 | [diff] [blame] | 546 | if (process) |
| 547 | { |
| 548 | uint32_t num; bool wp_triggers_after; |
| 549 | if (process->GetWatchpointSupportInfo(num, wp_triggers_after).Success()) |
| 550 | { |
| 551 | if (!wp_triggers_after) |
| 552 | { |
Enrico Granata | f04a219 | 2012-07-13 23:18:48 +0000 | [diff] [blame] | 553 | ThreadPlan *new_plan = m_thread.QueueThreadPlanForStepSingleInstruction(false, // step-over |
| 554 | false, // abort_other_plans |
| 555 | true); // stop_other_threads |
| 556 | new_plan->SetIsMasterPlan (true); |
| 557 | new_plan->SetOkayToDiscard (false); |
| 558 | process->GetThreadList().SetSelectedThreadByID (m_thread.GetID()); |
| 559 | process->Resume (); |
| 560 | process->WaitForProcessToStop (NULL); |
| 561 | process->GetThreadList().SetSelectedThreadByID (m_thread.GetID()); |
| 562 | MakeStopInfoValid(); // make sure we do not fail to stop because of the single-step taken above |
Enrico Granata | f04a219 | 2012-07-13 23:18:48 +0000 | [diff] [blame] | 563 | } |
| 564 | } |
| 565 | } |
| 566 | } |
Johnny Chen | 209bd65 | 2012-08-13 21:09:54 +0000 | [diff] [blame] | 567 | |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 568 | if (m_should_stop && wp_sp->GetConditionText() != NULL) |
| 569 | { |
| 570 | // We need to make sure the user sees any parse errors in their condition, so we'll hook the |
| 571 | // constructor errors up to the debugger's Async I/O. |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 572 | ExecutionResults result_code; |
| 573 | ValueObjectSP result_value_sp; |
| 574 | const bool discard_on_error = true; |
| 575 | Error error; |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 576 | result_code = ClangUserExpression::EvaluateWithError (exe_ctx, |
Sean Callanan | 2201905 | 2012-09-08 01:51:48 +0000 | [diff] [blame] | 577 | eExecutionPolicyOnlyWhenNeeded, |
Sean Callanan | c7b6506 | 2011-11-07 23:35:40 +0000 | [diff] [blame] | 578 | lldb::eLanguageTypeUnknown, |
Sean Callanan | 20bb3aa | 2011-12-21 22:22:58 +0000 | [diff] [blame] | 579 | ClangUserExpression::eResultTypeAny, |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 580 | discard_on_error, |
| 581 | wp_sp->GetConditionText(), |
| 582 | NULL, |
| 583 | result_value_sp, |
Enrico Granata | 3372f58 | 2012-07-16 23:10:35 +0000 | [diff] [blame] | 584 | error, |
Greg Clayton | 26ab83d | 2012-10-31 20:49:04 +0000 | [diff] [blame] | 585 | true, |
| 586 | ClangUserExpression::kDefaultTimeout); |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 587 | if (result_code == eExecutionCompleted) |
| 588 | { |
| 589 | if (result_value_sp) |
| 590 | { |
| 591 | Scalar scalar_value; |
| 592 | if (result_value_sp->ResolveValue (scalar_value)) |
| 593 | { |
| 594 | if (scalar_value.ULongLong(1) == 0) |
| 595 | { |
| 596 | // We have been vetoed. This takes precedence over querying |
| 597 | // the watchpoint whether it should stop (aka ignore count and |
| 598 | // friends). See also StopInfoWatchpoint::ShouldStop() as well |
| 599 | // as Process::ProcessEventData::DoOnRemoval(). |
| 600 | m_should_stop = false; |
| 601 | } |
| 602 | else |
| 603 | m_should_stop = true; |
| 604 | if (log) |
| 605 | log->Printf("Condition successfully evaluated, result is %s.\n", |
| 606 | m_should_stop ? "true" : "false"); |
| 607 | } |
| 608 | else |
| 609 | { |
| 610 | m_should_stop = true; |
| 611 | if (log) |
| 612 | log->Printf("Failed to get an integer result from the expression."); |
| 613 | } |
| 614 | } |
| 615 | } |
| 616 | else |
| 617 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 618 | Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger(); |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 619 | StreamSP error_sp = debugger.GetAsyncErrorStream (); |
Johnny Chen | 5f3bf63 | 2012-01-24 23:19:25 +0000 | [diff] [blame] | 620 | error_sp->Printf ("Stopped due to an error evaluating condition of watchpoint "); |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 621 | wp_sp->GetDescription (error_sp.get(), eDescriptionLevelBrief); |
| 622 | error_sp->Printf (": \"%s\"", |
| 623 | wp_sp->GetConditionText()); |
| 624 | error_sp->EOL(); |
| 625 | const char *err_str = error.AsCString("<Unknown Error>"); |
| 626 | if (log) |
| 627 | log->Printf("Error evaluating condition: \"%s\"\n", err_str); |
| 628 | |
| 629 | error_sp->PutCString (err_str); |
| 630 | error_sp->EOL(); |
| 631 | error_sp->Flush(); |
| 632 | // If the condition fails to be parsed or run, we should stop. |
| 633 | m_should_stop = true; |
| 634 | } |
| 635 | } |
Johnny Chen | 1320641 | 2012-08-09 23:10:57 +0000 | [diff] [blame] | 636 | |
| 637 | // If the condition says to stop, we run the callback to further decide whether to stop. |
| 638 | if (m_should_stop) |
| 639 | { |
Johnny Chen | 209bd65 | 2012-08-13 21:09:54 +0000 | [diff] [blame] | 640 | StoppointCallbackContext context (event_ptr, exe_ctx, false); |
Johnny Chen | 1320641 | 2012-08-09 23:10:57 +0000 | [diff] [blame] | 641 | bool stop_requested = wp_sp->InvokeCallback (&context); |
| 642 | // Also make sure that the callback hasn't continued the target. |
| 643 | // If it did, when we'll set m_should_stop to false and get out of here. |
| 644 | if (HasTargetRunSinceMe ()) |
| 645 | m_should_stop = false; |
| 646 | |
| 647 | if (m_should_stop && !stop_requested) |
| 648 | { |
| 649 | // We have been vetoed by the callback mechanism. |
| 650 | m_should_stop = false; |
| 651 | } |
| 652 | } |
Jim Ingham | a7dfb66 | 2012-10-23 07:20:06 +0000 | [diff] [blame] | 653 | // Finally, if we are going to stop, print out the new & old values: |
| 654 | if (m_should_stop) |
| 655 | { |
| 656 | wp_sp->CaptureWatchedValue(exe_ctx); |
| 657 | |
| 658 | Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger(); |
| 659 | StreamSP output_sp = debugger.GetAsyncOutputStream (); |
| 660 | wp_sp->DumpSnapshots(output_sp.get()); |
| 661 | output_sp->EOL(); |
| 662 | output_sp->Flush(); |
| 663 | } |
| 664 | |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 665 | } |
| 666 | else |
| 667 | { |
Jason Molenda | ccd41e5 | 2012-10-04 22:47:07 +0000 | [diff] [blame] | 668 | LogSP log_process(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 669 | |
Jason Molenda | ccd41e5 | 2012-10-04 22:47:07 +0000 | [diff] [blame] | 670 | if (log_process) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 671 | log_process->Printf ("Process::%s could not find watchpoint id: %" PRId64 "...", __FUNCTION__, m_value); |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 672 | } |
| 673 | if (log) |
| 674 | 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] | 675 | |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 676 | } |
| 677 | |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 678 | private: |
| 679 | std::string m_description; |
Johnny Chen | fd158f4 | 2011-09-21 22:47:15 +0000 | [diff] [blame] | 680 | bool m_should_stop; |
| 681 | bool m_should_stop_is_valid; |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 682 | }; |
| 683 | |
| 684 | |
| 685 | |
| 686 | //---------------------------------------------------------------------- |
| 687 | // StopInfoUnixSignal |
| 688 | //---------------------------------------------------------------------- |
| 689 | |
| 690 | class StopInfoUnixSignal : public StopInfo |
| 691 | { |
| 692 | public: |
| 693 | |
| 694 | StopInfoUnixSignal (Thread &thread, int signo) : |
Greg Clayton | a658fd2 | 2011-06-04 01:26:29 +0000 | [diff] [blame] | 695 | StopInfo (thread, signo) |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 696 | { |
| 697 | } |
| 698 | |
| 699 | virtual ~StopInfoUnixSignal () |
| 700 | { |
| 701 | } |
| 702 | |
| 703 | |
| 704 | virtual StopReason |
| 705 | GetStopReason () const |
| 706 | { |
| 707 | return eStopReasonSignal; |
| 708 | } |
| 709 | |
| 710 | virtual bool |
| 711 | ShouldStop (Event *event_ptr) |
| 712 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 713 | return m_thread.GetProcess()->GetUnixSignals().GetShouldStop (m_value); |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | |
| 717 | // If should stop returns false, check if we should notify of this event |
| 718 | virtual bool |
| 719 | ShouldNotify (Event *event_ptr) |
| 720 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 721 | return m_thread.GetProcess()->GetUnixSignals().GetShouldNotify (m_value); |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | |
| 725 | virtual void |
| 726 | WillResume (lldb::StateType resume_state) |
| 727 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 728 | if (m_thread.GetProcess()->GetUnixSignals().GetShouldSuppress(m_value) == false) |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 729 | m_thread.SetResumeSignal(m_value); |
| 730 | } |
| 731 | |
| 732 | virtual const char * |
| 733 | GetDescription () |
| 734 | { |
| 735 | if (m_description.empty()) |
| 736 | { |
| 737 | StreamString strm; |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 738 | const char *signal_name = m_thread.GetProcess()->GetUnixSignals().GetSignalAsCString (m_value); |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 739 | if (signal_name) |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 740 | strm.Printf("signal %s", signal_name); |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 741 | else |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 742 | strm.Printf("signal %" PRIi64, m_value); |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 743 | m_description.swap (strm.GetString()); |
| 744 | } |
| 745 | return m_description.c_str(); |
| 746 | } |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 747 | }; |
| 748 | |
| 749 | //---------------------------------------------------------------------- |
| 750 | // StopInfoTrace |
| 751 | //---------------------------------------------------------------------- |
| 752 | |
| 753 | class StopInfoTrace : public StopInfo |
| 754 | { |
| 755 | public: |
| 756 | |
| 757 | StopInfoTrace (Thread &thread) : |
| 758 | StopInfo (thread, LLDB_INVALID_UID) |
| 759 | { |
| 760 | } |
| 761 | |
| 762 | virtual ~StopInfoTrace () |
| 763 | { |
| 764 | } |
| 765 | |
| 766 | virtual StopReason |
| 767 | GetStopReason () const |
| 768 | { |
| 769 | return eStopReasonTrace; |
| 770 | } |
| 771 | |
| 772 | virtual const char * |
| 773 | GetDescription () |
| 774 | { |
Greg Clayton | a658fd2 | 2011-06-04 01:26:29 +0000 | [diff] [blame] | 775 | if (m_description.empty()) |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 776 | return "trace"; |
Greg Clayton | a658fd2 | 2011-06-04 01:26:29 +0000 | [diff] [blame] | 777 | else |
| 778 | return m_description.c_str(); |
| 779 | } |
| 780 | }; |
| 781 | |
| 782 | |
| 783 | //---------------------------------------------------------------------- |
| 784 | // StopInfoException |
| 785 | //---------------------------------------------------------------------- |
| 786 | |
| 787 | class StopInfoException : public StopInfo |
| 788 | { |
| 789 | public: |
| 790 | |
| 791 | StopInfoException (Thread &thread, const char *description) : |
| 792 | StopInfo (thread, LLDB_INVALID_UID) |
| 793 | { |
| 794 | if (description) |
| 795 | SetDescription (description); |
| 796 | } |
| 797 | |
| 798 | virtual |
| 799 | ~StopInfoException () |
| 800 | { |
| 801 | } |
| 802 | |
| 803 | virtual StopReason |
| 804 | GetStopReason () const |
| 805 | { |
| 806 | return eStopReasonException; |
| 807 | } |
| 808 | |
| 809 | virtual const char * |
| 810 | GetDescription () |
| 811 | { |
| 812 | if (m_description.empty()) |
| 813 | return "exception"; |
| 814 | else |
| 815 | return m_description.c_str(); |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 816 | } |
| 817 | }; |
| 818 | |
| 819 | |
| 820 | //---------------------------------------------------------------------- |
| 821 | // StopInfoThreadPlan |
| 822 | //---------------------------------------------------------------------- |
| 823 | |
| 824 | class StopInfoThreadPlan : public StopInfo |
| 825 | { |
| 826 | public: |
| 827 | |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 828 | StopInfoThreadPlan (ThreadPlanSP &plan_sp, ValueObjectSP &return_valobj_sp) : |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 829 | StopInfo (plan_sp->GetThread(), LLDB_INVALID_UID), |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 830 | m_plan_sp (plan_sp), |
| 831 | m_return_valobj_sp (return_valobj_sp) |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 832 | { |
| 833 | } |
| 834 | |
| 835 | virtual ~StopInfoThreadPlan () |
| 836 | { |
| 837 | } |
| 838 | |
| 839 | virtual StopReason |
| 840 | GetStopReason () const |
| 841 | { |
| 842 | return eStopReasonPlanComplete; |
| 843 | } |
| 844 | |
| 845 | virtual const char * |
| 846 | GetDescription () |
| 847 | { |
| 848 | if (m_description.empty()) |
| 849 | { |
| 850 | StreamString strm; |
| 851 | m_plan_sp->GetDescription (&strm, eDescriptionLevelBrief); |
| 852 | m_description.swap (strm.GetString()); |
| 853 | } |
| 854 | return m_description.c_str(); |
| 855 | } |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 856 | |
| 857 | ValueObjectSP |
| 858 | GetReturnValueObject() |
| 859 | { |
| 860 | return m_return_valobj_sp; |
| 861 | } |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 862 | |
| 863 | private: |
| 864 | ThreadPlanSP m_plan_sp; |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 865 | ValueObjectSP m_return_valobj_sp; |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 866 | }; |
Greg Clayton | 90ba811 | 2012-12-05 00:16:59 +0000 | [diff] [blame] | 867 | |
| 868 | class StopInfoExec : public StopInfo |
| 869 | { |
| 870 | public: |
| 871 | |
| 872 | StopInfoExec (Thread &thread) : |
| 873 | StopInfo (thread, LLDB_INVALID_UID), |
| 874 | m_performed_action (false) |
| 875 | { |
| 876 | } |
| 877 | |
| 878 | virtual |
| 879 | ~StopInfoExec () |
| 880 | { |
| 881 | } |
| 882 | |
| 883 | virtual StopReason |
| 884 | GetStopReason () const |
| 885 | { |
| 886 | return eStopReasonExec; |
| 887 | } |
| 888 | |
| 889 | virtual const char * |
| 890 | GetDescription () |
| 891 | { |
| 892 | return "exec"; |
| 893 | } |
| 894 | protected: |
| 895 | protected: |
| 896 | |
| 897 | virtual void |
| 898 | PerformAction (Event *event_ptr) |
| 899 | { |
| 900 | // Only perform the action once |
| 901 | if (m_performed_action) |
| 902 | return; |
| 903 | m_performed_action = true; |
| 904 | m_thread.GetProcess()->DidExec(); |
| 905 | } |
| 906 | |
| 907 | bool m_performed_action; |
| 908 | }; |
| 909 | |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 910 | } // namespace lldb_private |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 911 | |
| 912 | StopInfoSP |
| 913 | StopInfo::CreateStopReasonWithBreakpointSiteID (Thread &thread, break_id_t break_id) |
| 914 | { |
| 915 | return StopInfoSP (new StopInfoBreakpoint (thread, break_id)); |
| 916 | } |
| 917 | |
| 918 | StopInfoSP |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 919 | StopInfo::CreateStopReasonWithBreakpointSiteID (Thread &thread, break_id_t break_id, bool should_stop) |
| 920 | { |
| 921 | return StopInfoSP (new StopInfoBreakpoint (thread, break_id, should_stop)); |
| 922 | } |
| 923 | |
| 924 | StopInfoSP |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 925 | StopInfo::CreateStopReasonWithWatchpointID (Thread &thread, break_id_t watch_id) |
| 926 | { |
| 927 | return StopInfoSP (new StopInfoWatchpoint (thread, watch_id)); |
| 928 | } |
| 929 | |
| 930 | StopInfoSP |
| 931 | StopInfo::CreateStopReasonWithSignal (Thread &thread, int signo) |
| 932 | { |
| 933 | return StopInfoSP (new StopInfoUnixSignal (thread, signo)); |
| 934 | } |
| 935 | |
| 936 | StopInfoSP |
| 937 | StopInfo::CreateStopReasonToTrace (Thread &thread) |
| 938 | { |
| 939 | return StopInfoSP (new StopInfoTrace (thread)); |
| 940 | } |
| 941 | |
| 942 | StopInfoSP |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 943 | StopInfo::CreateStopReasonWithPlan (ThreadPlanSP &plan_sp, ValueObjectSP return_valobj_sp) |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 944 | { |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 945 | return StopInfoSP (new StopInfoThreadPlan (plan_sp, return_valobj_sp)); |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 946 | } |
Greg Clayton | a658fd2 | 2011-06-04 01:26:29 +0000 | [diff] [blame] | 947 | |
| 948 | StopInfoSP |
| 949 | StopInfo::CreateStopReasonWithException (Thread &thread, const char *description) |
| 950 | { |
| 951 | return StopInfoSP (new StopInfoException (thread, description)); |
| 952 | } |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 953 | |
Greg Clayton | 90ba811 | 2012-12-05 00:16:59 +0000 | [diff] [blame] | 954 | StopInfoSP |
| 955 | StopInfo::CreateStopReasonWithExec (Thread &thread) |
| 956 | { |
| 957 | return StopInfoSP (new StopInfoExec (thread)); |
| 958 | } |
| 959 | |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 960 | ValueObjectSP |
| 961 | StopInfo::GetReturnValueObject(StopInfoSP &stop_info_sp) |
| 962 | { |
| 963 | if (stop_info_sp && stop_info_sp->GetStopReason() == eStopReasonPlanComplete) |
| 964 | { |
| 965 | StopInfoThreadPlan *plan_stop_info = static_cast<StopInfoThreadPlan *>(stop_info_sp.get()); |
| 966 | return plan_stop_info->GetReturnValueObject(); |
| 967 | } |
| 968 | else |
| 969 | return ValueObjectSP(); |
| 970 | } |