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/Target/StopInfo.h"
16 // Other libraries and framework includes
18 #include "lldb/Core/Log.h"
19 #include "lldb/Breakpoint/Breakpoint.h"
20 #include "lldb/Breakpoint/BreakpointLocation.h"
21 #include "lldb/Breakpoint/StoppointCallbackContext.h"
22 #include "lldb/Breakpoint/Watchpoint.h"
23 #include "lldb/Core/Debugger.h"
24 #include "lldb/Core/StreamString.h"
25 #include "lldb/Core/ValueObject.h"
26 #include "lldb/Expression/ClangUserExpression.h"
27 #include "lldb/Target/Target.h"
28 #include "lldb/Target/Thread.h"
29 #include "lldb/Target/ThreadPlan.h"
30 #include "lldb/Target/Process.h"
31 #include "lldb/Target/UnixSignals.h"
34 using namespace lldb_private;
36 StopInfo::StopInfo (Thread &thread, uint64_t value) :
37 m_thread_wp (thread.shared_from_this()),
38 m_stop_id (thread.GetProcess()->GetStopID()),
39 m_resume_id (thread.GetProcess()->GetResumeID()),
42 m_override_should_notify (eLazyBoolCalculate),
43 m_override_should_stop (eLazyBoolCalculate),
49 StopInfo::IsValid () const
51 ThreadSP thread_sp (m_thread_wp.lock());
53 return thread_sp->GetProcess()->GetStopID() == m_stop_id;
58 StopInfo::MakeStopInfoValid ()
60 ThreadSP thread_sp (m_thread_wp.lock());
63 m_stop_id = thread_sp->GetProcess()->GetStopID();
64 m_resume_id = thread_sp->GetProcess()->GetResumeID();
69 StopInfo::HasTargetRunSinceMe ()
71 ThreadSP thread_sp (m_thread_wp.lock());
75 lldb::StateType ret_type = thread_sp->GetProcess()->GetPrivateState();
76 if (ret_type == eStateRunning)
80 else if (ret_type == eStateStopped)
82 // This is a little tricky. We want to count "run and stopped again before you could
83 // ask this question as a "TRUE" answer to HasTargetRunSinceMe. But we don't want to
84 // include any running of the target done for expressions. So we track both resumes,
85 // and resumes caused by expressions, and check if there are any resumes NOT caused
88 uint32_t curr_resume_id = thread_sp->GetProcess()->GetResumeID();
89 uint32_t last_user_expression_id = thread_sp->GetProcess()->GetLastUserExpressionResumeID ();
90 if (curr_resume_id == m_resume_id)
94 else if (curr_resume_id > last_user_expression_id)
103 //----------------------------------------------------------------------
104 // StopInfoBreakpoint
105 //----------------------------------------------------------------------
107 namespace lldb_private
109 class StopInfoBreakpoint : public StopInfo
112 StopInfoBreakpoint (Thread &thread, break_id_t break_id) :
113 StopInfo (thread, break_id),
114 m_should_stop (false),
115 m_should_stop_is_valid (false),
116 m_should_perform_action (true),
117 m_address (LLDB_INVALID_ADDRESS),
118 m_break_id(LLDB_INVALID_BREAK_ID),
119 m_was_one_shot (false)
124 StopInfoBreakpoint (Thread &thread, break_id_t break_id, bool should_stop) :
125 StopInfo (thread, break_id),
126 m_should_stop (should_stop),
127 m_should_stop_is_valid (true),
128 m_should_perform_action (true),
129 m_address (LLDB_INVALID_ADDRESS),
130 m_break_id(LLDB_INVALID_BREAK_ID),
131 m_was_one_shot (false)
139 ThreadSP thread_sp (m_thread_wp.lock());
142 BreakpointSiteSP bp_site_sp (thread_sp->GetProcess()->GetBreakpointSiteList().FindByID (m_value));
145 if (bp_site_sp->GetNumberOfOwners() == 1)
147 BreakpointLocationSP bp_loc_sp = bp_site_sp->GetOwnerAtIndex(0);
150 m_break_id = bp_loc_sp->GetBreakpoint().GetID();
151 m_was_one_shot = bp_loc_sp->GetBreakpoint().IsOneShot();
154 m_address = bp_site_sp->GetLoadAddress();
159 virtual ~StopInfoBreakpoint ()
164 IsValidForOperatingSystemThread (Thread &thread)
166 ProcessSP process_sp (thread.GetProcess());
169 BreakpointSiteSP bp_site_sp (process_sp->GetBreakpointSiteList().FindByID (m_value));
171 return bp_site_sp->ValidForThisThread (&thread);
177 GetStopReason () const
179 return eStopReasonBreakpoint;
183 ShouldStopSynchronous (Event *event_ptr)
185 ThreadSP thread_sp (m_thread_wp.lock());
188 if (!m_should_stop_is_valid)
190 // Only check once if we should stop at a breakpoint
191 BreakpointSiteSP bp_site_sp (thread_sp->GetProcess()->GetBreakpointSiteList().FindByID (m_value));
194 ExecutionContext exe_ctx (thread_sp->GetStackFrameAtIndex(0));
195 StoppointCallbackContext context (event_ptr, exe_ctx, true);
196 bp_site_sp->BumpHitCounts();
197 m_should_stop = bp_site_sp->ShouldStop (&context);
201 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
204 log->Printf ("Process::%s could not find breakpoint site id: %" PRId64 "...", __FUNCTION__, m_value);
206 m_should_stop = true;
208 m_should_stop_is_valid = true;
210 return m_should_stop;
216 DoShouldNotify (Event *event_ptr)
218 ThreadSP thread_sp (m_thread_wp.lock());
221 BreakpointSiteSP bp_site_sp (thread_sp->GetProcess()->GetBreakpointSiteList().FindByID (m_value));
224 bool all_internal = true;
226 for (uint32_t i = 0; i < bp_site_sp->GetNumberOfOwners(); i++)
228 if (!bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint().IsInternal())
230 all_internal = false;
234 return all_internal == false;
243 if (m_description.empty())
245 ThreadSP thread_sp (m_thread_wp.lock());
248 BreakpointSiteSP bp_site_sp (thread_sp->GetProcess()->GetBreakpointSiteList().FindByID (m_value));
252 // If we have just hit an internal breakpoint, and it has a kind description, print that instead of the
253 // full breakpoint printing:
254 if (bp_site_sp->IsInternal())
256 size_t num_owners = bp_site_sp->GetNumberOfOwners();
257 for (size_t idx = 0; idx < num_owners; idx++)
259 const char *kind = bp_site_sp->GetOwnerAtIndex(idx)->GetBreakpoint().GetBreakpointKind();
262 m_description.assign (kind);
268 strm.Printf("breakpoint ");
269 bp_site_sp->GetDescription(&strm, eDescriptionLevelBrief);
270 m_description.swap (strm.GetString());
275 if (m_break_id != LLDB_INVALID_BREAK_ID)
277 BreakpointSP break_sp = thread_sp->GetProcess()->GetTarget().GetBreakpointByID(m_break_id);
280 if (break_sp->IsInternal())
282 const char *kind = break_sp->GetBreakpointKind();
284 strm.Printf ("internal %s breakpoint(%d).", kind, m_break_id);
286 strm.Printf ("internal breakpoint(%d).", m_break_id);
290 strm.Printf ("breakpoint %d.", m_break_id);
296 strm.Printf ("one-shot breakpoint %d", m_break_id);
298 strm.Printf ("breakpoint %d which has been deleted.", m_break_id);
301 else if (m_address == LLDB_INVALID_ADDRESS)
302 strm.Printf("breakpoint site %" PRIi64 " which has been deleted - unknown address", m_value);
304 strm.Printf("breakpoint site %" PRIi64 " which has been deleted - was at 0x%" PRIx64, m_value, m_address);
306 m_description.swap (strm.GetString());
310 return m_description.c_str();
315 ShouldStop (Event *event_ptr)
317 // This just reports the work done by PerformAction or the synchronous stop. It should
318 // only ever get called after they have had a chance to run.
319 assert (m_should_stop_is_valid);
320 return m_should_stop;
324 PerformAction (Event *event_ptr)
326 if (!m_should_perform_action)
328 m_should_perform_action = false;
330 ThreadSP thread_sp (m_thread_wp.lock());
334 Log *log = lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_BREAKPOINTS | LIBLLDB_LOG_STEP);
336 if (!thread_sp->IsValid())
338 // This shouldn't ever happen, but just in case, don't do more harm.
341 log->Printf ("PerformAction got called with an invalid thread.");
343 m_should_stop = true;
344 m_should_stop_is_valid = true;
348 BreakpointSiteSP bp_site_sp (thread_sp->GetProcess()->GetBreakpointSiteList().FindByID (m_value));
349 std::unordered_set<break_id_t> precondition_breakpoints;
353 size_t num_owners = bp_site_sp->GetNumberOfOwners();
357 m_should_stop = true;
361 // We go through each location, and test first its precondition - this overrides everything. Note,
362 // we only do this once per breakpoint - not once per location...
363 // Then check the condition. If the condition says to stop,
364 // then we run the callback for that location. If that callback says to stop as well, then
365 // we set m_should_stop to true; we are going to stop.
366 // But we still want to give all the breakpoints whose conditions say we are going to stop a
367 // chance to run their callbacks.
368 // Of course if any callback restarts the target by putting "continue" in the callback, then
369 // we're going to restart, without running the rest of the callbacks. And in this case we will
370 // end up not stopping even if another location said we should stop. But that's better than not
371 // running all the callbacks.
373 m_should_stop = false;
375 ExecutionContext exe_ctx (thread_sp->GetStackFrameAtIndex(0));
376 Process *process = exe_ctx.GetProcessPtr();
377 if (process->GetModIDRef().IsLastResumeForUserExpression())
379 // If we are in the middle of evaluating an expression, don't run asynchronous breakpoint commands or
380 // expressions. That could lead to infinite recursion if the command or condition re-calls the function
381 // with this breakpoint.
382 // TODO: We can keep a list of the breakpoints we've seen while running expressions in the nested
383 // PerformAction calls that can arise when the action runs a function that hits another breakpoint,
384 // and only stop running commands when we see the same breakpoint hit a second time.
386 m_should_stop_is_valid = true;
388 log->Printf ("StopInfoBreakpoint::PerformAction - Hit a breakpoint while running an expression,"
389 " not running commands to avoid recursion.");
390 bool ignoring_breakpoints = process->GetIgnoreBreakpointsInExpressions();
391 if (ignoring_breakpoints)
393 m_should_stop = false;
394 // Internal breakpoints will always stop.
395 for (size_t j = 0; j < num_owners; j++)
397 lldb::BreakpointLocationSP bp_loc_sp = bp_site_sp->GetOwnerAtIndex(j);
398 if (bp_loc_sp->GetBreakpoint().IsInternal())
400 m_should_stop = true;
407 m_should_stop = true;
410 log->Printf ("StopInfoBreakpoint::PerformAction - in expression, continuing: %s.",
411 m_should_stop ? "true" : "false");
412 process->GetTarget().GetDebugger().GetAsyncOutputStream()->Printf("Warning: hit breakpoint while "
413 "running function, skipping commands and conditions to prevent recursion.");
417 StoppointCallbackContext context (event_ptr, exe_ctx, false);
419 // Let's copy the breakpoint locations out of the site and store them in a local list. That way if
420 // one of the breakpoint actions changes the site, then we won't be operating on a bad list.
421 // For safety's sake let's also grab an extra reference to the breakpoint owners of the locations we're
422 // going to examine, since the locations are going to have to get back to their breakpoints, and the
423 // locations don't keep their owners alive. I'm just sticking the BreakpointSP's in a vector since
424 // I'm only really using it to locally increment their retain counts.
426 BreakpointLocationCollection site_locations;
427 std::vector<lldb::BreakpointSP> location_owners;
429 for (size_t j = 0; j < num_owners; j++)
431 BreakpointLocationSP loc(bp_site_sp->GetOwnerAtIndex(j));
432 site_locations.Add(loc);
433 location_owners.push_back(loc->GetBreakpoint().shared_from_this());
437 for (size_t j = 0; j < num_owners; j++)
439 lldb::BreakpointLocationSP bp_loc_sp = site_locations.GetByIndex(j);
441 // If another action disabled this breakpoint or its location, then don't run the actions.
442 if (!bp_loc_sp->IsEnabled() || !bp_loc_sp->GetBreakpoint().IsEnabled())
445 // The breakpoint site may have many locations associated with it, not all of them valid for
446 // this thread. Skip the ones that aren't:
447 if (!bp_loc_sp->ValidForThisThread(thread_sp.get()))
452 bp_loc_sp->GetDescription(&s, eDescriptionLevelBrief);
453 log->Printf ("Breakpoint %s hit on thread 0x%llx but it was not for this thread, continuing.",
455 static_cast<unsigned long long>(thread_sp->GetID()));
460 // First run the precondition, but since the precondition is per breakpoint, only run it once
462 std::pair<std::unordered_set<break_id_t>::iterator, bool> result
463 = precondition_breakpoints.insert(bp_loc_sp->GetBreakpoint().GetID());
467 bool precondition_result = bp_loc_sp->GetBreakpoint().EvaluatePrecondition(context);
468 if (!precondition_result)
471 // Next run the condition for the breakpoint. If that says we should stop, then we'll run
472 // the callback for the breakpoint. If the callback says we shouldn't stop that will win.
474 if (bp_loc_sp->GetConditionText() != NULL)
476 Error condition_error;
477 bool condition_says_stop = bp_loc_sp->ConditionSaysStop(exe_ctx, condition_error);
479 if (!condition_error.Success())
481 Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger();
482 StreamSP error_sp = debugger.GetAsyncErrorStream ();
483 error_sp->Printf ("Stopped due to an error evaluating condition of breakpoint ");
484 bp_loc_sp->GetDescription (error_sp.get(), eDescriptionLevelBrief);
485 error_sp->Printf (": \"%s\"",
486 bp_loc_sp->GetConditionText());
488 const char *err_str = condition_error.AsCString("<Unknown Error>");
490 log->Printf("Error evaluating condition: \"%s\"\n", err_str);
492 error_sp->PutCString (err_str);
501 bp_loc_sp->GetDescription(&s, eDescriptionLevelBrief);
502 log->Printf ("Condition evaluated for breakpoint %s on thread 0x%llx conditon_says_stop: %i.",
504 static_cast<unsigned long long>(thread_sp->GetID()),
505 condition_says_stop);
507 if (!condition_says_stop)
509 // We don't want to increment the hit count of breakpoints if the condition fails.
510 // We've already bumped it by the time we get here, so undo the bump:
511 bp_loc_sp->UndoBumpHitCount();
517 bool callback_says_stop;
519 // FIXME: For now the callbacks have to run in async mode - the first time we restart we need
520 // to get out of there. So set it here.
521 // When we figure out how to nest breakpoint hits then this will change.
523 Debugger &debugger = thread_sp->CalculateTarget()->GetDebugger();
524 bool old_async = debugger.GetAsyncExecution();
525 debugger.SetAsyncExecution (true);
527 callback_says_stop = bp_loc_sp->InvokeCallback (&context);
529 debugger.SetAsyncExecution (old_async);
531 if (callback_says_stop)
532 m_should_stop = true;
534 // If we are going to stop for this breakpoint, then remove the breakpoint.
535 if (callback_says_stop && bp_loc_sp && bp_loc_sp->GetBreakpoint().IsOneShot())
537 thread_sp->GetProcess()->GetTarget().RemoveBreakpointByID (bp_loc_sp->GetBreakpoint().GetID());
540 // Also make sure that the callback hasn't continued the target.
541 // If it did, when we'll set m_should_start to false and get out of here.
542 if (HasTargetRunSinceMe ())
544 m_should_stop = false;
549 // We've figured out what this stop wants to do, so mark it as valid so we don't compute it again.
550 m_should_stop_is_valid = true;
555 m_should_stop = true;
556 m_should_stop_is_valid = true;
557 Log * log_process(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
560 log_process->Printf ("Process::%s could not find breakpoint site id: %" PRId64 "...", __FUNCTION__, m_value);
563 log->Printf ("Process::%s returning from action with m_should_stop: %d.", __FUNCTION__, m_should_stop);
569 bool m_should_stop_is_valid;
570 bool m_should_perform_action; // Since we are trying to preserve the "state" of the system even if we run functions
571 // etc. behind the users backs, we need to make sure we only REALLY perform the action once.
572 lldb::addr_t m_address; // We use this to capture the breakpoint site address when we create the StopInfo,
573 // in case somebody deletes it between the time the StopInfo is made and the
574 // description is asked for.
575 lldb::break_id_t m_break_id;
580 //----------------------------------------------------------------------
581 // StopInfoWatchpoint
582 //----------------------------------------------------------------------
584 class StopInfoWatchpoint : public StopInfo
587 // Make sure watchpoint is properly disabled and subsequently enabled while performing watchpoint actions.
588 class WatchpointSentry {
590 WatchpointSentry(Process *p, Watchpoint *w):
594 if (process && watchpoint)
596 const bool notify = false;
597 watchpoint->TurnOnEphemeralMode();
598 process->DisableWatchpoint(watchpoint, notify);
603 if (process && watchpoint)
605 if (!watchpoint->IsDisabledDuringEphemeralMode())
607 const bool notify = false;
608 process->EnableWatchpoint(watchpoint, notify);
610 watchpoint->TurnOffEphemeralMode();
615 Watchpoint *watchpoint;
618 StopInfoWatchpoint (Thread &thread, break_id_t watch_id) :
619 StopInfo(thread, watch_id),
620 m_should_stop(false),
621 m_should_stop_is_valid(false)
625 virtual ~StopInfoWatchpoint ()
630 GetStopReason () const
632 return eStopReasonWatchpoint;
638 if (m_description.empty())
641 strm.Printf("watchpoint %" PRIi64, m_value);
642 m_description.swap (strm.GetString());
644 return m_description.c_str();
649 ShouldStopSynchronous (Event *event_ptr)
651 // ShouldStop() method is idempotent and should not affect hit count.
652 // See Process::RunPrivateStateThread()->Process()->HandlePrivateEvent()
653 // -->Process()::ShouldBroadcastEvent()->ThreadList::ShouldStop()->
654 // Thread::ShouldStop()->ThreadPlanBase::ShouldStop()->
655 // StopInfoWatchpoint::ShouldStop() and
656 // Event::DoOnRemoval()->Process::ProcessEventData::DoOnRemoval()->
657 // StopInfoWatchpoint::PerformAction().
658 if (m_should_stop_is_valid)
659 return m_should_stop;
661 ThreadSP thread_sp (m_thread_wp.lock());
664 WatchpointSP wp_sp (thread_sp->CalculateTarget()->GetWatchpointList().FindByID(GetValue()));
667 // Check if we should stop at a watchpoint.
668 ExecutionContext exe_ctx (thread_sp->GetStackFrameAtIndex(0));
669 StoppointCallbackContext context (event_ptr, exe_ctx, true);
670 m_should_stop = wp_sp->ShouldStop (&context);
674 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
677 log->Printf ("Process::%s could not find watchpoint location id: %" PRId64 "...",
678 __FUNCTION__, GetValue());
680 m_should_stop = true;
683 m_should_stop_is_valid = true;
684 return m_should_stop;
688 ShouldStop (Event *event_ptr)
690 // This just reports the work done by PerformAction or the synchronous stop. It should
691 // only ever get called after they have had a chance to run.
692 assert (m_should_stop_is_valid);
693 return m_should_stop;
697 PerformAction (Event *event_ptr)
699 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS);
700 // We're going to calculate if we should stop or not in some way during the course of
701 // this code. Also by default we're going to stop, so set that here.
702 m_should_stop = true;
704 ThreadSP thread_sp (m_thread_wp.lock());
708 WatchpointSP wp_sp (thread_sp->CalculateTarget()->GetWatchpointList().FindByID(GetValue()));
711 ExecutionContext exe_ctx (thread_sp->GetStackFrameAtIndex(0));
712 Process* process = exe_ctx.GetProcessPtr();
714 // This sentry object makes sure the current watchpoint is disabled while performing watchpoint actions,
715 // and it is then enabled after we are finished.
716 WatchpointSentry sentry(process, wp_sp.get());
719 // check if this process is running on an architecture where watchpoints trigger
720 // before the associated instruction runs. if so, disable the WP, single-step and then
721 // re-enable the watchpoint
725 bool wp_triggers_after;
726 if (process->GetWatchpointSupportInfo(num, wp_triggers_after).Success())
728 if (!wp_triggers_after)
730 StopInfoSP stored_stop_info_sp = thread_sp->GetStopInfo();
731 assert (stored_stop_info_sp.get() == this);
733 ThreadPlanSP new_plan_sp(thread_sp->QueueThreadPlanForStepSingleInstruction(false, // step-over
734 false, // abort_other_plans
735 true)); // stop_other_threads
736 new_plan_sp->SetIsMasterPlan (true);
737 new_plan_sp->SetOkayToDiscard (false);
738 new_plan_sp->SetPrivate (true);
739 process->GetThreadList().SetSelectedThreadByID (thread_sp->GetID());
740 process->ResumeSynchronous(NULL);
741 process->GetThreadList().SetSelectedThreadByID (thread_sp->GetID());
742 thread_sp->SetStopInfo(stored_stop_info_sp);
748 if (m_should_stop && wp_sp->GetConditionText() != NULL)
750 // We need to make sure the user sees any parse errors in their condition, so we'll hook the
751 // constructor errors up to the debugger's Async I/O.
752 ExpressionResults result_code;
753 EvaluateExpressionOptions expr_options;
754 expr_options.SetUnwindOnError(true);
755 expr_options.SetIgnoreBreakpoints(true);
756 ValueObjectSP result_value_sp;
758 result_code = ClangUserExpression::Evaluate (exe_ctx,
760 wp_sp->GetConditionText(),
764 if (result_code == eExpressionCompleted)
769 if (result_value_sp->ResolveValue (scalar_value))
771 if (scalar_value.ULongLong(1) == 0)
773 // We have been vetoed. This takes precedence over querying
774 // the watchpoint whether it should stop (aka ignore count and
775 // friends). See also StopInfoWatchpoint::ShouldStop() as well
776 // as Process::ProcessEventData::DoOnRemoval().
777 m_should_stop = false;
780 m_should_stop = true;
782 log->Printf("Condition successfully evaluated, result is %s.\n",
783 m_should_stop ? "true" : "false");
787 m_should_stop = true;
789 log->Printf("Failed to get an integer result from the expression.");
795 Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger();
796 StreamSP error_sp = debugger.GetAsyncErrorStream ();
797 error_sp->Printf ("Stopped due to an error evaluating condition of watchpoint ");
798 wp_sp->GetDescription (error_sp.get(), eDescriptionLevelBrief);
799 error_sp->Printf (": \"%s\"",
800 wp_sp->GetConditionText());
802 const char *err_str = error.AsCString("<Unknown Error>");
804 log->Printf("Error evaluating condition: \"%s\"\n", err_str);
806 error_sp->PutCString (err_str);
809 // If the condition fails to be parsed or run, we should stop.
810 m_should_stop = true;
814 // If the condition says to stop, we run the callback to further decide whether to stop.
817 StoppointCallbackContext context (event_ptr, exe_ctx, false);
818 bool stop_requested = wp_sp->InvokeCallback (&context);
819 // Also make sure that the callback hasn't continued the target.
820 // If it did, when we'll set m_should_stop to false and get out of here.
821 if (HasTargetRunSinceMe ())
822 m_should_stop = false;
824 if (m_should_stop && !stop_requested)
826 // We have been vetoed by the callback mechanism.
827 m_should_stop = false;
830 // Finally, if we are going to stop, print out the new & old values:
833 wp_sp->CaptureWatchedValue(exe_ctx);
835 Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger();
836 StreamSP output_sp = debugger.GetAsyncOutputStream ();
837 wp_sp->DumpSnapshots(output_sp.get());
845 Log * log_process(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
848 log_process->Printf ("Process::%s could not find watchpoint id: %" PRId64 "...", __FUNCTION__, m_value);
851 log->Printf ("Process::%s returning from action with m_should_stop: %d.", __FUNCTION__, m_should_stop);
853 m_should_stop_is_valid = true;
859 bool m_should_stop_is_valid;
864 //----------------------------------------------------------------------
865 // StopInfoUnixSignal
866 //----------------------------------------------------------------------
868 class StopInfoUnixSignal : public StopInfo
872 StopInfoUnixSignal (Thread &thread, int signo, const char *description) :
873 StopInfo (thread, signo)
875 SetDescription (description);
878 virtual ~StopInfoUnixSignal ()
884 GetStopReason () const
886 return eStopReasonSignal;
890 ShouldStopSynchronous (Event *event_ptr)
892 ThreadSP thread_sp (m_thread_wp.lock());
894 return thread_sp->GetProcess()->GetUnixSignals()->GetShouldStop(m_value);
899 ShouldStop (Event *event_ptr)
901 ThreadSP thread_sp (m_thread_wp.lock());
903 return thread_sp->GetProcess()->GetUnixSignals()->GetShouldStop(m_value);
908 // If should stop returns false, check if we should notify of this event
910 DoShouldNotify (Event *event_ptr)
912 ThreadSP thread_sp (m_thread_wp.lock());
915 bool should_notify = thread_sp->GetProcess()->GetUnixSignals()->GetShouldNotify(m_value);
919 strm.Printf ("thread %d received signal: %s",
920 thread_sp->GetIndexID(),
921 thread_sp->GetProcess()->GetUnixSignals()->GetSignalAsCString(m_value));
922 Process::ProcessEventData::AddRestartedReason(event_ptr, strm.GetData());
924 return should_notify;
931 WillResume (lldb::StateType resume_state)
933 ThreadSP thread_sp (m_thread_wp.lock());
936 if (thread_sp->GetProcess()->GetUnixSignals()->GetShouldSuppress(m_value) == false)
937 thread_sp->SetResumeSignal(m_value);
944 if (m_description.empty())
946 ThreadSP thread_sp (m_thread_wp.lock());
950 const char *signal_name = thread_sp->GetProcess()->GetUnixSignals()->GetSignalAsCString(m_value);
952 strm.Printf("signal %s", signal_name);
954 strm.Printf("signal %" PRIi64, m_value);
955 m_description.swap (strm.GetString());
958 return m_description.c_str();
962 //----------------------------------------------------------------------
964 //----------------------------------------------------------------------
966 class StopInfoTrace : public StopInfo
970 StopInfoTrace (Thread &thread) :
971 StopInfo (thread, LLDB_INVALID_UID)
975 virtual ~StopInfoTrace ()
980 GetStopReason () const
982 return eStopReasonTrace;
988 if (m_description.empty())
991 return m_description.c_str();
996 //----------------------------------------------------------------------
998 //----------------------------------------------------------------------
1000 class StopInfoException : public StopInfo
1004 StopInfoException (Thread &thread, const char *description) :
1005 StopInfo (thread, LLDB_INVALID_UID)
1008 SetDescription (description);
1012 ~StopInfoException ()
1017 GetStopReason () const
1019 return eStopReasonException;
1022 virtual const char *
1025 if (m_description.empty())
1028 return m_description.c_str();
1033 //----------------------------------------------------------------------
1034 // StopInfoThreadPlan
1035 //----------------------------------------------------------------------
1037 class StopInfoThreadPlan : public StopInfo
1041 StopInfoThreadPlan (ThreadPlanSP &plan_sp, ValueObjectSP &return_valobj_sp, ClangExpressionVariableSP &expression_variable_sp) :
1042 StopInfo (plan_sp->GetThread(), LLDB_INVALID_UID),
1043 m_plan_sp (plan_sp),
1044 m_return_valobj_sp (return_valobj_sp),
1045 m_expression_variable_sp (expression_variable_sp)
1049 virtual ~StopInfoThreadPlan ()
1054 GetStopReason () const
1056 return eStopReasonPlanComplete;
1059 virtual const char *
1062 if (m_description.empty())
1065 m_plan_sp->GetDescription (&strm, eDescriptionLevelBrief);
1066 m_description.swap (strm.GetString());
1068 return m_description.c_str();
1072 GetReturnValueObject()
1074 return m_return_valobj_sp;
1077 ClangExpressionVariableSP
1078 GetExpressionVariable()
1080 return m_expression_variable_sp;
1085 ShouldStop (Event *event_ptr)
1088 return m_plan_sp->ShouldStop(event_ptr);
1090 return StopInfo::ShouldStop(event_ptr);
1094 ThreadPlanSP m_plan_sp;
1095 ValueObjectSP m_return_valobj_sp;
1096 ClangExpressionVariableSP m_expression_variable_sp;
1099 class StopInfoExec : public StopInfo
1103 StopInfoExec (Thread &thread) :
1104 StopInfo (thread, LLDB_INVALID_UID),
1105 m_performed_action (false)
1115 GetStopReason () const
1117 return eStopReasonExec;
1120 virtual const char *
1128 PerformAction (Event *event_ptr)
1130 // Only perform the action once
1131 if (m_performed_action)
1133 m_performed_action = true;
1134 ThreadSP thread_sp (m_thread_wp.lock());
1136 thread_sp->GetProcess()->DidExec();
1139 bool m_performed_action;
1142 } // namespace lldb_private
1145 StopInfo::CreateStopReasonWithBreakpointSiteID (Thread &thread, break_id_t break_id)
1147 return StopInfoSP (new StopInfoBreakpoint (thread, break_id));
1151 StopInfo::CreateStopReasonWithBreakpointSiteID (Thread &thread, break_id_t break_id, bool should_stop)
1153 return StopInfoSP (new StopInfoBreakpoint (thread, break_id, should_stop));
1157 StopInfo::CreateStopReasonWithWatchpointID (Thread &thread, break_id_t watch_id)
1159 return StopInfoSP (new StopInfoWatchpoint (thread, watch_id));
1163 StopInfo::CreateStopReasonWithSignal (Thread &thread, int signo, const char *description)
1165 return StopInfoSP (new StopInfoUnixSignal (thread, signo, description));
1169 StopInfo::CreateStopReasonToTrace (Thread &thread)
1171 return StopInfoSP (new StopInfoTrace (thread));
1175 StopInfo::CreateStopReasonWithPlan (ThreadPlanSP &plan_sp,
1176 ValueObjectSP return_valobj_sp,
1177 ClangExpressionVariableSP expression_variable_sp)
1179 return StopInfoSP (new StopInfoThreadPlan (plan_sp, return_valobj_sp, expression_variable_sp));
1183 StopInfo::CreateStopReasonWithException (Thread &thread, const char *description)
1185 return StopInfoSP (new StopInfoException (thread, description));
1189 StopInfo::CreateStopReasonWithExec (Thread &thread)
1191 return StopInfoSP (new StopInfoExec (thread));
1195 StopInfo::GetReturnValueObject(StopInfoSP &stop_info_sp)
1197 if (stop_info_sp && stop_info_sp->GetStopReason() == eStopReasonPlanComplete)
1199 StopInfoThreadPlan *plan_stop_info = static_cast<StopInfoThreadPlan *>(stop_info_sp.get());
1200 return plan_stop_info->GetReturnValueObject();
1203 return ValueObjectSP();
1206 ClangExpressionVariableSP
1207 StopInfo::GetExpressionVariable(StopInfoSP &stop_info_sp)
1209 if (stop_info_sp && stop_info_sp->GetStopReason() == eStopReasonPlanComplete)
1211 StopInfoThreadPlan *plan_stop_info = static_cast<StopInfoThreadPlan *>(stop_info_sp.get());
1212 return plan_stop_info->GetExpressionVariable();
1215 return ClangExpressionVariableSP();