LLDB  mainline
ThreadPlanCallOnFunctionExit.cpp
Go to the documentation of this file.
1 //===-- ThreadPlanCallOnFunctionExit.cpp ----------------------------------===//
2 //
3 // 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
6 //
7 //===----------------------------------------------------------------------===//
8 
10 
11 using namespace lldb;
12 using namespace lldb_private;
13 
14 ThreadPlanCallOnFunctionExit::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);
22 }
23 
25  // We now want to queue the "step out" thread plan so it executes and
26  // completes.
27 
28  // Set stop vote to eVoteNo.
29  Status status;
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 run state broadcasting
37  0, // frame_idx
38  status, // status
39  eLazyBoolCalculate // avoid code w/o debinfo
40  );
41 }
42 
43 // ThreadPlan API
44 
46  Stream *s, lldb::DescriptionLevel level) {
47  if (!s)
48  return;
49  s->Printf("Running until completion of current function, then making "
50  "callback.");
51 }
52 
54  // We'll say we're always good since I don't know what would make this
55  // invalid.
56  return true;
57 }
58 
60  // 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...)
63  if (m_step_out_threadplan_sp && m_step_out_threadplan_sp->IsPlanComplete()) {
64  m_callback();
65 
66  // We no longer need the pointer to the step-out thread plan.
68 
69  // Indicate that this plan is done and can be discarded.
71 
72  // We're done now, but we want to return false so that we don't cause the
73  // thread to really stop.
74  }
75 
76  return false;
77 }
78 
80  // The code looks like the return value is ignored via ThreadList::
81  // ShouldStop(). This is called when we really are going to stop. We don't
82  // care and don't need to do anything here.
83  return false;
84 }
85 
87  // 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.
90  return false;
91 }
92 
94  // This value doesn't matter - we'll never be the top thread plan, so nobody
95  // will ask us this question.
96  return eStateRunning;
97 }
lldb_private::ThreadPlanCallOnFunctionExit::GetPlanRunState
lldb::StateType GetPlanRunState() override
Definition: ThreadPlanCallOnFunctionExit.cpp:93
lldb_private::ThreadPlanCallOnFunctionExit::DoPlanExplainsStop
bool DoPlanExplainsStop(Event *event_ptr) override
Definition: ThreadPlanCallOnFunctionExit.cpp:86
lldb_private::ThreadPlan::GetThread
Thread & GetThread()
Returns the Thread that is using this thread plan.
Definition: ThreadPlan.cpp:41
lldb_private::Event
Definition: Event.h:180
lldb_private::ThreadPlanCallOnFunctionExit::m_callback
Callback m_callback
Definition: ThreadPlanCallOnFunctionExit.h:48
lldb_private::Thread::QueueThreadPlanForStepOut
virtual lldb::ThreadPlanSP QueueThreadPlanForStepOut(bool abort_other_plans, SymbolContext *addr_context, bool first_insn, bool stop_other_threads, Vote report_stop_vote, Vote report_run_vote, uint32_t frame_idx, Status &status, LazyBool step_out_avoids_code_without_debug_info=eLazyBoolCalculate)
Queue the plan used to step out of the function at the current PC of thread.
Definition: Thread.cpp:1303
lldb_private::eVoteNoOpinion
@ eVoteNoOpinion
Definition: lldb-private-enumerations.h:59
lldb_private::Stream
Definition: Stream.h:28
lldb_private::ThreadPlanCallOnFunctionExit::ValidatePlan
bool ValidatePlan(Stream *error) override
Returns whether this plan could be successfully created.
Definition: ThreadPlanCallOnFunctionExit.cpp:53
lldb_private::ThreadPlan::SetIsMasterPlan
bool SetIsMasterPlan(bool value)
Definition: ThreadPlan.h:391
lldb_private::ThreadPlanCallOnFunctionExit::GetDescription
void GetDescription(Stream *s, lldb::DescriptionLevel level) override
Print a description of this thread to the stream s.
Definition: ThreadPlanCallOnFunctionExit.cpp:45
lldb_private::ThreadPlan::ThreadPlanKind
ThreadPlanKind
Definition: ThreadPlan.h:287
lldb_private::ThreadPlanCallOnFunctionExit::WillStop
bool WillStop() override
Definition: ThreadPlanCallOnFunctionExit.cpp:79
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::ThreadPlan
Definition: ThreadPlan.h:282
lldb_private::eVoteNo
@ eVoteNo
Definition: lldb-private-enumerations.h:59
lldb_private::Thread
Definition: Thread.h:60
lldb_private::ThreadPlanCallOnFunctionExit::m_step_out_threadplan_sp
lldb::ThreadPlanSP m_step_out_threadplan_sp
Definition: ThreadPlanCallOnFunctionExit.h:49
lldb_private::ThreadPlanCallOnFunctionExit::ShouldStop
bool ShouldStop(Event *event_ptr) override
Definition: ThreadPlanCallOnFunctionExit.cpp:59
lldb_private::ThreadPlan::SetPlanComplete
void SetPlanComplete(bool success=true)
Definition: ThreadPlan.cpp:65
lldb_private::ThreadPlanCallOnFunctionExit::Callback
std::function< void()> Callback
Definition for the callback made when the currently executing thread finishes executing its function.
Definition: ThreadPlanCallOnFunctionExit.h:26
lldb_private::Status
Definition: Status.h:44
lldb_private::ThreadPlanCallOnFunctionExit::DidPush
void DidPush() override
Definition: ThreadPlanCallOnFunctionExit.cpp:24
ThreadPlanCallOnFunctionExit.h
lldb_private::Stream::Printf
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::eLazyBoolCalculate
@ eLazyBoolCalculate
Definition: lldb-private-enumerations.h:115
lldb::StateType
StateType
Process and Thread States.
Definition: lldb-enumerations.h:73
lldb
Definition: SBAddress.h:15
lldb::eStateRunning
@ eStateRunning
Process or thread is running and can't be examined.
Definition: lldb-enumerations.h:85
lldb::DescriptionLevel
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
Definition: lldb-enumerations.h:207