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