blob: 7471e9b3d7ac3dc88185f38705b9f2957ff4986a [file] [log] [blame]
Raphael Isemann80814282020-01-24 08:23:27 +01001//===-- ThreadPlanCallOnFunctionExit.cpp ----------------------------------===//
Todd Fiala75930012016-08-19 04:21:48 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Todd Fiala75930012016-08-19 04:21:48 +00006//
7//===----------------------------------------------------------------------===//
8
9#include "lldb/Target/ThreadPlanCallOnFunctionExit.h"
10
11using namespace lldb;
12using namespace lldb_private;
13
Kate Stoneb9c1b512016-09-06 20:57:50 +000014ThreadPlanCallOnFunctionExit::ThreadPlanCallOnFunctionExit(
15 Thread &thread, const Callback &callback)
16 : ThreadPlan(ThreadPlanKind::eKindGeneric, "CallOnFunctionExit", thread,
17 eVoteNoOpinion, eVoteNoOpinion // TODO check with Jim on these
18 ),
19 m_callback(callback) {
20 // We are not a user-generated plan.
21 SetIsMasterPlan(false);
Todd Fiala75930012016-08-19 04:21:48 +000022}
23
Kate Stoneb9c1b512016-09-06 20:57:50 +000024void ThreadPlanCallOnFunctionExit::DidPush() {
Adrian Prantl05097242018-04-30 16:49:04 +000025 // We now want to queue the "step out" thread plan so it executes and
26 // completes.
Todd Fiala75930012016-08-19 04:21:48 +000027
Kate Stoneb9c1b512016-09-06 20:57:50 +000028 // Set stop vote to eVoteNo.
Jonas Devliegheree103ae92018-11-15 01:18:15 +000029 Status status;
Kate Stoneb9c1b512016-09-06 20:57:50 +000030 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"
Jonas Devliegheree103ae92018-11-15 01:18:15 +000036 eVoteNoOpinion, // don't care about run state broadcasting
Kate Stoneb9c1b512016-09-06 20:57:50 +000037 0, // frame_idx
Jonas Devliegheree103ae92018-11-15 01:18:15 +000038 status, // status
Kate Stoneb9c1b512016-09-06 20:57:50 +000039 eLazyBoolCalculate // avoid code w/o debinfo
Jonas Devliegheree103ae92018-11-15 01:18:15 +000040 );
Todd Fiala75930012016-08-19 04:21:48 +000041}
42
Todd Fiala75930012016-08-19 04:21:48 +000043// ThreadPlan API
Todd Fiala75930012016-08-19 04:21:48 +000044
Kate Stoneb9c1b512016-09-06 20:57:50 +000045void ThreadPlanCallOnFunctionExit::GetDescription(
46 Stream *s, lldb::DescriptionLevel level) {
47 if (!s)
48 return;
49 s->Printf("Running until completion of current function, then making "
50 "callback.");
Todd Fiala75930012016-08-19 04:21:48 +000051}
52
Kate Stoneb9c1b512016-09-06 20:57:50 +000053bool ThreadPlanCallOnFunctionExit::ValidatePlan(Stream *error) {
54 // We'll say we're always good since I don't know what would make this
55 // invalid.
56 return true;
Todd Fiala75930012016-08-19 04:21:48 +000057}
58
Kate Stoneb9c1b512016-09-06 20:57:50 +000059bool ThreadPlanCallOnFunctionExit::ShouldStop(Event *event_ptr) {
Adrian Prantl05097242018-04-30 16:49:04 +000060 // If this is where we find out that an internal stop came in, then: Check if
61 // the step-out plan completed. If it did, then we want to run the callback
62 // here (our reason for living...)
Kate Stoneb9c1b512016-09-06 20:57:50 +000063 if (m_step_out_threadplan_sp && m_step_out_threadplan_sp->IsPlanComplete()) {
64 m_callback();
Todd Fiala75930012016-08-19 04:21:48 +000065
Kate Stoneb9c1b512016-09-06 20:57:50 +000066 // We no longer need the pointer to the step-out thread plan.
67 m_step_out_threadplan_sp.reset();
Todd Fiala75930012016-08-19 04:21:48 +000068
Kate Stoneb9c1b512016-09-06 20:57:50 +000069 // Indicate that this plan is done and can be discarded.
70 SetPlanComplete();
Todd Fiala75930012016-08-19 04:21:48 +000071
Adrian Prantl05097242018-04-30 16:49:04 +000072 // We're done now, but we want to return false so that we don't cause the
73 // thread to really stop.
Kate Stoneb9c1b512016-09-06 20:57:50 +000074 }
Todd Fiala75930012016-08-19 04:21:48 +000075
Kate Stoneb9c1b512016-09-06 20:57:50 +000076 return false;
Todd Fiala75930012016-08-19 04:21:48 +000077}
78
Kate Stoneb9c1b512016-09-06 20:57:50 +000079bool ThreadPlanCallOnFunctionExit::WillStop() {
80 // The code looks like the return value is ignored via ThreadList::
Adrian Prantl05097242018-04-30 16:49:04 +000081 // ShouldStop(). This is called when we really are going to stop. We don't
82 // care and don't need to do anything here.
Kate Stoneb9c1b512016-09-06 20:57:50 +000083 return false;
Todd Fiala75930012016-08-19 04:21:48 +000084}
85
Kate Stoneb9c1b512016-09-06 20:57:50 +000086bool ThreadPlanCallOnFunctionExit::DoPlanExplainsStop(Event *event_ptr) {
Adrian Prantl05097242018-04-30 16:49:04 +000087 // We don't ever explain a stop. The only stop that is relevant to us
88 // directly is the step_out plan we added to do the heavy lifting of getting
89 // us past the current method.
Kate Stoneb9c1b512016-09-06 20:57:50 +000090 return false;
Todd Fiala75930012016-08-19 04:21:48 +000091}
92
Kate Stoneb9c1b512016-09-06 20:57:50 +000093lldb::StateType ThreadPlanCallOnFunctionExit::GetPlanRunState() {
Adrian Prantl05097242018-04-30 16:49:04 +000094 // This value doesn't matter - we'll never be the top thread plan, so nobody
95 // will ask us this question.
Kate Stoneb9c1b512016-09-06 20:57:50 +000096 return eStateRunning;
Todd Fiala75930012016-08-19 04:21:48 +000097}