blob: 3977d620860bdf4335301f15d16eefc996346f81 [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
Greg Clayton1ac04c32012-02-21 00:09:25 +0000290 BreakpointSiteSP bp_site_sp (m_thread.GetProcess()->GetBreakpointSiteList().FindByID (m_value));
Jim Ingham79ea1d82011-12-09 04:17:31 +0000291
Jim Ingham3ebcf7f2010-08-10 00:59:59 +0000292 if (bp_site_sp)
293 {
294 size_t num_owners = bp_site_sp->GetNumberOfOwners();
Jim Ingham79ea1d82011-12-09 04:17:31 +0000295
296 if (num_owners == 0)
Jim Ingham3ebcf7f2010-08-10 00:59:59 +0000297 {
Jim Ingham79ea1d82011-12-09 04:17:31 +0000298 m_should_stop = true;
299 }
300 else
301 {
302 // We go through each location, and test first its condition. If the condition says to stop,
303 // then we run the callback for that location. If that callback says to stop as well, then
304 // we set m_should_stop to true; we are going to stop.
305 // But we still want to give all the breakpoints whose conditions say we are going to stop a
306 // chance to run their callbacks.
307 // Of course if any callback restarts the target by putting "continue" in the callback, then
308 // we're going to restart, without running the rest of the callbacks. And in this case we will
309 // end up not stopping even if another location said we should stop. But that's better than not
310 // running all the callbacks.
311
312 m_should_stop = false;
313
Greg Clayton1ac04c32012-02-21 00:09:25 +0000314 ExecutionContext exe_ctx (m_thread.GetStackFrameAtIndex(0));
Jim Ingham184e9812013-01-15 02:47:48 +0000315 Process *process = exe_ctx.GetProcessPtr();
316 if (process->GetModIDRef().IsLastResumeForUserExpression())
317 {
318 // If we are in the middle of evaluating an expression, don't run asynchronous breakpoint commands or
319 // expressions. That could lead to infinite recursion if the command or condition re-calls the function
320 // with this breakpoint.
321 // TODO: We can keep a list of the breakpoints we've seen while running expressions in the nested
322 // PerformAction calls that can arise when the action runs a function that hits another breakpoint,
323 // and only stop running commands when we see the same breakpoint hit a second time.
324
325 m_should_stop_is_valid = true;
326 if (log)
327 log->Printf ("StopInfoBreakpoint::PerformAction - Hit a breakpoint while running an expression,"
328 " not running commands to avoid recursion.");
329 bool ignoring_breakpoints = process->GetIgnoreBreakpointsInExpressions();
330 if (ignoring_breakpoints)
331 {
332 m_should_stop = false;
333 // Internal breakpoints will always stop.
334 for (size_t j = 0; j < num_owners; j++)
335 {
336 lldb::BreakpointLocationSP bp_loc_sp = bp_site_sp->GetOwnerAtIndex(j);
337 if (bp_loc_sp->GetBreakpoint().IsInternal())
338 {
339 m_should_stop = true;
340 break;
341 }
342 }
343 }
344 else
345 {
346 m_should_stop = true;
347 }
348 if (log)
349 log->Printf ("StopInfoBreakpoint::PerformAction - in expression, continuing: %s.",
350 m_should_stop ? "true" : "false");
351 process->GetTarget().GetDebugger().GetAsyncOutputStream()->Printf("Warning: hit breakpoint while "
352 "running function, skipping commands and conditions to prevent recursion.");
353 return;
354 }
355
Greg Clayton1ac04c32012-02-21 00:09:25 +0000356 StoppointCallbackContext context (event_ptr, exe_ctx, false);
Jim Ingham4b536182011-08-09 02:12:22 +0000357
Jim Ingham4b536182011-08-09 02:12:22 +0000358 for (size_t j = 0; j < num_owners; j++)
359 {
360 lldb::BreakpointLocationSP bp_loc_sp = bp_site_sp->GetOwnerAtIndex(j);
Jim Ingham79ea1d82011-12-09 04:17:31 +0000361
362 // First run the condition for the breakpoint. If that says we should stop, then we'll run
363 // the callback for the breakpoint. If the callback says we shouldn't stop that will win.
364
365 bool condition_says_stop = true;
Jim Ingham4b536182011-08-09 02:12:22 +0000366 if (bp_loc_sp->GetConditionText() != NULL)
367 {
368 // We need to make sure the user sees any parse errors in their condition, so we'll hook the
369 // constructor errors up to the debugger's Async I/O.
370
Jim Ingham4b536182011-08-09 02:12:22 +0000371 ValueObjectSP result_valobj_sp;
372
373 ExecutionResults result_code;
374 ValueObjectSP result_value_sp;
Jim Ingham184e9812013-01-15 02:47:48 +0000375 const bool unwind_on_error = true;
376 const bool ignore_breakpoints = true;
Jim Ingham4b536182011-08-09 02:12:22 +0000377 Error error;
Greg Clayton1ac04c32012-02-21 00:09:25 +0000378 result_code = ClangUserExpression::EvaluateWithError (exe_ctx,
Jim Ingham6d66ce62012-04-20 21:16:56 +0000379 eExecutionPolicyOnlyWhenNeeded,
Sean Callananc7b65062011-11-07 23:35:40 +0000380 lldb::eLanguageTypeUnknown,
Sean Callanan20bb3aa2011-12-21 22:22:58 +0000381 ClangUserExpression::eResultTypeAny,
Jim Ingham184e9812013-01-15 02:47:48 +0000382 unwind_on_error,
383 ignore_breakpoints,
Sean Callanan3bfdaa22011-09-15 02:13:07 +0000384 bp_loc_sp->GetConditionText(),
385 NULL,
386 result_value_sp,
Greg Clayton26ab83d2012-10-31 20:49:04 +0000387 error,
388 true,
389 ClangUserExpression::kDefaultTimeout);
Jim Ingham4b536182011-08-09 02:12:22 +0000390 if (result_code == eExecutionCompleted)
391 {
392 if (result_value_sp)
393 {
394 Scalar scalar_value;
395 if (result_value_sp->ResolveValue (scalar_value))
396 {
397 if (scalar_value.ULongLong(1) == 0)
Jim Ingham79ea1d82011-12-09 04:17:31 +0000398 condition_says_stop = false;
Jim Ingham4b536182011-08-09 02:12:22 +0000399 else
Jim Ingham79ea1d82011-12-09 04:17:31 +0000400 condition_says_stop = true;
Jim Ingham4b536182011-08-09 02:12:22 +0000401 if (log)
402 log->Printf("Condition successfully evaluated, result is %s.\n",
403 m_should_stop ? "true" : "false");
404 }
405 else
406 {
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("Failed to get an integer result from the expression.");
410 }
411 }
412 }
413 else
414 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000415 Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger();
Jim Ingham4b536182011-08-09 02:12:22 +0000416 StreamSP error_sp = debugger.GetAsyncErrorStream ();
417 error_sp->Printf ("Stopped due to an error evaluating condition of breakpoint ");
418 bp_loc_sp->GetDescription (error_sp.get(), eDescriptionLevelBrief);
419 error_sp->Printf (": \"%s\"",
420 bp_loc_sp->GetConditionText());
421 error_sp->EOL();
422 const char *err_str = error.AsCString("<Unknown Error>");
423 if (log)
424 log->Printf("Error evaluating condition: \"%s\"\n", err_str);
425
426 error_sp->PutCString (err_str);
427 error_sp->EOL();
428 error_sp->Flush();
429 // If the condition fails to be parsed or run, we should stop.
Jim Ingham79ea1d82011-12-09 04:17:31 +0000430 condition_says_stop = true;
Jim Ingham4b536182011-08-09 02:12:22 +0000431 }
432 }
433
Jim Ingham79ea1d82011-12-09 04:17:31 +0000434 // If this location's condition says we should aren't going to stop,
435 // then don't run the callback for this location.
436 if (!condition_says_stop)
437 continue;
438
439 bool callback_says_stop;
440
441 // FIXME: For now the callbacks have to run in async mode - the first time we restart we need
442 // to get out of there. So set it here.
443 // When we figure out how to nest breakpoint hits then this will change.
444
Greg Clayton1ac04c32012-02-21 00:09:25 +0000445 Debugger &debugger = m_thread.CalculateTarget()->GetDebugger();
Jim Ingham79ea1d82011-12-09 04:17:31 +0000446 bool old_async = debugger.GetAsyncExecution();
447 debugger.SetAsyncExecution (true);
448
449 callback_says_stop = bp_loc_sp->InvokeCallback (&context);
450
451 debugger.SetAsyncExecution (old_async);
452
453 if (callback_says_stop)
454 m_should_stop = true;
Jim Inghamca36cd12012-10-05 19:16:31 +0000455
456 // If we are going to stop for this breakpoint, then remove the breakpoint.
457 if (callback_says_stop && bp_loc_sp && bp_loc_sp->GetBreakpoint().IsOneShot())
458 {
459 m_thread.GetProcess()->GetTarget().RemoveBreakpointByID (bp_loc_sp->GetBreakpoint().GetID());
460 }
Jim Ingham79ea1d82011-12-09 04:17:31 +0000461
462 // Also make sure that the callback hasn't continued the target.
463 // If it did, when we'll set m_should_start to false and get out of here.
464 if (HasTargetRunSinceMe ())
465 {
466 m_should_stop = false;
Jim Ingham4b536182011-08-09 02:12:22 +0000467 break;
Jim Ingham79ea1d82011-12-09 04:17:31 +0000468 }
Jim Ingham4b536182011-08-09 02:12:22 +0000469 }
Jim Ingham3ebcf7f2010-08-10 00:59:59 +0000470 }
Jim Ingham79ea1d82011-12-09 04:17:31 +0000471 // We've figured out what this stop wants to do, so mark it as valid so we don't compute it again.
472 m_should_stop_is_valid = true;
473
Jim Ingham3ebcf7f2010-08-10 00:59:59 +0000474 }
475 else
476 {
Jim Ingham79ea1d82011-12-09 04:17:31 +0000477 m_should_stop = true;
478 m_should_stop_is_valid = true;
Greg Clayton5160ce52013-03-27 23:08:40 +0000479 Log * log_process(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
Jim Ingham3ebcf7f2010-08-10 00:59:59 +0000480
Jason Molendaccd41e52012-10-04 22:47:07 +0000481 if (log_process)
Daniel Malead01b2952012-11-29 21:49:15 +0000482 log_process->Printf ("Process::%s could not find breakpoint site id: %" PRId64 "...", __FUNCTION__, m_value);
Jim Ingham3ebcf7f2010-08-10 00:59:59 +0000483 }
Jim Ingham4b536182011-08-09 02:12:22 +0000484 if (log)
485 log->Printf ("Process::%s returning from action with m_should_stop: %d.", __FUNCTION__, m_should_stop);
Jim Ingham3ebcf7f2010-08-10 00:59:59 +0000486 }
Greg Claytonf4b47e12010-08-04 01:40:35 +0000487
488private:
489 std::string m_description;
490 bool m_should_stop;
491 bool m_should_stop_is_valid;
Jim Ingham0f16e732011-02-08 05:20:59 +0000492 bool m_should_perform_action; // Since we are trying to preserve the "state" of the system even if we run functions
493 // etc. behind the users backs, we need to make sure we only REALLY perform the action once.
Jim Ingham52c7d202011-10-28 01:12:19 +0000494 lldb::addr_t m_address; // We use this to capture the breakpoint site address when we create the StopInfo,
495 // in case somebody deletes it between the time the StopInfo is made and the
496 // description is asked for.
Jim Inghamca36cd12012-10-05 19:16:31 +0000497 lldb::break_id_t m_break_id;
498 bool m_was_one_shot;
Greg Claytonf4b47e12010-08-04 01:40:35 +0000499};
500
501
502//----------------------------------------------------------------------
503// StopInfoWatchpoint
504//----------------------------------------------------------------------
505
506class StopInfoWatchpoint : public StopInfo
507{
508public:
Jim Inghamf57b4352012-11-10 02:08:14 +0000509 // Make sure watchpoint is properly disabled and subsequently enabled while performing watchpoint actions.
510 class WatchpointSentry {
511 public:
512 WatchpointSentry(Process *p, Watchpoint *w):
513 process(p),
514 watchpoint(w)
515 {
516 if (process && watchpoint)
517 {
Jim Ingham1b5792e2012-12-18 02:03:49 +0000518 const bool notify = false;
Jim Inghamf57b4352012-11-10 02:08:14 +0000519 watchpoint->TurnOnEphemeralMode();
Jim Ingham1b5792e2012-12-18 02:03:49 +0000520 process->DisableWatchpoint(watchpoint, notify);
Jim Inghamf57b4352012-11-10 02:08:14 +0000521 }
522 }
523 ~WatchpointSentry()
524 {
525 if (process && watchpoint)
526 {
527 if (!watchpoint->IsDisabledDuringEphemeralMode())
Jim Ingham1b5792e2012-12-18 02:03:49 +0000528 {
529 const bool notify = false;
530 process->EnableWatchpoint(watchpoint, notify);
531 }
Jim Inghamf57b4352012-11-10 02:08:14 +0000532 watchpoint->TurnOffEphemeralMode();
533 }
534 }
535 private:
536 Process *process;
537 Watchpoint *watchpoint;
538 };
Greg Claytonf4b47e12010-08-04 01:40:35 +0000539
540 StopInfoWatchpoint (Thread &thread, break_id_t watch_id) :
Johnny Chenfd158f42011-09-21 22:47:15 +0000541 StopInfo(thread, watch_id),
542 m_description(),
543 m_should_stop(false),
544 m_should_stop_is_valid(false)
Greg Claytonf4b47e12010-08-04 01:40:35 +0000545 {
546 }
547
548 virtual ~StopInfoWatchpoint ()
549 {
550 }
551
552 virtual StopReason
553 GetStopReason () const
554 {
555 return eStopReasonWatchpoint;
556 }
557
Jim Inghamf57b4352012-11-10 02:08:14 +0000558 virtual const char *
559 GetDescription ()
560 {
561 if (m_description.empty())
562 {
563 StreamString strm;
Daniel Malead01b2952012-11-29 21:49:15 +0000564 strm.Printf("watchpoint %" PRIi64, m_value);
Jim Inghamf57b4352012-11-10 02:08:14 +0000565 m_description.swap (strm.GetString());
566 }
567 return m_description.c_str();
568 }
569
570protected:
Johnny Chenfd158f42011-09-21 22:47:15 +0000571 virtual bool
Jim Ingham9b620f32013-02-22 21:23:43 +0000572 ShouldStopSynchronous (Event *event_ptr)
Johnny Chenfd158f42011-09-21 22:47:15 +0000573 {
574 // ShouldStop() method is idempotent and should not affect hit count.
Johnny Chen16dcf712011-10-17 18:58:00 +0000575 // See Process::RunPrivateStateThread()->Process()->HandlePrivateEvent()
576 // -->Process()::ShouldBroadcastEvent()->ThreadList::ShouldStop()->
577 // Thread::ShouldStop()->ThreadPlanBase::ShouldStop()->
578 // StopInfoWatchpoint::ShouldStop() and
579 // Event::DoOnRemoval()->Process::ProcessEventData::DoOnRemoval()->
580 // StopInfoWatchpoint::PerformAction().
Johnny Chenfd158f42011-09-21 22:47:15 +0000581 if (m_should_stop_is_valid)
582 return m_should_stop;
583
Johnny Chen01a67862011-10-14 00:42:25 +0000584 WatchpointSP wp_sp =
Greg Clayton1ac04c32012-02-21 00:09:25 +0000585 m_thread.CalculateTarget()->GetWatchpointList().FindByID(GetValue());
Johnny Chen01a67862011-10-14 00:42:25 +0000586 if (wp_sp)
Johnny Chenfd158f42011-09-21 22:47:15 +0000587 {
588 // Check if we should stop at a watchpoint.
Greg Clayton1ac04c32012-02-21 00:09:25 +0000589 ExecutionContext exe_ctx (m_thread.GetStackFrameAtIndex(0));
590 StoppointCallbackContext context (event_ptr, exe_ctx, true);
Johnny Chen01a67862011-10-14 00:42:25 +0000591 m_should_stop = wp_sp->ShouldStop (&context);
Johnny Chenfd158f42011-09-21 22:47:15 +0000592 }
593 else
594 {
Greg Clayton5160ce52013-03-27 23:08:40 +0000595 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
Johnny Chenfd158f42011-09-21 22:47:15 +0000596
597 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +0000598 log->Printf ("Process::%s could not find watchpoint location id: %" PRId64 "...",
Johnny Chenfd158f42011-09-21 22:47:15 +0000599 __FUNCTION__, GetValue());
600
601 m_should_stop = true;
602 }
603 m_should_stop_is_valid = true;
604 return m_should_stop;
605 }
606
Jim Ingham9b620f32013-02-22 21:23:43 +0000607 bool
608 ShouldStop (Event *event_ptr)
609 {
610 // This just reports the work done by PerformAction or the synchronous stop. It should
611 // only ever get called after they have had a chance to run.
612 assert (m_should_stop_is_valid);
613 return m_should_stop;
614 }
615
Johnny Chen16dcf712011-10-17 18:58:00 +0000616 virtual void
617 PerformAction (Event *event_ptr)
618 {
Greg Clayton5160ce52013-03-27 23:08:40 +0000619 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS);
Johnny Chen16dcf712011-10-17 18:58:00 +0000620 // We're going to calculate if we should stop or not in some way during the course of
621 // this code. Also by default we're going to stop, so set that here.
622 m_should_stop = true;
623
624 WatchpointSP wp_sp =
Greg Clayton1ac04c32012-02-21 00:09:25 +0000625 m_thread.CalculateTarget()->GetWatchpointList().FindByID(GetValue());
Johnny Chen16dcf712011-10-17 18:58:00 +0000626 if (wp_sp)
627 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000628 ExecutionContext exe_ctx (m_thread.GetStackFrameAtIndex(0));
Johnny Chen209bd652012-08-13 21:09:54 +0000629 Process* process = exe_ctx.GetProcessPtr();
Johnny Chen0f7ad8d2012-08-21 22:06:34 +0000630
Johnny Chen66535a32012-08-21 22:15:58 +0000631 // This sentry object makes sure the current watchpoint is disabled while performing watchpoint actions,
632 // and it is then enabled after we are finished.
Johnny Chen0f7ad8d2012-08-21 22:06:34 +0000633 WatchpointSentry sentry(process, wp_sp.get());
634
Enrico Granataf04a2192012-07-13 23:18:48 +0000635 {
636 // check if this process is running on an architecture where watchpoints trigger
637 // before the associated instruction runs. if so, disable the WP, single-step and then
638 // re-enable the watchpoint
Enrico Granataf04a2192012-07-13 23:18:48 +0000639 if (process)
640 {
641 uint32_t num; bool wp_triggers_after;
642 if (process->GetWatchpointSupportInfo(num, wp_triggers_after).Success())
643 {
644 if (!wp_triggers_after)
645 {
Enrico Granataf04a2192012-07-13 23:18:48 +0000646 ThreadPlan *new_plan = m_thread.QueueThreadPlanForStepSingleInstruction(false, // step-over
647 false, // abort_other_plans
648 true); // stop_other_threads
649 new_plan->SetIsMasterPlan (true);
650 new_plan->SetOkayToDiscard (false);
651 process->GetThreadList().SetSelectedThreadByID (m_thread.GetID());
652 process->Resume ();
653 process->WaitForProcessToStop (NULL);
654 process->GetThreadList().SetSelectedThreadByID (m_thread.GetID());
655 MakeStopInfoValid(); // make sure we do not fail to stop because of the single-step taken above
Enrico Granataf04a2192012-07-13 23:18:48 +0000656 }
657 }
658 }
659 }
Johnny Chen209bd652012-08-13 21:09:54 +0000660
Johnny Chen16dcf712011-10-17 18:58:00 +0000661 if (m_should_stop && wp_sp->GetConditionText() != NULL)
662 {
663 // We need to make sure the user sees any parse errors in their condition, so we'll hook the
664 // constructor errors up to the debugger's Async I/O.
Johnny Chen16dcf712011-10-17 18:58:00 +0000665 ExecutionResults result_code;
666 ValueObjectSP result_value_sp;
Jim Ingham184e9812013-01-15 02:47:48 +0000667 const bool unwind_on_error = true;
668 const bool ignore_breakpoints = true;
Johnny Chen16dcf712011-10-17 18:58:00 +0000669 Error error;
Greg Clayton1ac04c32012-02-21 00:09:25 +0000670 result_code = ClangUserExpression::EvaluateWithError (exe_ctx,
Sean Callanan22019052012-09-08 01:51:48 +0000671 eExecutionPolicyOnlyWhenNeeded,
Sean Callananc7b65062011-11-07 23:35:40 +0000672 lldb::eLanguageTypeUnknown,
Sean Callanan20bb3aa2011-12-21 22:22:58 +0000673 ClangUserExpression::eResultTypeAny,
Jim Ingham184e9812013-01-15 02:47:48 +0000674 unwind_on_error,
675 ignore_breakpoints,
Johnny Chen16dcf712011-10-17 18:58:00 +0000676 wp_sp->GetConditionText(),
677 NULL,
678 result_value_sp,
Enrico Granata3372f582012-07-16 23:10:35 +0000679 error,
Greg Clayton26ab83d2012-10-31 20:49:04 +0000680 true,
681 ClangUserExpression::kDefaultTimeout);
Johnny Chen16dcf712011-10-17 18:58:00 +0000682 if (result_code == eExecutionCompleted)
683 {
684 if (result_value_sp)
685 {
686 Scalar scalar_value;
687 if (result_value_sp->ResolveValue (scalar_value))
688 {
689 if (scalar_value.ULongLong(1) == 0)
690 {
691 // We have been vetoed. This takes precedence over querying
692 // the watchpoint whether it should stop (aka ignore count and
693 // friends). See also StopInfoWatchpoint::ShouldStop() as well
694 // as Process::ProcessEventData::DoOnRemoval().
695 m_should_stop = false;
696 }
697 else
698 m_should_stop = true;
699 if (log)
700 log->Printf("Condition successfully evaluated, result is %s.\n",
701 m_should_stop ? "true" : "false");
702 }
703 else
704 {
705 m_should_stop = true;
706 if (log)
707 log->Printf("Failed to get an integer result from the expression.");
708 }
709 }
710 }
711 else
712 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000713 Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger();
Johnny Chen16dcf712011-10-17 18:58:00 +0000714 StreamSP error_sp = debugger.GetAsyncErrorStream ();
Johnny Chen5f3bf632012-01-24 23:19:25 +0000715 error_sp->Printf ("Stopped due to an error evaluating condition of watchpoint ");
Johnny Chen16dcf712011-10-17 18:58:00 +0000716 wp_sp->GetDescription (error_sp.get(), eDescriptionLevelBrief);
717 error_sp->Printf (": \"%s\"",
718 wp_sp->GetConditionText());
719 error_sp->EOL();
720 const char *err_str = error.AsCString("<Unknown Error>");
721 if (log)
722 log->Printf("Error evaluating condition: \"%s\"\n", err_str);
723
724 error_sp->PutCString (err_str);
725 error_sp->EOL();
726 error_sp->Flush();
727 // If the condition fails to be parsed or run, we should stop.
728 m_should_stop = true;
729 }
730 }
Johnny Chen13206412012-08-09 23:10:57 +0000731
732 // If the condition says to stop, we run the callback to further decide whether to stop.
733 if (m_should_stop)
734 {
Johnny Chen209bd652012-08-13 21:09:54 +0000735 StoppointCallbackContext context (event_ptr, exe_ctx, false);
Johnny Chen13206412012-08-09 23:10:57 +0000736 bool stop_requested = wp_sp->InvokeCallback (&context);
737 // Also make sure that the callback hasn't continued the target.
738 // If it did, when we'll set m_should_stop to false and get out of here.
739 if (HasTargetRunSinceMe ())
740 m_should_stop = false;
741
742 if (m_should_stop && !stop_requested)
743 {
744 // We have been vetoed by the callback mechanism.
745 m_should_stop = false;
746 }
747 }
Jim Inghama7dfb662012-10-23 07:20:06 +0000748 // Finally, if we are going to stop, print out the new & old values:
749 if (m_should_stop)
750 {
751 wp_sp->CaptureWatchedValue(exe_ctx);
752
753 Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger();
754 StreamSP output_sp = debugger.GetAsyncOutputStream ();
755 wp_sp->DumpSnapshots(output_sp.get());
756 output_sp->EOL();
757 output_sp->Flush();
758 }
759
Johnny Chen16dcf712011-10-17 18:58:00 +0000760 }
761 else
762 {
Greg Clayton5160ce52013-03-27 23:08:40 +0000763 Log * log_process(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
Johnny Chen16dcf712011-10-17 18:58:00 +0000764
Jason Molendaccd41e52012-10-04 22:47:07 +0000765 if (log_process)
Daniel Malead01b2952012-11-29 21:49:15 +0000766 log_process->Printf ("Process::%s could not find watchpoint id: %" PRId64 "...", __FUNCTION__, m_value);
Johnny Chen16dcf712011-10-17 18:58:00 +0000767 }
768 if (log)
769 log->Printf ("Process::%s returning from action with m_should_stop: %d.", __FUNCTION__, m_should_stop);
Jim Inghama7dfb662012-10-23 07:20:06 +0000770
Jim Ingham9b620f32013-02-22 21:23:43 +0000771 m_should_stop_is_valid = true;
772
Johnny Chen16dcf712011-10-17 18:58:00 +0000773 }
774
Greg Claytonf4b47e12010-08-04 01:40:35 +0000775private:
776 std::string m_description;
Johnny Chenfd158f42011-09-21 22:47:15 +0000777 bool m_should_stop;
778 bool m_should_stop_is_valid;
Greg Claytonf4b47e12010-08-04 01:40:35 +0000779};
780
781
782
783//----------------------------------------------------------------------
784// StopInfoUnixSignal
785//----------------------------------------------------------------------
786
787class StopInfoUnixSignal : public StopInfo
788{
789public:
790
791 StopInfoUnixSignal (Thread &thread, int signo) :
Greg Claytona658fd22011-06-04 01:26:29 +0000792 StopInfo (thread, signo)
Greg Claytonf4b47e12010-08-04 01:40:35 +0000793 {
794 }
795
796 virtual ~StopInfoUnixSignal ()
797 {
798 }
799
800
801 virtual StopReason
802 GetStopReason () const
803 {
804 return eStopReasonSignal;
805 }
806
807 virtual bool
Jim Ingham0161b492013-02-09 01:29:05 +0000808 ShouldStopSynchronous (Event *event_ptr)
809 {
810 return m_thread.GetProcess()->GetUnixSignals().GetShouldStop (m_value);
811 }
812
813 virtual bool
Greg Claytonf4b47e12010-08-04 01:40:35 +0000814 ShouldStop (Event *event_ptr)
815 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000816 return m_thread.GetProcess()->GetUnixSignals().GetShouldStop (m_value);
Greg Claytonf4b47e12010-08-04 01:40:35 +0000817 }
818
819
820 // If should stop returns false, check if we should notify of this event
821 virtual bool
822 ShouldNotify (Event *event_ptr)
823 {
Jim Ingham0161b492013-02-09 01:29:05 +0000824 bool should_notify = m_thread.GetProcess()->GetUnixSignals().GetShouldNotify (m_value);
825 if (should_notify)
826 {
827 StreamString strm;
828 strm.Printf ("thread %d received signal: %s",
829 m_thread.GetIndexID(),
830 m_thread.GetProcess()->GetUnixSignals().GetSignalAsCString (m_value));
831 Process::ProcessEventData::AddRestartedReason(event_ptr, strm.GetData());
832 }
833 return should_notify;
Greg Claytonf4b47e12010-08-04 01:40:35 +0000834 }
835
836
837 virtual void
838 WillResume (lldb::StateType resume_state)
839 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000840 if (m_thread.GetProcess()->GetUnixSignals().GetShouldSuppress(m_value) == false)
Greg Claytonf4b47e12010-08-04 01:40:35 +0000841 m_thread.SetResumeSignal(m_value);
842 }
843
844 virtual const char *
845 GetDescription ()
846 {
847 if (m_description.empty())
848 {
849 StreamString strm;
Greg Clayton1ac04c32012-02-21 00:09:25 +0000850 const char *signal_name = m_thread.GetProcess()->GetUnixSignals().GetSignalAsCString (m_value);
Greg Claytonf4b47e12010-08-04 01:40:35 +0000851 if (signal_name)
Greg Clayton0603aa92010-10-04 01:05:56 +0000852 strm.Printf("signal %s", signal_name);
Greg Claytonf4b47e12010-08-04 01:40:35 +0000853 else
Daniel Malead01b2952012-11-29 21:49:15 +0000854 strm.Printf("signal %" PRIi64, m_value);
Greg Claytonf4b47e12010-08-04 01:40:35 +0000855 m_description.swap (strm.GetString());
856 }
857 return m_description.c_str();
858 }
Greg Claytonf4b47e12010-08-04 01:40:35 +0000859};
860
861//----------------------------------------------------------------------
862// StopInfoTrace
863//----------------------------------------------------------------------
864
865class StopInfoTrace : public StopInfo
866{
867public:
868
869 StopInfoTrace (Thread &thread) :
870 StopInfo (thread, LLDB_INVALID_UID)
871 {
872 }
873
874 virtual ~StopInfoTrace ()
875 {
876 }
877
878 virtual StopReason
879 GetStopReason () const
880 {
881 return eStopReasonTrace;
882 }
883
884 virtual const char *
885 GetDescription ()
886 {
Greg Claytona658fd22011-06-04 01:26:29 +0000887 if (m_description.empty())
Greg Claytonf4b47e12010-08-04 01:40:35 +0000888 return "trace";
Greg Claytona658fd22011-06-04 01:26:29 +0000889 else
890 return m_description.c_str();
891 }
892};
893
894
895//----------------------------------------------------------------------
896// StopInfoException
897//----------------------------------------------------------------------
898
899class StopInfoException : public StopInfo
900{
901public:
902
903 StopInfoException (Thread &thread, const char *description) :
904 StopInfo (thread, LLDB_INVALID_UID)
905 {
906 if (description)
907 SetDescription (description);
908 }
909
910 virtual
911 ~StopInfoException ()
912 {
913 }
914
915 virtual StopReason
916 GetStopReason () const
917 {
918 return eStopReasonException;
919 }
920
921 virtual const char *
922 GetDescription ()
923 {
924 if (m_description.empty())
925 return "exception";
926 else
927 return m_description.c_str();
Greg Claytonf4b47e12010-08-04 01:40:35 +0000928 }
929};
930
931
932//----------------------------------------------------------------------
933// StopInfoThreadPlan
934//----------------------------------------------------------------------
935
936class StopInfoThreadPlan : public StopInfo
937{
938public:
939
Jim Ingham73ca05a2011-12-17 01:35:57 +0000940 StopInfoThreadPlan (ThreadPlanSP &plan_sp, ValueObjectSP &return_valobj_sp) :
Greg Claytonf4b47e12010-08-04 01:40:35 +0000941 StopInfo (plan_sp->GetThread(), LLDB_INVALID_UID),
Jim Ingham73ca05a2011-12-17 01:35:57 +0000942 m_plan_sp (plan_sp),
943 m_return_valobj_sp (return_valobj_sp)
Greg Claytonf4b47e12010-08-04 01:40:35 +0000944 {
945 }
946
947 virtual ~StopInfoThreadPlan ()
948 {
949 }
950
951 virtual StopReason
952 GetStopReason () const
953 {
954 return eStopReasonPlanComplete;
955 }
956
957 virtual const char *
958 GetDescription ()
959 {
960 if (m_description.empty())
961 {
962 StreamString strm;
963 m_plan_sp->GetDescription (&strm, eDescriptionLevelBrief);
964 m_description.swap (strm.GetString());
965 }
966 return m_description.c_str();
967 }
Jim Ingham73ca05a2011-12-17 01:35:57 +0000968
969 ValueObjectSP
970 GetReturnValueObject()
971 {
972 return m_return_valobj_sp;
973 }
Jim Ingham0161b492013-02-09 01:29:05 +0000974
975protected:
976 virtual bool
977 ShouldStop (Event *event_ptr)
978 {
979 if (m_plan_sp)
980 return m_plan_sp->ShouldStop(event_ptr);
981 else
982 return StopInfo::ShouldStop(event_ptr);
983 }
Greg Claytonf4b47e12010-08-04 01:40:35 +0000984
985private:
986 ThreadPlanSP m_plan_sp;
Jim Ingham73ca05a2011-12-17 01:35:57 +0000987 ValueObjectSP m_return_valobj_sp;
Greg Claytonf4b47e12010-08-04 01:40:35 +0000988};
Greg Clayton90ba8112012-12-05 00:16:59 +0000989
990class StopInfoExec : public StopInfo
991{
992public:
993
994 StopInfoExec (Thread &thread) :
995 StopInfo (thread, LLDB_INVALID_UID),
996 m_performed_action (false)
997 {
998 }
999
1000 virtual
1001 ~StopInfoExec ()
1002 {
1003 }
1004
1005 virtual StopReason
1006 GetStopReason () const
1007 {
1008 return eStopReasonExec;
1009 }
1010
1011 virtual const char *
1012 GetDescription ()
1013 {
1014 return "exec";
1015 }
1016protected:
Greg Clayton90ba8112012-12-05 00:16:59 +00001017
1018 virtual void
1019 PerformAction (Event *event_ptr)
1020 {
1021 // Only perform the action once
1022 if (m_performed_action)
1023 return;
1024 m_performed_action = true;
1025 m_thread.GetProcess()->DidExec();
1026 }
1027
1028 bool m_performed_action;
1029};
1030
Jim Ingham4b536182011-08-09 02:12:22 +00001031} // namespace lldb_private
Greg Claytonf4b47e12010-08-04 01:40:35 +00001032
1033StopInfoSP
1034StopInfo::CreateStopReasonWithBreakpointSiteID (Thread &thread, break_id_t break_id)
1035{
1036 return StopInfoSP (new StopInfoBreakpoint (thread, break_id));
1037}
1038
1039StopInfoSP
Jim Ingham36f3b362010-10-14 23:45:03 +00001040StopInfo::CreateStopReasonWithBreakpointSiteID (Thread &thread, break_id_t break_id, bool should_stop)
1041{
1042 return StopInfoSP (new StopInfoBreakpoint (thread, break_id, should_stop));
1043}
1044
1045StopInfoSP
Greg Claytonf4b47e12010-08-04 01:40:35 +00001046StopInfo::CreateStopReasonWithWatchpointID (Thread &thread, break_id_t watch_id)
1047{
1048 return StopInfoSP (new StopInfoWatchpoint (thread, watch_id));
1049}
1050
1051StopInfoSP
1052StopInfo::CreateStopReasonWithSignal (Thread &thread, int signo)
1053{
1054 return StopInfoSP (new StopInfoUnixSignal (thread, signo));
1055}
1056
1057StopInfoSP
1058StopInfo::CreateStopReasonToTrace (Thread &thread)
1059{
1060 return StopInfoSP (new StopInfoTrace (thread));
1061}
1062
1063StopInfoSP
Jim Ingham73ca05a2011-12-17 01:35:57 +00001064StopInfo::CreateStopReasonWithPlan (ThreadPlanSP &plan_sp, ValueObjectSP return_valobj_sp)
Greg Claytonf4b47e12010-08-04 01:40:35 +00001065{
Jim Ingham73ca05a2011-12-17 01:35:57 +00001066 return StopInfoSP (new StopInfoThreadPlan (plan_sp, return_valobj_sp));
Greg Claytonf4b47e12010-08-04 01:40:35 +00001067}
Greg Claytona658fd22011-06-04 01:26:29 +00001068
1069StopInfoSP
1070StopInfo::CreateStopReasonWithException (Thread &thread, const char *description)
1071{
1072 return StopInfoSP (new StopInfoException (thread, description));
1073}
Jim Ingham73ca05a2011-12-17 01:35:57 +00001074
Greg Clayton90ba8112012-12-05 00:16:59 +00001075StopInfoSP
1076StopInfo::CreateStopReasonWithExec (Thread &thread)
1077{
1078 return StopInfoSP (new StopInfoExec (thread));
1079}
1080
Jim Ingham73ca05a2011-12-17 01:35:57 +00001081ValueObjectSP
1082StopInfo::GetReturnValueObject(StopInfoSP &stop_info_sp)
1083{
1084 if (stop_info_sp && stop_info_sp->GetStopReason() == eStopReasonPlanComplete)
1085 {
1086 StopInfoThreadPlan *plan_stop_info = static_cast<StopInfoThreadPlan *>(stop_info_sp.get());
1087 return plan_stop_info->GetReturnValueObject();
1088 }
1089 else
1090 return ValueObjectSP();
1091}