remote-notif.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /* Remote notification in GDB protocol
  2. Copyright (C) 1988-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 REMOTE_NOTIF_H
  15. #define REMOTE_NOTIF_H
  16. #include <list>
  17. #include <memory>
  18. /* An event of a type of async remote notification. */
  19. struct notif_event
  20. {
  21. virtual ~notif_event ()
  22. {
  23. }
  24. };
  25. /* A unique pointer holding a notif_event. */
  26. typedef std::unique_ptr<notif_event> notif_event_up;
  27. /* ID of the notif_client. */
  28. enum REMOTE_NOTIF_ID
  29. {
  30. REMOTE_NOTIF_STOP = 0,
  31. REMOTE_NOTIF_LAST,
  32. };
  33. struct remote_target;
  34. /* A client to a sort of async remote notification. */
  35. struct notif_client
  36. {
  37. /* The name of notification packet. */
  38. const char *name;
  39. /* The packet to acknowledge a previous reply. */
  40. const char *ack_command;
  41. /* Parse BUF to get the expected event and update EVENT. This
  42. function may throw exception if contents in BUF is not the
  43. expected event. */
  44. void (*parse) (remote_target *remote,
  45. struct notif_client *self, const char *buf,
  46. struct notif_event *event);
  47. /* Send field <ack_command> to remote, and do some checking. If
  48. something wrong, throw an exception. */
  49. void (*ack) (remote_target *remote,
  50. struct notif_client *self, const char *buf,
  51. struct notif_event *event);
  52. /* Check this notification client can get pending events in
  53. 'remote_notif_process'. */
  54. int (*can_get_pending_events) (remote_target *remote,
  55. struct notif_client *self);
  56. /* Allocate an event. */
  57. notif_event_up (*alloc_event) ();
  58. /* Id of this notif_client. */
  59. const enum REMOTE_NOTIF_ID id;
  60. };
  61. /* State on remote async notification. */
  62. struct remote_notif_state
  63. {
  64. remote_notif_state () = default;
  65. ~remote_notif_state ();
  66. DISABLE_COPY_AND_ASSIGN (remote_notif_state);
  67. /* The remote target. */
  68. remote_target *remote;
  69. /* Notification queue. */
  70. std::list<notif_client *> notif_queue;
  71. /* Asynchronous signal handle registered as event loop source for when
  72. the remote sent us a notification. The registered callback
  73. will do a ACK sequence to pull the rest of the events out of
  74. the remote side into our event queue. */
  75. struct async_event_handler *get_pending_events_token;
  76. /* One pending event for each notification client. This is where we
  77. keep it until it is acknowledged. When there is a notification
  78. packet, parse it, and create an object of 'struct notif_event' to
  79. assign to it. This field is unchanged until GDB starts to ack
  80. this notification (which is done by
  81. remote.c:remote_notif_pending_replies). */
  82. struct notif_event *pending_event[REMOTE_NOTIF_LAST] {};
  83. };
  84. void remote_notif_ack (remote_target *remote, notif_client *nc,
  85. const char *buf);
  86. struct notif_event *remote_notif_parse (remote_target *remote,
  87. notif_client *nc,
  88. const char *buf);
  89. void handle_notification (struct remote_notif_state *notif_state,
  90. const char *buf);
  91. void remote_notif_process (struct remote_notif_state *state,
  92. struct notif_client *except);
  93. remote_notif_state *remote_notif_state_allocate (remote_target *remote);
  94. extern struct notif_client notif_client_stop;
  95. extern bool notif_debug;
  96. #endif /* REMOTE_NOTIF_H */