Raphael Isemann | 8081428 | 2020-01-24 08:23:27 +0100 | [diff] [blame] | 1 | //===-- ThreadPlanCallOnFunctionExit.cpp ----------------------------------===// |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "lldb/Target/ThreadPlanCallOnFunctionExit.h" |
| 10 | |
| 11 | using namespace lldb; |
| 12 | using namespace lldb_private; |
| 13 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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); |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 22 | } |
| 23 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 24 | void ThreadPlanCallOnFunctionExit::DidPush() { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 25 | // We now want to queue the "step out" thread plan so it executes and |
| 26 | // completes. |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 27 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 28 | // Set stop vote to eVoteNo. |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 29 | Status status; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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" |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 36 | eVoteNoOpinion, // don't care about run state broadcasting |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 37 | 0, // frame_idx |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 38 | status, // status |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 39 | eLazyBoolCalculate // avoid code w/o debinfo |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 40 | ); |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 41 | } |
| 42 | |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 43 | // ThreadPlan API |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 44 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 45 | void 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 Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 51 | } |
| 52 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 53 | bool 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 Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 59 | bool ThreadPlanCallOnFunctionExit::ShouldStop(Event *event_ptr) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 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...) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 63 | if (m_step_out_threadplan_sp && m_step_out_threadplan_sp->IsPlanComplete()) { |
| 64 | m_callback(); |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 65 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 66 | // We no longer need the pointer to the step-out thread plan. |
| 67 | m_step_out_threadplan_sp.reset(); |
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 | // Indicate that this plan is done and can be discarded. |
| 70 | SetPlanComplete(); |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 71 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 72 | // We're done now, but we want to return false so that we don't cause the |
| 73 | // thread to really stop. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 74 | } |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 75 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 76 | return false; |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 77 | } |
| 78 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 79 | bool ThreadPlanCallOnFunctionExit::WillStop() { |
| 80 | // The code looks like the return value is ignored via ThreadList:: |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 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. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 83 | return false; |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 84 | } |
| 85 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 86 | bool ThreadPlanCallOnFunctionExit::DoPlanExplainsStop(Event *event_ptr) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 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. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 90 | return false; |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 91 | } |
| 92 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 93 | lldb::StateType ThreadPlanCallOnFunctionExit::GetPlanRunState() { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 94 | // This value doesn't matter - we'll never be the top thread plan, so nobody |
| 95 | // will ask us this question. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 96 | return eStateRunning; |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 97 | } |