1 //===-- StopInfo.cpp ---------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/lldb-python.h"
12 #include "lldb/Target/StopInfo.h"
18 // Other libraries and framework includes
20 #include "lldb/Core/Log.h"
21 #include "lldb/Breakpoint/Breakpoint.h"
22 #include "lldb/Breakpoint/BreakpointLocation.h"
23 #include "lldb/Breakpoint/StoppointCallbackContext.h"
24 #include "lldb/Breakpoint/Watchpoint.h"
25 #include "lldb/Core/Debugger.h"
26 #include "lldb/Core/StreamString.h"
27 #include "lldb/Expression/ClangUserExpression.h"
28 #include "lldb/Target/Target.h"
29 #include "lldb/Target/Thread.h"
30 #include "lldb/Target/ThreadPlan.h"
31 #include "lldb/Target/Process.h"
32 #include "lldb/Target/UnixSignals.h"
35 using namespace lldb_private;
37 StopInfo::StopInfo (Thread &thread, uint64_t value) :
38 m_thread_wp (thread.shared_from_this()),
39 m_stop_id (thread.GetProcess()->GetStopID()),
40 m_resume_id (thread.GetProcess()->GetResumeID()),
42 m_override_should_notify (eLazyBoolCalculate),
43 m_override_should_stop (eLazyBoolCalculate)
48 StopInfo::IsValid () const
50 ThreadSP thread_sp (m_thread_wp.lock());
52 return thread_sp->GetProcess()->GetStopID() == m_stop_id;
57 StopInfo::MakeStopInfoValid ()
59 ThreadSP thread_sp (m_thread_wp.lock());
62 m_stop_id = thread_sp->GetProcess()->GetStopID();
63 m_resume_id = thread_sp->GetProcess()->GetResumeID();
68 StopInfo::HasTargetRunSinceMe ()
70 ThreadSP thread_sp (m_thread_wp.lock());
74 lldb::StateType ret_type = thread_sp->GetProcess()->GetPrivateState();
75 if (ret_type == eStateRunning)
79 else if (ret_type == eStateStopped)
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
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)
93 else if (curr_resume_id > last_user_expression_id)
102 //----------------------------------------------------------------------
103 // StopInfoBreakpoint
104 //----------------------------------------------------------------------
106 namespace lldb_private
108 class StopInfoBreakpoint : public StopInfo
112 StopInfoBreakpoint (Thread &thread, break_id_t break_id) :
113 StopInfo (thread, break_id),
115 m_should_stop (false),
116 m_should_stop_is_valid (false),
117 m_should_perform_action (true),
118 m_address (LLDB_INVALID_ADDRESS),
119 m_break_id(LLDB_INVALID_BREAK_ID),
120 m_was_one_shot (false)
125 StopInfoBreakpoint (Thread &thread, break_id_t break_id, bool should_stop) :
126 StopInfo (thread, break_id),
128 m_should_stop (should_stop),
129 m_should_stop_is_valid (true),
130 m_should_perform_action (true),
131 m_address (LLDB_INVALID_ADDRESS),
132 m_break_id(LLDB_INVALID_BREAK_ID),
133 m_was_one_shot (false)
141 ThreadSP thread_sp (m_thread_wp.lock());
144 BreakpointSiteSP bp_site_sp (thread_sp->GetProcess()->GetBreakpointSiteList().FindByID (m_value));
147 if (bp_site_sp->GetNumberOfOwners() == 1)
149 BreakpointLocationSP bp_loc_sp = bp_site_sp->GetOwnerAtIndex(0);
152 m_break_id = bp_loc_sp->GetBreakpoint().GetID();
153 m_was_one_shot = bp_loc_sp->GetBreakpoint().IsOneShot();
156 m_address = bp_site_sp->GetLoadAddress();
161 virtual ~StopInfoBreakpoint ()
166 GetStopReason () const
168 return eStopReasonBreakpoint;
172 ShouldStopSynchronous (Event *event_ptr)
174 ThreadSP thread_sp (m_thread_wp.lock());
177 if (!m_should_stop_is_valid)
179 // Only check once if we should stop at a breakpoint
180 BreakpointSiteSP bp_site_sp (thread_sp->GetProcess()->GetBreakpointSiteList().FindByID (m_value));
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);
189 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
192 log->Printf ("Process::%s could not find breakpoint site id: %" PRId64 "...", __FUNCTION__, m_value);
194 m_should_stop = true;
196 m_should_stop_is_valid = true;
198 return m_should_stop;
204 DoShouldNotify (Event *event_ptr)
206 ThreadSP thread_sp (m_thread_wp.lock());
209 BreakpointSiteSP bp_site_sp (thread_sp->GetProcess()->GetBreakpointSiteList().FindByID (m_value));
212 bool all_internal = true;
214 for (uint32_t i = 0; i < bp_site_sp->GetNumberOfOwners(); i++)
216 if (!bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint().IsInternal())
218 all_internal = false;
222 return all_internal == false;
231 if (m_description.empty())
233 ThreadSP thread_sp (m_thread_wp.lock());
236 BreakpointSiteSP bp_site_sp (thread_sp->GetProcess()->GetBreakpointSiteList().FindByID (m_value));
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())
244 size_t num_owners = bp_site_sp->GetNumberOfOwners();
245 for (size_t idx = 0; idx < num_owners; idx++)
247 const char *kind = bp_site_sp->GetOwnerAtIndex(idx)->GetBreakpoint().GetBreakpointKind();
250 m_description.assign (kind);
256 strm.Printf("breakpoint ");
257 bp_site_sp->GetDescription(&strm, eDescriptionLevelBrief);
258 m_description.swap (strm.GetString());
263 if (m_break_id != LLDB_INVALID_BREAK_ID)
265 BreakpointSP break_sp = thread_sp->GetProcess()->GetTarget().GetBreakpointByID(m_break_id);
268 if (break_sp->IsInternal())
270 const char *kind = break_sp->GetBreakpointKind();
272 strm.Printf ("internal %s breakpoint(%d).", kind, m_break_id);
274 strm.Printf ("internal breakpoint(%d).", m_break_id);
278 strm.Printf ("breakpoint %d.", m_break_id);
284 strm.Printf ("one-shot breakpoint %d", m_break_id);
286 strm.Printf ("breakpoint %d which has been deleted.", m_break_id);
289 else if (m_address == LLDB_INVALID_ADDRESS)
290 strm.Printf("breakpoint site %" PRIi64 " which has been deleted - unknown address", m_value);
292 strm.Printf("breakpoint site %" PRIi64 " which has been deleted - was at 0x%" PRIx64, m_value, m_address);
294 m_description.swap (strm.GetString());
298 return m_description.c_str();
303 ShouldStop (Event *event_ptr)
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;
312 PerformAction (Event *event_ptr)
314 if (!m_should_perform_action)
316 m_should_perform_action = false;
318 ThreadSP thread_sp (m_thread_wp.lock());
322 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS);
324 if (!thread_sp->IsValid())
326 // This shouldn't ever happen, but just in case, don't do more harm.
329 log->Printf ("PerformAction got called with an invalid thread.");
331 m_should_stop = true;
332 m_should_stop_is_valid = true;
336 BreakpointSiteSP bp_site_sp (thread_sp->GetProcess()->GetBreakpointSiteList().FindByID (m_value));
340 size_t num_owners = bp_site_sp->GetNumberOfOwners();
344 m_should_stop = true;
348 // We go through each location, and test first its condition. If the condition says to stop,
349 // then we run the callback for that location. If that callback says to stop as well, then
350 // we set m_should_stop to true; we are going to stop.
351 // But we still want to give all the breakpoints whose conditions say we are going to stop a
352 // chance to run their callbacks.
353 // Of course if any callback restarts the target by putting "continue" in the callback, then
354 // we're going to restart, without running the rest of the callbacks. And in this case we will
355 // end up not stopping even if another location said we should stop. But that's better than not
356 // running all the callbacks.
358 m_should_stop = false;
360 ExecutionContext exe_ctx (thread_sp->GetStackFrameAtIndex(0));
361 Process *process = exe_ctx.GetProcessPtr();
362 if (process->GetModIDRef().IsLastResumeForUserExpression())
364 // If we are in the middle of evaluating an expression, don't run asynchronous breakpoint commands or
365 // expressions. That could lead to infinite recursion if the command or condition re-calls the function
366 // with this breakpoint.
367 // TODO: We can keep a list of the breakpoints we've seen while running expressions in the nested
368 // PerformAction calls that can arise when the action runs a function that hits another breakpoint,
369 // and only stop running commands when we see the same breakpoint hit a second time.
371 m_should_stop_is_valid = true;
373 log->Printf ("StopInfoBreakpoint::PerformAction - Hit a breakpoint while running an expression,"
374 " not running commands to avoid recursion.");
375 bool ignoring_breakpoints = process->GetIgnoreBreakpointsInExpressions();
376 if (ignoring_breakpoints)
378 m_should_stop = false;
379 // Internal breakpoints will always stop.
380 for (size_t j = 0; j < num_owners; j++)
382 lldb::BreakpointLocationSP bp_loc_sp = bp_site_sp->GetOwnerAtIndex(j);
383 if (bp_loc_sp->GetBreakpoint().IsInternal())
385 m_should_stop = true;
392 m_should_stop = true;
395 log->Printf ("StopInfoBreakpoint::PerformAction - in expression, continuing: %s.",
396 m_should_stop ? "true" : "false");
397 process->GetTarget().GetDebugger().GetAsyncOutputStream()->Printf("Warning: hit breakpoint while "
398 "running function, skipping commands and conditions to prevent recursion.");
402 StoppointCallbackContext context (event_ptr, exe_ctx, false);
404 // Let's copy the breakpoint locations out of the site and store them in a local list. That way if
405 // one of the breakpoint actions changes the site, then we won't be operating on a bad list.
407 BreakpointLocationCollection site_locations;
408 for (size_t j = 0; j < num_owners; j++)
409 site_locations.Add(bp_site_sp->GetOwnerAtIndex(j));
411 for (size_t j = 0; j < num_owners; j++)
413 lldb::BreakpointLocationSP bp_loc_sp = site_locations.GetByIndex(j);
415 // If another action disabled this breakpoint or its location, then don't run the actions.
416 if (!bp_loc_sp->IsEnabled() || !bp_loc_sp->GetBreakpoint().IsEnabled())
419 // The breakpoint site may have many locations associated with it, not all of them valid for
420 // this thread. Skip the ones that aren't:
421 if (!bp_loc_sp->ValidForThisThread(thread_sp.get()))
426 bp_loc_sp->GetDescription(&s, eDescriptionLevelBrief);
427 log->Printf ("Breakpoint %s hit on thread 0x%llx but it was not for this thread, continuing.", s.GetData(), thread_sp->GetID());
431 // First run the condition for the breakpoint. If that says we should stop, then we'll run
432 // the callback for the breakpoint. If the callback says we shouldn't stop that will win.
434 if (bp_loc_sp->GetConditionText() != NULL)
436 Error condition_error;
437 bool condition_says_stop = bp_loc_sp->ConditionSaysStop(exe_ctx, condition_error);
439 if (!condition_error.Success())
441 Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger();
442 StreamSP error_sp = debugger.GetAsyncErrorStream ();
443 error_sp->Printf ("Stopped due to an error evaluating condition of breakpoint ");
444 bp_loc_sp->GetDescription (error_sp.get(), eDescriptionLevelBrief);
445 error_sp->Printf (": \"%s\"",
446 bp_loc_sp->GetConditionText());
448 const char *err_str = condition_error.AsCString("<Unknown Error>");
450 log->Printf("Error evaluating condition: \"%s\"\n", err_str);
452 error_sp->PutCString (err_str);
455 // If the condition fails to be parsed or run, we should stop.
456 condition_says_stop = true;
463 bp_loc_sp->GetDescription(&s, eDescriptionLevelBrief);
464 log->Printf ("Condition evaluated for breakpoint %s on thread 0x%llx conditon_says_stop: %i.", s.GetData(), thread_sp->GetID(), condition_says_stop);
466 if (!condition_says_stop)
471 bool callback_says_stop;
473 // FIXME: For now the callbacks have to run in async mode - the first time we restart we need
474 // to get out of there. So set it here.
475 // When we figure out how to nest breakpoint hits then this will change.
477 Debugger &debugger = thread_sp->CalculateTarget()->GetDebugger();
478 bool old_async = debugger.GetAsyncExecution();
479 debugger.SetAsyncExecution (true);
481 callback_says_stop = bp_loc_sp->InvokeCallback (&context);
483 debugger.SetAsyncExecution (old_async);
485 if (callback_says_stop)
486 m_should_stop = true;
488 // If we are going to stop for this breakpoint, then remove the breakpoint.
489 if (callback_says_stop && bp_loc_sp && bp_loc_sp->GetBreakpoint().IsOneShot())
491 thread_sp->GetProcess()->GetTarget().RemoveBreakpointByID (bp_loc_sp->GetBreakpoint().GetID());
494 // Also make sure that the callback hasn't continued the target.
495 // If it did, when we'll set m_should_start to false and get out of here.
496 if (HasTargetRunSinceMe ())
498 m_should_stop = false;
503 // We've figured out what this stop wants to do, so mark it as valid so we don't compute it again.
504 m_should_stop_is_valid = true;
509 m_should_stop = true;
510 m_should_stop_is_valid = true;
511 Log * log_process(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
514 log_process->Printf ("Process::%s could not find breakpoint site id: %" PRId64 "...", __FUNCTION__, m_value);
517 log->Printf ("Process::%s returning from action with m_should_stop: %d.", __FUNCTION__, m_should_stop);
522 std::string m_description;
524 bool m_should_stop_is_valid;
525 bool m_should_perform_action; // Since we are trying to preserve the "state" of the system even if we run functions
526 // etc. behind the users backs, we need to make sure we only REALLY perform the action once.
527 lldb::addr_t m_address; // We use this to capture the breakpoint site address when we create the StopInfo,
528 // in case somebody deletes it between the time the StopInfo is made and the
529 // description is asked for.
530 lldb::break_id_t m_break_id;
535 //----------------------------------------------------------------------
536 // StopInfoWatchpoint
537 //----------------------------------------------------------------------
539 class StopInfoWatchpoint : public StopInfo
542 // Make sure watchpoint is properly disabled and subsequently enabled while performing watchpoint actions.
543 class WatchpointSentry {
545 WatchpointSentry(Process *p, Watchpoint *w):
549 if (process && watchpoint)
551 const bool notify = false;
552 watchpoint->TurnOnEphemeralMode();
553 process->DisableWatchpoint(watchpoint, notify);
558 if (process && watchpoint)
560 if (!watchpoint->IsDisabledDuringEphemeralMode())
562 const bool notify = false;
563 process->EnableWatchpoint(watchpoint, notify);
565 watchpoint->TurnOffEphemeralMode();
570 Watchpoint *watchpoint;
573 StopInfoWatchpoint (Thread &thread, break_id_t watch_id) :
574 StopInfo(thread, watch_id),
576 m_should_stop(false),
577 m_should_stop_is_valid(false)
581 virtual ~StopInfoWatchpoint ()
586 GetStopReason () const
588 return eStopReasonWatchpoint;
594 if (m_description.empty())
597 strm.Printf("watchpoint %" PRIi64, m_value);
598 m_description.swap (strm.GetString());
600 return m_description.c_str();
605 ShouldStopSynchronous (Event *event_ptr)
607 // ShouldStop() method is idempotent and should not affect hit count.
608 // See Process::RunPrivateStateThread()->Process()->HandlePrivateEvent()
609 // -->Process()::ShouldBroadcastEvent()->ThreadList::ShouldStop()->
610 // Thread::ShouldStop()->ThreadPlanBase::ShouldStop()->
611 // StopInfoWatchpoint::ShouldStop() and
612 // Event::DoOnRemoval()->Process::ProcessEventData::DoOnRemoval()->
613 // StopInfoWatchpoint::PerformAction().
614 if (m_should_stop_is_valid)
615 return m_should_stop;
617 ThreadSP thread_sp (m_thread_wp.lock());
620 WatchpointSP wp_sp (thread_sp->CalculateTarget()->GetWatchpointList().FindByID(GetValue()));
623 // Check if we should stop at a watchpoint.
624 ExecutionContext exe_ctx (thread_sp->GetStackFrameAtIndex(0));
625 StoppointCallbackContext context (event_ptr, exe_ctx, true);
626 m_should_stop = wp_sp->ShouldStop (&context);
630 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
633 log->Printf ("Process::%s could not find watchpoint location id: %" PRId64 "...",
634 __FUNCTION__, GetValue());
636 m_should_stop = true;
639 m_should_stop_is_valid = true;
640 return m_should_stop;
644 ShouldStop (Event *event_ptr)
646 // This just reports the work done by PerformAction or the synchronous stop. It should
647 // only ever get called after they have had a chance to run.
648 assert (m_should_stop_is_valid);
649 return m_should_stop;
653 PerformAction (Event *event_ptr)
655 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS);
656 // We're going to calculate if we should stop or not in some way during the course of
657 // this code. Also by default we're going to stop, so set that here.
658 m_should_stop = true;
660 ThreadSP thread_sp (m_thread_wp.lock());
664 WatchpointSP wp_sp (thread_sp->CalculateTarget()->GetWatchpointList().FindByID(GetValue()));
667 ExecutionContext exe_ctx (thread_sp->GetStackFrameAtIndex(0));
668 Process* process = exe_ctx.GetProcessPtr();
670 // This sentry object makes sure the current watchpoint is disabled while performing watchpoint actions,
671 // and it is then enabled after we are finished.
672 WatchpointSentry sentry(process, wp_sp.get());
675 // check if this process is running on an architecture where watchpoints trigger
676 // before the associated instruction runs. if so, disable the WP, single-step and then
677 // re-enable the watchpoint
681 bool wp_triggers_after;
682 if (process->GetWatchpointSupportInfo(num, wp_triggers_after).Success())
684 if (!wp_triggers_after)
686 StopInfoSP stored_stop_info_sp = thread_sp->GetStopInfo();
687 assert (stored_stop_info_sp.get() == this);
689 ThreadPlanSP new_plan_sp(thread_sp->QueueThreadPlanForStepSingleInstruction(false, // step-over
690 false, // abort_other_plans
691 true)); // stop_other_threads
692 new_plan_sp->SetIsMasterPlan (true);
693 new_plan_sp->SetOkayToDiscard (false);
694 new_plan_sp->SetPrivate (true);
695 process->GetThreadList().SetSelectedThreadByID (thread_sp->GetID());
697 process->WaitForProcessToStop (NULL);
698 process->GetThreadList().SetSelectedThreadByID (thread_sp->GetID());
699 thread_sp->SetStopInfo(stored_stop_info_sp);
705 if (m_should_stop && wp_sp->GetConditionText() != NULL)
707 // We need to make sure the user sees any parse errors in their condition, so we'll hook the
708 // constructor errors up to the debugger's Async I/O.
709 ExecutionResults result_code;
710 EvaluateExpressionOptions expr_options;
711 expr_options.SetUnwindOnError(true);
712 expr_options.SetIgnoreBreakpoints(true);
713 ValueObjectSP result_value_sp;
715 result_code = ClangUserExpression::Evaluate (exe_ctx,
717 wp_sp->GetConditionText(),
721 if (result_code == eExecutionCompleted)
726 if (result_value_sp->ResolveValue (scalar_value))
728 if (scalar_value.ULongLong(1) == 0)
730 // We have been vetoed. This takes precedence over querying
731 // the watchpoint whether it should stop (aka ignore count and
732 // friends). See also StopInfoWatchpoint::ShouldStop() as well
733 // as Process::ProcessEventData::DoOnRemoval().
734 m_should_stop = false;
737 m_should_stop = true;
739 log->Printf("Condition successfully evaluated, result is %s.\n",
740 m_should_stop ? "true" : "false");
744 m_should_stop = true;
746 log->Printf("Failed to get an integer result from the expression.");
752 Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger();
753 StreamSP error_sp = debugger.GetAsyncErrorStream ();
754 error_sp->Printf ("Stopped due to an error evaluating condition of watchpoint ");
755 wp_sp->GetDescription (error_sp.get(), eDescriptionLevelBrief);
756 error_sp->Printf (": \"%s\"",
757 wp_sp->GetConditionText());
759 const char *err_str = error.AsCString("<Unknown Error>");
761 log->Printf("Error evaluating condition: \"%s\"\n", err_str);
763 error_sp->PutCString (err_str);
766 // If the condition fails to be parsed or run, we should stop.
767 m_should_stop = true;
771 // If the condition says to stop, we run the callback to further decide whether to stop.
774 StoppointCallbackContext context (event_ptr, exe_ctx, false);
775 bool stop_requested = wp_sp->InvokeCallback (&context);
776 // Also make sure that the callback hasn't continued the target.
777 // If it did, when we'll set m_should_stop to false and get out of here.
778 if (HasTargetRunSinceMe ())
779 m_should_stop = false;
781 if (m_should_stop && !stop_requested)
783 // We have been vetoed by the callback mechanism.
784 m_should_stop = false;
787 // Finally, if we are going to stop, print out the new & old values:
790 wp_sp->CaptureWatchedValue(exe_ctx);
792 Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger();
793 StreamSP output_sp = debugger.GetAsyncOutputStream ();
794 wp_sp->DumpSnapshots(output_sp.get());
802 Log * log_process(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
805 log_process->Printf ("Process::%s could not find watchpoint id: %" PRId64 "...", __FUNCTION__, m_value);
808 log->Printf ("Process::%s returning from action with m_should_stop: %d.", __FUNCTION__, m_should_stop);
810 m_should_stop_is_valid = true;
815 std::string m_description;
817 bool m_should_stop_is_valid;
822 //----------------------------------------------------------------------
823 // StopInfoUnixSignal
824 //----------------------------------------------------------------------
826 class StopInfoUnixSignal : public StopInfo
830 StopInfoUnixSignal (Thread &thread, int signo) :
831 StopInfo (thread, signo)
835 virtual ~StopInfoUnixSignal ()
841 GetStopReason () const
843 return eStopReasonSignal;
847 ShouldStopSynchronous (Event *event_ptr)
849 ThreadSP thread_sp (m_thread_wp.lock());
851 return thread_sp->GetProcess()->GetUnixSignals().GetShouldStop (m_value);
856 ShouldStop (Event *event_ptr)
858 ThreadSP thread_sp (m_thread_wp.lock());
860 return thread_sp->GetProcess()->GetUnixSignals().GetShouldStop (m_value);
865 // If should stop returns false, check if we should notify of this event
867 DoShouldNotify (Event *event_ptr)
869 ThreadSP thread_sp (m_thread_wp.lock());
872 bool should_notify = thread_sp->GetProcess()->GetUnixSignals().GetShouldNotify (m_value);
876 strm.Printf ("thread %d received signal: %s",
877 thread_sp->GetIndexID(),
878 thread_sp->GetProcess()->GetUnixSignals().GetSignalAsCString (m_value));
879 Process::ProcessEventData::AddRestartedReason(event_ptr, strm.GetData());
881 return should_notify;
888 WillResume (lldb::StateType resume_state)
890 ThreadSP thread_sp (m_thread_wp.lock());
893 if (thread_sp->GetProcess()->GetUnixSignals().GetShouldSuppress(m_value) == false)
894 thread_sp->SetResumeSignal(m_value);
901 if (m_description.empty())
903 ThreadSP thread_sp (m_thread_wp.lock());
907 const char *signal_name = thread_sp->GetProcess()->GetUnixSignals().GetSignalAsCString (m_value);
909 strm.Printf("signal %s", signal_name);
911 strm.Printf("signal %" PRIi64, m_value);
912 m_description.swap (strm.GetString());
915 return m_description.c_str();
919 //----------------------------------------------------------------------
921 //----------------------------------------------------------------------
923 class StopInfoTrace : public StopInfo
927 StopInfoTrace (Thread &thread) :
928 StopInfo (thread, LLDB_INVALID_UID)
932 virtual ~StopInfoTrace ()
937 GetStopReason () const
939 return eStopReasonTrace;
945 if (m_description.empty())
948 return m_description.c_str();
953 //----------------------------------------------------------------------
955 //----------------------------------------------------------------------
957 class StopInfoException : public StopInfo
961 StopInfoException (Thread &thread, const char *description) :
962 StopInfo (thread, LLDB_INVALID_UID)
965 SetDescription (description);
969 ~StopInfoException ()
974 GetStopReason () const
976 return eStopReasonException;
982 if (m_description.empty())
985 return m_description.c_str();
990 //----------------------------------------------------------------------
991 // StopInfoThreadPlan
992 //----------------------------------------------------------------------
994 class StopInfoThreadPlan : public StopInfo
998 StopInfoThreadPlan (ThreadPlanSP &plan_sp, ValueObjectSP &return_valobj_sp) :
999 StopInfo (plan_sp->GetThread(), LLDB_INVALID_UID),
1000 m_plan_sp (plan_sp),
1001 m_return_valobj_sp (return_valobj_sp)
1005 virtual ~StopInfoThreadPlan ()
1010 GetStopReason () const
1012 return eStopReasonPlanComplete;
1015 virtual const char *
1018 if (m_description.empty())
1021 m_plan_sp->GetDescription (&strm, eDescriptionLevelBrief);
1022 m_description.swap (strm.GetString());
1024 return m_description.c_str();
1028 GetReturnValueObject()
1030 return m_return_valobj_sp;
1035 ShouldStop (Event *event_ptr)
1038 return m_plan_sp->ShouldStop(event_ptr);
1040 return StopInfo::ShouldStop(event_ptr);
1044 ThreadPlanSP m_plan_sp;
1045 ValueObjectSP m_return_valobj_sp;
1048 class StopInfoExec : public StopInfo
1052 StopInfoExec (Thread &thread) :
1053 StopInfo (thread, LLDB_INVALID_UID),
1054 m_performed_action (false)
1064 GetStopReason () const
1066 return eStopReasonExec;
1069 virtual const char *
1077 PerformAction (Event *event_ptr)
1079 // Only perform the action once
1080 if (m_performed_action)
1082 m_performed_action = true;
1083 ThreadSP thread_sp (m_thread_wp.lock());
1085 thread_sp->GetProcess()->DidExec();
1088 bool m_performed_action;
1091 } // namespace lldb_private
1094 StopInfo::CreateStopReasonWithBreakpointSiteID (Thread &thread, break_id_t break_id)
1096 return StopInfoSP (new StopInfoBreakpoint (thread, break_id));
1100 StopInfo::CreateStopReasonWithBreakpointSiteID (Thread &thread, break_id_t break_id, bool should_stop)
1102 return StopInfoSP (new StopInfoBreakpoint (thread, break_id, should_stop));
1106 StopInfo::CreateStopReasonWithWatchpointID (Thread &thread, break_id_t watch_id)
1108 return StopInfoSP (new StopInfoWatchpoint (thread, watch_id));
1112 StopInfo::CreateStopReasonWithSignal (Thread &thread, int signo)
1114 return StopInfoSP (new StopInfoUnixSignal (thread, signo));
1118 StopInfo::CreateStopReasonToTrace (Thread &thread)
1120 return StopInfoSP (new StopInfoTrace (thread));
1124 StopInfo::CreateStopReasonWithPlan (ThreadPlanSP &plan_sp, ValueObjectSP return_valobj_sp)
1126 return StopInfoSP (new StopInfoThreadPlan (plan_sp, return_valobj_sp));
1130 StopInfo::CreateStopReasonWithException (Thread &thread, const char *description)
1132 return StopInfoSP (new StopInfoException (thread, description));
1136 StopInfo::CreateStopReasonWithExec (Thread &thread)
1138 return StopInfoSP (new StopInfoExec (thread));
1142 StopInfo::GetReturnValueObject(StopInfoSP &stop_info_sp)
1144 if (stop_info_sp && stop_info_sp->GetStopReason() == eStopReasonPlanComplete)
1146 StopInfoThreadPlan *plan_stop_info = static_cast<StopInfoThreadPlan *>(stop_info_sp.get());
1147 return plan_stop_info->GetReturnValueObject();
1150 return ValueObjectSP();