inf-loop.c 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* Handling of inferior events for the event loop for GDB, the GNU debugger.
  2. Copyright (C) 1999-2022 Free Software Foundation, Inc.
  3. Written by Elena Zannoni <ezannoni@cygnus.com> of Cygnus Solutions.
  4. This file is part of GDB.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  15. #include "defs.h"
  16. #include "inferior.h"
  17. #include "infrun.h"
  18. #include "gdbsupport/event-loop.h"
  19. #include "event-top.h"
  20. #include "inf-loop.h"
  21. #include "remote.h"
  22. #include "language.h"
  23. #include "gdbthread.h"
  24. #include "interps.h"
  25. #include "top.h"
  26. #include "observable.h"
  27. /* General function to handle events in the inferior. */
  28. void
  29. inferior_event_handler (enum inferior_event_type event_type)
  30. {
  31. switch (event_type)
  32. {
  33. case INF_REG_EVENT:
  34. fetch_inferior_event ();
  35. break;
  36. case INF_EXEC_COMPLETE:
  37. if (!non_stop)
  38. {
  39. /* Unregister the inferior from the event loop. This is done
  40. so that when the inferior is not running we don't get
  41. distracted by spurious inferior output. */
  42. if (target_has_execution () && target_can_async_p ())
  43. target_async (0);
  44. }
  45. /* Do all continuations associated with the whole inferior (not
  46. a particular thread). */
  47. if (inferior_ptid != null_ptid)
  48. current_inferior ()->do_all_continuations ();
  49. /* When running a command list (from a user command, say), these
  50. are only run when the command list is all done. */
  51. if (current_ui->async)
  52. {
  53. check_frame_language_change ();
  54. /* Don't propagate breakpoint commands errors. Either we're
  55. stopping or some command resumes the inferior. The user will
  56. be informed. */
  57. try
  58. {
  59. bpstat_do_actions ();
  60. }
  61. catch (const gdb_exception &e)
  62. {
  63. /* If the user was running a foreground execution
  64. command, then propagate the error so that the prompt
  65. can be reenabled. Otherwise, the user already has
  66. the prompt and is typing some unrelated command, so
  67. just inform the user and swallow the exception. */
  68. if (current_ui->prompt_state == PROMPT_BLOCKED)
  69. throw;
  70. else
  71. exception_print (gdb_stderr, e);
  72. }
  73. }
  74. break;
  75. default:
  76. gdb_printf (gdb_stderr, _("Event type not recognized.\n"));
  77. break;
  78. }
  79. }