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