blob: e8ea73f3c6a0be89c1b2ea28459de1f8df56dcfa [file] [log] [blame]
Todd Fiala75930012016-08-19 04:21:48 +00001//===-- ThreadPlanCallOnFunctionExit.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
10#include "lldb/Target/ThreadPlanCallOnFunctionExit.h"
11
12using namespace lldb;
13using namespace lldb_private;
14
Kate Stoneb9c1b512016-09-06 20:57:50 +000015ThreadPlanCallOnFunctionExit::ThreadPlanCallOnFunctionExit(
16 Thread &thread, const Callback &callback)
17 : ThreadPlan(ThreadPlanKind::eKindGeneric, "CallOnFunctionExit", thread,
18 eVoteNoOpinion, eVoteNoOpinion // TODO check with Jim on these
19 ),
20 m_callback(callback) {
21 // We are not a user-generated plan.
22 SetIsMasterPlan(false);
Todd Fiala75930012016-08-19 04:21:48 +000023}
24
Kate Stoneb9c1b512016-09-06 20:57:50 +000025void ThreadPlanCallOnFunctionExit::DidPush() {
Adrian Prantl05097242018-04-30 16:49:04 +000026 // We now want to queue the "step out" thread plan so it executes and
27 // completes.
Todd Fiala75930012016-08-19 04:21:48 +000028
Kate Stoneb9c1b512016-09-06 20:57:50 +000029 // Set stop vote to eVoteNo.
30 m_step_out_threadplan_sp = GetThread().QueueThreadPlanForStepOut(
31 false, // abort other plans
32 nullptr, // addr_context
33 true, // first instruction
34 true, // stop other threads
35 eVoteNo, // do not say "we're stopping"
36 eVoteNoOpinion, // don't care about
37 // run state broadcasting
38 0, // frame_idx
39 eLazyBoolCalculate // avoid code w/o debinfo
40 );
Todd Fiala75930012016-08-19 04:21:48 +000041}
42
43// -------------------------------------------------------------------------
44// ThreadPlan API
45// -------------------------------------------------------------------------
46
Kate Stoneb9c1b512016-09-06 20:57:50 +000047void ThreadPlanCallOnFunctionExit::GetDescription(
48 Stream *s, lldb::DescriptionLevel level) {
49 if (!s)
50 return;
51 s->Printf("Running until completion of current function, then making "
52 "callback.");
Todd Fiala75930012016-08-19 04:21:48 +000053}
54
Kate Stoneb9c1b512016-09-06 20:57:50 +000055bool ThreadPlanCallOnFunctionExit::ValidatePlan(Stream *error) {
56 // We'll say we're always good since I don't know what would make this
57 // invalid.
58 return true;
Todd Fiala75930012016-08-19 04:21:48 +000059}
60
Kate Stoneb9c1b512016-09-06 20:57:50 +000061bool ThreadPlanCallOnFunctionExit::ShouldStop(Event *event_ptr) {
Adrian Prantl05097242018-04-30 16:49:04 +000062 // If this is where we find out that an internal stop came in, then: Check if
63 // the step-out plan completed. If it did, then we want to run the callback
64 // here (our reason for living...)
Kate Stoneb9c1b512016-09-06 20:57:50 +000065 if (m_step_out_threadplan_sp && m_step_out_threadplan_sp->IsPlanComplete()) {
66 m_callback();
Todd Fiala75930012016-08-19 04:21:48 +000067
Kate Stoneb9c1b512016-09-06 20:57:50 +000068 // We no longer need the pointer to the step-out thread plan.
69 m_step_out_threadplan_sp.reset();
Todd Fiala75930012016-08-19 04:21:48 +000070
Kate Stoneb9c1b512016-09-06 20:57:50 +000071 // Indicate that this plan is done and can be discarded.
72 SetPlanComplete();
Todd Fiala75930012016-08-19 04:21:48 +000073
Adrian Prantl05097242018-04-30 16:49:04 +000074 // We're done now, but we want to return false so that we don't cause the
75 // thread to really stop.
Kate Stoneb9c1b512016-09-06 20:57:50 +000076 }
Todd Fiala75930012016-08-19 04:21:48 +000077
Kate Stoneb9c1b512016-09-06 20:57:50 +000078 return false;
Todd Fiala75930012016-08-19 04:21:48 +000079}
80
Kate Stoneb9c1b512016-09-06 20:57:50 +000081bool ThreadPlanCallOnFunctionExit::WillStop() {
82 // The code looks like the return value is ignored via ThreadList::
Adrian Prantl05097242018-04-30 16:49:04 +000083 // ShouldStop(). This is called when we really are going to stop. We don't
84 // care and don't need to do anything here.
Kate Stoneb9c1b512016-09-06 20:57:50 +000085 return false;
Todd Fiala75930012016-08-19 04:21:48 +000086}
87
Kate Stoneb9c1b512016-09-06 20:57:50 +000088bool ThreadPlanCallOnFunctionExit::DoPlanExplainsStop(Event *event_ptr) {
Adrian Prantl05097242018-04-30 16:49:04 +000089 // We don't ever explain a stop. The only stop that is relevant to us
90 // directly is the step_out plan we added to do the heavy lifting of getting
91 // us past the current method.
Kate Stoneb9c1b512016-09-06 20:57:50 +000092 return false;
Todd Fiala75930012016-08-19 04:21:48 +000093}
94
Kate Stoneb9c1b512016-09-06 20:57:50 +000095lldb::StateType ThreadPlanCallOnFunctionExit::GetPlanRunState() {
Adrian Prantl05097242018-04-30 16:49:04 +000096 // This value doesn't matter - we'll never be the top thread plan, so nobody
97 // will ask us this question.
Kate Stoneb9c1b512016-09-06 20:57:50 +000098 return eStateRunning;
Todd Fiala75930012016-08-19 04:21:48 +000099}