gdb/inf-loop.c - gdb

Functions defined

Source code

  1. /* Handling of inferior events for the event loop for GDB, the GNU debugger.
  2.    Copyright (C) 1999-2015 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 "target.h"             /* For enum inferior_event_type.  */
  19. #include "event-loop.h"
  20. #include "event-top.h"
  21. #include "inf-loop.h"
  22. #include "remote.h"
  23. #include "language.h"
  24. #include "gdbthread.h"
  25. #include "continuations.h"
  26. #include "interps.h"
  27. #include "top.h"
  28. #include "observer.h"

  29. /* General function to handle events in the inferior.  So far it just
  30.    takes care of detecting errors reported by select() or poll(),
  31.    otherwise it assumes that all is OK, and goes on reading data from
  32.    the fd.  This however may not always be what we want to do.  */
  33. void
  34. inferior_event_handler (enum inferior_event_type event_type,
  35.                         gdb_client_data client_data)
  36. {
  37.   struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup ();

  38.   switch (event_type)
  39.     {
  40.     case INF_REG_EVENT:
  41.       /* Catch errors for now, until the inner layers of
  42.          fetch_inferior_event (i.e. readchar) can return meaningful
  43.          error status.  If an error occurs while getting an event from
  44.          the target, just cancel the current command.  */
  45.       {
  46.         volatile struct gdb_exception ex;

  47.         TRY_CATCH (ex, RETURN_MASK_ALL)
  48.           {
  49.             fetch_inferior_event (client_data);
  50.           }
  51.         if (ex.reason < 0)
  52.           {
  53.             bpstat_clear_actions ();
  54.             do_all_intermediate_continuations (1);
  55.             do_all_continuations (1);

  56.             throw_exception (ex);
  57.           }
  58.       }
  59.       break;

  60.     case INF_EXEC_COMPLETE:
  61.       if (!non_stop)
  62.         {
  63.           /* Unregister the inferior from the event loop.  This is done
  64.              so that when the inferior is not running we don't get
  65.              distracted by spurious inferior output.  */
  66.           if (target_has_execution)
  67.             target_async (NULL, 0);
  68.         }

  69.       /* Do all continuations associated with the whole inferior (not
  70.          a particular thread).  */
  71.       if (!ptid_equal (inferior_ptid, null_ptid))
  72.         do_all_inferior_continuations (0);

  73.       /* If we were doing a multi-step (eg: step n, next n), but it
  74.          got interrupted by a breakpoint, still do the pending
  75.          continuations.  The continuation itself is responsible for
  76.          distinguishing the cases.  The continuations are allowed to
  77.          touch the inferior memory, e.g. to remove breakpoints, so run
  78.          them before running breakpoint commands, which may resume the
  79.          target.  */
  80.       if (non_stop
  81.           && target_has_execution
  82.           && !ptid_equal (inferior_ptid, null_ptid))
  83.         do_all_intermediate_continuations_thread (inferior_thread (), 0);
  84.       else
  85.         do_all_intermediate_continuations (0);

  86.       /* Always finish the previous command before running any
  87.          breakpoint commands.  Any stop cancels the previous command.
  88.          E.g. a "finish" or "step-n" command interrupted by an
  89.          unrelated breakpoint is canceled.  */
  90.       if (non_stop
  91.           && target_has_execution
  92.           && !ptid_equal (inferior_ptid, null_ptid))
  93.         do_all_continuations_thread (inferior_thread (), 0);
  94.       else
  95.         do_all_continuations (0);

  96.       /* When running a command list (from a user command, say), these
  97.          are only run when the command list is all done.  */
  98.       if (interpreter_async)
  99.         {
  100.           volatile struct gdb_exception e;

  101.           check_frame_language_change ();

  102.           /* Don't propagate breakpoint commands errors.  Either we're
  103.              stopping or some command resumes the inferior.  The user will
  104.              be informed.  */
  105.           TRY_CATCH (e, RETURN_MASK_ALL)
  106.             {
  107.               bpstat_do_actions ();
  108.             }
  109.           exception_print (gdb_stderr, e);
  110.         }
  111.       break;

  112.     case INF_EXEC_CONTINUE:
  113.       /* Is there anything left to do for the command issued to
  114.          complete?  */

  115.       if (non_stop)
  116.         do_all_intermediate_continuations_thread (inferior_thread (), 0);
  117.       else
  118.         do_all_intermediate_continuations (0);
  119.       break;

  120.     case INF_TIMER:
  121.     default:
  122.       printf_unfiltered (_("Event type not recognized.\n"));
  123.       break;
  124.     }

  125.   discard_cleanups (cleanup_if_error);
  126. }