Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 1 | //===-- 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 | |
| 12 | using namespace lldb; |
| 13 | using namespace lldb_private; |
| 14 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 15 | ThreadPlanCallOnFunctionExit::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 Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 23 | } |
| 24 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 25 | void ThreadPlanCallOnFunctionExit::DidPush() { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 26 | // We now want to queue the "step out" thread plan so it executes and |
| 27 | // completes. |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 28 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 29 | // Set stop vote to eVoteNo. |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 30 | Status status; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 31 | 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 Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 37 | eVoteNoOpinion, // don't care about run state broadcasting |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 38 | 0, // frame_idx |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 39 | status, // status |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 40 | eLazyBoolCalculate // avoid code w/o debinfo |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 41 | ); |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | // ------------------------------------------------------------------------- |
| 45 | // ThreadPlan API |
| 46 | // ------------------------------------------------------------------------- |
| 47 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 48 | void 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 Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 54 | } |
| 55 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 56 | bool 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 Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 60 | } |
| 61 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 62 | bool ThreadPlanCallOnFunctionExit::ShouldStop(Event *event_ptr) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 63 | // 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 Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 66 | if (m_step_out_threadplan_sp && m_step_out_threadplan_sp->IsPlanComplete()) { |
| 67 | m_callback(); |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 68 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 69 | // We no longer need the pointer to the step-out thread plan. |
| 70 | m_step_out_threadplan_sp.reset(); |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 71 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 72 | // Indicate that this plan is done and can be discarded. |
| 73 | SetPlanComplete(); |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 74 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 75 | // We're done now, but we want to return false so that we don't cause the |
| 76 | // thread to really stop. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 77 | } |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 78 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 79 | return false; |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 80 | } |
| 81 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 82 | bool ThreadPlanCallOnFunctionExit::WillStop() { |
| 83 | // The code looks like the return value is ignored via ThreadList:: |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 84 | // 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 Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 86 | return false; |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 87 | } |
| 88 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 89 | bool ThreadPlanCallOnFunctionExit::DoPlanExplainsStop(Event *event_ptr) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 90 | // 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 Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 93 | return false; |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 94 | } |
| 95 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 96 | lldb::StateType ThreadPlanCallOnFunctionExit::GetPlanRunState() { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 97 | // This value doesn't matter - we'll never be the top thread plan, so nobody |
| 98 | // will ask us this question. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 99 | return eStateRunning; |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 100 | } |