GDB (API)
/home/stan/gdb/src/gdb/inf-loop.c
Go to the documentation of this file.
00001 /* Handling of inferior events for the event loop for GDB, the GNU debugger.
00002    Copyright (C) 1999-2013 Free Software Foundation, Inc.
00003    Written by Elena Zannoni <ezannoni@cygnus.com> of Cygnus Solutions.
00004 
00005    This file is part of GDB.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 3 of the License, or
00010    (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00019 
00020 #include "defs.h"
00021 #include "inferior.h"           /* For fetch_inferior_event.  */
00022 #include "target.h"             /* For enum inferior_event_type.  */
00023 #include "event-loop.h"
00024 #include "event-top.h"
00025 #include "inf-loop.h"
00026 #include "remote.h"
00027 #include "exceptions.h"
00028 #include "language.h"
00029 #include "gdbthread.h"
00030 #include "continuations.h"
00031 #include "interps.h"
00032 #include "top.h"
00033 
00034 static int fetch_inferior_event_wrapper (gdb_client_data client_data);
00035 
00036 /* General function to handle events in the inferior.  So far it just
00037    takes care of detecting errors reported by select() or poll(),
00038    otherwise it assumes that all is OK, and goes on reading data from
00039    the fd.  This however may not always be what we want to do.  */
00040 void
00041 inferior_event_handler (enum inferior_event_type event_type, 
00042                         gdb_client_data client_data)
00043 {
00044   struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup ();
00045 
00046   switch (event_type)
00047     {
00048     case INF_REG_EVENT:
00049       /* Use catch errors for now, until the inner layers of
00050          fetch_inferior_event (i.e. readchar) can return meaningful
00051          error status.  If an error occurs while getting an event from
00052          the target, just cancel the current command.  */
00053       if (!catch_errors (fetch_inferior_event_wrapper, 
00054                          client_data, "", RETURN_MASK_ALL))
00055         {
00056           bpstat_clear_actions ();
00057           do_all_intermediate_continuations (1);
00058           do_all_continuations (1);
00059           async_enable_stdin ();
00060           display_gdb_prompt (0);
00061         }
00062       break;
00063 
00064     case INF_EXEC_COMPLETE:
00065       if (!non_stop)
00066         {
00067           /* Unregister the inferior from the event loop.  This is done
00068              so that when the inferior is not running we don't get
00069              distracted by spurious inferior output.  */
00070           if (target_has_execution)
00071             target_async (NULL, 0);
00072         }
00073 
00074       /* Do all continuations associated with the whole inferior (not
00075          a particular thread).  */
00076       if (!ptid_equal (inferior_ptid, null_ptid))
00077         do_all_inferior_continuations (0);
00078 
00079       /* If we were doing a multi-step (eg: step n, next n), but it
00080          got interrupted by a breakpoint, still do the pending
00081          continuations.  The continuation itself is responsible for
00082          distinguishing the cases.  The continuations are allowed to
00083          touch the inferior memory, e.g. to remove breakpoints, so run
00084          them before running breakpoint commands, which may resume the
00085          target.  */
00086       if (non_stop
00087           && target_has_execution
00088           && !ptid_equal (inferior_ptid, null_ptid))
00089         do_all_intermediate_continuations_thread (inferior_thread (), 0);
00090       else
00091         do_all_intermediate_continuations (0);
00092 
00093       /* Always finish the previous command before running any
00094          breakpoint commands.  Any stop cancels the previous command.
00095          E.g. a "finish" or "step-n" command interrupted by an
00096          unrelated breakpoint is canceled.  */
00097       if (non_stop
00098           && target_has_execution
00099           && !ptid_equal (inferior_ptid, null_ptid))
00100         do_all_continuations_thread (inferior_thread (), 0);
00101       else
00102         do_all_continuations (0);
00103 
00104       /* When running a command list (from a user command, say), these
00105          are only run when the command list is all done.  */
00106       if (interpreter_async)
00107         {
00108           volatile struct gdb_exception e;
00109 
00110           check_frame_language_change ();
00111 
00112           /* Don't propagate breakpoint commands errors.  Either we're
00113              stopping or some command resumes the inferior.  The user will
00114              be informed.  */
00115           TRY_CATCH (e, RETURN_MASK_ALL)
00116             {
00117               bpstat_do_actions ();
00118             }
00119           exception_print (gdb_stderr, e);
00120         }
00121       break;
00122 
00123     case INF_EXEC_CONTINUE:
00124       /* Is there anything left to do for the command issued to
00125          complete?  */
00126 
00127       if (non_stop)
00128         do_all_intermediate_continuations_thread (inferior_thread (), 0);
00129       else
00130         do_all_intermediate_continuations (0);
00131       break;
00132 
00133     case INF_TIMER:
00134     default:
00135       printf_unfiltered (_("Event type not recognized.\n"));
00136       break;
00137     }
00138 
00139   discard_cleanups (cleanup_if_error);
00140 }
00141 
00142 static int 
00143 fetch_inferior_event_wrapper (gdb_client_data client_data)
00144 {
00145   fetch_inferior_event (client_data);
00146   return 1;
00147 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines