blob: 54c1049f98f9e5bb5a21645f0aa57ce7543a7f81 [file] [log] [blame]
Greg Claytonf4b47e12010-08-04 01:40:35 +00001//===-- StopInfo.cpp ---------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Daniel Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Greg Claytonf4b47e12010-08-04 01:40:35 +000012#include "lldb/Target/StopInfo.h"
13
14// C Includes
15// C++ Includes
16#include <string>
17
18// Other libraries and framework includes
19// Project includes
20#include "lldb/Core/Log.h"
Greg Clayton4e78f602010-11-18 18:52:36 +000021#include "lldb/Breakpoint/Breakpoint.h"
Greg Claytonf4b47e12010-08-04 01:40:35 +000022#include "lldb/Breakpoint/BreakpointLocation.h"
23#include "lldb/Breakpoint/StoppointCallbackContext.h"
Johnny Chen01a67862011-10-14 00:42:25 +000024#include "lldb/Breakpoint/Watchpoint.h"
Jim Ingham4b536182011-08-09 02:12:22 +000025#include "lldb/Core/Debugger.h"
Greg Claytonf4b47e12010-08-04 01:40:35 +000026#include "lldb/Core/StreamString.h"
Jim Ingham4b536182011-08-09 02:12:22 +000027#include "lldb/Expression/ClangUserExpression.h"
28#include "lldb/Target/Target.h"
Greg Claytonf4b47e12010-08-04 01:40:35 +000029#include "lldb/Target/Thread.h"
30#include "lldb/Target/ThreadPlan.h"
31#include "lldb/Target/Process.h"
32#include "lldb/Target/UnixSignals.h"
33
34using namespace lldb;
35using namespace lldb_private;
36
37StopInfo::StopInfo (Thread &thread, uint64_t value) :
38 m_thread (thread),
Greg Clayton1ac04c32012-02-21 00:09:25 +000039 m_stop_id (thread.GetProcess()->GetStopID()),
40 m_resume_id (thread.GetProcess()->GetResumeID()),
Jim Ingham0161b492013-02-09 01:29:05 +000041 m_value (value),
42 m_override_set(false),
43 m_override_value(true)
Greg Claytonf4b47e12010-08-04 01:40:35 +000044{
45}
46
47bool
48StopInfo::IsValid () const
49{
Greg Clayton1ac04c32012-02-21 00:09:25 +000050 return m_thread.GetProcess()->GetStopID() == m_stop_id;
Greg Claytonf4b47e12010-08-04 01:40:35 +000051}
52
Jim Ingham77787032011-01-20 02:03:18 +000053void
54StopInfo::MakeStopInfoValid ()
55{
Greg Clayton1ac04c32012-02-21 00:09:25 +000056 m_stop_id = m_thread.GetProcess()->GetStopID();
57 m_resume_id = m_thread.GetProcess()->GetResumeID();
Jim Ingham77787032011-01-20 02:03:18 +000058}
59
Jim Ingham0faa43f2011-11-08 03:00:11 +000060bool
61StopInfo::HasTargetRunSinceMe ()
Jim Ingham4b536182011-08-09 02:12:22 +000062{
Greg Clayton1ac04c32012-02-21 00:09:25 +000063 lldb::StateType ret_type = m_thread.GetProcess()->GetPrivateState();
Jim Ingham0faa43f2011-11-08 03:00:11 +000064 if (ret_type == eStateRunning)
65 {
66 return true;
67 }
68 else if (ret_type == eStateStopped)
69 {
70 // This is a little tricky. We want to count "run and stopped again before you could
71 // ask this question as a "TRUE" answer to HasTargetRunSinceMe. But we don't want to
72 // include any running of the target done for expressions. So we track both resumes,
73 // and resumes caused by expressions, and check if there are any resumes NOT caused
74 // by expressions.
75
Greg Clayton1ac04c32012-02-21 00:09:25 +000076 uint32_t curr_resume_id = m_thread.GetProcess()->GetResumeID();
77 uint32_t last_user_expression_id = m_thread.GetProcess()->GetLastUserExpressionResumeID ();
Jim Ingham0faa43f2011-11-08 03:00:11 +000078 if (curr_resume_id == m_resume_id)
79 {
80 return false;
81 }
82 else if (curr_resume_id > last_user_expression_id)
83 {
84 return true;
85 }
86 }
87 return false;
Jim Ingham4b536182011-08-09 02:12:22 +000088}
89
Greg Claytonf4b47e12010-08-04 01:40:35 +000090//----------------------------------------------------------------------
91// StopInfoBreakpoint
92//----------------------------------------------------------------------
93
Jim Ingham4b536182011-08-09 02:12:22 +000094namespace lldb_private
95{
Greg Claytonf4b47e12010-08-04 01:40:35 +000096class StopInfoBreakpoint : public StopInfo
97{
98public:
99
100 StopInfoBreakpoint (Thread &thread, break_id_t break_id) :
101 StopInfo (thread, break_id),
102 m_description(),
103 m_should_stop (false),
Jim Ingham0f16e732011-02-08 05:20:59 +0000104 m_should_stop_is_valid (false),
Jim Ingham52c7d202011-10-28 01:12:19 +0000105 m_should_perform_action (true),
Jim Inghamca36cd12012-10-05 19:16:31 +0000106 m_address (LLDB_INVALID_ADDRESS),
107 m_break_id(LLDB_INVALID_BREAK_ID),
108 m_was_one_shot (false)
Greg Claytonf4b47e12010-08-04 01:40:35 +0000109 {
Jim Inghamca36cd12012-10-05 19:16:31 +0000110 StoreBPInfo();
Greg Claytonf4b47e12010-08-04 01:40:35 +0000111 }
112
Jim Ingham36f3b362010-10-14 23:45:03 +0000113 StopInfoBreakpoint (Thread &thread, break_id_t break_id, bool should_stop) :
114 StopInfo (thread, break_id),
115 m_description(),
116 m_should_stop (should_stop),
Jim Ingham0f16e732011-02-08 05:20:59 +0000117 m_should_stop_is_valid (true),
Jim Ingham52c7d202011-10-28 01:12:19 +0000118 m_should_perform_action (true),
Jim Inghamca36cd12012-10-05 19:16:31 +0000119 m_address (LLDB_INVALID_ADDRESS),
120 m_break_id(LLDB_INVALID_BREAK_ID),
121 m_was_one_shot (false)
122 {
123 StoreBPInfo();
124 }
125
126 void StoreBPInfo ()
Jim Ingham36f3b362010-10-14 23:45:03 +0000127 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000128 BreakpointSiteSP bp_site_sp (m_thread.GetProcess()->GetBreakpointSiteList().FindByID (m_value));
Jim Ingham52c7d202011-10-28 01:12:19 +0000129 if (bp_site_sp)
130 {
Jim Inghamca36cd12012-10-05 19:16:31 +0000131 if (bp_site_sp->GetNumberOfOwners() == 1)
132 {
133 BreakpointLocationSP bp_loc_sp = bp_site_sp->GetOwnerAtIndex(0);
134 if (bp_loc_sp)
135 {
136 m_break_id = bp_loc_sp->GetBreakpoint().GetID();
137 m_was_one_shot = bp_loc_sp->GetBreakpoint().IsOneShot();
138 }
139 }
140 m_address = bp_site_sp->GetLoadAddress();
Jim Ingham52c7d202011-10-28 01:12:19 +0000141 }
Jim Ingham36f3b362010-10-14 23:45:03 +0000142 }
143
Greg Claytonf4b47e12010-08-04 01:40:35 +0000144 virtual ~StopInfoBreakpoint ()
145 {
146 }
147
148 virtual StopReason
149 GetStopReason () const
150 {
151 return eStopReasonBreakpoint;
152 }
153
154 virtual bool
Jim Ingham6d66ce62012-04-20 21:16:56 +0000155 ShouldStopSynchronous (Event *event_ptr)
Greg Claytonf4b47e12010-08-04 01:40:35 +0000156 {
157 if (!m_should_stop_is_valid)
158 {
159 // Only check once if we should stop at a breakpoint
Greg Clayton1ac04c32012-02-21 00:09:25 +0000160 BreakpointSiteSP bp_site_sp (m_thread.GetProcess()->GetBreakpointSiteList().FindByID (m_value));
Greg Claytonf4b47e12010-08-04 01:40:35 +0000161 if (bp_site_sp)
162 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000163 ExecutionContext exe_ctx (m_thread.GetStackFrameAtIndex(0));
164 StoppointCallbackContext context (event_ptr, exe_ctx, true);
Greg Claytonf4b47e12010-08-04 01:40:35 +0000165 m_should_stop = bp_site_sp->ShouldStop (&context);
166 }
167 else
168 {
Greg Clayton5160ce52013-03-27 23:08:40 +0000169 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
Greg Claytonf4b47e12010-08-04 01:40:35 +0000170
171 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +0000172 log->Printf ("Process::%s could not find breakpoint site id: %" PRId64 "...", __FUNCTION__, m_value);
Greg Claytonf4b47e12010-08-04 01:40:35 +0000173
174 m_should_stop = true;
175 }
176 m_should_stop_is_valid = true;
177 }
178 return m_should_stop;
179 }
Jim Ingham3ebcf7f2010-08-10 00:59:59 +0000180
Jim Inghamf57b4352012-11-10 02:08:14 +0000181 virtual bool
182 ShouldNotify (Event *event_ptr)
183 {
184 BreakpointSiteSP bp_site_sp (m_thread.GetProcess()->GetBreakpointSiteList().FindByID (m_value));
185 if (bp_site_sp)
186 {
187 bool all_internal = true;
188
189 for (uint32_t i = 0; i < bp_site_sp->GetNumberOfOwners(); i++)
190 {
191 if (!bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint().IsInternal())
192 {
193 all_internal = false;
194 break;
195 }
196 }
197 return all_internal == false;
198 }
199 return true;
200 }
201
202 virtual const char *
203 GetDescription ()
204 {
205 if (m_description.empty())
206 {
207 BreakpointSiteSP bp_site_sp (m_thread.GetProcess()->GetBreakpointSiteList().FindByID (m_value));
208 if (bp_site_sp)
209 {
210 StreamString strm;
Jim Ingham29950772013-01-26 02:19:28 +0000211 // If we have just hit an internal breakpoint, and it has a kind description, print that instead of the
212 // full breakpoint printing:
213 if (bp_site_sp->IsInternal())
214 {
215 size_t num_owners = bp_site_sp->GetNumberOfOwners();
216 for (size_t idx = 0; idx < num_owners; idx++)
217 {
218 const char *kind = bp_site_sp->GetOwnerAtIndex(idx)->GetBreakpoint().GetBreakpointKind();
219 if (kind != NULL)
220 {
221 m_description.assign (kind);
222 return kind;
223 }
224 }
225 }
226
Jim Inghamf57b4352012-11-10 02:08:14 +0000227 strm.Printf("breakpoint ");
228 bp_site_sp->GetDescription(&strm, eDescriptionLevelBrief);
229 m_description.swap (strm.GetString());
230 }
231 else
232 {
233 StreamString strm;
234 if (m_break_id != LLDB_INVALID_BREAK_ID)
235 {
Jim Ingham0ac57092013-02-14 03:05:42 +0000236 BreakpointSP break_sp = m_thread.GetProcess()->GetTarget().GetBreakpointByID(m_break_id);
237 if (break_sp)
238 {
239 if (break_sp->IsInternal())
240 {
241 const char *kind = break_sp->GetBreakpointKind();
242 if (kind)
243 strm.Printf ("internal %s breakpoint(%d).", kind, m_break_id);
244 else
245 strm.Printf ("internal breakpoint(%d).", m_break_id);
246 }
247 else
248 {
249 strm.Printf ("breakpoint %d.", m_break_id);
250 }
251 }
Jim Inghamf57b4352012-11-10 02:08:14 +0000252 else
Jim Ingham0ac57092013-02-14 03:05:42 +0000253 {
254 if (m_was_one_shot)
255 strm.Printf ("one-shot breakpoint %d", m_break_id);
256 else
257 strm.Printf ("breakpoint %d which has been deleted.", m_break_id);
258 }
Jim Inghamf57b4352012-11-10 02:08:14 +0000259 }
260 else if (m_address == LLDB_INVALID_ADDRESS)
Daniel Malead01b2952012-11-29 21:49:15 +0000261 strm.Printf("breakpoint site %" PRIi64 " which has been deleted - unknown address", m_value);
Jim Inghamf57b4352012-11-10 02:08:14 +0000262 else
Daniel Malead01b2952012-11-29 21:49:15 +0000263 strm.Printf("breakpoint site %" PRIi64 " which has been deleted - was at 0x%" PRIx64, m_value, m_address);
Jim Inghamf57b4352012-11-10 02:08:14 +0000264
265 m_description.swap (strm.GetString());
266 }
267 }
268 return m_description.c_str();
269 }
270
271protected:
Jim Ingham6d66ce62012-04-20 21:16:56 +0000272 bool
273 ShouldStop (Event *event_ptr)
274 {
275 // This just reports the work done by PerformAction or the synchronous stop. It should
276 // only ever get called after they have had a chance to run.
277 assert (m_should_stop_is_valid);
278 return m_should_stop;
279 }
280
Jim Ingham3ebcf7f2010-08-10 00:59:59 +0000281 virtual void
282 PerformAction (Event *event_ptr)
283 {
Jim Ingham0f16e732011-02-08 05:20:59 +0000284 if (!m_should_perform_action)
285 return;
286 m_should_perform_action = false;
287
Greg Clayton5160ce52013-03-27 23:08:40 +0000288 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS);
Jim Ingham4b536182011-08-09 02:12:22 +0000289
Jim Ingham5cb9a182013-03-28 00:13:30 +0000290 if (!m_thread.IsValid())
291 {
292 // This shouldn't ever happen, but just in case, don't do more harm.
293 log->Printf ("PerformAction got called with an invalid thread.");
294 return;
295 }
296
Greg Clayton1ac04c32012-02-21 00:09:25 +0000297 BreakpointSiteSP bp_site_sp (m_thread.GetProcess()->GetBreakpointSiteList().FindByID (m_value));
Jim Ingham79ea1d82011-12-09 04:17:31 +0000298
Jim Ingham3ebcf7f2010-08-10 00:59:59 +0000299 if (bp_site_sp)
300 {
301 size_t num_owners = bp_site_sp->GetNumberOfOwners();
Jim Ingham79ea1d82011-12-09 04:17:31 +0000302
303 if (num_owners == 0)
Jim Ingham3ebcf7f2010-08-10 00:59:59 +0000304 {
Jim Ingham79ea1d82011-12-09 04:17:31 +0000305 m_should_stop = true;
306 }
307 else
308 {
309 // We go through each location, and test first its condition. If the condition says to stop,
310 // then we run the callback for that location. If that callback says to stop as well, then
311 // we set m_should_stop to true; we are going to stop.
312 // But we still want to give all the breakpoints whose conditions say we are going to stop a
313 // chance to run their callbacks.
314 // Of course if any callback restarts the target by putting "continue" in the callback, then
315 // we're going to restart, without running the rest of the callbacks. And in this case we will
316 // end up not stopping even if another location said we should stop. But that's better than not
317 // running all the callbacks.
318
319 m_should_stop = false;
320
Greg Clayton1ac04c32012-02-21 00:09:25 +0000321 ExecutionContext exe_ctx (m_thread.GetStackFrameAtIndex(0));
Jim Ingham184e9812013-01-15 02:47:48 +0000322 Process *process = exe_ctx.GetProcessPtr();
323 if (process->GetModIDRef().IsLastResumeForUserExpression())
324 {
325 // If we are in the middle of evaluating an expression, don't run asynchronous breakpoint commands or
326 // expressions. That could lead to infinite recursion if the command or condition re-calls the function
327 // with this breakpoint.
328 // TODO: We can keep a list of the breakpoints we've seen while running expressions in the nested
329 // PerformAction calls that can arise when the action runs a function that hits another breakpoint,
330 // and only stop running commands when we see the same breakpoint hit a second time.
331
332 m_should_stop_is_valid = true;
333 if (log)
334 log->Printf ("StopInfoBreakpoint::PerformAction - Hit a breakpoint while running an expression,"
335 " not running commands to avoid recursion.");
336 bool ignoring_breakpoints = process->GetIgnoreBreakpointsInExpressions();
337 if (ignoring_breakpoints)
338 {
339 m_should_stop = false;
340 // Internal breakpoints will always stop.
341 for (size_t j = 0; j < num_owners; j++)
342 {
343 lldb::BreakpointLocationSP bp_loc_sp = bp_site_sp->GetOwnerAtIndex(j);
344 if (bp_loc_sp->GetBreakpoint().IsInternal())
345 {
346 m_should_stop = true;
347 break;
348 }
349 }
350 }
351 else
352 {
353 m_should_stop = true;
354 }
355 if (log)
356 log->Printf ("StopInfoBreakpoint::PerformAction - in expression, continuing: %s.",
357 m_should_stop ? "true" : "false");
358 process->GetTarget().GetDebugger().GetAsyncOutputStream()->Printf("Warning: hit breakpoint while "
359 "running function, skipping commands and conditions to prevent recursion.");
360 return;
361 }
362
Greg Clayton1ac04c32012-02-21 00:09:25 +0000363 StoppointCallbackContext context (event_ptr, exe_ctx, false);
Jim Ingham4b536182011-08-09 02:12:22 +0000364
Jim Ingham4b536182011-08-09 02:12:22 +0000365 for (size_t j = 0; j < num_owners; j++)
366 {
367 lldb::BreakpointLocationSP bp_loc_sp = bp_site_sp->GetOwnerAtIndex(j);
Jim Ingham79ea1d82011-12-09 04:17:31 +0000368
369 // First run the condition for the breakpoint. If that says we should stop, then we'll run
370 // the callback for the breakpoint. If the callback says we shouldn't stop that will win.
371
372 bool condition_says_stop = true;
Jim Ingham4b536182011-08-09 02:12:22 +0000373 if (bp_loc_sp->GetConditionText() != NULL)
374 {
375 // We need to make sure the user sees any parse errors in their condition, so we'll hook the
376 // constructor errors up to the debugger's Async I/O.
377
Jim Ingham4b536182011-08-09 02:12:22 +0000378 ValueObjectSP result_valobj_sp;
379
380 ExecutionResults result_code;
381 ValueObjectSP result_value_sp;
Jim Ingham184e9812013-01-15 02:47:48 +0000382 const bool unwind_on_error = true;
383 const bool ignore_breakpoints = true;
Jim Ingham4b536182011-08-09 02:12:22 +0000384 Error error;
Greg Clayton1ac04c32012-02-21 00:09:25 +0000385 result_code = ClangUserExpression::EvaluateWithError (exe_ctx,
Jim Ingham6d66ce62012-04-20 21:16:56 +0000386 eExecutionPolicyOnlyWhenNeeded,
Sean Callananc7b65062011-11-07 23:35:40 +0000387 lldb::eLanguageTypeUnknown,
Sean Callanan20bb3aa2011-12-21 22:22:58 +0000388 ClangUserExpression::eResultTypeAny,
Jim Ingham184e9812013-01-15 02:47:48 +0000389 unwind_on_error,
390 ignore_breakpoints,
Sean Callanan3bfdaa22011-09-15 02:13:07 +0000391 bp_loc_sp->GetConditionText(),
392 NULL,
393 result_value_sp,
Greg Clayton26ab83d2012-10-31 20:49:04 +0000394 error,
395 true,
396 ClangUserExpression::kDefaultTimeout);
Jim Ingham4b536182011-08-09 02:12:22 +0000397 if (result_code == eExecutionCompleted)
398 {
399 if (result_value_sp)
400 {
401 Scalar scalar_value;
402 if (result_value_sp->ResolveValue (scalar_value))
403 {
404 if (scalar_value.ULongLong(1) == 0)
Jim Ingham79ea1d82011-12-09 04:17:31 +0000405 condition_says_stop = false;
Jim Ingham4b536182011-08-09 02:12:22 +0000406 else
Jim Ingham79ea1d82011-12-09 04:17:31 +0000407 condition_says_stop = true;
Jim Ingham4b536182011-08-09 02:12:22 +0000408 if (log)
409 log->Printf("Condition successfully evaluated, result is %s.\n",
410 m_should_stop ? "true" : "false");
411 }
412 else
413 {
Jim Ingham79ea1d82011-12-09 04:17:31 +0000414 condition_says_stop = true;
Jim Ingham4b536182011-08-09 02:12:22 +0000415 if (log)
416 log->Printf("Failed to get an integer result from the expression.");
417 }
418 }
419 }
420 else
421 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000422 Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger();
Jim Ingham4b536182011-08-09 02:12:22 +0000423 StreamSP error_sp = debugger.GetAsyncErrorStream ();
424 error_sp->Printf ("Stopped due to an error evaluating condition of breakpoint ");
425 bp_loc_sp->GetDescription (error_sp.get(), eDescriptionLevelBrief);
426 error_sp->Printf (": \"%s\"",
427 bp_loc_sp->GetConditionText());
428 error_sp->EOL();
429 const char *err_str = error.AsCString("<Unknown Error>");
430 if (log)
431 log->Printf("Error evaluating condition: \"%s\"\n", err_str);
432
433 error_sp->PutCString (err_str);
434 error_sp->EOL();
435 error_sp->Flush();
436 // If the condition fails to be parsed or run, we should stop.
Jim Ingham79ea1d82011-12-09 04:17:31 +0000437 condition_says_stop = true;
Jim Ingham4b536182011-08-09 02:12:22 +0000438 }
439 }
440
Jim Ingham79ea1d82011-12-09 04:17:31 +0000441 // If this location's condition says we should aren't going to stop,
442 // then don't run the callback for this location.
443 if (!condition_says_stop)
444 continue;
445
446 bool callback_says_stop;
447
448 // FIXME: For now the callbacks have to run in async mode - the first time we restart we need
449 // to get out of there. So set it here.
450 // When we figure out how to nest breakpoint hits then this will change.
451
Greg Clayton1ac04c32012-02-21 00:09:25 +0000452 Debugger &debugger = m_thread.CalculateTarget()->GetDebugger();
Jim Ingham79ea1d82011-12-09 04:17:31 +0000453 bool old_async = debugger.GetAsyncExecution();
454 debugger.SetAsyncExecution (true);
455
456 callback_says_stop = bp_loc_sp->InvokeCallback (&context);
457
458 debugger.SetAsyncExecution (old_async);
459
460 if (callback_says_stop)
461 m_should_stop = true;
Jim Inghamca36cd12012-10-05 19:16:31 +0000462
463 // If we are going to stop for this breakpoint, then remove the breakpoint.
464 if (callback_says_stop && bp_loc_sp && bp_loc_sp->GetBreakpoint().IsOneShot())
465 {
466 m_thread.GetProcess()->GetTarget().RemoveBreakpointByID (bp_loc_sp->GetBreakpoint().GetID());
467 }
Jim Ingham79ea1d82011-12-09 04:17:31 +0000468
469 // Also make sure that the callback hasn't continued the target.
470 // If it did, when we'll set m_should_start to false and get out of here.
471 if (HasTargetRunSinceMe ())
472 {
473 m_should_stop = false;
Jim Ingham4b536182011-08-09 02:12:22 +0000474 break;
Jim Ingham79ea1d82011-12-09 04:17:31 +0000475 }
Jim Ingham4b536182011-08-09 02:12:22 +0000476 }
Jim Ingham3ebcf7f2010-08-10 00:59:59 +0000477 }
Jim Ingham79ea1d82011-12-09 04:17:31 +0000478 // We've figured out what this stop wants to do, so mark it as valid so we don't compute it again.
479 m_should_stop_is_valid = true;
480
Jim Ingham3ebcf7f2010-08-10 00:59:59 +0000481 }
482 else
483 {
Jim Ingham79ea1d82011-12-09 04:17:31 +0000484 m_should_stop = true;
485 m_should_stop_is_valid = true;
Greg Clayton5160ce52013-03-27 23:08:40 +0000486 Log * log_process(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
Jim Ingham3ebcf7f2010-08-10 00:59:59 +0000487
Jason Molendaccd41e52012-10-04 22:47:07 +0000488 if (log_process)
Daniel Malead01b2952012-11-29 21:49:15 +0000489 log_process->Printf ("Process::%s could not find breakpoint site id: %" PRId64 "...", __FUNCTION__, m_value);
Jim Ingham3ebcf7f2010-08-10 00:59:59 +0000490 }
Jim Ingham4b536182011-08-09 02:12:22 +0000491 if (log)
492 log->Printf ("Process::%s returning from action with m_should_stop: %d.", __FUNCTION__, m_should_stop);
Jim Ingham3ebcf7f2010-08-10 00:59:59 +0000493 }
Greg Claytonf4b47e12010-08-04 01:40:35 +0000494
495private:
496 std::string m_description;
497 bool m_should_stop;
498 bool m_should_stop_is_valid;
Jim Ingham0f16e732011-02-08 05:20:59 +0000499 bool m_should_perform_action; // Since we are trying to preserve the "state" of the system even if we run functions
500 // etc. behind the users backs, we need to make sure we only REALLY perform the action once.
Jim Ingham52c7d202011-10-28 01:12:19 +0000501 lldb::addr_t m_address; // We use this to capture the breakpoint site address when we create the StopInfo,
502 // in case somebody deletes it between the time the StopInfo is made and the
503 // description is asked for.
Jim Inghamca36cd12012-10-05 19:16:31 +0000504 lldb::break_id_t m_break_id;
505 bool m_was_one_shot;
Greg Claytonf4b47e12010-08-04 01:40:35 +0000506};
507
508
509//----------------------------------------------------------------------
510// StopInfoWatchpoint
511//----------------------------------------------------------------------
512
513class StopInfoWatchpoint : public StopInfo
514{
515public:
Jim Inghamf57b4352012-11-10 02:08:14 +0000516 // Make sure watchpoint is properly disabled and subsequently enabled while performing watchpoint actions.
517 class WatchpointSentry {
518 public:
519 WatchpointSentry(Process *p, Watchpoint *w):
520 process(p),
521 watchpoint(w)
522 {
523 if (process && watchpoint)
524 {
Jim Ingham1b5792e2012-12-18 02:03:49 +0000525 const bool notify = false;
Jim Inghamf57b4352012-11-10 02:08:14 +0000526 watchpoint->TurnOnEphemeralMode();
Jim Ingham1b5792e2012-12-18 02:03:49 +0000527 process->DisableWatchpoint(watchpoint, notify);
Jim Inghamf57b4352012-11-10 02:08:14 +0000528 }
529 }
530 ~WatchpointSentry()
531 {
532 if (process && watchpoint)
533 {
534 if (!watchpoint->IsDisabledDuringEphemeralMode())
Jim Ingham1b5792e2012-12-18 02:03:49 +0000535 {
536 const bool notify = false;
537 process->EnableWatchpoint(watchpoint, notify);
538 }
Jim Inghamf57b4352012-11-10 02:08:14 +0000539 watchpoint->TurnOffEphemeralMode();
540 }
541 }
542 private:
543 Process *process;
544 Watchpoint *watchpoint;
545 };
Greg Claytonf4b47e12010-08-04 01:40:35 +0000546
547 StopInfoWatchpoint (Thread &thread, break_id_t watch_id) :
Johnny Chenfd158f42011-09-21 22:47:15 +0000548 StopInfo(thread, watch_id),
549 m_description(),
550 m_should_stop(false),
551 m_should_stop_is_valid(false)
Greg Claytonf4b47e12010-08-04 01:40:35 +0000552 {
553 }
554
555 virtual ~StopInfoWatchpoint ()
556 {
557 }
558
559 virtual StopReason
560 GetStopReason () const
561 {
562 return eStopReasonWatchpoint;
563 }
564
Jim Inghamf57b4352012-11-10 02:08:14 +0000565 virtual const char *
566 GetDescription ()
567 {
568 if (m_description.empty())
569 {
570 StreamString strm;
Daniel Malead01b2952012-11-29 21:49:15 +0000571 strm.Printf("watchpoint %" PRIi64, m_value);
Jim Inghamf57b4352012-11-10 02:08:14 +0000572 m_description.swap (strm.GetString());
573 }
574 return m_description.c_str();
575 }
576
577protected:
Johnny Chenfd158f42011-09-21 22:47:15 +0000578 virtual bool
Jim Ingham9b620f32013-02-22 21:23:43 +0000579 ShouldStopSynchronous (Event *event_ptr)
Johnny Chenfd158f42011-09-21 22:47:15 +0000580 {
581 // ShouldStop() method is idempotent and should not affect hit count.
Johnny Chen16dcf712011-10-17 18:58:00 +0000582 // See Process::RunPrivateStateThread()->Process()->HandlePrivateEvent()
583 // -->Process()::ShouldBroadcastEvent()->ThreadList::ShouldStop()->
584 // Thread::ShouldStop()->ThreadPlanBase::ShouldStop()->
585 // StopInfoWatchpoint::ShouldStop() and
586 // Event::DoOnRemoval()->Process::ProcessEventData::DoOnRemoval()->
587 // StopInfoWatchpoint::PerformAction().
Johnny Chenfd158f42011-09-21 22:47:15 +0000588 if (m_should_stop_is_valid)
589 return m_should_stop;
590
Johnny Chen01a67862011-10-14 00:42:25 +0000591 WatchpointSP wp_sp =
Greg Clayton1ac04c32012-02-21 00:09:25 +0000592 m_thread.CalculateTarget()->GetWatchpointList().FindByID(GetValue());
Johnny Chen01a67862011-10-14 00:42:25 +0000593 if (wp_sp)
Johnny Chenfd158f42011-09-21 22:47:15 +0000594 {
595 // Check if we should stop at a watchpoint.
Greg Clayton1ac04c32012-02-21 00:09:25 +0000596 ExecutionContext exe_ctx (m_thread.GetStackFrameAtIndex(0));
597 StoppointCallbackContext context (event_ptr, exe_ctx, true);
Johnny Chen01a67862011-10-14 00:42:25 +0000598 m_should_stop = wp_sp->ShouldStop (&context);
Johnny Chenfd158f42011-09-21 22:47:15 +0000599 }
600 else
601 {
Greg Clayton5160ce52013-03-27 23:08:40 +0000602 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
Johnny Chenfd158f42011-09-21 22:47:15 +0000603
604 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +0000605 log->Printf ("Process::%s could not find watchpoint location id: %" PRId64 "...",
Johnny Chenfd158f42011-09-21 22:47:15 +0000606 __FUNCTION__, GetValue());
607
608 m_should_stop = true;
609 }
610 m_should_stop_is_valid = true;
611 return m_should_stop;
612 }
613
Jim Ingham9b620f32013-02-22 21:23:43 +0000614 bool
615 ShouldStop (Event *event_ptr)
616 {
617 // This just reports the work done by PerformAction or the synchronous stop. It should
618 // only ever get called after they have had a chance to run.
619 assert (m_should_stop_is_valid);
620 return m_should_stop;
621 }
622
Johnny Chen16dcf712011-10-17 18:58:00 +0000623 virtual void
624 PerformAction (Event *event_ptr)
625 {
Greg Clayton5160ce52013-03-27 23:08:40 +0000626 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS);
Johnny Chen16dcf712011-10-17 18:58:00 +0000627 // We're going to calculate if we should stop or not in some way during the course of
628 // this code. Also by default we're going to stop, so set that here.
629 m_should_stop = true;
630
631 WatchpointSP wp_sp =
Greg Clayton1ac04c32012-02-21 00:09:25 +0000632 m_thread.CalculateTarget()->GetWatchpointList().FindByID(GetValue());
Johnny Chen16dcf712011-10-17 18:58:00 +0000633 if (wp_sp)
634 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000635 ExecutionContext exe_ctx (m_thread.GetStackFrameAtIndex(0));
Johnny Chen209bd652012-08-13 21:09:54 +0000636 Process* process = exe_ctx.GetProcessPtr();
Johnny Chen0f7ad8d2012-08-21 22:06:34 +0000637
Johnny Chen66535a32012-08-21 22:15:58 +0000638 // This sentry object makes sure the current watchpoint is disabled while performing watchpoint actions,
639 // and it is then enabled after we are finished.
Johnny Chen0f7ad8d2012-08-21 22:06:34 +0000640 WatchpointSentry sentry(process, wp_sp.get());
641
Enrico Granataf04a2192012-07-13 23:18:48 +0000642 {
643 // check if this process is running on an architecture where watchpoints trigger
644 // before the associated instruction runs. if so, disable the WP, single-step and then
645 // re-enable the watchpoint
Enrico Granataf04a2192012-07-13 23:18:48 +0000646 if (process)
647 {
648 uint32_t num; bool wp_triggers_after;
649 if (process->GetWatchpointSupportInfo(num, wp_triggers_after).Success())
650 {
651 if (!wp_triggers_after)
652 {
Enrico Granataf04a2192012-07-13 23:18:48 +0000653 ThreadPlan *new_plan = m_thread.QueueThreadPlanForStepSingleInstruction(false, // step-over
654 false, // abort_other_plans
655 true); // stop_other_threads
656 new_plan->SetIsMasterPlan (true);
657 new_plan->SetOkayToDiscard (false);
658 process->GetThreadList().SetSelectedThreadByID (m_thread.GetID());
659 process->Resume ();
660 process->WaitForProcessToStop (NULL);
661 process->GetThreadList().SetSelectedThreadByID (m_thread.GetID());
662 MakeStopInfoValid(); // make sure we do not fail to stop because of the single-step taken above
Enrico Granataf04a2192012-07-13 23:18:48 +0000663 }
664 }
665 }
666 }
Johnny Chen209bd652012-08-13 21:09:54 +0000667
Johnny Chen16dcf712011-10-17 18:58:00 +0000668 if (m_should_stop && wp_sp->GetConditionText() != NULL)
669 {
670 // We need to make sure the user sees any parse errors in their condition, so we'll hook the
671 // constructor errors up to the debugger's Async I/O.
Johnny Chen16dcf712011-10-17 18:58:00 +0000672 ExecutionResults result_code;
673 ValueObjectSP result_value_sp;
Jim Ingham184e9812013-01-15 02:47:48 +0000674 const bool unwind_on_error = true;
675 const bool ignore_breakpoints = true;
Johnny Chen16dcf712011-10-17 18:58:00 +0000676 Error error;
Greg Clayton1ac04c32012-02-21 00:09:25 +0000677 result_code = ClangUserExpression::EvaluateWithError (exe_ctx,
Sean Callanan22019052012-09-08 01:51:48 +0000678 eExecutionPolicyOnlyWhenNeeded,
Sean Callananc7b65062011-11-07 23:35:40 +0000679 lldb::eLanguageTypeUnknown,
Sean Callanan20bb3aa2011-12-21 22:22:58 +0000680 ClangUserExpression::eResultTypeAny,
Jim Ingham184e9812013-01-15 02:47:48 +0000681 unwind_on_error,
682 ignore_breakpoints,
Johnny Chen16dcf712011-10-17 18:58:00 +0000683 wp_sp->GetConditionText(),
684 NULL,
685 result_value_sp,
Enrico Granata3372f582012-07-16 23:10:35 +0000686 error,
Greg Clayton26ab83d2012-10-31 20:49:04 +0000687 true,
688 ClangUserExpression::kDefaultTimeout);
Johnny Chen16dcf712011-10-17 18:58:00 +0000689 if (result_code == eExecutionCompleted)
690 {
691 if (result_value_sp)
692 {
693 Scalar scalar_value;
694 if (result_value_sp->ResolveValue (scalar_value))
695 {
696 if (scalar_value.ULongLong(1) == 0)
697 {
698 // We have been vetoed. This takes precedence over querying
699 // the watchpoint whether it should stop (aka ignore count and
700 // friends). See also StopInfoWatchpoint::ShouldStop() as well
701 // as Process::ProcessEventData::DoOnRemoval().
702 m_should_stop = false;
703 }
704 else
705 m_should_stop = true;
706 if (log)
707 log->Printf("Condition successfully evaluated, result is %s.\n",
708 m_should_stop ? "true" : "false");
709 }
710 else
711 {
712 m_should_stop = true;
713 if (log)
714 log->Printf("Failed to get an integer result from the expression.");
715 }
716 }
717 }
718 else
719 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000720 Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger();
Johnny Chen16dcf712011-10-17 18:58:00 +0000721 StreamSP error_sp = debugger.GetAsyncErrorStream ();
Johnny Chen5f3bf632012-01-24 23:19:25 +0000722 error_sp->Printf ("Stopped due to an error evaluating condition of watchpoint ");
Johnny Chen16dcf712011-10-17 18:58:00 +0000723 wp_sp->GetDescription (error_sp.get(), eDescriptionLevelBrief);
724 error_sp->Printf (": \"%s\"",
725 wp_sp->GetConditionText());
726 error_sp->EOL();
727 const char *err_str = error.AsCString("<Unknown Error>");
728 if (log)
729 log->Printf("Error evaluating condition: \"%s\"\n", err_str);
730
731 error_sp->PutCString (err_str);
732 error_sp->EOL();
733 error_sp->Flush();
734 // If the condition fails to be parsed or run, we should stop.
735 m_should_stop = true;
736 }
737 }
Johnny Chen13206412012-08-09 23:10:57 +0000738
739 // If the condition says to stop, we run the callback to further decide whether to stop.
740 if (m_should_stop)
741 {
Johnny Chen209bd652012-08-13 21:09:54 +0000742 StoppointCallbackContext context (event_ptr, exe_ctx, false);
Johnny Chen13206412012-08-09 23:10:57 +0000743 bool stop_requested = wp_sp->InvokeCallback (&context);
744 // Also make sure that the callback hasn't continued the target.
745 // If it did, when we'll set m_should_stop to false and get out of here.
746 if (HasTargetRunSinceMe ())
747 m_should_stop = false;
748
749 if (m_should_stop && !stop_requested)
750 {
751 // We have been vetoed by the callback mechanism.
752 m_should_stop = false;
753 }
754 }
Jim Inghama7dfb662012-10-23 07:20:06 +0000755 // Finally, if we are going to stop, print out the new & old values:
756 if (m_should_stop)
757 {
758 wp_sp->CaptureWatchedValue(exe_ctx);
759
760 Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger();
761 StreamSP output_sp = debugger.GetAsyncOutputStream ();
762 wp_sp->DumpSnapshots(output_sp.get());
763 output_sp->EOL();
764 output_sp->Flush();
765 }
766
Johnny Chen16dcf712011-10-17 18:58:00 +0000767 }
768 else
769 {
Greg Clayton5160ce52013-03-27 23:08:40 +0000770 Log * log_process(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
Johnny Chen16dcf712011-10-17 18:58:00 +0000771
Jason Molendaccd41e52012-10-04 22:47:07 +0000772 if (log_process)
Daniel Malead01b2952012-11-29 21:49:15 +0000773 log_process->Printf ("Process::%s could not find watchpoint id: %" PRId64 "...", __FUNCTION__, m_value);
Johnny Chen16dcf712011-10-17 18:58:00 +0000774 }
775 if (log)
776 log->Printf ("Process::%s returning from action with m_should_stop: %d.", __FUNCTION__, m_should_stop);
Jim Inghama7dfb662012-10-23 07:20:06 +0000777
Jim Ingham9b620f32013-02-22 21:23:43 +0000778 m_should_stop_is_valid = true;
779
Johnny Chen16dcf712011-10-17 18:58:00 +0000780 }
781
Greg Claytonf4b47e12010-08-04 01:40:35 +0000782private:
783 std::string m_description;
Johnny Chenfd158f42011-09-21 22:47:15 +0000784 bool m_should_stop;
785 bool m_should_stop_is_valid;
Greg Claytonf4b47e12010-08-04 01:40:35 +0000786};
787
788
789
790//----------------------------------------------------------------------
791// StopInfoUnixSignal
792//----------------------------------------------------------------------
793
794class StopInfoUnixSignal : public StopInfo
795{
796public:
797
798 StopInfoUnixSignal (Thread &thread, int signo) :
Greg Claytona658fd22011-06-04 01:26:29 +0000799 StopInfo (thread, signo)
Greg Claytonf4b47e12010-08-04 01:40:35 +0000800 {
801 }
802
803 virtual ~StopInfoUnixSignal ()
804 {
805 }
806
807
808 virtual StopReason
809 GetStopReason () const
810 {
811 return eStopReasonSignal;
812 }
813
814 virtual bool
Jim Ingham0161b492013-02-09 01:29:05 +0000815 ShouldStopSynchronous (Event *event_ptr)
816 {
817 return m_thread.GetProcess()->GetUnixSignals().GetShouldStop (m_value);
818 }
819
820 virtual bool
Greg Claytonf4b47e12010-08-04 01:40:35 +0000821 ShouldStop (Event *event_ptr)
822 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000823 return m_thread.GetProcess()->GetUnixSignals().GetShouldStop (m_value);
Greg Claytonf4b47e12010-08-04 01:40:35 +0000824 }
825
826
827 // If should stop returns false, check if we should notify of this event
828 virtual bool
829 ShouldNotify (Event *event_ptr)
830 {
Jim Ingham0161b492013-02-09 01:29:05 +0000831 bool should_notify = m_thread.GetProcess()->GetUnixSignals().GetShouldNotify (m_value);
832 if (should_notify)
833 {
834 StreamString strm;
835 strm.Printf ("thread %d received signal: %s",
836 m_thread.GetIndexID(),
837 m_thread.GetProcess()->GetUnixSignals().GetSignalAsCString (m_value));
838 Process::ProcessEventData::AddRestartedReason(event_ptr, strm.GetData());
839 }
840 return should_notify;
Greg Claytonf4b47e12010-08-04 01:40:35 +0000841 }
842
843
844 virtual void
845 WillResume (lldb::StateType resume_state)
846 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000847 if (m_thread.GetProcess()->GetUnixSignals().GetShouldSuppress(m_value) == false)
Greg Claytonf4b47e12010-08-04 01:40:35 +0000848 m_thread.SetResumeSignal(m_value);
849 }
850
851 virtual const char *
852 GetDescription ()
853 {
854 if (m_description.empty())
855 {
856 StreamString strm;
Greg Clayton1ac04c32012-02-21 00:09:25 +0000857 const char *signal_name = m_thread.GetProcess()->GetUnixSignals().GetSignalAsCString (m_value);
Greg Claytonf4b47e12010-08-04 01:40:35 +0000858 if (signal_name)
Greg Clayton0603aa92010-10-04 01:05:56 +0000859 strm.Printf("signal %s", signal_name);
Greg Claytonf4b47e12010-08-04 01:40:35 +0000860 else
Daniel Malead01b2952012-11-29 21:49:15 +0000861 strm.Printf("signal %" PRIi64, m_value);
Greg Claytonf4b47e12010-08-04 01:40:35 +0000862 m_description.swap (strm.GetString());
863 }
864 return m_description.c_str();
865 }
Greg Claytonf4b47e12010-08-04 01:40:35 +0000866};
867
868//----------------------------------------------------------------------
869// StopInfoTrace
870//----------------------------------------------------------------------
871
872class StopInfoTrace : public StopInfo
873{
874public:
875
876 StopInfoTrace (Thread &thread) :
877 StopInfo (thread, LLDB_INVALID_UID)
878 {
879 }
880
881 virtual ~StopInfoTrace ()
882 {
883 }
884
885 virtual StopReason
886 GetStopReason () const
887 {
888 return eStopReasonTrace;
889 }
890
891 virtual const char *
892 GetDescription ()
893 {
Greg Claytona658fd22011-06-04 01:26:29 +0000894 if (m_description.empty())
Greg Claytonf4b47e12010-08-04 01:40:35 +0000895 return "trace";
Greg Claytona658fd22011-06-04 01:26:29 +0000896 else
897 return m_description.c_str();
898 }
899};
900
901
902//----------------------------------------------------------------------
903// StopInfoException
904//----------------------------------------------------------------------
905
906class StopInfoException : public StopInfo
907{
908public:
909
910 StopInfoException (Thread &thread, const char *description) :
911 StopInfo (thread, LLDB_INVALID_UID)
912 {
913 if (description)
914 SetDescription (description);
915 }
916
917 virtual
918 ~StopInfoException ()
919 {
920 }
921
922 virtual StopReason
923 GetStopReason () const
924 {
925 return eStopReasonException;
926 }
927
928 virtual const char *
929 GetDescription ()
930 {
931 if (m_description.empty())
932 return "exception";
933 else
934 return m_description.c_str();
Greg Claytonf4b47e12010-08-04 01:40:35 +0000935 }
936};
937
938
939//----------------------------------------------------------------------
940// StopInfoThreadPlan
941//----------------------------------------------------------------------
942
943class StopInfoThreadPlan : public StopInfo
944{
945public:
946
Jim Ingham73ca05a2011-12-17 01:35:57 +0000947 StopInfoThreadPlan (ThreadPlanSP &plan_sp, ValueObjectSP &return_valobj_sp) :
Greg Claytonf4b47e12010-08-04 01:40:35 +0000948 StopInfo (plan_sp->GetThread(), LLDB_INVALID_UID),
Jim Ingham73ca05a2011-12-17 01:35:57 +0000949 m_plan_sp (plan_sp),
950 m_return_valobj_sp (return_valobj_sp)
Greg Claytonf4b47e12010-08-04 01:40:35 +0000951 {
952 }
953
954 virtual ~StopInfoThreadPlan ()
955 {
956 }
957
958 virtual StopReason
959 GetStopReason () const
960 {
961 return eStopReasonPlanComplete;
962 }
963
964 virtual const char *
965 GetDescription ()
966 {
967 if (m_description.empty())
968 {
969 StreamString strm;
970 m_plan_sp->GetDescription (&strm, eDescriptionLevelBrief);
971 m_description.swap (strm.GetString());
972 }
973 return m_description.c_str();
974 }
Jim Ingham73ca05a2011-12-17 01:35:57 +0000975
976 ValueObjectSP
977 GetReturnValueObject()
978 {
979 return m_return_valobj_sp;
980 }
Jim Ingham0161b492013-02-09 01:29:05 +0000981
982protected:
983 virtual bool
984 ShouldStop (Event *event_ptr)
985 {
986 if (m_plan_sp)
987 return m_plan_sp->ShouldStop(event_ptr);
988 else
989 return StopInfo::ShouldStop(event_ptr);
990 }
Greg Claytonf4b47e12010-08-04 01:40:35 +0000991
992private:
993 ThreadPlanSP m_plan_sp;
Jim Ingham73ca05a2011-12-17 01:35:57 +0000994 ValueObjectSP m_return_valobj_sp;
Greg Claytonf4b47e12010-08-04 01:40:35 +0000995};
Greg Clayton90ba8112012-12-05 00:16:59 +0000996
997class StopInfoExec : public StopInfo
998{
999public:
1000
1001 StopInfoExec (Thread &thread) :
1002 StopInfo (thread, LLDB_INVALID_UID),
1003 m_performed_action (false)
1004 {
1005 }
1006
1007 virtual
1008 ~StopInfoExec ()
1009 {
1010 }
1011
1012 virtual StopReason
1013 GetStopReason () const
1014 {
1015 return eStopReasonExec;
1016 }
1017
1018 virtual const char *
1019 GetDescription ()
1020 {
1021 return "exec";
1022 }
1023protected:
Greg Clayton90ba8112012-12-05 00:16:59 +00001024
1025 virtual void
1026 PerformAction (Event *event_ptr)
1027 {
1028 // Only perform the action once
1029 if (m_performed_action)
1030 return;
1031 m_performed_action = true;
1032 m_thread.GetProcess()->DidExec();
1033 }
1034
1035 bool m_performed_action;
1036};
1037
Jim Ingham4b536182011-08-09 02:12:22 +00001038} // namespace lldb_private
Greg Claytonf4b47e12010-08-04 01:40:35 +00001039
1040StopInfoSP
1041StopInfo::CreateStopReasonWithBreakpointSiteID (Thread &thread, break_id_t break_id)
1042{
1043 return StopInfoSP (new StopInfoBreakpoint (thread, break_id));
1044}
1045
1046StopInfoSP
Jim Ingham36f3b362010-10-14 23:45:03 +00001047StopInfo::CreateStopReasonWithBreakpointSiteID (Thread &thread, break_id_t break_id, bool should_stop)
1048{
1049 return StopInfoSP (new StopInfoBreakpoint (thread, break_id, should_stop));
1050}
1051
1052StopInfoSP
Greg Claytonf4b47e12010-08-04 01:40:35 +00001053StopInfo::CreateStopReasonWithWatchpointID (Thread &thread, break_id_t watch_id)
1054{
1055 return StopInfoSP (new StopInfoWatchpoint (thread, watch_id));
1056}
1057
1058StopInfoSP
1059StopInfo::CreateStopReasonWithSignal (Thread &thread, int signo)
1060{
1061 return StopInfoSP (new StopInfoUnixSignal (thread, signo));
1062}
1063
1064StopInfoSP
1065StopInfo::CreateStopReasonToTrace (Thread &thread)
1066{
1067 return StopInfoSP (new StopInfoTrace (thread));
1068}
1069
1070StopInfoSP
Jim Ingham73ca05a2011-12-17 01:35:57 +00001071StopInfo::CreateStopReasonWithPlan (ThreadPlanSP &plan_sp, ValueObjectSP return_valobj_sp)
Greg Claytonf4b47e12010-08-04 01:40:35 +00001072{
Jim Ingham73ca05a2011-12-17 01:35:57 +00001073 return StopInfoSP (new StopInfoThreadPlan (plan_sp, return_valobj_sp));
Greg Claytonf4b47e12010-08-04 01:40:35 +00001074}
Greg Claytona658fd22011-06-04 01:26:29 +00001075
1076StopInfoSP
1077StopInfo::CreateStopReasonWithException (Thread &thread, const char *description)
1078{
1079 return StopInfoSP (new StopInfoException (thread, description));
1080}
Jim Ingham73ca05a2011-12-17 01:35:57 +00001081
Greg Clayton90ba8112012-12-05 00:16:59 +00001082StopInfoSP
1083StopInfo::CreateStopReasonWithExec (Thread &thread)
1084{
1085 return StopInfoSP (new StopInfoExec (thread));
1086}
1087
Jim Ingham73ca05a2011-12-17 01:35:57 +00001088ValueObjectSP
1089StopInfo::GetReturnValueObject(StopInfoSP &stop_info_sp)
1090{
1091 if (stop_info_sp && stop_info_sp->GetStopReason() == eStopReasonPlanComplete)
1092 {
1093 StopInfoThreadPlan *plan_stop_info = static_cast<StopInfoThreadPlan *>(stop_info_sp.get());
1094 return plan_stop_info->GetReturnValueObject();
1095 }
1096 else
1097 return ValueObjectSP();
1098}