blob: 2ea083dac45e9973e7afd83f53cd824f3caf9a6d [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.
Jonas Devliegheree103ae92018-11-15 01:18:15 +000030 Status status;
Kate Stoneb9c1b512016-09-06 20:57:50 +000031 m_step_out_threadplan_sp = GetThread().QueueThreadPlanForStepOut(
32 false, // abort other plans
33 nullptr, // addr_context
34 true, // first instruction
35 true, // stop other threads
36 eVoteNo, // do not say "we're stopping"
Jonas Devliegheree103ae92018-11-15 01:18:15 +000037 eVoteNoOpinion, // don't care about run state broadcasting
Kate Stoneb9c1b512016-09-06 20:57:50 +000038 0, // frame_idx
Jonas Devliegheree103ae92018-11-15 01:18:15 +000039 status, // status
Kate Stoneb9c1b512016-09-06 20:57:50 +000040 eLazyBoolCalculate // avoid code w/o debinfo
Jonas Devliegheree103ae92018-11-15 01:18:15 +000041 );
Todd Fiala75930012016-08-19 04:21:48 +000042}
43
44// -------------------------------------------------------------------------
45// ThreadPlan API
46// -------------------------------------------------------------------------
47
Kate Stoneb9c1b512016-09-06 20:57:50 +000048void ThreadPlanCallOnFunctionExit::GetDescription(
49 Stream *s, lldb::DescriptionLevel level) {
50 if (!s)
51 return;
52 s->Printf("Running until completion of current function, then making "
53 "callback.");
Todd Fiala75930012016-08-19 04:21:48 +000054}
55
Kate Stoneb9c1b512016-09-06 20:57:50 +000056bool ThreadPlanCallOnFunctionExit::ValidatePlan(Stream *error) {
57 // We'll say we're always good since I don't know what would make this
58 // invalid.
59 return true;
Todd Fiala75930012016-08-19 04:21:48 +000060}
61
Kate Stoneb9c1b512016-09-06 20:57:50 +000062bool ThreadPlanCallOnFunctionExit::ShouldStop(Event *event_ptr) {
Adrian Prantl05097242018-04-30 16:49:04 +000063 // If this is where we find out that an internal stop came in, then: Check if
64 // the step-out plan completed. If it did, then we want to run the callback
65 // here (our reason for living...)
Kate Stoneb9c1b512016-09-06 20:57:50 +000066 if (m_step_out_threadplan_sp && m_step_out_threadplan_sp->IsPlanComplete()) {
67 m_callback();
Todd Fiala75930012016-08-19 04:21:48 +000068
Kate Stoneb9c1b512016-09-06 20:57:50 +000069 // We no longer need the pointer to the step-out thread plan.
70 m_step_out_threadplan_sp.reset();
Todd Fiala75930012016-08-19 04:21:48 +000071
Kate Stoneb9c1b512016-09-06 20:57:50 +000072 // Indicate that this plan is done and can be discarded.
73 SetPlanComplete();
Todd Fiala75930012016-08-19 04:21:48 +000074
Adrian Prantl05097242018-04-30 16:49:04 +000075 // We're done now, but we want to return false so that we don't cause the
76 // thread to really stop.
Kate Stoneb9c1b512016-09-06 20:57:50 +000077 }
Todd Fiala75930012016-08-19 04:21:48 +000078
Kate Stoneb9c1b512016-09-06 20:57:50 +000079 return false;
Todd Fiala75930012016-08-19 04:21:48 +000080}
81
Kate Stoneb9c1b512016-09-06 20:57:50 +000082bool ThreadPlanCallOnFunctionExit::WillStop() {
83 // The code looks like the return value is ignored via ThreadList::
Adrian Prantl05097242018-04-30 16:49:04 +000084 // ShouldStop(). This is called when we really are going to stop. We don't
85 // care and don't need to do anything here.
Kate Stoneb9c1b512016-09-06 20:57:50 +000086 return false;
Todd Fiala75930012016-08-19 04:21:48 +000087}
88
Kate Stoneb9c1b512016-09-06 20:57:50 +000089bool ThreadPlanCallOnFunctionExit::DoPlanExplainsStop(Event *event_ptr) {
Adrian Prantl05097242018-04-30 16:49:04 +000090 // We don't ever explain a stop. The only stop that is relevant to us
91 // directly is the step_out plan we added to do the heavy lifting of getting
92 // us past the current method.
Kate Stoneb9c1b512016-09-06 20:57:50 +000093 return false;
Todd Fiala75930012016-08-19 04:21:48 +000094}
95
Kate Stoneb9c1b512016-09-06 20:57:50 +000096lldb::StateType ThreadPlanCallOnFunctionExit::GetPlanRunState() {
Adrian Prantl05097242018-04-30 16:49:04 +000097 // This value doesn't matter - we'll never be the top thread plan, so nobody
98 // will ask us this question.
Kate Stoneb9c1b512016-09-06 20:57:50 +000099 return eStateRunning;
Todd Fiala75930012016-08-19 04:21:48 +0000100}