ThreadPlan.h revision 5a47e8bcc7277dc3683f2af2aeb9717184e8360c
18015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane//===-- ThreadPlan.h --------------------------------------------*- C++ -*-===// 2f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu// 38015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// The LLVM Compiler Infrastructure 4f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu// 5f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu// This file is distributed under the University of Illinois Open Source 68015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// License. See LICENSE.TXT for details. 7f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu// 88015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane//===----------------------------------------------------------------------===// 98015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane 108015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane#ifndef liblldb_ThreadPlan_h_ 118015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane#define liblldb_ThreadPlan_h_ 128015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane 138015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// C Includes 148015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// C++ Includes 15f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu#include <string> 168015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// Other libraries and framework includes 178015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// Project includes 188015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane#include "lldb/lldb-private.h" 19f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu#include "lldb/Core/UserID.h" 20f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu#include "lldb/Host/Mutex.h" 21f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu 22f2001df508fda599a18b3586d2775e970a3db13aChia-I Wunamespace lldb_private { 23f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu 24f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu//------------------------------------------------------------------ 25f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu// ThreadPlan: 26f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu// This is the pure virtual base class for thread plans. 27f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu// 288015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// The thread plans provide the "atoms" of behavior that 298015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// all the logical process control, either directly from commands or through 308015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// more complex composite plans will rely on. 318015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// 328015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// Plan Stack: 338015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// 348015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// The thread maintaining a thread plan stack, and you program the actions of a particular thread 358015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// by pushing plans onto the plan stack. 368015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// There is always a "Current" plan, which is the head of the plan stack, though in some cases 378015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// a plan may defer to plans higher in the stack for some piece of information. 3878c3a351bc91eed49a07108682013a323d87540eChia-I Wu// 3978c3a351bc91eed49a07108682013a323d87540eChia-I Wu// The plan stack is never empty, there is always a Base Plan which persists through the life 408015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// of the running process. 4115f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// 4215f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// 4378c3a351bc91eed49a07108682013a323d87540eChia-I Wu// DEPRECATED: This ended up causing a real hassle, too many cases where the immediate plan 448015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// got stranded. So the better way to do this is to post any plans you need to do right before 458015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// running in the PrepareToResume method. 46e6a7ee7fbb7a058bf3c7de965197f19a9bcede8eBrian Paul//f 478015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// Immediate Plans: 488015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// 4994cb321b5d246185abf71d89968d472a626f1a23Chia-I Wu// One other complexity of the plan stack is that sometimes you need to do a piece of work immediately 508015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// on resume, regardless of what other plans have been pushed on the stack while the process has 518015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// been stopped. The classic example is stepping over a breakpoint. To that end the plan stack is 528015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// actually two stacks, an "immediate" plan stack and the normal plan stack. A plan can indicate that it 538015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// should go on the immediate plan stack by returning "true" from the IsImmediate method. 548015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// 5578c3a351bc91eed49a07108682013a323d87540eChia-I Wu// END DEPRECATED... 5678c3a351bc91eed49a07108682013a323d87540eChia-I Wu// 5778c3a351bc91eed49a07108682013a323d87540eChia-I Wu// Creating Plans: 5878c3a351bc91eed49a07108682013a323d87540eChia-I Wu// 5915f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// The thread plan is generally created and added to the plan stack through the QueueThreadPlanFor... API 6015f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// in lldb::Thread. Those API's will return the plan that performs the named operation in a manner 6115f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// appropriate for the current process. The plans in lldb/source/Target are generic 6215f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// implementations, but a Process plugin can override them. 6315f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// 6415f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// ValidatePlan is then called. If it returns false, the plan is unshipped. This is a little 6515f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// convenience which keeps us from having to error out of the constructor. 6615f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// 6715f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// Then the plan is added to the plan stack. When the plan is added to the plan stack its DidPush 6815f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// will get called. This is useful if a plan wants to push any additional plans as it is constructed, 6915f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// since you need to make sure you're already on the stack before you push additional plans. 7015f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// 7115f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// Completed Plans: 7215f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// 7315f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// When the target process stops the plans are queried, among other things, for whether their job is done. 7415f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// If it is they are moved from the plan stack to the Completed Plan stack in reverse order from their position 7515f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// on the plan stack (since multiple plans may be done at a given stop.) This is used primarily so that 768015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// the lldb::Thread::StopInfo for the thread can be set properly. If one plan pushes another to achieve part of 778015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// its job, but it doesn't want that sub-plan to be the one that sets the StopInfo, then call SetPrivate on the 788015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// sub-plan when you create it, and the Thread will pass over that plan in reporting the reason for the stop. 798015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// 8015f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// When the plan is moved from the plan stack to the completed plan stack its DidPop method is called. You should 8115f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// undo anything that affects target state in this method so the target state is clear for new plans. 8215f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// But be sure to leave whatever state might be needed to correctly fill the StopInfo. 8315f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// 8415f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// Over the lifetime of the plan, various methods of the ThreadPlan are then called in response to changes of state in 8515f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// the process we are debugging as follows: 8615f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// 8715f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// Resuming: 8815f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// 8915f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// When the target process is about to be restarted, the plan's WillResume method is called, 9015f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// giving the plan a chance to prepare for the run. If WillResume returns false, then the 9115f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// process is not restarted. Be sure to set an appropriate error value in the Process if 9215f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// you have to do this. 9315f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// Next the "StopOthers" method of all the threads are polled, and if one thread's Current plan 9415f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// returns "true" then only that thread gets to run. If more than one returns "true" the threads that want to run solo 9515f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// get run one by one round robin fashion. Otherwise all are let to run. 9615f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// Finally, for each thread that is running, it run state is set to the return of RunState from the 9715f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// thread's Current plan. 9815f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// 9915f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// Responding to a stop: 10015f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// 10115f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// When the target process stops, the plan is called in the following stages: 10215f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// 10315f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// First the thread asks the Current Plan if it can handle this stop by calling PlanExplainsStop. 10415f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// If the Current plan answers "true" then it is asked if the stop should percolate all the way to the 10515f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// user by calling the ShouldStop method. If the current plan doesn't explain the stop, then we query down 10615f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// the plan stack for a plan that does explain the stop. The plan that does explain the stop then needs to 10715f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// figure out what to do about the plans below it in the stack. If the stop is recoverable, then the plan that 10815f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// understands it can just do what it needs to set up to restart, and then continue. 10915f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// Otherwise, the plan that understood the stop should call DiscardPlanStack to clean up the stack below it. 11015f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// In the normal case, this will just collapse the plan stack up to the point of the plan that understood 11115f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// the stop reason. However, if a plan wishes to stay on the stack after an event it didn't directly handle 11215f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// it can designate itself a "Master" plan by responding true to IsMasterPlan, and then if it wants not to be 11315f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// discarded, it can return true to OkayToDiscard, and it and all its dependent plans will be preserved when 11415f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// we resume execution. 11515f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// 11615f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// Actually Stopping: 11715f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// 11815f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu// If a plan says responds "true" to ShouldStop, then it is asked if it's job is complete by calling 119f5a06fad62cd43d7854bafa60bbe6f48e8cf90afChia-I Wu// MischiefManaged. If that returns true, the thread is popped from the plan stack and added to the 1208015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// Completed Plan Stack. Then the next plan in the stack is asked if it ShouldStop, and it returns "true", 121f5a06fad62cd43d7854bafa60bbe6f48e8cf90afChia-I Wu// it is asked if it is done, and if yes popped, and so on till we reach a plan that is not done. 122f5a06fad62cd43d7854bafa60bbe6f48e8cf90afChia-I Wu// 123f5a06fad62cd43d7854bafa60bbe6f48e8cf90afChia-I Wu// Since you often know in the ShouldStop method whether your plan is complete, as a convenience you can call 124f5a06fad62cd43d7854bafa60bbe6f48e8cf90afChia-I Wu// SetPlanComplete and the ThreadPlan implementation of MischiefManaged will return "true", without your having 125f5a06fad62cd43d7854bafa60bbe6f48e8cf90afChia-I Wu// to redo the calculation when your sub-classes MischiefManaged is called. If you call SetPlanComplete, you can 1268015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// later use IsPlanComplete to determine whether the plan is complete. This is only a convenience for sub-classes, 12790039225935a817ee6004dfabc8f5c404affc726Alan Hourihane// the logic in lldb::Thread will only call MischiefManaged. 12804ef91af8bf77b483249719ddc02839acd192f42Alan Hourihane// 12904ef91af8bf77b483249719ddc02839acd192f42Alan Hourihane// One slightly tricky point is you have to be careful using SetPlanComplete in PlanExplainsStop because you 13078c3a351bc91eed49a07108682013a323d87540eChia-I Wu// are not guaranteed that PlanExplainsStop for a plan will get called before ShouldStop gets called. If your sub-plan 13178c3a351bc91eed49a07108682013a323d87540eChia-I Wu// explained the stop and then popped itself, only your ShouldStop will get called. 13278c3a351bc91eed49a07108682013a323d87540eChia-I Wu// 13378c3a351bc91eed49a07108682013a323d87540eChia-I Wu// If ShouldStop for any thread returns "true", then the WillStop method of the Current plan of 13478c3a351bc91eed49a07108682013a323d87540eChia-I Wu// all threads will be called, the stop event is placed on the Process's public broadcaster, and 13578c3a351bc91eed49a07108682013a323d87540eChia-I Wu// control returns to the upper layers of the debugger. 13678c3a351bc91eed49a07108682013a323d87540eChia-I Wu// 13778c3a351bc91eed49a07108682013a323d87540eChia-I Wu// Automatically Resuming: 13878c3a351bc91eed49a07108682013a323d87540eChia-I Wu// 13978c3a351bc91eed49a07108682013a323d87540eChia-I Wu// If ShouldStop for all threads returns "false", then the target process will resume. This then cycles back to 1408015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// Resuming above. 1418015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// 1428015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// Reporting eStateStopped events when the target is restarted: 1438015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// 1448015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// If a plan decides to auto-continue the target by returning "false" from ShouldStop, then it will be asked 1458015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// whether the Stopped event should still be reported. For instance, if you hit a breakpoint that is a User set 1468015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// breakpoint, but the breakpoint callback said to continue the target process, you might still want to inform 1478015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// the upper layers of lldb that the stop had happened. 1488015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// The way this works is every thread gets to vote on whether to report the stop. If all votes are eVoteNoOpinion, 1498015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// then the thread list will decide what to do (at present it will pretty much always suppress these stopped events.) 1508015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// If there is an eVoteYes, then the event will be reported regardless of the other votes. If there is an eVoteNo 1518015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// and no eVoteYes's, then the event won't be reported. 1528015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// 1538015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// One other little detail here, sometimes a plan will push another plan onto the plan stack to do some part of 1548015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// the first plan's job, and it would be convenient to tell that plan how it should respond to ShouldReportStop. 1558015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// You can do that by setting the stop_vote in the child plan when you create it. 1568015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// 157c407c7024495b19eec5ce978b611c7359c247f81Chia-I Wu// Suppressing the initial eStateRunning event: 158c407c7024495b19eec5ce978b611c7359c247f81Chia-I Wu// 15917330479b39409a63a06ec9e6b0f8e28b585db12Chia-I Wu// The private process running thread will take care of ensuring that only one "eStateRunning" event will be 16017330479b39409a63a06ec9e6b0f8e28b585db12Chia-I Wu// delivered to the public Process broadcaster per public eStateStopped event. However there are some cases 1618015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// where the public state of this process is eStateStopped, but a thread plan needs to restart the target, but 1628015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// doesn't want the running event to be publically broadcast. The obvious example of this is running functions 1638015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// by hand as part of expression evaluation. To suppress the running event return eVoteNo from ShouldReportStop, 1648015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// to force a running event to be reported return eVoteYes, in general though you should return eVoteNoOpinion 1658015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// which will allow the ThreadList to figure out the right thing to do. 1668015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// The run_vote argument to the constructor works like stop_vote, and is a way for a plan to instruct a sub-plan 1678015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane// on how to respond to ShouldReportStop. 16878c3a351bc91eed49a07108682013a323d87540eChia-I Wu// 169f5a06fad62cd43d7854bafa60bbe6f48e8cf90afChia-I Wu//------------------------------------------------------------------ 1708015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane 1718015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihaneclass ThreadPlan: 1729a3de505dc5377a47a6ccb29fe60343feb2f5b14Chia-I Wu public UserID 1739a3de505dc5377a47a6ccb29fe60343feb2f5b14Chia-I Wu{ 1748015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihanepublic: 1752f2cf461c57974abd89e4917945cc8ae6a67a72eChia-I Wu typedef enum 176f5a06fad62cd43d7854bafa60bbe6f48e8cf90afChia-I Wu { 1772f2cf461c57974abd89e4917945cc8ae6a67a72eChia-I Wu eAllThreads, 1789a3de505dc5377a47a6ccb29fe60343feb2f5b14Chia-I Wu eSomeThreads, 1799a3de505dc5377a47a6ccb29fe60343feb2f5b14Chia-I Wu eThisThread 1802f2cf461c57974abd89e4917945cc8ae6a67a72eChia-I Wu } ThreadScope; 1812f2cf461c57974abd89e4917945cc8ae6a67a72eChia-I Wu 1828015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane typedef enum 18378c3a351bc91eed49a07108682013a323d87540eChia-I Wu { 18478c3a351bc91eed49a07108682013a323d87540eChia-I Wu eKindGeneric, 1856eda3f311bc24999835003e404d5eda5599bc5deKristian Høgsberg eKindBase, 18678c3a351bc91eed49a07108682013a323d87540eChia-I Wu eKindCallFunction, 18778c3a351bc91eed49a07108682013a323d87540eChia-I Wu eKindStepInstruction, 188ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu eKindStepOut, 189ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu eKindStepOverBreakpoint, 190ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu eKindStepOverRange, 191ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu eKindStepInRange, 192ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu eKindRunToAddress, 193ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu eKindStepThrough, 194ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu eKindStepUntil 195ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu 196ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu } ThreadPlanKind; 197ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu 198ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu //------------------------------------------------------------------ 199ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu // Constructors and Destructors 200ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu //------------------------------------------------------------------ 201ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu ThreadPlan (ThreadPlanKind kind, 202ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu const char *name, 203ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu Thread &thread, 204ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu lldb::Vote stop_vote, 205ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu lldb::Vote run_vote); 206ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu 207ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu virtual 208ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu ~ThreadPlan(); 209ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu 210ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu //------------------------------------------------------------------ 211ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu /// Returns the name of this thread plan. 212ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu /// 213ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu /// @return 214ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu /// A const char * pointer to the thread plan's name. 215ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu //------------------------------------------------------------------ 216ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu const char * 217ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu GetName () const; 218ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu 219ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu //------------------------------------------------------------------ 22078c3a351bc91eed49a07108682013a323d87540eChia-I Wu /// Returns the Thread that is using this thread plan. 2218015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane /// 2228015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane /// @return 22378c3a351bc91eed49a07108682013a323d87540eChia-I Wu /// A pointer to the thread plan's owning thread. 22415f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu //------------------------------------------------------------------ 22515f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu Thread & 22678c3a351bc91eed49a07108682013a323d87540eChia-I Wu GetThread(); 22778c3a351bc91eed49a07108682013a323d87540eChia-I Wu 22815f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu const Thread & 229ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu GetThread() const; 230e4bd50c232ed9d8c5a8a76a662a29a03d4237593Ian Romanick 231ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu //------------------------------------------------------------------ 232ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu /// Print a description of this thread to the stream \a s. 23315f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu /// \a thread. 234ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu /// 235ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu /// @param[in] s 236ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu /// The stream to which to print the description. 237ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu /// 23815f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu /// @param[in] level 239ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu /// The level of description desired. Note that eDescriptionLevelBrief 240ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu /// will be used in the stop message printed when the plan is complete. 241ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu //------------------------------------------------------------------ 242ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu virtual void 243ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu GetDescription (Stream *s, 244ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu lldb::DescriptionLevel level) = 0; 24578c3a351bc91eed49a07108682013a323d87540eChia-I Wu 24678c3a351bc91eed49a07108682013a323d87540eChia-I Wu //------------------------------------------------------------------ 247ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu /// Returns whether this plan needs to be executed immediatly on resume. 248ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu /// 24978c3a351bc91eed49a07108682013a323d87540eChia-I Wu /// @return 2506eda3f311bc24999835003e404d5eda5599bc5deKristian Høgsberg /// \b true if the plan is immediate, \b false otherwise. 251ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu //------------------------------------------------------------------ 252ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu virtual bool 253ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu IsImmediate() const 25415f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu { 25578c3a351bc91eed49a07108682013a323d87540eChia-I Wu return false; 25678c3a351bc91eed49a07108682013a323d87540eChia-I Wu } 25778c3a351bc91eed49a07108682013a323d87540eChia-I Wu 25878c3a351bc91eed49a07108682013a323d87540eChia-I Wu //------------------------------------------------------------------ 25978c3a351bc91eed49a07108682013a323d87540eChia-I Wu /// Returns whether this plan could be successfully created. 26078c3a351bc91eed49a07108682013a323d87540eChia-I Wu /// 26178c3a351bc91eed49a07108682013a323d87540eChia-I Wu /// @param[in] error 2626eda3f311bc24999835003e404d5eda5599bc5deKristian Høgsberg /// A stream to which to print some reason why the plan could not be created. 263ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu /// 264ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu /// @return 265ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu /// \b true if the plan should be queued, \b false otherwise. 266ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu //------------------------------------------------------------------ 267ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu virtual bool 268ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu ValidatePlan (Stream *error) = 0; 269ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu 270ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu virtual bool 271ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu PlanExplainsStop () = 0; 272ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu 273ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu 274ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu virtual lldb::StateType 275ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu RunState () = 0; 276ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu 277ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu virtual bool 278ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu ShouldStop (Event *event_ptr) = 0; 279ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu 280ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu virtual bool 281ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu ShouldAutoContinue (Event *event_ptr) 282ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu { 283ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu return false; 284ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu } 285ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu 286ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu // Whether a "stop class" event should be reported to the "outside world". In general 287ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu // if a thread plan is active, events should not be reported. 288ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu 289ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu virtual lldb::Vote 290ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu ShouldReportStop (Event *event_ptr); 291ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu 292ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu virtual lldb::Vote 293ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu ShouldReportRun (Event *event_ptr); 294ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu 295ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu virtual bool 296ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu StopOthers (); 297ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu 298ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu virtual bool 299ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu WillResume (lldb::StateType resume_state, bool current_plan); 300ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu 301ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu virtual bool 302ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu WillStop () = 0; 303ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu 304ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu virtual bool 305ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu IsMasterPlan() 306ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu { 307ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu return false; 308ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu } 309ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu 310ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu virtual bool 311ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu OkayToDiscard(); 312ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu 313ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu void 314ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu SetOkayToDiscard (bool value) 315ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu { 316ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu m_okay_to_discard = value; 317ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu } 318ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu 319ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu // The base class MischiefManaged does some cleanup - so you have to call it 320ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu // in your MischiefManaged derived class. 3218015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane virtual bool 32278c3a351bc91eed49a07108682013a323d87540eChia-I Wu MischiefManaged (); 32378c3a351bc91eed49a07108682013a323d87540eChia-I Wu 3248015f3ae3b96d93e8b1338b8254bcbead45bb91aAlan Hourihane bool 325ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu GetPrivate (); 32678c3a351bc91eed49a07108682013a323d87540eChia-I Wu 32778c3a351bc91eed49a07108682013a323d87540eChia-I Wu void 3286eda3f311bc24999835003e404d5eda5599bc5deKristian Høgsberg SetPrivate (bool input); 3296eda3f311bc24999835003e404d5eda5599bc5deKristian Høgsberg 33078c3a351bc91eed49a07108682013a323d87540eChia-I Wu virtual void 33178c3a351bc91eed49a07108682013a323d87540eChia-I Wu DidPush(); 33278c3a351bc91eed49a07108682013a323d87540eChia-I Wu 3336eda3f311bc24999835003e404d5eda5599bc5deKristian Høgsberg virtual void 33478c3a351bc91eed49a07108682013a323d87540eChia-I Wu WillPop(); 33578c3a351bc91eed49a07108682013a323d87540eChia-I Wu 336ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu // This pushes \a plan onto the plan stack of the current plan's thread. 337ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu void 338ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu PushPlan (lldb::ThreadPlanSP &thread_plan_sp); 339ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu 340ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu ThreadPlanKind GetKind() const 341ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu { 342ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu return m_kind; 343ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu } 344ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu 345ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wuprotected: 346ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu //------------------------------------------------------------------ 347ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu // Classes that inherit from ThreadPlan can see and modify these 348ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu //------------------------------------------------------------------ 349ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu 350ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu bool 351ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu IsPlanComplete(); 352ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu 353ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu void 354ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu SetPlanComplete (); 355ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu 356ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu // This gets the previous plan to the current plan (for forwarding requests). 357ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu // This is mostly a formal requirement, it allows us to make the Thread's 35878c3a351bc91eed49a07108682013a323d87540eChia-I Wu // GetPreviousPlan protected, but only friend ThreadPlan to thread. 35978c3a351bc91eed49a07108682013a323d87540eChia-I Wu 36078c3a351bc91eed49a07108682013a323d87540eChia-I Wu ThreadPlan * 36115f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu GetPreviousPlan (); 36215f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu 36378c3a351bc91eed49a07108682013a323d87540eChia-I Wu Thread &m_thread; 36490039225935a817ee6004dfabc8f5c404affc726Alan Hourihane lldb::Vote m_stop_vote; 36515f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu lldb::Vote m_run_vote; 366ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu 367e4bd50c232ed9d8c5a8a76a662a29a03d4237593Ian Romanickprivate: 36878c3a351bc91eed49a07108682013a323d87540eChia-I Wu //------------------------------------------------------------------ 369ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu // For ThreadPlan only 37015f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu //------------------------------------------------------------------ 371ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu static lldb::user_id_t GetNextID (); 37215f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu 37378c3a351bc91eed49a07108682013a323d87540eChia-I Wu ThreadPlanKind m_kind; 37478c3a351bc91eed49a07108682013a323d87540eChia-I Wu std::string m_name; 37578c3a351bc91eed49a07108682013a323d87540eChia-I Wu Mutex m_plan_complete_mutex; 376ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu bool m_plan_complete; 37715f0223931e32ef5ff82b39a2b6c433400edbd9dChia-I Wu bool m_plan_private; 378ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu bool m_okay_to_discard; 379ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu 380ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wuprivate: 381ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu DISALLOW_COPY_AND_ASSIGN(ThreadPlan); 382ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu}; 383ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu 384ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu 385ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu} // namespace lldb_private 386ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu 387ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu#endif // liblldb_ThreadPlan_h_ 388ecca5571b6df9a35dc16280b3556f4b11a8493a2Chia-I Wu