gdb/
[deliverable/binutils-gdb.git] / gdb / event-top.c
index 61c431dabf271e6d67187fd842cb271daf474fda..a49bddb3d1a62f4948209bfdba3b6e4435be539f 100644 (file)
@@ -1,6 +1,6 @@
 /* Top level stuff for GDB, the GNU debugger.
 
-   Copyright (C) 1999, 2000, 2001, 2002, 2004, 2005, 2007, 2008
+   Copyright (C) 1999, 2000, 2001, 2002, 2004, 2005, 2007, 2008, 2009, 2010
    Free Software Foundation, Inc.
 
    Written by Elena Zannoni <ezannoni@cygnus.com> of Cygnus Solutions.
@@ -372,22 +372,22 @@ change_annotation_level (void)
 /* Pushes a new prompt on the prompt stack. Each prompt has three
    parts: prefix, prompt, suffix. Usually prefix and suffix are empty
    strings, except when the annotation level is 2. Memory is allocated
-   within savestring for the new prompt. */
+   within xstrdup for the new prompt. */
 void
 push_prompt (char *prefix, char *prompt, char *suffix)
 {
   the_prompts.top++;
-  PREFIX (0) = savestring (prefix, strlen (prefix));
+  PREFIX (0) = xstrdup (prefix);
 
   /* Note that this function is used by the set annotate 2
      command. This is why we take care of saving the old prompt
      in case a new one is not specified. */
   if (prompt)
-    PROMPT (0) = savestring (prompt, strlen (prompt));
+    PROMPT (0) = xstrdup (prompt);
   else
-    PROMPT (0) = savestring (PROMPT (-1), strlen (PROMPT (-1)));
+    PROMPT (0) = xstrdup (PROMPT (-1));
 
-  SUFFIX (0) = savestring (suffix, strlen (suffix));
+  SUFFIX (0) = xstrdup (suffix);
 }
 
 /* Pops the top of the prompt stack, and frees the memory allocated for it. */
@@ -404,7 +404,7 @@ pop_prompt (void)
     if (strcmp (PROMPT (0), PROMPT (-1)))
       {
        xfree (PROMPT (-1));
-       PROMPT (-1) = savestring (PROMPT (0), strlen (PROMPT (0)));
+       PROMPT (-1) = xstrdup (PROMPT (0));
       }
 
   xfree (PREFIX (0));
@@ -458,14 +458,11 @@ async_enable_stdin (void)
 void
 async_disable_stdin (void)
 {
-  sync_execution = 1;
-  push_prompt ("", "", "");
-  /* FIXME: cagney/1999-09-27: At present this call is technically
-     redundant since infcmd.c and infrun.c both already call
-     target_terminal_inferior().  As the terminal handling (in
-     sync/async mode) is refined, the duplicate calls can be
-     eliminated (Here or in infcmd.c/infrun.c). */
-  target_terminal_inferior ();
+  if (!sync_execution)
+    {
+      sync_execution = 1;
+      push_prompt ("", "", "");
+    }
 }
 \f
 
@@ -478,19 +475,12 @@ async_disable_stdin (void)
 static void
 command_handler (char *command)
 {
-  struct cleanup *old_chain;
   int stdin_is_tty = ISATTY (stdin);
-  long time_at_cmd_start;
-#ifdef HAVE_SBRK
-  long space_at_cmd_start = 0;
-#endif
-  extern int display_time;
-  extern int display_space;
+  struct cleanup *stat_chain;
 
   quit_flag = 0;
   if (instream == stdin && stdin_is_tty)
     reinitialize_more_filter ();
-  old_chain = make_cleanup (null_cleanup, 0);
 
   /* If readline returned a NULL command, it means that the 
      connection with the terminal is gone. This happens at the
@@ -503,48 +493,14 @@ command_handler (char *command)
       execute_command ("quit", stdin == instream);
     }
 
-  time_at_cmd_start = get_run_time ();
-
-  if (display_space)
-    {
-#ifdef HAVE_SBRK
-      char *lim = (char *) sbrk (0);
-      space_at_cmd_start = lim - lim_at_start;
-#endif
-    }
+  stat_chain = make_command_stats_cleanup (1);
 
   execute_command (command, instream == stdin);
 
-  /* Do any commands attached to breakpoint we stopped at. Only if we
-     are always running synchronously. Or if we have just executed a
-     command that doesn't start the target. */
-  if (!target_can_async_p () || is_stopped (inferior_ptid))
-    {
-      bpstat_do_actions (&stop_bpstat);
-      do_cleanups (old_chain);
-
-      if (display_time)
-       {
-         long cmd_time = get_run_time () - time_at_cmd_start;
-
-         printf_unfiltered (_("Command execution time: %ld.%06ld\n"),
-                            cmd_time / 1000000, cmd_time % 1000000);
-       }
+  /* Do any commands attached to breakpoint we stopped at.  */
+  bpstat_do_actions ();
 
-      if (display_space)
-       {
-#ifdef HAVE_SBRK
-         char *lim = (char *) sbrk (0);
-         long space_now = lim - lim_at_start;
-         long space_diff = space_now - space_at_cmd_start;
-
-         printf_unfiltered (_("Space used: %ld (%c%ld for this command)\n"),
-                            space_now,
-                            (space_diff >= 0 ? '+' : '-'),
-                            space_diff);
-#endif
-       }
-    }
+  do_cleanups (stat_chain);
 }
 
 /* Handle a complete line of input. This is called by the callback
@@ -567,7 +523,6 @@ command_line_handler (char *rl)
   char *nline;
   char got_eof = 0;
 
-
   int repeat = (instream == stdin);
 
   if (annotation_level > 1 && instream == stdin)
@@ -633,10 +588,10 @@ command_line_handler (char *rl)
 
   if (p > linebuffer && *(p - 1) == '\\')
     {
+      *p = '\0';
       p--;                     /* Put on top of '\'.  */
 
-      readline_input_state.linebuffer = savestring (linebuffer,
-                                                   strlen (linebuffer));
+      readline_input_state.linebuffer = xstrdup (linebuffer);
       readline_input_state.linebuffer_ptr = p;
 
       /* We will not invoke a execute_command if there is more
@@ -985,7 +940,7 @@ async_disconnect (gdb_client_data arg)
                "Could not kill the program being debugged",
                RETURN_MASK_ALL);
   signal (SIGHUP, SIG_DFL);    /*FIXME: ??????????? */
-  kill (getpid (), SIGHUP);
+  raise (SIGHUP);
 }
 #endif
 
@@ -1001,6 +956,7 @@ static void
 async_stop_sig (gdb_client_data arg)
 {
   char *prompt = get_prompt ();
+
 #if STOP_SIGNAL == SIGTSTP
   signal (SIGTSTP, SIG_DFL);
 #if HAVE_SIGPROCMASK
@@ -1013,7 +969,7 @@ async_stop_sig (gdb_client_data arg)
 #elif HAVE_SIGSETMASK
   sigsetmask (0);
 #endif
-  kill (getpid (), SIGTSTP);
+  raise (SIGTSTP);
   signal (SIGTSTP, handle_stop_sig);
 #else
   signal (STOP_SIGNAL, handle_stop_sig);
@@ -1074,7 +1030,7 @@ set_async_annotation_level (char *args, int from_tty, struct cmd_list_element *c
 void
 set_async_prompt (char *args, int from_tty, struct cmd_list_element *c)
 {
-  PROMPT (0) = savestring (new_async_prompt, strlen (new_async_prompt));
+  PROMPT (0) = xstrdup (new_async_prompt);
 }
 
 /* Set things up for readline to be invoked via the alternate
@@ -1092,6 +1048,7 @@ gdb_setup_readline (void)
   gdb_stderr = stdio_fileopen (stderr);
   gdb_stdlog = gdb_stderr;  /* for moment */
   gdb_stdtarg = gdb_stderr; /* for moment */
+  gdb_stdtargerr = gdb_stderr; /* for moment */
 
   /* If the input stream is connected to a terminal, turn on
      editing.  */
@@ -1150,6 +1107,7 @@ gdb_disable_readline (void)
   ui_file_delete (gdb_stderr);
   gdb_stdlog = NULL;
   gdb_stdtarg = NULL;
+  gdb_stdtargerr = NULL;
 #endif
 
   rl_callback_handler_remove ();
This page took 0.030181 seconds and 4 git commands to generate.