1 /* Thread command's finish-state machine, for GDB, the GNU debugger.
2 Copyright (C) 2015-2019 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "mi/mi-common.h" /* For enum async_reply_reason. */
24 struct return_value_info;
25 struct thread_fsm_ops;
27 /* A thread finite-state machine structure contains the necessary info
28 and callbacks to manage the state machine protocol of a thread's
33 explicit thread_fsm (struct interp *cmd_interp)
34 : command_interp (cmd_interp)
38 /* The destructor. This should simply free heap allocated data
39 structures. Cleaning up target resources (like, e.g.,
40 breakpoints) should be done in the clean_up method. */
41 virtual ~thread_fsm () = default;
43 DISABLE_COPY_AND_ASSIGN (thread_fsm);
45 /* Called to clean up target resources after the FSM. E.g., if the
46 FSM created internal breakpoints, this is where they should be
48 virtual void clean_up (struct thread_info *thread)
52 /* Called after handle_inferior_event decides the target is done
53 (that is, after stop_waiting). The FSM is given a chance to
54 decide whether the command is done and thus the target should
55 stop, or whether there's still more to do and thus the thread
56 should be re-resumed. This is a good place to cache target data
57 too. For example, the "finish" command saves the just-finished
58 function's return value here. */
59 virtual bool should_stop (struct thread_info *thread) = 0;
61 /* If this FSM saved a function's return value, you can use this
62 method to retrieve it. Otherwise, this returns NULL. */
63 virtual struct return_value_info *return_value ()
68 enum async_reply_reason async_reply_reason ()
70 /* If we didn't finish, then the stop reason must come from
71 elsewhere. E.g., a breakpoint hit or a signal intercepted. */
72 gdb_assert (finished_p ());
73 return do_async_reply_reason ();
76 /* Whether the stop should be notified to the user/frontend. */
77 virtual bool should_notify_stop ()
87 bool finished_p () const
92 /* The interpreter that issued the execution command that caused
93 this thread to resume. If the top level interpreter is MI/async,
94 and the execution command was a CLI command (next/step/etc.),
95 we'll want to print stop event output to the MI console channel
96 (the stepped-to line, etc.), as if the user entered the execution
97 command on a real GDB console. */
98 struct interp *command_interp = nullptr;
102 /* Whether the FSM is done successfully. */
103 bool finished = false;
105 /* The async_reply_reason that is broadcast to MI clients if this
106 FSM finishes successfully. */
107 virtual enum async_reply_reason do_async_reply_reason ()
109 gdb_assert_not_reached (_("should not call async_reply_reason here"));
113 #endif /* THREAD_FSM_H */