thread-fsm.h 3.6 KB

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