2002-12-13 Jeff Johnston <jjohnstn@redhat.com>
[deliverable/binutils-gdb.git] / gdb / event-top.c
index f37ff7577ae9e2efb77a609f891f297ce88c9482..8f39998ed9b1a8009273f99e5fa1531f604cca73 100644 (file)
@@ -1,5 +1,5 @@
 /* Top level stuff for GDB, the GNU debugger.
-   Copyright 1999 Free Software Foundation, Inc.
+   Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
    Written by Elena Zannoni <ezannoni@cygnus.com> of Cygnus Solutions.
 
    This file is part of GDB.
@@ -24,9 +24,9 @@
 #include "inferior.h"
 #include "target.h"
 #include "terminal.h"          /* for job_control */
-#include "signals.h"
 #include "event-loop.h"
 #include "event-top.h"
+#include <signal.h>
 
 /* For dont_repeat() */
 #include "gdbcmd.h"
@@ -35,8 +35,6 @@
 #include <readline/readline.h>
 #include <readline/history.h>
 
-#include <signal.h>
-
 /* readline defines this.  */
 #undef savestring
 
@@ -155,6 +153,10 @@ struct readline_input_state
     char *linebuffer_ptr;
   }
 readline_input_state;
+
+/* This hook is called by rl_callback_read_char_wrapper after each
+   character is processed.  */
+void (*after_char_processing_hook) ();
 \f
 
 /* Wrapper function for calling into the readline library. The event
@@ -164,6 +166,8 @@ static void
 rl_callback_read_char_wrapper (gdb_client_data client_data)
 {
   rl_callback_read_char ();
+  if (after_char_processing_hook)
+    (*after_char_processing_hook) ();
 }
 
 /* Initialize all the necessary variables, start the event loop,
@@ -246,12 +250,10 @@ display_gdb_prompt (char *new_prompt)
   int prompt_length = 0;
   char *gdb_prompt = get_prompt ();
 
-#ifdef UI_OUT
   /* When an alternative interpreter has been installed, do not
      display the comand prompt. */
   if (interpreter_p)
     return;
-#endif
 
   if (target_executing && sync_execution)
     {
@@ -303,12 +305,6 @@ display_gdb_prompt (char *new_prompt)
          character position to be off, since the newline we read from
          the user is not accounted for.  */
       fputs_unfiltered (new_prompt, gdb_stdout);
-
-#ifdef MPW
-      /* Move to a new line so the entered line doesn't have a prompt
-         on the front of it. */
-      fputs_unfiltered ("\n", gdb_stdout);
-#endif /* MPW */
       gdb_flush (gdb_stdout);
     }
 }
@@ -393,13 +389,13 @@ pop_prompt (void)
        in effect, until the user does another 'set prompt'. */
     if (strcmp (PROMPT (0), PROMPT (-1)))
       {
-       free (PROMPT (-1));
+       xfree (PROMPT (-1));
        PROMPT (-1) = savestring (PROMPT (0), strlen (PROMPT (0)));
       }
 
-  free (PREFIX (0));
-  free (PROMPT (0));
-  free (SUFFIX (0));
+  xfree (PREFIX (0));
+  xfree (PROMPT (0));
+  xfree (SUFFIX (0));
   the_prompts.top--;
 }
 
@@ -480,18 +476,11 @@ command_handler (char *command)
   extern int display_time;
   extern int display_space;
 
-#if defined(TUI)
-  extern int insert_mode;
-#endif
-
   quit_flag = 0;
   if (instream == stdin && stdin_is_tty)
     reinitialize_more_filter ();
   old_chain = make_cleanup (null_cleanup, 0);
 
-#if defined(TUI)
-  insert_mode = 0;
-#endif
   /* If readline returned a NULL command, it means that the 
      connection with the terminal is gone. This happens at the
      end of a testsuite run, after Expect has hung up 
@@ -525,8 +514,10 @@ command_handler (char *command)
        (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
       arg1->next = arg2;
       arg2->next = NULL;
-      arg1->data.integer = time_at_cmd_start;
-      arg2->data.integer = space_at_cmd_start;
+      arg1->data.longint = time_at_cmd_start;
+#ifdef HAVE_SBRK
+      arg2->data.longint = space_at_cmd_start;
+#endif
       add_continuation (command_line_handler_continuation, arg1);
     }
 
@@ -643,7 +634,7 @@ command_line_handler (char *rl)
     {
       strcpy (linebuffer, readline_input_state.linebuffer);
       p = readline_input_state.linebuffer_ptr;
-      free (readline_input_state.linebuffer);
+      xfree (readline_input_state.linebuffer);
       more_to_come = 0;
       pop_prompt ();
     }
@@ -690,26 +681,23 @@ command_line_handler (char *rl)
   while (*p1)
     *p++ = *p1++;
 
-  free (rl);                   /* Allocated in readline.  */
+  xfree (rl);                  /* Allocated in readline.  */
 
-  if (*(p - 1) == '\\')
+  if (p > linebuffer && *(p - 1) == '\\')
     {
       p--;                     /* Put on top of '\'.  */
 
-      if (*p == '\\')
-       {
-         readline_input_state.linebuffer = savestring (linebuffer,
-                                                       strlen (linebuffer));
-         readline_input_state.linebuffer_ptr = p;
-
-         /* We will not invoke a execute_command if there is more
-            input expected to complete the command. So, we need to
-            print an empty prompt here. */
-         more_to_come = 1;
-         push_prompt ("", "", "");
-         display_gdb_prompt (0);
-         return;
-       }
+      readline_input_state.linebuffer = savestring (linebuffer,
+                                                   strlen (linebuffer));
+      readline_input_state.linebuffer_ptr = p;
+
+      /* We will not invoke a execute_command if there is more
+        input expected to complete the command. So, we need to
+        print an empty prompt here. */
+      more_to_come = 1;
+      push_prompt ("", "", "");
+      display_gdb_prompt (0);
+      return;
     }
 
 #ifdef STOP_SIGNAL
@@ -749,7 +737,7 @@ command_line_handler (char *rl)
          /* If there was an error, call this function again.  */
          if (expanded < 0)
            {
-             free (history_value);
+             xfree (history_value);
              return;
            }
          if (strlen (history_value) > linelength)
@@ -759,7 +747,7 @@ command_line_handler (char *rl)
            }
          strcpy (linebuffer, history_value);
          p = linebuffer + strlen (linebuffer);
-         free (history_value);
+         xfree (history_value);
        }
     }
 
@@ -868,7 +856,7 @@ gdb_readline2 (gdb_client_data client_data)
               if we are called again fgetc will still return EOF and
               we'll return NULL then.  */
            break;
-         free (result);
+         xfree (result);
          (*input_handler) (0);
        }
 
@@ -1051,10 +1039,11 @@ async_stop_sig (gdb_client_data arg)
 #if HAVE_SIGPROCMASK
   {
     sigset_t zero;
+
     sigemptyset (&zero);
     sigprocmask (SIG_SETMASK, &zero, 0);
   }
-#else
+#elif HAVE_SIGSETMASK
   sigsetmask (0);
 #endif
   kill (getpid (), SIGTSTP);
@@ -1128,8 +1117,12 @@ set_async_prompt (char *args, int from_tty, struct cmd_list_element *c)
    interface, i.e. via a callback function (rl_callback_read_char),
    and hook up instream to the event loop. */
 void
-_initialize_event_loop (void)
+gdb_setup_readline (void)
 {
+  /* This function is a noop for the sync case.  The assumption is that
+     the sync setup is ALL done in gdb_init, and we would only mess it up
+     here.  The sync stuff should really go away over time. */
+
   if (event_loop_p)
     {
       /* If the input stream is connected to a terminal, turn on
@@ -1164,9 +1157,6 @@ _initialize_event_loop (void)
          register it with the event loop. */
       input_fd = fileno (instream);
 
-      /* Tell gdb to use the cli_command_loop as the main loop. */
-      command_loop_hook = cli_command_loop;
-
       /* Now we need to create the event sources for the input file
          descriptor. */
       /* At this point in time, this is the only event source that we
@@ -1177,3 +1167,40 @@ _initialize_event_loop (void)
       add_file_handler (input_fd, stdin_event_handler, 0);
     }
 }
+
+/* Disable command input through the standard CLI channels.  Used in
+   the suspend proc for interpreters that use the standard gdb readline
+   interface, like the cli & the mi.  */
+void
+gdb_disable_readline (void)
+{
+  if (event_loop_p)
+    {
+      /* FIXME - It is too heavyweight to delete and remake these
+         every time you run an interpreter that needs readline.
+         It is probably better to have the interpreters cache these,
+         which in turn means that this needs to be moved into interpreter
+         specific code. */
+
+#if 0
+      ui_file_delete (gdb_stdout);
+      ui_file_delete (gdb_stderr);
+      gdb_stdlog = NULL;
+      gdb_stdtarg = NULL;
+#endif
+
+      rl_callback_handler_remove ();
+      delete_file_handler (input_fd);
+    }
+}
+
+void
+_initialize_event_loop (void)
+{
+  gdb_setup_readline ();
+
+  /* Tell gdb to use the cli_command_loop as the main loop. */
+  if (event_loop_p && command_loop_hook == NULL)
+    command_loop_hook = cli_command_loop;
+}
+
This page took 0.038859 seconds and 4 git commands to generate.