blob: 05e59915a40ac9bcb55020dc8ad7282b5273c7f5 [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) :
Greg Clayton46c2b6e2013-04-29 23:30:46 +000038 m_thread_wp (thread.shared_from_this()),
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 Clayton46c2b6e2013-04-29 23:30:46 +000050 ThreadSP thread_sp (m_thread_wp.lock());
51 if (thread_sp)
52 return thread_sp->GetProcess()->GetStopID() == m_stop_id;
53 return false;
Greg Claytonf4b47e12010-08-04 01:40:35 +000054}
55
Jim Ingham77787032011-01-20 02:03:18 +000056void
57StopInfo::MakeStopInfoValid ()
58{
Greg Clayton46c2b6e2013-04-29 23:30:46 +000059 ThreadSP thread_sp (m_thread_wp.lock());
60 if (thread_sp)
61 {
62 m_stop_id = thread_sp->GetProcess()->GetStopID();
63 m_resume_id = thread_sp->GetProcess()->GetResumeID();
64 }
Jim Ingham77787032011-01-20 02:03:18 +000065}
66
Jim Ingham0faa43f2011-11-08 03:00:11 +000067bool
68StopInfo::HasTargetRunSinceMe ()
Jim Ingham4b536182011-08-09 02:12:22 +000069{
Greg Clayton46c2b6e2013-04-29 23:30:46 +000070 ThreadSP thread_sp (m_thread_wp.lock());
71
72 if (thread_sp)
Jim Ingham0faa43f2011-11-08 03:00:11 +000073 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +000074 lldb::StateType ret_type = thread_sp->GetProcess()->GetPrivateState();
75 if (ret_type == eStateRunning)
Jim Ingham0faa43f2011-11-08 03:00:11 +000076 {
77 return true;
78 }
Greg Clayton46c2b6e2013-04-29 23:30:46 +000079 else if (ret_type == eStateStopped)
80 {
81 // This is a little tricky. We want to count "run and stopped again before you could
82 // ask this question as a "TRUE" answer to HasTargetRunSinceMe. But we don't want to
83 // include any running of the target done for expressions. So we track both resumes,
84 // and resumes caused by expressions, and check if there are any resumes NOT caused
85 // by expressions.
86
87 uint32_t curr_resume_id = thread_sp->GetProcess()->GetResumeID();
88 uint32_t last_user_expression_id = thread_sp->GetProcess()->GetLastUserExpressionResumeID ();
89 if (curr_resume_id == m_resume_id)
90 {
91 return false;
92 }
93 else if (curr_resume_id > last_user_expression_id)
94 {
95 return true;
96 }
97 }
Jim Ingham0faa43f2011-11-08 03:00:11 +000098 }
99 return false;
Jim Ingham4b536182011-08-09 02:12:22 +0000100}
101
Greg Claytonf4b47e12010-08-04 01:40:35 +0000102//----------------------------------------------------------------------
103// StopInfoBreakpoint
104//----------------------------------------------------------------------
105
Jim Ingham4b536182011-08-09 02:12:22 +0000106namespace lldb_private
107{
Greg Claytonf4b47e12010-08-04 01:40:35 +0000108class StopInfoBreakpoint : public StopInfo
109{
110public:
111
112 StopInfoBreakpoint (Thread &thread, break_id_t break_id) :
113 StopInfo (thread, break_id),
114 m_description(),
115 m_should_stop (false),
Jim Ingham0f16e732011-02-08 05:20:59 +0000116 m_should_stop_is_valid (false),
Jim Ingham52c7d202011-10-28 01:12:19 +0000117 m_should_perform_action (true),
Jim Inghamca36cd12012-10-05 19:16:31 +0000118 m_address (LLDB_INVALID_ADDRESS),
119 m_break_id(LLDB_INVALID_BREAK_ID),
120 m_was_one_shot (false)
Greg Claytonf4b47e12010-08-04 01:40:35 +0000121 {
Jim Inghamca36cd12012-10-05 19:16:31 +0000122 StoreBPInfo();
Greg Claytonf4b47e12010-08-04 01:40:35 +0000123 }
124
Jim Ingham36f3b362010-10-14 23:45:03 +0000125 StopInfoBreakpoint (Thread &thread, break_id_t break_id, bool should_stop) :
126 StopInfo (thread, break_id),
127 m_description(),
128 m_should_stop (should_stop),
Jim Ingham0f16e732011-02-08 05:20:59 +0000129 m_should_stop_is_valid (true),
Jim Ingham52c7d202011-10-28 01:12:19 +0000130 m_should_perform_action (true),
Jim Inghamca36cd12012-10-05 19:16:31 +0000131 m_address (LLDB_INVALID_ADDRESS),
132 m_break_id(LLDB_INVALID_BREAK_ID),
133 m_was_one_shot (false)
134 {
135 StoreBPInfo();
136 }
137
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000138 void
139 StoreBPInfo ()
Jim Ingham36f3b362010-10-14 23:45:03 +0000140 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000141 ThreadSP thread_sp (m_thread_wp.lock());
142 if (thread_sp)
Jim Ingham52c7d202011-10-28 01:12:19 +0000143 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000144 BreakpointSiteSP bp_site_sp (thread_sp->GetProcess()->GetBreakpointSiteList().FindByID (m_value));
145 if (bp_site_sp)
Jim Inghamca36cd12012-10-05 19:16:31 +0000146 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000147 if (bp_site_sp->GetNumberOfOwners() == 1)
Jim Inghamca36cd12012-10-05 19:16:31 +0000148 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000149 BreakpointLocationSP bp_loc_sp = bp_site_sp->GetOwnerAtIndex(0);
150 if (bp_loc_sp)
151 {
152 m_break_id = bp_loc_sp->GetBreakpoint().GetID();
153 m_was_one_shot = bp_loc_sp->GetBreakpoint().IsOneShot();
154 }
Jim Inghamca36cd12012-10-05 19:16:31 +0000155 }
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000156 m_address = bp_site_sp->GetLoadAddress();
Jim Inghamca36cd12012-10-05 19:16:31 +0000157 }
Jim Ingham52c7d202011-10-28 01:12:19 +0000158 }
Jim Ingham36f3b362010-10-14 23:45:03 +0000159 }
160
Greg Claytonf4b47e12010-08-04 01:40:35 +0000161 virtual ~StopInfoBreakpoint ()
162 {
163 }
164
165 virtual StopReason
166 GetStopReason () const
167 {
168 return eStopReasonBreakpoint;
169 }
170
171 virtual bool
Jim Ingham6d66ce62012-04-20 21:16:56 +0000172 ShouldStopSynchronous (Event *event_ptr)
Greg Claytonf4b47e12010-08-04 01:40:35 +0000173 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000174 ThreadSP thread_sp (m_thread_wp.lock());
175 if (thread_sp)
Greg Claytonf4b47e12010-08-04 01:40:35 +0000176 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000177 if (!m_should_stop_is_valid)
Greg Claytonf4b47e12010-08-04 01:40:35 +0000178 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000179 // Only check once if we should stop at a breakpoint
180 BreakpointSiteSP bp_site_sp (thread_sp->GetProcess()->GetBreakpointSiteList().FindByID (m_value));
181 if (bp_site_sp)
182 {
183 ExecutionContext exe_ctx (thread_sp->GetStackFrameAtIndex(0));
184 StoppointCallbackContext context (event_ptr, exe_ctx, true);
185 m_should_stop = bp_site_sp->ShouldStop (&context);
186 }
187 else
188 {
189 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
Greg Claytonf4b47e12010-08-04 01:40:35 +0000190
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000191 if (log)
192 log->Printf ("Process::%s could not find breakpoint site id: %" PRId64 "...", __FUNCTION__, m_value);
Greg Claytonf4b47e12010-08-04 01:40:35 +0000193
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000194 m_should_stop = true;
195 }
196 m_should_stop_is_valid = true;
Greg Claytonf4b47e12010-08-04 01:40:35 +0000197 }
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000198 return m_should_stop;
Greg Claytonf4b47e12010-08-04 01:40:35 +0000199 }
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000200 return false;
Greg Claytonf4b47e12010-08-04 01:40:35 +0000201 }
Jim Ingham3ebcf7f2010-08-10 00:59:59 +0000202
Jim Inghamf57b4352012-11-10 02:08:14 +0000203 virtual bool
204 ShouldNotify (Event *event_ptr)
205 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000206 ThreadSP thread_sp (m_thread_wp.lock());
207 if (thread_sp)
Jim Inghamf57b4352012-11-10 02:08:14 +0000208 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000209 BreakpointSiteSP bp_site_sp (thread_sp->GetProcess()->GetBreakpointSiteList().FindByID (m_value));
210 if (bp_site_sp)
Jim Inghamf57b4352012-11-10 02:08:14 +0000211 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000212 bool all_internal = true;
213
214 for (uint32_t i = 0; i < bp_site_sp->GetNumberOfOwners(); i++)
Jim Inghamf57b4352012-11-10 02:08:14 +0000215 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000216 if (!bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint().IsInternal())
217 {
218 all_internal = false;
219 break;
220 }
Jim Inghamf57b4352012-11-10 02:08:14 +0000221 }
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000222 return all_internal == false;
Jim Inghamf57b4352012-11-10 02:08:14 +0000223 }
Jim Inghamf57b4352012-11-10 02:08:14 +0000224 }
225 return true;
226 }
227
228 virtual const char *
229 GetDescription ()
230 {
231 if (m_description.empty())
232 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000233 ThreadSP thread_sp (m_thread_wp.lock());
234 if (thread_sp)
Jim Inghamf57b4352012-11-10 02:08:14 +0000235 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000236 BreakpointSiteSP bp_site_sp (thread_sp->GetProcess()->GetBreakpointSiteList().FindByID (m_value));
237 if (bp_site_sp)
Jim Ingham29950772013-01-26 02:19:28 +0000238 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000239 StreamString strm;
240 // If we have just hit an internal breakpoint, and it has a kind description, print that instead of the
241 // full breakpoint printing:
242 if (bp_site_sp->IsInternal())
Jim Ingham29950772013-01-26 02:19:28 +0000243 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000244 size_t num_owners = bp_site_sp->GetNumberOfOwners();
245 for (size_t idx = 0; idx < num_owners; idx++)
Jim Ingham29950772013-01-26 02:19:28 +0000246 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000247 const char *kind = bp_site_sp->GetOwnerAtIndex(idx)->GetBreakpoint().GetBreakpointKind();
248 if (kind != NULL)
249 {
250 m_description.assign (kind);
251 return kind;
252 }
Jim Ingham29950772013-01-26 02:19:28 +0000253 }
254 }
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000255
256 strm.Printf("breakpoint ");
257 bp_site_sp->GetDescription(&strm, eDescriptionLevelBrief);
258 m_description.swap (strm.GetString());
Jim Ingham29950772013-01-26 02:19:28 +0000259 }
Jim Inghamf57b4352012-11-10 02:08:14 +0000260 else
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000261 {
262 StreamString strm;
263 if (m_break_id != LLDB_INVALID_BREAK_ID)
264 {
265 BreakpointSP break_sp = thread_sp->GetProcess()->GetTarget().GetBreakpointByID(m_break_id);
266 if (break_sp)
267 {
268 if (break_sp->IsInternal())
269 {
270 const char *kind = break_sp->GetBreakpointKind();
271 if (kind)
272 strm.Printf ("internal %s breakpoint(%d).", kind, m_break_id);
273 else
274 strm.Printf ("internal breakpoint(%d).", m_break_id);
275 }
276 else
277 {
278 strm.Printf ("breakpoint %d.", m_break_id);
279 }
280 }
281 else
282 {
283 if (m_was_one_shot)
284 strm.Printf ("one-shot breakpoint %d", m_break_id);
285 else
286 strm.Printf ("breakpoint %d which has been deleted.", m_break_id);
287 }
288 }
289 else if (m_address == LLDB_INVALID_ADDRESS)
290 strm.Printf("breakpoint site %" PRIi64 " which has been deleted - unknown address", m_value);
291 else
292 strm.Printf("breakpoint site %" PRIi64 " which has been deleted - was at 0x%" PRIx64, m_value, m_address);
293
294 m_description.swap (strm.GetString());
295 }
Jim Inghamf57b4352012-11-10 02:08:14 +0000296 }
297 }
298 return m_description.c_str();
299 }
300
301protected:
Jim Ingham6d66ce62012-04-20 21:16:56 +0000302 bool
303 ShouldStop (Event *event_ptr)
304 {
305 // This just reports the work done by PerformAction or the synchronous stop. It should
306 // only ever get called after they have had a chance to run.
307 assert (m_should_stop_is_valid);
308 return m_should_stop;
309 }
310
Jim Ingham3ebcf7f2010-08-10 00:59:59 +0000311 virtual void
312 PerformAction (Event *event_ptr)
313 {
Jim Ingham0f16e732011-02-08 05:20:59 +0000314 if (!m_should_perform_action)
315 return;
316 m_should_perform_action = false;
317
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000318 ThreadSP thread_sp (m_thread_wp.lock());
319
320 if (thread_sp)
Jim Ingham5cb9a182013-03-28 00:13:30 +0000321 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000322 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS);
323
324 if (!thread_sp->IsValid())
Jim Ingham3ebcf7f2010-08-10 00:59:59 +0000325 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000326 // This shouldn't ever happen, but just in case, don't do more harm.
327 log->Printf ("PerformAction got called with an invalid thread.");
Jim Ingham79ea1d82011-12-09 04:17:31 +0000328 m_should_stop = true;
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000329 m_should_stop_is_valid = true;
330 return;
Jim Ingham79ea1d82011-12-09 04:17:31 +0000331 }
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000332
333 BreakpointSiteSP bp_site_sp (thread_sp->GetProcess()->GetBreakpointSiteList().FindByID (m_value));
334
335 if (bp_site_sp)
Jim Ingham79ea1d82011-12-09 04:17:31 +0000336 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000337 size_t num_owners = bp_site_sp->GetNumberOfOwners();
Jim Ingham184e9812013-01-15 02:47:48 +0000338
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000339 if (num_owners == 0)
340 {
341 m_should_stop = true;
Jim Ingham184e9812013-01-15 02:47:48 +0000342 }
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000343 else
Jim Ingham4b536182011-08-09 02:12:22 +0000344 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000345 // We go through each location, and test first its condition. If the condition says to stop,
346 // then we run the callback for that location. If that callback says to stop as well, then
347 // we set m_should_stop to true; we are going to stop.
348 // But we still want to give all the breakpoints whose conditions say we are going to stop a
349 // chance to run their callbacks.
350 // Of course if any callback restarts the target by putting "continue" in the callback, then
351 // we're going to restart, without running the rest of the callbacks. And in this case we will
352 // end up not stopping even if another location said we should stop. But that's better than not
353 // running all the callbacks.
Jim Inghamdbd3c4d2013-04-11 22:53:47 +0000354
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000355 m_should_stop = false;
356
357 ExecutionContext exe_ctx (thread_sp->GetStackFrameAtIndex(0));
358 Process *process = exe_ctx.GetProcessPtr();
359 if (process->GetModIDRef().IsLastResumeForUserExpression())
Jim Ingham4b536182011-08-09 02:12:22 +0000360 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000361 // If we are in the middle of evaluating an expression, don't run asynchronous breakpoint commands or
362 // expressions. That could lead to infinite recursion if the command or condition re-calls the function
363 // with this breakpoint.
364 // TODO: We can keep a list of the breakpoints we've seen while running expressions in the nested
365 // PerformAction calls that can arise when the action runs a function that hits another breakpoint,
366 // and only stop running commands when we see the same breakpoint hit a second time.
Jim Ingham4b536182011-08-09 02:12:22 +0000367
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000368 m_should_stop_is_valid = true;
369 if (log)
370 log->Printf ("StopInfoBreakpoint::PerformAction - Hit a breakpoint while running an expression,"
371 " not running commands to avoid recursion.");
372 bool ignoring_breakpoints = process->GetIgnoreBreakpointsInExpressions();
373 if (ignoring_breakpoints)
Jim Ingham4b536182011-08-09 02:12:22 +0000374 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000375 m_should_stop = false;
376 // Internal breakpoints will always stop.
377 for (size_t j = 0; j < num_owners; j++)
378 {
379 lldb::BreakpointLocationSP bp_loc_sp = bp_site_sp->GetOwnerAtIndex(j);
380 if (bp_loc_sp->GetBreakpoint().IsInternal())
381 {
382 m_should_stop = true;
383 break;
384 }
385 }
Jim Ingham4b536182011-08-09 02:12:22 +0000386 }
Sean Callanan3dbf3462013-04-19 07:09:15 +0000387 else
388 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000389 m_should_stop = true;
390 }
391 if (log)
392 log->Printf ("StopInfoBreakpoint::PerformAction - in expression, continuing: %s.",
393 m_should_stop ? "true" : "false");
394 process->GetTarget().GetDebugger().GetAsyncOutputStream()->Printf("Warning: hit breakpoint while "
395 "running function, skipping commands and conditions to prevent recursion.");
396 return;
397 }
398
399 StoppointCallbackContext context (event_ptr, exe_ctx, false);
400
401 // Let's copy the breakpoint locations out of the site and store them in a local list. That way if
402 // one of the breakpoint actions changes the site, then we won't be operating on a bad list.
403
404 BreakpointLocationCollection site_locations;
405 for (size_t j = 0; j < num_owners; j++)
406 site_locations.Add(bp_site_sp->GetOwnerAtIndex(j));
407
408 for (size_t j = 0; j < num_owners; j++)
409 {
410 lldb::BreakpointLocationSP bp_loc_sp = site_locations.GetByIndex(j);
411
412 // If another action disabled this breakpoint or its location, then don't run the actions.
413 if (!bp_loc_sp->IsEnabled() || !bp_loc_sp->GetBreakpoint().IsEnabled())
414 continue;
415
416 // The breakpoint site may have many locations associated with it, not all of them valid for
417 // this thread. Skip the ones that aren't:
418 if (!bp_loc_sp->ValidForThisThread(thread_sp.get()))
419 continue;
420
421 // First run the condition for the breakpoint. If that says we should stop, then we'll run
422 // the callback for the breakpoint. If the callback says we shouldn't stop that will win.
423
424 if (bp_loc_sp->GetConditionText() != NULL)
425 {
426 Error condition_error;
427 bool condition_says_stop = bp_loc_sp->ConditionSaysStop(exe_ctx, condition_error);
428
429 if (!condition_error.Success())
430 {
431 Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger();
432 StreamSP error_sp = debugger.GetAsyncErrorStream ();
433 error_sp->Printf ("Stopped due to an error evaluating condition of breakpoint ");
434 bp_loc_sp->GetDescription (error_sp.get(), eDescriptionLevelBrief);
435 error_sp->Printf (": \"%s\"",
436 bp_loc_sp->GetConditionText());
437 error_sp->EOL();
438 const char *err_str = condition_error.AsCString("<Unknown Error>");
439 if (log)
440 log->Printf("Error evaluating condition: \"%s\"\n", err_str);
441
442 error_sp->PutCString (err_str);
443 error_sp->EOL();
444 error_sp->Flush();
445 // If the condition fails to be parsed or run, we should stop.
446 condition_says_stop = true;
447 }
448 else
449 {
450 if (!condition_says_stop)
451 continue;
452 }
453 }
454
455 bool callback_says_stop;
456
457 // FIXME: For now the callbacks have to run in async mode - the first time we restart we need
458 // to get out of there. So set it here.
459 // When we figure out how to nest breakpoint hits then this will change.
460
461 Debugger &debugger = thread_sp->CalculateTarget()->GetDebugger();
462 bool old_async = debugger.GetAsyncExecution();
463 debugger.SetAsyncExecution (true);
464
465 callback_says_stop = bp_loc_sp->InvokeCallback (&context);
466
467 debugger.SetAsyncExecution (old_async);
468
469 if (callback_says_stop)
470 m_should_stop = true;
471
472 // If we are going to stop for this breakpoint, then remove the breakpoint.
473 if (callback_says_stop && bp_loc_sp && bp_loc_sp->GetBreakpoint().IsOneShot())
474 {
475 thread_sp->GetProcess()->GetTarget().RemoveBreakpointByID (bp_loc_sp->GetBreakpoint().GetID());
476 }
477
478 // Also make sure that the callback hasn't continued the target.
479 // If it did, when we'll set m_should_start to false and get out of here.
480 if (HasTargetRunSinceMe ())
481 {
482 m_should_stop = false;
483 break;
Sean Callanan3dbf3462013-04-19 07:09:15 +0000484 }
Jim Ingham4b536182011-08-09 02:12:22 +0000485 }
Jim Ingham4b536182011-08-09 02:12:22 +0000486 }
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000487 // We've figured out what this stop wants to do, so mark it as valid so we don't compute it again.
488 m_should_stop_is_valid = true;
489
Jim Ingham3ebcf7f2010-08-10 00:59:59 +0000490 }
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000491 else
492 {
493 m_should_stop = true;
494 m_should_stop_is_valid = true;
495 Log * log_process(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
Jim Ingham79ea1d82011-12-09 04:17:31 +0000496
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000497 if (log_process)
498 log_process->Printf ("Process::%s could not find breakpoint site id: %" PRId64 "...", __FUNCTION__, m_value);
499 }
500 if (log)
501 log->Printf ("Process::%s returning from action with m_should_stop: %d.", __FUNCTION__, m_should_stop);
Jim Ingham3ebcf7f2010-08-10 00:59:59 +0000502 }
Jim Ingham3ebcf7f2010-08-10 00:59:59 +0000503 }
Greg Claytonf4b47e12010-08-04 01:40:35 +0000504
505private:
506 std::string m_description;
507 bool m_should_stop;
508 bool m_should_stop_is_valid;
Jim Ingham0f16e732011-02-08 05:20:59 +0000509 bool m_should_perform_action; // Since we are trying to preserve the "state" of the system even if we run functions
510 // etc. behind the users backs, we need to make sure we only REALLY perform the action once.
Jim Ingham52c7d202011-10-28 01:12:19 +0000511 lldb::addr_t m_address; // We use this to capture the breakpoint site address when we create the StopInfo,
512 // in case somebody deletes it between the time the StopInfo is made and the
513 // description is asked for.
Jim Inghamca36cd12012-10-05 19:16:31 +0000514 lldb::break_id_t m_break_id;
515 bool m_was_one_shot;
Greg Claytonf4b47e12010-08-04 01:40:35 +0000516};
517
518
519//----------------------------------------------------------------------
520// StopInfoWatchpoint
521//----------------------------------------------------------------------
522
523class StopInfoWatchpoint : public StopInfo
524{
525public:
Jim Inghamf57b4352012-11-10 02:08:14 +0000526 // Make sure watchpoint is properly disabled and subsequently enabled while performing watchpoint actions.
527 class WatchpointSentry {
528 public:
529 WatchpointSentry(Process *p, Watchpoint *w):
530 process(p),
531 watchpoint(w)
532 {
533 if (process && watchpoint)
534 {
Jim Ingham1b5792e2012-12-18 02:03:49 +0000535 const bool notify = false;
Jim Inghamf57b4352012-11-10 02:08:14 +0000536 watchpoint->TurnOnEphemeralMode();
Jim Ingham1b5792e2012-12-18 02:03:49 +0000537 process->DisableWatchpoint(watchpoint, notify);
Jim Inghamf57b4352012-11-10 02:08:14 +0000538 }
539 }
540 ~WatchpointSentry()
541 {
542 if (process && watchpoint)
543 {
544 if (!watchpoint->IsDisabledDuringEphemeralMode())
Jim Ingham1b5792e2012-12-18 02:03:49 +0000545 {
546 const bool notify = false;
547 process->EnableWatchpoint(watchpoint, notify);
548 }
Jim Inghamf57b4352012-11-10 02:08:14 +0000549 watchpoint->TurnOffEphemeralMode();
550 }
551 }
552 private:
553 Process *process;
554 Watchpoint *watchpoint;
555 };
Greg Claytonf4b47e12010-08-04 01:40:35 +0000556
557 StopInfoWatchpoint (Thread &thread, break_id_t watch_id) :
Johnny Chenfd158f42011-09-21 22:47:15 +0000558 StopInfo(thread, watch_id),
559 m_description(),
560 m_should_stop(false),
561 m_should_stop_is_valid(false)
Greg Claytonf4b47e12010-08-04 01:40:35 +0000562 {
563 }
564
565 virtual ~StopInfoWatchpoint ()
566 {
567 }
568
569 virtual StopReason
570 GetStopReason () const
571 {
572 return eStopReasonWatchpoint;
573 }
574
Jim Inghamf57b4352012-11-10 02:08:14 +0000575 virtual const char *
576 GetDescription ()
577 {
578 if (m_description.empty())
579 {
580 StreamString strm;
Daniel Malead01b2952012-11-29 21:49:15 +0000581 strm.Printf("watchpoint %" PRIi64, m_value);
Jim Inghamf57b4352012-11-10 02:08:14 +0000582 m_description.swap (strm.GetString());
583 }
584 return m_description.c_str();
585 }
586
587protected:
Johnny Chenfd158f42011-09-21 22:47:15 +0000588 virtual bool
Jim Ingham9b620f32013-02-22 21:23:43 +0000589 ShouldStopSynchronous (Event *event_ptr)
Johnny Chenfd158f42011-09-21 22:47:15 +0000590 {
591 // ShouldStop() method is idempotent and should not affect hit count.
Johnny Chen16dcf712011-10-17 18:58:00 +0000592 // See Process::RunPrivateStateThread()->Process()->HandlePrivateEvent()
593 // -->Process()::ShouldBroadcastEvent()->ThreadList::ShouldStop()->
594 // Thread::ShouldStop()->ThreadPlanBase::ShouldStop()->
595 // StopInfoWatchpoint::ShouldStop() and
596 // Event::DoOnRemoval()->Process::ProcessEventData::DoOnRemoval()->
597 // StopInfoWatchpoint::PerformAction().
Johnny Chenfd158f42011-09-21 22:47:15 +0000598 if (m_should_stop_is_valid)
599 return m_should_stop;
600
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000601 ThreadSP thread_sp (m_thread_wp.lock());
602 if (thread_sp)
Johnny Chenfd158f42011-09-21 22:47:15 +0000603 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000604 WatchpointSP wp_sp (thread_sp->CalculateTarget()->GetWatchpointList().FindByID(GetValue()));
605 if (wp_sp)
606 {
607 // Check if we should stop at a watchpoint.
608 ExecutionContext exe_ctx (thread_sp->GetStackFrameAtIndex(0));
609 StoppointCallbackContext context (event_ptr, exe_ctx, true);
610 m_should_stop = wp_sp->ShouldStop (&context);
611 }
612 else
613 {
614 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
Johnny Chenfd158f42011-09-21 22:47:15 +0000615
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000616 if (log)
617 log->Printf ("Process::%s could not find watchpoint location id: %" PRId64 "...",
618 __FUNCTION__, GetValue());
Johnny Chenfd158f42011-09-21 22:47:15 +0000619
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000620 m_should_stop = true;
621 }
Johnny Chenfd158f42011-09-21 22:47:15 +0000622 }
623 m_should_stop_is_valid = true;
624 return m_should_stop;
625 }
626
Jim Ingham9b620f32013-02-22 21:23:43 +0000627 bool
628 ShouldStop (Event *event_ptr)
629 {
630 // This just reports the work done by PerformAction or the synchronous stop. It should
631 // only ever get called after they have had a chance to run.
632 assert (m_should_stop_is_valid);
633 return m_should_stop;
634 }
635
Johnny Chen16dcf712011-10-17 18:58:00 +0000636 virtual void
637 PerformAction (Event *event_ptr)
638 {
Greg Clayton5160ce52013-03-27 23:08:40 +0000639 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS);
Johnny Chen16dcf712011-10-17 18:58:00 +0000640 // We're going to calculate if we should stop or not in some way during the course of
641 // this code. Also by default we're going to stop, so set that here.
642 m_should_stop = true;
643
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000644 ThreadSP thread_sp (m_thread_wp.lock());
645 if (thread_sp)
Johnny Chen16dcf712011-10-17 18:58:00 +0000646 {
Johnny Chen0f7ad8d2012-08-21 22:06:34 +0000647
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000648 WatchpointSP wp_sp (thread_sp->CalculateTarget()->GetWatchpointList().FindByID(GetValue()));
649 if (wp_sp)
Enrico Granataf04a2192012-07-13 23:18:48 +0000650 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000651 ExecutionContext exe_ctx (thread_sp->GetStackFrameAtIndex(0));
652 Process* process = exe_ctx.GetProcessPtr();
653
654 // This sentry object makes sure the current watchpoint is disabled while performing watchpoint actions,
655 // and it is then enabled after we are finished.
656 WatchpointSentry sentry(process, wp_sp.get());
657
Enrico Granataf04a2192012-07-13 23:18:48 +0000658 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000659 // check if this process is running on an architecture where watchpoints trigger
660 // before the associated instruction runs. if so, disable the WP, single-step and then
661 // re-enable the watchpoint
662 if (process)
Enrico Granataf04a2192012-07-13 23:18:48 +0000663 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000664 uint32_t num; bool wp_triggers_after;
665 if (process->GetWatchpointSupportInfo(num, wp_triggers_after).Success())
Enrico Granataf04a2192012-07-13 23:18:48 +0000666 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000667 if (!wp_triggers_after)
668 {
669 ThreadPlan *new_plan = thread_sp->QueueThreadPlanForStepSingleInstruction(false, // step-over
670 false, // abort_other_plans
671 true); // stop_other_threads
672 new_plan->SetIsMasterPlan (true);
673 new_plan->SetOkayToDiscard (false);
674 process->GetThreadList().SetSelectedThreadByID (thread_sp->GetID());
675 process->Resume ();
676 process->WaitForProcessToStop (NULL);
677 process->GetThreadList().SetSelectedThreadByID (thread_sp->GetID());
678 MakeStopInfoValid(); // make sure we do not fail to stop because of the single-step taken above
679 }
Enrico Granataf04a2192012-07-13 23:18:48 +0000680 }
681 }
682 }
Johnny Chen209bd652012-08-13 21:09:54 +0000683
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000684 if (m_should_stop && wp_sp->GetConditionText() != NULL)
Johnny Chen16dcf712011-10-17 18:58:00 +0000685 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000686 // We need to make sure the user sees any parse errors in their condition, so we'll hook the
687 // constructor errors up to the debugger's Async I/O.
688 ExecutionResults result_code;
689 ValueObjectSP result_value_sp;
690 const bool unwind_on_error = true;
691 const bool ignore_breakpoints = true;
692 Error error;
693 result_code = ClangUserExpression::EvaluateWithError (exe_ctx,
694 eExecutionPolicyOnlyWhenNeeded,
695 lldb::eLanguageTypeUnknown,
696 ClangUserExpression::eResultTypeAny,
697 unwind_on_error,
698 ignore_breakpoints,
699 wp_sp->GetConditionText(),
700 NULL,
701 result_value_sp,
702 error,
703 true,
704 ClangUserExpression::kDefaultTimeout);
705 if (result_code == eExecutionCompleted)
Johnny Chen16dcf712011-10-17 18:58:00 +0000706 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000707 if (result_value_sp)
Johnny Chen16dcf712011-10-17 18:58:00 +0000708 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000709 Scalar scalar_value;
710 if (result_value_sp->ResolveValue (scalar_value))
Johnny Chen16dcf712011-10-17 18:58:00 +0000711 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000712 if (scalar_value.ULongLong(1) == 0)
713 {
714 // We have been vetoed. This takes precedence over querying
715 // the watchpoint whether it should stop (aka ignore count and
716 // friends). See also StopInfoWatchpoint::ShouldStop() as well
717 // as Process::ProcessEventData::DoOnRemoval().
718 m_should_stop = false;
719 }
720 else
721 m_should_stop = true;
722 if (log)
723 log->Printf("Condition successfully evaluated, result is %s.\n",
724 m_should_stop ? "true" : "false");
Johnny Chen16dcf712011-10-17 18:58:00 +0000725 }
726 else
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000727 {
Johnny Chen16dcf712011-10-17 18:58:00 +0000728 m_should_stop = true;
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000729 if (log)
730 log->Printf("Failed to get an integer result from the expression.");
731 }
Johnny Chen16dcf712011-10-17 18:58:00 +0000732 }
733 }
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000734 else
735 {
736 Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger();
737 StreamSP error_sp = debugger.GetAsyncErrorStream ();
738 error_sp->Printf ("Stopped due to an error evaluating condition of watchpoint ");
739 wp_sp->GetDescription (error_sp.get(), eDescriptionLevelBrief);
740 error_sp->Printf (": \"%s\"",
741 wp_sp->GetConditionText());
742 error_sp->EOL();
743 const char *err_str = error.AsCString("<Unknown Error>");
744 if (log)
745 log->Printf("Error evaluating condition: \"%s\"\n", err_str);
746
747 error_sp->PutCString (err_str);
748 error_sp->EOL();
749 error_sp->Flush();
750 // If the condition fails to be parsed or run, we should stop.
751 m_should_stop = true;
752 }
Johnny Chen16dcf712011-10-17 18:58:00 +0000753 }
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000754
755 // If the condition says to stop, we run the callback to further decide whether to stop.
756 if (m_should_stop)
Johnny Chen16dcf712011-10-17 18:58:00 +0000757 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000758 StoppointCallbackContext context (event_ptr, exe_ctx, false);
759 bool stop_requested = wp_sp->InvokeCallback (&context);
760 // Also make sure that the callback hasn't continued the target.
761 // If it did, when we'll set m_should_stop to false and get out of here.
762 if (HasTargetRunSinceMe ())
763 m_should_stop = false;
764
765 if (m_should_stop && !stop_requested)
766 {
767 // We have been vetoed by the callback mechanism.
768 m_should_stop = false;
769 }
770 }
771 // Finally, if we are going to stop, print out the new & old values:
772 if (m_should_stop)
773 {
774 wp_sp->CaptureWatchedValue(exe_ctx);
775
Greg Clayton1ac04c32012-02-21 00:09:25 +0000776 Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger();
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000777 StreamSP output_sp = debugger.GetAsyncOutputStream ();
778 wp_sp->DumpSnapshots(output_sp.get());
779 output_sp->EOL();
780 output_sp->Flush();
Johnny Chen16dcf712011-10-17 18:58:00 +0000781 }
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000782
Johnny Chen16dcf712011-10-17 18:58:00 +0000783 }
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000784 else
785 {
786 Log * log_process(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
Johnny Chen13206412012-08-09 23:10:57 +0000787
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000788 if (log_process)
789 log_process->Printf ("Process::%s could not find watchpoint id: %" PRId64 "...", __FUNCTION__, m_value);
Johnny Chen13206412012-08-09 23:10:57 +0000790 }
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000791 if (log)
792 log->Printf ("Process::%s returning from action with m_should_stop: %d.", __FUNCTION__, m_should_stop);
Jim Inghama7dfb662012-10-23 07:20:06 +0000793
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000794 m_should_stop_is_valid = true;
Johnny Chen16dcf712011-10-17 18:58:00 +0000795 }
Johnny Chen16dcf712011-10-17 18:58:00 +0000796 }
797
Greg Claytonf4b47e12010-08-04 01:40:35 +0000798private:
799 std::string m_description;
Johnny Chenfd158f42011-09-21 22:47:15 +0000800 bool m_should_stop;
801 bool m_should_stop_is_valid;
Greg Claytonf4b47e12010-08-04 01:40:35 +0000802};
803
804
805
806//----------------------------------------------------------------------
807// StopInfoUnixSignal
808//----------------------------------------------------------------------
809
810class StopInfoUnixSignal : public StopInfo
811{
812public:
813
814 StopInfoUnixSignal (Thread &thread, int signo) :
Greg Claytona658fd22011-06-04 01:26:29 +0000815 StopInfo (thread, signo)
Greg Claytonf4b47e12010-08-04 01:40:35 +0000816 {
817 }
818
819 virtual ~StopInfoUnixSignal ()
820 {
821 }
822
823
824 virtual StopReason
825 GetStopReason () const
826 {
827 return eStopReasonSignal;
828 }
829
830 virtual bool
Jim Ingham0161b492013-02-09 01:29:05 +0000831 ShouldStopSynchronous (Event *event_ptr)
832 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000833 ThreadSP thread_sp (m_thread_wp.lock());
834 if (thread_sp)
835 return thread_sp->GetProcess()->GetUnixSignals().GetShouldStop (m_value);
836 return false;
Jim Ingham0161b492013-02-09 01:29:05 +0000837 }
838
839 virtual bool
Greg Claytonf4b47e12010-08-04 01:40:35 +0000840 ShouldStop (Event *event_ptr)
841 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000842 ThreadSP thread_sp (m_thread_wp.lock());
843 if (thread_sp)
844 return thread_sp->GetProcess()->GetUnixSignals().GetShouldStop (m_value);
845 return false;
Greg Claytonf4b47e12010-08-04 01:40:35 +0000846 }
847
848
849 // If should stop returns false, check if we should notify of this event
850 virtual bool
851 ShouldNotify (Event *event_ptr)
852 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000853 ThreadSP thread_sp (m_thread_wp.lock());
854 if (thread_sp)
Jim Ingham0161b492013-02-09 01:29:05 +0000855 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000856 bool should_notify = thread_sp->GetProcess()->GetUnixSignals().GetShouldNotify (m_value);
857 if (should_notify)
858 {
859 StreamString strm;
860 strm.Printf ("thread %d received signal: %s",
861 thread_sp->GetIndexID(),
862 thread_sp->GetProcess()->GetUnixSignals().GetSignalAsCString (m_value));
863 Process::ProcessEventData::AddRestartedReason(event_ptr, strm.GetData());
864 }
865 return should_notify;
Jim Ingham0161b492013-02-09 01:29:05 +0000866 }
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000867 return true;
Greg Claytonf4b47e12010-08-04 01:40:35 +0000868 }
869
870
871 virtual void
872 WillResume (lldb::StateType resume_state)
873 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000874 ThreadSP thread_sp (m_thread_wp.lock());
875 if (thread_sp)
876 {
877 if (thread_sp->GetProcess()->GetUnixSignals().GetShouldSuppress(m_value) == false)
878 thread_sp->SetResumeSignal(m_value);
879 }
Greg Claytonf4b47e12010-08-04 01:40:35 +0000880 }
881
882 virtual const char *
883 GetDescription ()
884 {
885 if (m_description.empty())
886 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000887 ThreadSP thread_sp (m_thread_wp.lock());
888 if (thread_sp)
889 {
890 StreamString strm;
891 const char *signal_name = thread_sp->GetProcess()->GetUnixSignals().GetSignalAsCString (m_value);
892 if (signal_name)
893 strm.Printf("signal %s", signal_name);
894 else
895 strm.Printf("signal %" PRIi64, m_value);
896 m_description.swap (strm.GetString());
897 }
Greg Claytonf4b47e12010-08-04 01:40:35 +0000898 }
899 return m_description.c_str();
900 }
Greg Claytonf4b47e12010-08-04 01:40:35 +0000901};
902
903//----------------------------------------------------------------------
904// StopInfoTrace
905//----------------------------------------------------------------------
906
907class StopInfoTrace : public StopInfo
908{
909public:
910
911 StopInfoTrace (Thread &thread) :
912 StopInfo (thread, LLDB_INVALID_UID)
913 {
914 }
915
916 virtual ~StopInfoTrace ()
917 {
918 }
919
920 virtual StopReason
921 GetStopReason () const
922 {
923 return eStopReasonTrace;
924 }
925
926 virtual const char *
927 GetDescription ()
928 {
Greg Claytona658fd22011-06-04 01:26:29 +0000929 if (m_description.empty())
Greg Claytonf4b47e12010-08-04 01:40:35 +0000930 return "trace";
Greg Claytona658fd22011-06-04 01:26:29 +0000931 else
932 return m_description.c_str();
933 }
934};
935
936
937//----------------------------------------------------------------------
938// StopInfoException
939//----------------------------------------------------------------------
940
941class StopInfoException : public StopInfo
942{
943public:
944
945 StopInfoException (Thread &thread, const char *description) :
946 StopInfo (thread, LLDB_INVALID_UID)
947 {
948 if (description)
949 SetDescription (description);
950 }
951
952 virtual
953 ~StopInfoException ()
954 {
955 }
956
957 virtual StopReason
958 GetStopReason () const
959 {
960 return eStopReasonException;
961 }
962
963 virtual const char *
964 GetDescription ()
965 {
966 if (m_description.empty())
967 return "exception";
968 else
969 return m_description.c_str();
Greg Claytonf4b47e12010-08-04 01:40:35 +0000970 }
971};
972
973
974//----------------------------------------------------------------------
975// StopInfoThreadPlan
976//----------------------------------------------------------------------
977
978class StopInfoThreadPlan : public StopInfo
979{
980public:
981
Jim Ingham73ca05a2011-12-17 01:35:57 +0000982 StopInfoThreadPlan (ThreadPlanSP &plan_sp, ValueObjectSP &return_valobj_sp) :
Greg Claytonf4b47e12010-08-04 01:40:35 +0000983 StopInfo (plan_sp->GetThread(), LLDB_INVALID_UID),
Jim Ingham73ca05a2011-12-17 01:35:57 +0000984 m_plan_sp (plan_sp),
985 m_return_valobj_sp (return_valobj_sp)
Greg Claytonf4b47e12010-08-04 01:40:35 +0000986 {
987 }
988
989 virtual ~StopInfoThreadPlan ()
990 {
991 }
992
993 virtual StopReason
994 GetStopReason () const
995 {
996 return eStopReasonPlanComplete;
997 }
998
999 virtual const char *
1000 GetDescription ()
1001 {
1002 if (m_description.empty())
1003 {
1004 StreamString strm;
1005 m_plan_sp->GetDescription (&strm, eDescriptionLevelBrief);
1006 m_description.swap (strm.GetString());
1007 }
1008 return m_description.c_str();
1009 }
Jim Ingham73ca05a2011-12-17 01:35:57 +00001010
1011 ValueObjectSP
1012 GetReturnValueObject()
1013 {
1014 return m_return_valobj_sp;
1015 }
Jim Ingham0161b492013-02-09 01:29:05 +00001016
1017protected:
1018 virtual bool
1019 ShouldStop (Event *event_ptr)
1020 {
1021 if (m_plan_sp)
1022 return m_plan_sp->ShouldStop(event_ptr);
1023 else
1024 return StopInfo::ShouldStop(event_ptr);
1025 }
Greg Claytonf4b47e12010-08-04 01:40:35 +00001026
1027private:
1028 ThreadPlanSP m_plan_sp;
Jim Ingham73ca05a2011-12-17 01:35:57 +00001029 ValueObjectSP m_return_valobj_sp;
Greg Claytonf4b47e12010-08-04 01:40:35 +00001030};
Greg Clayton90ba8112012-12-05 00:16:59 +00001031
1032class StopInfoExec : public StopInfo
1033{
1034public:
1035
1036 StopInfoExec (Thread &thread) :
1037 StopInfo (thread, LLDB_INVALID_UID),
1038 m_performed_action (false)
1039 {
1040 }
1041
1042 virtual
1043 ~StopInfoExec ()
1044 {
1045 }
1046
1047 virtual StopReason
1048 GetStopReason () const
1049 {
1050 return eStopReasonExec;
1051 }
1052
1053 virtual const char *
1054 GetDescription ()
1055 {
1056 return "exec";
1057 }
1058protected:
Greg Clayton90ba8112012-12-05 00:16:59 +00001059
1060 virtual void
1061 PerformAction (Event *event_ptr)
1062 {
1063 // Only perform the action once
1064 if (m_performed_action)
1065 return;
1066 m_performed_action = true;
Greg Clayton46c2b6e2013-04-29 23:30:46 +00001067 ThreadSP thread_sp (m_thread_wp.lock());
1068 if (thread_sp)
1069 thread_sp->GetProcess()->DidExec();
Greg Clayton90ba8112012-12-05 00:16:59 +00001070 }
1071
1072 bool m_performed_action;
1073};
1074
Jim Ingham4b536182011-08-09 02:12:22 +00001075} // namespace lldb_private
Greg Claytonf4b47e12010-08-04 01:40:35 +00001076
1077StopInfoSP
1078StopInfo::CreateStopReasonWithBreakpointSiteID (Thread &thread, break_id_t break_id)
1079{
1080 return StopInfoSP (new StopInfoBreakpoint (thread, break_id));
1081}
1082
1083StopInfoSP
Jim Ingham36f3b362010-10-14 23:45:03 +00001084StopInfo::CreateStopReasonWithBreakpointSiteID (Thread &thread, break_id_t break_id, bool should_stop)
1085{
1086 return StopInfoSP (new StopInfoBreakpoint (thread, break_id, should_stop));
1087}
1088
1089StopInfoSP
Greg Claytonf4b47e12010-08-04 01:40:35 +00001090StopInfo::CreateStopReasonWithWatchpointID (Thread &thread, break_id_t watch_id)
1091{
1092 return StopInfoSP (new StopInfoWatchpoint (thread, watch_id));
1093}
1094
1095StopInfoSP
1096StopInfo::CreateStopReasonWithSignal (Thread &thread, int signo)
1097{
1098 return StopInfoSP (new StopInfoUnixSignal (thread, signo));
1099}
1100
1101StopInfoSP
1102StopInfo::CreateStopReasonToTrace (Thread &thread)
1103{
1104 return StopInfoSP (new StopInfoTrace (thread));
1105}
1106
1107StopInfoSP
Jim Ingham73ca05a2011-12-17 01:35:57 +00001108StopInfo::CreateStopReasonWithPlan (ThreadPlanSP &plan_sp, ValueObjectSP return_valobj_sp)
Greg Claytonf4b47e12010-08-04 01:40:35 +00001109{
Jim Ingham73ca05a2011-12-17 01:35:57 +00001110 return StopInfoSP (new StopInfoThreadPlan (plan_sp, return_valobj_sp));
Greg Claytonf4b47e12010-08-04 01:40:35 +00001111}
Greg Claytona658fd22011-06-04 01:26:29 +00001112
1113StopInfoSP
1114StopInfo::CreateStopReasonWithException (Thread &thread, const char *description)
1115{
1116 return StopInfoSP (new StopInfoException (thread, description));
1117}
Jim Ingham73ca05a2011-12-17 01:35:57 +00001118
Greg Clayton90ba8112012-12-05 00:16:59 +00001119StopInfoSP
1120StopInfo::CreateStopReasonWithExec (Thread &thread)
1121{
1122 return StopInfoSP (new StopInfoExec (thread));
1123}
1124
Jim Ingham73ca05a2011-12-17 01:35:57 +00001125ValueObjectSP
1126StopInfo::GetReturnValueObject(StopInfoSP &stop_info_sp)
1127{
1128 if (stop_info_sp && stop_info_sp->GetStopReason() == eStopReasonPlanComplete)
1129 {
1130 StopInfoThreadPlan *plan_stop_info = static_cast<StopInfoThreadPlan *>(stop_info_sp.get());
1131 return plan_stop_info->GetReturnValueObject();
1132 }
1133 else
1134 return ValueObjectSP();
1135}