blob: 33ade1eef1abaf0daa3dd4d9105bf2a235260a1c [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.");
Jim Ingham8af3b9c2013-03-29 01:18:12 +0000294 m_should_stop = true;
295 m_should_stop_is_valid = true;
Jim Ingham5cb9a182013-03-28 00:13:30 +0000296 return;
297 }
298
Greg Clayton1ac04c32012-02-21 00:09:25 +0000299 BreakpointSiteSP bp_site_sp (m_thread.GetProcess()->GetBreakpointSiteList().FindByID (m_value));
Jim Ingham79ea1d82011-12-09 04:17:31 +0000300
Jim Ingham3ebcf7f2010-08-10 00:59:59 +0000301 if (bp_site_sp)
302 {
303 size_t num_owners = bp_site_sp->GetNumberOfOwners();
Jim Ingham79ea1d82011-12-09 04:17:31 +0000304
305 if (num_owners == 0)
Jim Ingham3ebcf7f2010-08-10 00:59:59 +0000306 {
Jim Ingham79ea1d82011-12-09 04:17:31 +0000307 m_should_stop = true;
308 }
309 else
310 {
311 // We go through each location, and test first its condition. If the condition says to stop,
312 // then we run the callback for that location. If that callback says to stop as well, then
313 // we set m_should_stop to true; we are going to stop.
314 // But we still want to give all the breakpoints whose conditions say we are going to stop a
315 // chance to run their callbacks.
316 // Of course if any callback restarts the target by putting "continue" in the callback, then
317 // we're going to restart, without running the rest of the callbacks. And in this case we will
318 // end up not stopping even if another location said we should stop. But that's better than not
319 // running all the callbacks.
320
321 m_should_stop = false;
322
Greg Clayton1ac04c32012-02-21 00:09:25 +0000323 ExecutionContext exe_ctx (m_thread.GetStackFrameAtIndex(0));
Jim Ingham184e9812013-01-15 02:47:48 +0000324 Process *process = exe_ctx.GetProcessPtr();
325 if (process->GetModIDRef().IsLastResumeForUserExpression())
326 {
327 // If we are in the middle of evaluating an expression, don't run asynchronous breakpoint commands or
328 // expressions. That could lead to infinite recursion if the command or condition re-calls the function
329 // with this breakpoint.
330 // TODO: We can keep a list of the breakpoints we've seen while running expressions in the nested
331 // PerformAction calls that can arise when the action runs a function that hits another breakpoint,
332 // and only stop running commands when we see the same breakpoint hit a second time.
333
334 m_should_stop_is_valid = true;
335 if (log)
336 log->Printf ("StopInfoBreakpoint::PerformAction - Hit a breakpoint while running an expression,"
337 " not running commands to avoid recursion.");
338 bool ignoring_breakpoints = process->GetIgnoreBreakpointsInExpressions();
339 if (ignoring_breakpoints)
340 {
341 m_should_stop = false;
342 // Internal breakpoints will always stop.
343 for (size_t j = 0; j < num_owners; j++)
344 {
345 lldb::BreakpointLocationSP bp_loc_sp = bp_site_sp->GetOwnerAtIndex(j);
346 if (bp_loc_sp->GetBreakpoint().IsInternal())
347 {
348 m_should_stop = true;
349 break;
350 }
351 }
352 }
353 else
354 {
355 m_should_stop = true;
356 }
357 if (log)
358 log->Printf ("StopInfoBreakpoint::PerformAction - in expression, continuing: %s.",
359 m_should_stop ? "true" : "false");
360 process->GetTarget().GetDebugger().GetAsyncOutputStream()->Printf("Warning: hit breakpoint while "
361 "running function, skipping commands and conditions to prevent recursion.");
362 return;
363 }
364
Greg Clayton1ac04c32012-02-21 00:09:25 +0000365 StoppointCallbackContext context (event_ptr, exe_ctx, false);
Jim Ingham4b536182011-08-09 02:12:22 +0000366
Jim Ingham4b536182011-08-09 02:12:22 +0000367 for (size_t j = 0; j < num_owners; j++)
368 {
369 lldb::BreakpointLocationSP bp_loc_sp = bp_site_sp->GetOwnerAtIndex(j);
Jim Ingham79ea1d82011-12-09 04:17:31 +0000370
371 // First run the condition for the breakpoint. If that says we should stop, then we'll run
372 // the callback for the breakpoint. If the callback says we shouldn't stop that will win.
373
374 bool condition_says_stop = true;
Jim Ingham4b536182011-08-09 02:12:22 +0000375 if (bp_loc_sp->GetConditionText() != NULL)
376 {
377 // We need to make sure the user sees any parse errors in their condition, so we'll hook the
378 // constructor errors up to the debugger's Async I/O.
379
Jim Ingham4b536182011-08-09 02:12:22 +0000380 ValueObjectSP result_valobj_sp;
381
382 ExecutionResults result_code;
383 ValueObjectSP result_value_sp;
Jim Ingham184e9812013-01-15 02:47:48 +0000384 const bool unwind_on_error = true;
385 const bool ignore_breakpoints = true;
Jim Ingham4b536182011-08-09 02:12:22 +0000386 Error error;
Greg Clayton1ac04c32012-02-21 00:09:25 +0000387 result_code = ClangUserExpression::EvaluateWithError (exe_ctx,
Jim Ingham6d66ce62012-04-20 21:16:56 +0000388 eExecutionPolicyOnlyWhenNeeded,
Sean Callananc7b65062011-11-07 23:35:40 +0000389 lldb::eLanguageTypeUnknown,
Sean Callanan20bb3aa2011-12-21 22:22:58 +0000390 ClangUserExpression::eResultTypeAny,
Jim Ingham184e9812013-01-15 02:47:48 +0000391 unwind_on_error,
392 ignore_breakpoints,
Sean Callanan3bfdaa22011-09-15 02:13:07 +0000393 bp_loc_sp->GetConditionText(),
394 NULL,
395 result_value_sp,
Greg Clayton26ab83d2012-10-31 20:49:04 +0000396 error,
397 true,
398 ClangUserExpression::kDefaultTimeout);
Jim Ingham4b536182011-08-09 02:12:22 +0000399 if (result_code == eExecutionCompleted)
400 {
401 if (result_value_sp)
402 {
403 Scalar scalar_value;
404 if (result_value_sp->ResolveValue (scalar_value))
405 {
406 if (scalar_value.ULongLong(1) == 0)
Jim Ingham79ea1d82011-12-09 04:17:31 +0000407 condition_says_stop = false;
Jim Ingham4b536182011-08-09 02:12:22 +0000408 else
Jim Ingham79ea1d82011-12-09 04:17:31 +0000409 condition_says_stop = true;
Jim Ingham4b536182011-08-09 02:12:22 +0000410 if (log)
411 log->Printf("Condition successfully evaluated, result is %s.\n",
412 m_should_stop ? "true" : "false");
413 }
414 else
415 {
Jim Ingham79ea1d82011-12-09 04:17:31 +0000416 condition_says_stop = true;
Jim Ingham4b536182011-08-09 02:12:22 +0000417 if (log)
418 log->Printf("Failed to get an integer result from the expression.");
419 }
420 }
421 }
422 else
423 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000424 Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger();
Jim Ingham4b536182011-08-09 02:12:22 +0000425 StreamSP error_sp = debugger.GetAsyncErrorStream ();
426 error_sp->Printf ("Stopped due to an error evaluating condition of breakpoint ");
427 bp_loc_sp->GetDescription (error_sp.get(), eDescriptionLevelBrief);
428 error_sp->Printf (": \"%s\"",
429 bp_loc_sp->GetConditionText());
430 error_sp->EOL();
431 const char *err_str = error.AsCString("<Unknown Error>");
432 if (log)
433 log->Printf("Error evaluating condition: \"%s\"\n", err_str);
434
435 error_sp->PutCString (err_str);
436 error_sp->EOL();
437 error_sp->Flush();
438 // If the condition fails to be parsed or run, we should stop.
Jim Ingham79ea1d82011-12-09 04:17:31 +0000439 condition_says_stop = true;
Jim Ingham4b536182011-08-09 02:12:22 +0000440 }
441 }
442
Jim Ingham79ea1d82011-12-09 04:17:31 +0000443 // If this location's condition says we should aren't going to stop,
444 // then don't run the callback for this location.
445 if (!condition_says_stop)
446 continue;
447
448 bool callback_says_stop;
449
450 // FIXME: For now the callbacks have to run in async mode - the first time we restart we need
451 // to get out of there. So set it here.
452 // When we figure out how to nest breakpoint hits then this will change.
453
Greg Clayton1ac04c32012-02-21 00:09:25 +0000454 Debugger &debugger = m_thread.CalculateTarget()->GetDebugger();
Jim Ingham79ea1d82011-12-09 04:17:31 +0000455 bool old_async = debugger.GetAsyncExecution();
456 debugger.SetAsyncExecution (true);
457
458 callback_says_stop = bp_loc_sp->InvokeCallback (&context);
459
460 debugger.SetAsyncExecution (old_async);
461
462 if (callback_says_stop)
463 m_should_stop = true;
Jim Inghamca36cd12012-10-05 19:16:31 +0000464
465 // If we are going to stop for this breakpoint, then remove the breakpoint.
466 if (callback_says_stop && bp_loc_sp && bp_loc_sp->GetBreakpoint().IsOneShot())
467 {
468 m_thread.GetProcess()->GetTarget().RemoveBreakpointByID (bp_loc_sp->GetBreakpoint().GetID());
469 }
Jim Ingham79ea1d82011-12-09 04:17:31 +0000470
471 // Also make sure that the callback hasn't continued the target.
472 // If it did, when we'll set m_should_start to false and get out of here.
473 if (HasTargetRunSinceMe ())
474 {
475 m_should_stop = false;
Jim Ingham4b536182011-08-09 02:12:22 +0000476 break;
Jim Ingham79ea1d82011-12-09 04:17:31 +0000477 }
Jim Ingham4b536182011-08-09 02:12:22 +0000478 }
Jim Ingham3ebcf7f2010-08-10 00:59:59 +0000479 }
Jim Ingham79ea1d82011-12-09 04:17:31 +0000480 // We've figured out what this stop wants to do, so mark it as valid so we don't compute it again.
481 m_should_stop_is_valid = true;
482
Jim Ingham3ebcf7f2010-08-10 00:59:59 +0000483 }
484 else
485 {
Jim Ingham79ea1d82011-12-09 04:17:31 +0000486 m_should_stop = true;
487 m_should_stop_is_valid = true;
Greg Clayton5160ce52013-03-27 23:08:40 +0000488 Log * log_process(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
Jim Ingham3ebcf7f2010-08-10 00:59:59 +0000489
Jason Molendaccd41e52012-10-04 22:47:07 +0000490 if (log_process)
Daniel Malead01b2952012-11-29 21:49:15 +0000491 log_process->Printf ("Process::%s could not find breakpoint site id: %" PRId64 "...", __FUNCTION__, m_value);
Jim Ingham3ebcf7f2010-08-10 00:59:59 +0000492 }
Jim Ingham4b536182011-08-09 02:12:22 +0000493 if (log)
494 log->Printf ("Process::%s returning from action with m_should_stop: %d.", __FUNCTION__, m_should_stop);
Jim Ingham3ebcf7f2010-08-10 00:59:59 +0000495 }
Greg Claytonf4b47e12010-08-04 01:40:35 +0000496
497private:
498 std::string m_description;
499 bool m_should_stop;
500 bool m_should_stop_is_valid;
Jim Ingham0f16e732011-02-08 05:20:59 +0000501 bool m_should_perform_action; // Since we are trying to preserve the "state" of the system even if we run functions
502 // etc. behind the users backs, we need to make sure we only REALLY perform the action once.
Jim Ingham52c7d202011-10-28 01:12:19 +0000503 lldb::addr_t m_address; // We use this to capture the breakpoint site address when we create the StopInfo,
504 // in case somebody deletes it between the time the StopInfo is made and the
505 // description is asked for.
Jim Inghamca36cd12012-10-05 19:16:31 +0000506 lldb::break_id_t m_break_id;
507 bool m_was_one_shot;
Greg Claytonf4b47e12010-08-04 01:40:35 +0000508};
509
510
511//----------------------------------------------------------------------
512// StopInfoWatchpoint
513//----------------------------------------------------------------------
514
515class StopInfoWatchpoint : public StopInfo
516{
517public:
Jim Inghamf57b4352012-11-10 02:08:14 +0000518 // Make sure watchpoint is properly disabled and subsequently enabled while performing watchpoint actions.
519 class WatchpointSentry {
520 public:
521 WatchpointSentry(Process *p, Watchpoint *w):
522 process(p),
523 watchpoint(w)
524 {
525 if (process && watchpoint)
526 {
Jim Ingham1b5792e2012-12-18 02:03:49 +0000527 const bool notify = false;
Jim Inghamf57b4352012-11-10 02:08:14 +0000528 watchpoint->TurnOnEphemeralMode();
Jim Ingham1b5792e2012-12-18 02:03:49 +0000529 process->DisableWatchpoint(watchpoint, notify);
Jim Inghamf57b4352012-11-10 02:08:14 +0000530 }
531 }
532 ~WatchpointSentry()
533 {
534 if (process && watchpoint)
535 {
536 if (!watchpoint->IsDisabledDuringEphemeralMode())
Jim Ingham1b5792e2012-12-18 02:03:49 +0000537 {
538 const bool notify = false;
539 process->EnableWatchpoint(watchpoint, notify);
540 }
Jim Inghamf57b4352012-11-10 02:08:14 +0000541 watchpoint->TurnOffEphemeralMode();
542 }
543 }
544 private:
545 Process *process;
546 Watchpoint *watchpoint;
547 };
Greg Claytonf4b47e12010-08-04 01:40:35 +0000548
549 StopInfoWatchpoint (Thread &thread, break_id_t watch_id) :
Johnny Chenfd158f42011-09-21 22:47:15 +0000550 StopInfo(thread, watch_id),
551 m_description(),
552 m_should_stop(false),
553 m_should_stop_is_valid(false)
Greg Claytonf4b47e12010-08-04 01:40:35 +0000554 {
555 }
556
557 virtual ~StopInfoWatchpoint ()
558 {
559 }
560
561 virtual StopReason
562 GetStopReason () const
563 {
564 return eStopReasonWatchpoint;
565 }
566
Jim Inghamf57b4352012-11-10 02:08:14 +0000567 virtual const char *
568 GetDescription ()
569 {
570 if (m_description.empty())
571 {
572 StreamString strm;
Daniel Malead01b2952012-11-29 21:49:15 +0000573 strm.Printf("watchpoint %" PRIi64, m_value);
Jim Inghamf57b4352012-11-10 02:08:14 +0000574 m_description.swap (strm.GetString());
575 }
576 return m_description.c_str();
577 }
578
579protected:
Johnny Chenfd158f42011-09-21 22:47:15 +0000580 virtual bool
Jim Ingham9b620f32013-02-22 21:23:43 +0000581 ShouldStopSynchronous (Event *event_ptr)
Johnny Chenfd158f42011-09-21 22:47:15 +0000582 {
583 // ShouldStop() method is idempotent and should not affect hit count.
Johnny Chen16dcf712011-10-17 18:58:00 +0000584 // See Process::RunPrivateStateThread()->Process()->HandlePrivateEvent()
585 // -->Process()::ShouldBroadcastEvent()->ThreadList::ShouldStop()->
586 // Thread::ShouldStop()->ThreadPlanBase::ShouldStop()->
587 // StopInfoWatchpoint::ShouldStop() and
588 // Event::DoOnRemoval()->Process::ProcessEventData::DoOnRemoval()->
589 // StopInfoWatchpoint::PerformAction().
Johnny Chenfd158f42011-09-21 22:47:15 +0000590 if (m_should_stop_is_valid)
591 return m_should_stop;
592
Johnny Chen01a67862011-10-14 00:42:25 +0000593 WatchpointSP wp_sp =
Greg Clayton1ac04c32012-02-21 00:09:25 +0000594 m_thread.CalculateTarget()->GetWatchpointList().FindByID(GetValue());
Johnny Chen01a67862011-10-14 00:42:25 +0000595 if (wp_sp)
Johnny Chenfd158f42011-09-21 22:47:15 +0000596 {
597 // Check if we should stop at a watchpoint.
Greg Clayton1ac04c32012-02-21 00:09:25 +0000598 ExecutionContext exe_ctx (m_thread.GetStackFrameAtIndex(0));
599 StoppointCallbackContext context (event_ptr, exe_ctx, true);
Johnny Chen01a67862011-10-14 00:42:25 +0000600 m_should_stop = wp_sp->ShouldStop (&context);
Johnny Chenfd158f42011-09-21 22:47:15 +0000601 }
602 else
603 {
Greg Clayton5160ce52013-03-27 23:08:40 +0000604 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
Johnny Chenfd158f42011-09-21 22:47:15 +0000605
606 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +0000607 log->Printf ("Process::%s could not find watchpoint location id: %" PRId64 "...",
Johnny Chenfd158f42011-09-21 22:47:15 +0000608 __FUNCTION__, GetValue());
609
610 m_should_stop = true;
611 }
612 m_should_stop_is_valid = true;
613 return m_should_stop;
614 }
615
Jim Ingham9b620f32013-02-22 21:23:43 +0000616 bool
617 ShouldStop (Event *event_ptr)
618 {
619 // This just reports the work done by PerformAction or the synchronous stop. It should
620 // only ever get called after they have had a chance to run.
621 assert (m_should_stop_is_valid);
622 return m_should_stop;
623 }
624
Johnny Chen16dcf712011-10-17 18:58:00 +0000625 virtual void
626 PerformAction (Event *event_ptr)
627 {
Greg Clayton5160ce52013-03-27 23:08:40 +0000628 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS);
Johnny Chen16dcf712011-10-17 18:58:00 +0000629 // We're going to calculate if we should stop or not in some way during the course of
630 // this code. Also by default we're going to stop, so set that here.
631 m_should_stop = true;
632
633 WatchpointSP wp_sp =
Greg Clayton1ac04c32012-02-21 00:09:25 +0000634 m_thread.CalculateTarget()->GetWatchpointList().FindByID(GetValue());
Johnny Chen16dcf712011-10-17 18:58:00 +0000635 if (wp_sp)
636 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000637 ExecutionContext exe_ctx (m_thread.GetStackFrameAtIndex(0));
Johnny Chen209bd652012-08-13 21:09:54 +0000638 Process* process = exe_ctx.GetProcessPtr();
Johnny Chen0f7ad8d2012-08-21 22:06:34 +0000639
Johnny Chen66535a32012-08-21 22:15:58 +0000640 // This sentry object makes sure the current watchpoint is disabled while performing watchpoint actions,
641 // and it is then enabled after we are finished.
Johnny Chen0f7ad8d2012-08-21 22:06:34 +0000642 WatchpointSentry sentry(process, wp_sp.get());
643
Enrico Granataf04a2192012-07-13 23:18:48 +0000644 {
645 // check if this process is running on an architecture where watchpoints trigger
646 // before the associated instruction runs. if so, disable the WP, single-step and then
647 // re-enable the watchpoint
Enrico Granataf04a2192012-07-13 23:18:48 +0000648 if (process)
649 {
650 uint32_t num; bool wp_triggers_after;
651 if (process->GetWatchpointSupportInfo(num, wp_triggers_after).Success())
652 {
653 if (!wp_triggers_after)
654 {
Enrico Granataf04a2192012-07-13 23:18:48 +0000655 ThreadPlan *new_plan = m_thread.QueueThreadPlanForStepSingleInstruction(false, // step-over
656 false, // abort_other_plans
657 true); // stop_other_threads
658 new_plan->SetIsMasterPlan (true);
659 new_plan->SetOkayToDiscard (false);
660 process->GetThreadList().SetSelectedThreadByID (m_thread.GetID());
661 process->Resume ();
662 process->WaitForProcessToStop (NULL);
663 process->GetThreadList().SetSelectedThreadByID (m_thread.GetID());
664 MakeStopInfoValid(); // make sure we do not fail to stop because of the single-step taken above
Enrico Granataf04a2192012-07-13 23:18:48 +0000665 }
666 }
667 }
668 }
Johnny Chen209bd652012-08-13 21:09:54 +0000669
Johnny Chen16dcf712011-10-17 18:58:00 +0000670 if (m_should_stop && wp_sp->GetConditionText() != NULL)
671 {
672 // We need to make sure the user sees any parse errors in their condition, so we'll hook the
673 // constructor errors up to the debugger's Async I/O.
Johnny Chen16dcf712011-10-17 18:58:00 +0000674 ExecutionResults result_code;
675 ValueObjectSP result_value_sp;
Jim Ingham184e9812013-01-15 02:47:48 +0000676 const bool unwind_on_error = true;
677 const bool ignore_breakpoints = true;
Johnny Chen16dcf712011-10-17 18:58:00 +0000678 Error error;
Greg Clayton1ac04c32012-02-21 00:09:25 +0000679 result_code = ClangUserExpression::EvaluateWithError (exe_ctx,
Sean Callanan22019052012-09-08 01:51:48 +0000680 eExecutionPolicyOnlyWhenNeeded,
Sean Callananc7b65062011-11-07 23:35:40 +0000681 lldb::eLanguageTypeUnknown,
Sean Callanan20bb3aa2011-12-21 22:22:58 +0000682 ClangUserExpression::eResultTypeAny,
Jim Ingham184e9812013-01-15 02:47:48 +0000683 unwind_on_error,
684 ignore_breakpoints,
Johnny Chen16dcf712011-10-17 18:58:00 +0000685 wp_sp->GetConditionText(),
686 NULL,
687 result_value_sp,
Enrico Granata3372f582012-07-16 23:10:35 +0000688 error,
Greg Clayton26ab83d2012-10-31 20:49:04 +0000689 true,
690 ClangUserExpression::kDefaultTimeout);
Johnny Chen16dcf712011-10-17 18:58:00 +0000691 if (result_code == eExecutionCompleted)
692 {
693 if (result_value_sp)
694 {
695 Scalar scalar_value;
696 if (result_value_sp->ResolveValue (scalar_value))
697 {
698 if (scalar_value.ULongLong(1) == 0)
699 {
700 // We have been vetoed. This takes precedence over querying
701 // the watchpoint whether it should stop (aka ignore count and
702 // friends). See also StopInfoWatchpoint::ShouldStop() as well
703 // as Process::ProcessEventData::DoOnRemoval().
704 m_should_stop = false;
705 }
706 else
707 m_should_stop = true;
708 if (log)
709 log->Printf("Condition successfully evaluated, result is %s.\n",
710 m_should_stop ? "true" : "false");
711 }
712 else
713 {
714 m_should_stop = true;
715 if (log)
716 log->Printf("Failed to get an integer result from the expression.");
717 }
718 }
719 }
720 else
721 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000722 Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger();
Johnny Chen16dcf712011-10-17 18:58:00 +0000723 StreamSP error_sp = debugger.GetAsyncErrorStream ();
Johnny Chen5f3bf632012-01-24 23:19:25 +0000724 error_sp->Printf ("Stopped due to an error evaluating condition of watchpoint ");
Johnny Chen16dcf712011-10-17 18:58:00 +0000725 wp_sp->GetDescription (error_sp.get(), eDescriptionLevelBrief);
726 error_sp->Printf (": \"%s\"",
727 wp_sp->GetConditionText());
728 error_sp->EOL();
729 const char *err_str = error.AsCString("<Unknown Error>");
730 if (log)
731 log->Printf("Error evaluating condition: \"%s\"\n", err_str);
732
733 error_sp->PutCString (err_str);
734 error_sp->EOL();
735 error_sp->Flush();
736 // If the condition fails to be parsed or run, we should stop.
737 m_should_stop = true;
738 }
739 }
Johnny Chen13206412012-08-09 23:10:57 +0000740
741 // If the condition says to stop, we run the callback to further decide whether to stop.
742 if (m_should_stop)
743 {
Johnny Chen209bd652012-08-13 21:09:54 +0000744 StoppointCallbackContext context (event_ptr, exe_ctx, false);
Johnny Chen13206412012-08-09 23:10:57 +0000745 bool stop_requested = wp_sp->InvokeCallback (&context);
746 // Also make sure that the callback hasn't continued the target.
747 // If it did, when we'll set m_should_stop to false and get out of here.
748 if (HasTargetRunSinceMe ())
749 m_should_stop = false;
750
751 if (m_should_stop && !stop_requested)
752 {
753 // We have been vetoed by the callback mechanism.
754 m_should_stop = false;
755 }
756 }
Jim Inghama7dfb662012-10-23 07:20:06 +0000757 // Finally, if we are going to stop, print out the new & old values:
758 if (m_should_stop)
759 {
760 wp_sp->CaptureWatchedValue(exe_ctx);
761
762 Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger();
763 StreamSP output_sp = debugger.GetAsyncOutputStream ();
764 wp_sp->DumpSnapshots(output_sp.get());
765 output_sp->EOL();
766 output_sp->Flush();
767 }
768
Johnny Chen16dcf712011-10-17 18:58:00 +0000769 }
770 else
771 {
Greg Clayton5160ce52013-03-27 23:08:40 +0000772 Log * log_process(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
Johnny Chen16dcf712011-10-17 18:58:00 +0000773
Jason Molendaccd41e52012-10-04 22:47:07 +0000774 if (log_process)
Daniel Malead01b2952012-11-29 21:49:15 +0000775 log_process->Printf ("Process::%s could not find watchpoint id: %" PRId64 "...", __FUNCTION__, m_value);
Johnny Chen16dcf712011-10-17 18:58:00 +0000776 }
777 if (log)
778 log->Printf ("Process::%s returning from action with m_should_stop: %d.", __FUNCTION__, m_should_stop);
Jim Inghama7dfb662012-10-23 07:20:06 +0000779
Jim Ingham9b620f32013-02-22 21:23:43 +0000780 m_should_stop_is_valid = true;
781
Johnny Chen16dcf712011-10-17 18:58:00 +0000782 }
783
Greg Claytonf4b47e12010-08-04 01:40:35 +0000784private:
785 std::string m_description;
Johnny Chenfd158f42011-09-21 22:47:15 +0000786 bool m_should_stop;
787 bool m_should_stop_is_valid;
Greg Claytonf4b47e12010-08-04 01:40:35 +0000788};
789
790
791
792//----------------------------------------------------------------------
793// StopInfoUnixSignal
794//----------------------------------------------------------------------
795
796class StopInfoUnixSignal : public StopInfo
797{
798public:
799
800 StopInfoUnixSignal (Thread &thread, int signo) :
Greg Claytona658fd22011-06-04 01:26:29 +0000801 StopInfo (thread, signo)
Greg Claytonf4b47e12010-08-04 01:40:35 +0000802 {
803 }
804
805 virtual ~StopInfoUnixSignal ()
806 {
807 }
808
809
810 virtual StopReason
811 GetStopReason () const
812 {
813 return eStopReasonSignal;
814 }
815
816 virtual bool
Jim Ingham0161b492013-02-09 01:29:05 +0000817 ShouldStopSynchronous (Event *event_ptr)
818 {
819 return m_thread.GetProcess()->GetUnixSignals().GetShouldStop (m_value);
820 }
821
822 virtual bool
Greg Claytonf4b47e12010-08-04 01:40:35 +0000823 ShouldStop (Event *event_ptr)
824 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000825 return m_thread.GetProcess()->GetUnixSignals().GetShouldStop (m_value);
Greg Claytonf4b47e12010-08-04 01:40:35 +0000826 }
827
828
829 // If should stop returns false, check if we should notify of this event
830 virtual bool
831 ShouldNotify (Event *event_ptr)
832 {
Jim Ingham0161b492013-02-09 01:29:05 +0000833 bool should_notify = m_thread.GetProcess()->GetUnixSignals().GetShouldNotify (m_value);
834 if (should_notify)
835 {
836 StreamString strm;
837 strm.Printf ("thread %d received signal: %s",
838 m_thread.GetIndexID(),
839 m_thread.GetProcess()->GetUnixSignals().GetSignalAsCString (m_value));
840 Process::ProcessEventData::AddRestartedReason(event_ptr, strm.GetData());
841 }
842 return should_notify;
Greg Claytonf4b47e12010-08-04 01:40:35 +0000843 }
844
845
846 virtual void
847 WillResume (lldb::StateType resume_state)
848 {
Greg Clayton1ac04c32012-02-21 00:09:25 +0000849 if (m_thread.GetProcess()->GetUnixSignals().GetShouldSuppress(m_value) == false)
Greg Claytonf4b47e12010-08-04 01:40:35 +0000850 m_thread.SetResumeSignal(m_value);
851 }
852
853 virtual const char *
854 GetDescription ()
855 {
856 if (m_description.empty())
857 {
858 StreamString strm;
Greg Clayton1ac04c32012-02-21 00:09:25 +0000859 const char *signal_name = m_thread.GetProcess()->GetUnixSignals().GetSignalAsCString (m_value);
Greg Claytonf4b47e12010-08-04 01:40:35 +0000860 if (signal_name)
Greg Clayton0603aa92010-10-04 01:05:56 +0000861 strm.Printf("signal %s", signal_name);
Greg Claytonf4b47e12010-08-04 01:40:35 +0000862 else
Daniel Malead01b2952012-11-29 21:49:15 +0000863 strm.Printf("signal %" PRIi64, m_value);
Greg Claytonf4b47e12010-08-04 01:40:35 +0000864 m_description.swap (strm.GetString());
865 }
866 return m_description.c_str();
867 }
Greg Claytonf4b47e12010-08-04 01:40:35 +0000868};
869
870//----------------------------------------------------------------------
871// StopInfoTrace
872//----------------------------------------------------------------------
873
874class StopInfoTrace : public StopInfo
875{
876public:
877
878 StopInfoTrace (Thread &thread) :
879 StopInfo (thread, LLDB_INVALID_UID)
880 {
881 }
882
883 virtual ~StopInfoTrace ()
884 {
885 }
886
887 virtual StopReason
888 GetStopReason () const
889 {
890 return eStopReasonTrace;
891 }
892
893 virtual const char *
894 GetDescription ()
895 {
Greg Claytona658fd22011-06-04 01:26:29 +0000896 if (m_description.empty())
Greg Claytonf4b47e12010-08-04 01:40:35 +0000897 return "trace";
Greg Claytona658fd22011-06-04 01:26:29 +0000898 else
899 return m_description.c_str();
900 }
901};
902
903
904//----------------------------------------------------------------------
905// StopInfoException
906//----------------------------------------------------------------------
907
908class StopInfoException : public StopInfo
909{
910public:
911
912 StopInfoException (Thread &thread, const char *description) :
913 StopInfo (thread, LLDB_INVALID_UID)
914 {
915 if (description)
916 SetDescription (description);
917 }
918
919 virtual
920 ~StopInfoException ()
921 {
922 }
923
924 virtual StopReason
925 GetStopReason () const
926 {
927 return eStopReasonException;
928 }
929
930 virtual const char *
931 GetDescription ()
932 {
933 if (m_description.empty())
934 return "exception";
935 else
936 return m_description.c_str();
Greg Claytonf4b47e12010-08-04 01:40:35 +0000937 }
938};
939
940
941//----------------------------------------------------------------------
942// StopInfoThreadPlan
943//----------------------------------------------------------------------
944
945class StopInfoThreadPlan : public StopInfo
946{
947public:
948
Jim Ingham73ca05a2011-12-17 01:35:57 +0000949 StopInfoThreadPlan (ThreadPlanSP &plan_sp, ValueObjectSP &return_valobj_sp) :
Greg Claytonf4b47e12010-08-04 01:40:35 +0000950 StopInfo (plan_sp->GetThread(), LLDB_INVALID_UID),
Jim Ingham73ca05a2011-12-17 01:35:57 +0000951 m_plan_sp (plan_sp),
952 m_return_valobj_sp (return_valobj_sp)
Greg Claytonf4b47e12010-08-04 01:40:35 +0000953 {
954 }
955
956 virtual ~StopInfoThreadPlan ()
957 {
958 }
959
960 virtual StopReason
961 GetStopReason () const
962 {
963 return eStopReasonPlanComplete;
964 }
965
966 virtual const char *
967 GetDescription ()
968 {
969 if (m_description.empty())
970 {
971 StreamString strm;
972 m_plan_sp->GetDescription (&strm, eDescriptionLevelBrief);
973 m_description.swap (strm.GetString());
974 }
975 return m_description.c_str();
976 }
Jim Ingham73ca05a2011-12-17 01:35:57 +0000977
978 ValueObjectSP
979 GetReturnValueObject()
980 {
981 return m_return_valobj_sp;
982 }
Jim Ingham0161b492013-02-09 01:29:05 +0000983
984protected:
985 virtual bool
986 ShouldStop (Event *event_ptr)
987 {
988 if (m_plan_sp)
989 return m_plan_sp->ShouldStop(event_ptr);
990 else
991 return StopInfo::ShouldStop(event_ptr);
992 }
Greg Claytonf4b47e12010-08-04 01:40:35 +0000993
994private:
995 ThreadPlanSP m_plan_sp;
Jim Ingham73ca05a2011-12-17 01:35:57 +0000996 ValueObjectSP m_return_valobj_sp;
Greg Claytonf4b47e12010-08-04 01:40:35 +0000997};
Greg Clayton90ba8112012-12-05 00:16:59 +0000998
999class StopInfoExec : public StopInfo
1000{
1001public:
1002
1003 StopInfoExec (Thread &thread) :
1004 StopInfo (thread, LLDB_INVALID_UID),
1005 m_performed_action (false)
1006 {
1007 }
1008
1009 virtual
1010 ~StopInfoExec ()
1011 {
1012 }
1013
1014 virtual StopReason
1015 GetStopReason () const
1016 {
1017 return eStopReasonExec;
1018 }
1019
1020 virtual const char *
1021 GetDescription ()
1022 {
1023 return "exec";
1024 }
1025protected:
Greg Clayton90ba8112012-12-05 00:16:59 +00001026
1027 virtual void
1028 PerformAction (Event *event_ptr)
1029 {
1030 // Only perform the action once
1031 if (m_performed_action)
1032 return;
1033 m_performed_action = true;
1034 m_thread.GetProcess()->DidExec();
1035 }
1036
1037 bool m_performed_action;
1038};
1039
Jim Ingham4b536182011-08-09 02:12:22 +00001040} // namespace lldb_private
Greg Claytonf4b47e12010-08-04 01:40:35 +00001041
1042StopInfoSP
1043StopInfo::CreateStopReasonWithBreakpointSiteID (Thread &thread, break_id_t break_id)
1044{
1045 return StopInfoSP (new StopInfoBreakpoint (thread, break_id));
1046}
1047
1048StopInfoSP
Jim Ingham36f3b362010-10-14 23:45:03 +00001049StopInfo::CreateStopReasonWithBreakpointSiteID (Thread &thread, break_id_t break_id, bool should_stop)
1050{
1051 return StopInfoSP (new StopInfoBreakpoint (thread, break_id, should_stop));
1052}
1053
1054StopInfoSP
Greg Claytonf4b47e12010-08-04 01:40:35 +00001055StopInfo::CreateStopReasonWithWatchpointID (Thread &thread, break_id_t watch_id)
1056{
1057 return StopInfoSP (new StopInfoWatchpoint (thread, watch_id));
1058}
1059
1060StopInfoSP
1061StopInfo::CreateStopReasonWithSignal (Thread &thread, int signo)
1062{
1063 return StopInfoSP (new StopInfoUnixSignal (thread, signo));
1064}
1065
1066StopInfoSP
1067StopInfo::CreateStopReasonToTrace (Thread &thread)
1068{
1069 return StopInfoSP (new StopInfoTrace (thread));
1070}
1071
1072StopInfoSP
Jim Ingham73ca05a2011-12-17 01:35:57 +00001073StopInfo::CreateStopReasonWithPlan (ThreadPlanSP &plan_sp, ValueObjectSP return_valobj_sp)
Greg Claytonf4b47e12010-08-04 01:40:35 +00001074{
Jim Ingham73ca05a2011-12-17 01:35:57 +00001075 return StopInfoSP (new StopInfoThreadPlan (plan_sp, return_valobj_sp));
Greg Claytonf4b47e12010-08-04 01:40:35 +00001076}
Greg Claytona658fd22011-06-04 01:26:29 +00001077
1078StopInfoSP
1079StopInfo::CreateStopReasonWithException (Thread &thread, const char *description)
1080{
1081 return StopInfoSP (new StopInfoException (thread, description));
1082}
Jim Ingham73ca05a2011-12-17 01:35:57 +00001083
Greg Clayton90ba8112012-12-05 00:16:59 +00001084StopInfoSP
1085StopInfo::CreateStopReasonWithExec (Thread &thread)
1086{
1087 return StopInfoSP (new StopInfoExec (thread));
1088}
1089
Jim Ingham73ca05a2011-12-17 01:35:57 +00001090ValueObjectSP
1091StopInfo::GetReturnValueObject(StopInfoSP &stop_info_sp)
1092{
1093 if (stop_info_sp && stop_info_sp->GetStopReason() == eStopReasonPlanComplete)
1094 {
1095 StopInfoThreadPlan *plan_stop_info = static_cast<StopInfoThreadPlan *>(stop_info_sp.get());
1096 return plan_stop_info->GetReturnValueObject();
1097 }
1098 else
1099 return ValueObjectSP();
1100}