- current_interp_command_loop ();
- /* FIXME: cagney/1999-11-05: A correct command_loop() implementaton
- would clean things up (restoring the cleanup chain) to the state
- they were just prior to the call. Technically, this means that
- the do_cleanups() below is redundant. Unfortunately, many FUNCs
- are not that well behaved. do_cleanups should either be replaced
- with a do_cleanups call (to cover the problem) or an assertion
- check to detect bad FUNCs code. */
- do_cleanups (ALL_CLEANUPS);
+ /* Loop until there is nothing to do. This is the entry point to
+ the event loop engine. gdb_do_one_event will process one event
+ for each invocation. It blocks waiting for an event and then
+ processes it. */
+ while (1)
+ {
+ int result = 0;
+
+ try
+ {
+ result = gdb_do_one_event ();
+ }
+ catch (const gdb_exception &ex)
+ {
+ exception_print (gdb_stderr, ex);
+
+ /* If any exception escaped to here, we better enable
+ stdin. Otherwise, any command that calls async_disable_stdin,
+ and then throws, will leave stdin inoperable. */
+ SWITCH_THRU_ALL_UIS ()
+ {
+ async_enable_stdin ();
+ }
+ /* If we long-jumped out of do_one_event, we probably didn't
+ get around to resetting the prompt, which leaves readline
+ in a messed-up state. Reset it here. */
+ current_ui->prompt_state = PROMPT_NEEDED;
+ gdb::observers::command_error.notify ();
+ /* This call looks bizarre, but it is required. If the user
+ entered a command that caused an error,
+ after_char_processing_hook won't be called from
+ rl_callback_read_char_wrapper. Using a cleanup there
+ won't work, since we want this function to be called
+ after a new prompt is printed. */
+ if (after_char_processing_hook)
+ (*after_char_processing_hook) ();
+ /* Maybe better to set a flag to be checked somewhere as to
+ whether display the prompt or not. */
+ }
+
+ if (result < 0)
+ break;
+ }
+
+ /* We are done with the event loop. There are no more event sources
+ to listen to. So we exit GDB. */
+ return;
+}
+
+/* Call command_loop. */
+
+/* Prevent inlining this function for the benefit of GDB's selftests
+ in the testsuite. Those tests want to run GDB under GDB and stop
+ here. */
+static void captured_command_loop () __attribute__((noinline));
+
+static void
+captured_command_loop ()
+{
+ struct ui *ui = current_ui;
+
+ /* Top-level execution commands can be run in the background from
+ here on. */
+ current_ui->async = 1;
+
+ /* Give the interpreter a chance to print a prompt, if necessary */
+ if (ui->prompt_state != PROMPT_BLOCKED)
+ interp_pre_command_loop (top_level_interpreter ());
+
+ /* Now it's time to start the event loop. */
+ start_event_loop ();
+