This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] python prompt additions at first prompt.


sorry, think i'm done now...
this patch is intended to be functionally equivalent to the one i sent
yesterday wrt prompt bugs,
I thought (too late), that the sync_execution && !is_running behavior
of 'display an empty prompt followed by an actual prompt' is odd, and
since it happens only in obscure cases
is easily missed.

it seems clearer to return early in all sync_execution cases, and
limit the potential for introducing the double prompting type of bug.
I haven't been able to find any problems with this approach.

2011-08-12  Matt Rice  <ratmice@gmail.com>

        * event-top.c (cli_command_loop): Call display_gdb_prompt
        unconditionally.
        (display_gdb_prompt): Exit early if sync_execution is set.
        Move observer calls after early exits.
        Remove extra semi-colon.
        (async_enable_stdin): Don't pop an empty prompt.
        (async_disable_stdin): Don't push an empty prompt.


more information on PR 10720, which I'd had random difficulties
reproducing, I managed to figure out why, the process being attached
to must be on the same tty as the gdb process to reproduce it.
Haven't been able to reproduce that in the testsuite though.

thus the following gdb command lines on the various PID tty's the
buggy gdb process which gets Stopped is frobbed.

$ ~/tests/test &
[10] 18413
$ tty
/dev/pts/0
$ ~/tests/test  &
[3] 18415
$ tty
/dev/pts/4
$ gdb/gdb -quiet -ex 'set target-async on' -ex 'attach 18415' -ex 'continue&'
Attaching to process 18415
Continuing.

[4]+  Stopped                 gdb/gdb -quiet -ex 'set target-async on'
-ex 'attach 18415' -ex 'continue&'

$ gdb/gdb -quiet -ex 'set target-async on' -ex 'attach 18413' -ex 'continue&'
Attaching to process 18413
Continuing.

Program received signal SIGSTOP, Stopped (signal).
0x00400525 in ?? ()
Reading symbols from /home/ratmice/tests/test...done.
Reading symbols from /lib64/libc.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib64/libc.so.6
Reading symbols from /lib64/ld-linux-x86-64.so.2...(no debugging
symbols found)...done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
main (argc=1, argv=0x7fff67d42c68) at test.c:39
39	    ;
(gdb)
diff --git a/gdb/event-top.c b/gdb/event-top.c
index 37882728..29a57f1 100644
--- a/gdb/event-top.c
+++ b/gdb/event-top.c
@@ -185,27 +185,7 @@ rl_callback_read_char_wrapper (gdb_client_data client_data)
 void
 cli_command_loop (void)
 {
-  /* If we are using readline, set things up and display the first
-     prompt, otherwise just print the prompt.  */
-  if (async_command_editing_p)
-    {
-      int length;
-      char *a_prompt;
-      char *gdb_prompt = get_prompt (0);
-
-      /* Tell readline what the prompt to display is and what function
-         it will need to call after a whole line is read.  This also
-         displays the first prompt.  */
-      length = strlen (get_prefix (0))
-	+ strlen (gdb_prompt) + strlen (get_suffix(0)) + 1;
-      a_prompt = (char *) alloca (length);
-      strcpy (a_prompt, get_prefix (0));
-      strcat (a_prompt, gdb_prompt);
-      strcat (a_prompt, get_suffix (0));
-      rl_callback_handler_install (a_prompt, input_handler);
-    }
-  else
-    display_gdb_prompt (0);
+  display_gdb_prompt (0);
 
   /* Now it's time to start the event loop.  */
   start_event_loop ();
@@ -269,26 +249,7 @@ display_gdb_prompt (char *new_prompt)
   if (!current_interp_display_prompt_p ())
     return;
 
-  /* Get the prompt before the observers are called as observer hook
-     functions may change the prompt.  Do not call observers on an
-     explicit prompt change as passed to this function, as this forms
-     a temporary prompt, IE, displayed but not set.  */
-  if (! new_prompt)
-    {
-      char *post_gdb_prompt = NULL;
-      char *pre_gdb_prompt = xstrdup (get_prompt (0));
-
-      observer_notify_before_prompt (pre_gdb_prompt);
-      post_gdb_prompt = get_prompt (0);
-
-      /* If the observer changed the prompt, use that prompt.  */
-      if (strcmp (pre_gdb_prompt, post_gdb_prompt) != 0)
-	actual_gdb_prompt = post_gdb_prompt;
-
-      xfree (pre_gdb_prompt);
-    }
-
-  if (sync_execution && is_running (inferior_ptid))
+  if (sync_execution)
     {
       /* This is to trick readline into not trying to display the
          prompt.  Even though we display the prompt using this
@@ -305,10 +266,31 @@ display_gdb_prompt (char *new_prompt)
          between the calls to the above two functions.
          Calling rl_callback_handler_remove(), does the job.  */
 
-      rl_callback_handler_remove ();
+      if (is_running (inferior_ptid))
+        rl_callback_handler_remove ();
+
       return;
     }
 
+  /* Get the prompt before the observers are called as observer hook
+     functions may change the prompt.  Do not call observers on an
+     explicit prompt change as passed to this function, as this forms
+     a temporary prompt, IE, displayed but not set.  */
+  if (! new_prompt)
+    {
+      char *post_gdb_prompt = NULL;
+      char *pre_gdb_prompt = xstrdup (get_prompt (0));
+
+      observer_notify_before_prompt (pre_gdb_prompt);
+      post_gdb_prompt = get_prompt (0);
+
+      /* If the observer changed the prompt, use that prompt.  */
+      if (strcmp (pre_gdb_prompt, post_gdb_prompt) != 0)
+	actual_gdb_prompt = post_gdb_prompt;
+
+      xfree (pre_gdb_prompt);
+    }
+
   /* If the observer changed the prompt, ACTUAL_GDB_PROMPT will not be
      NULL.  Otherwise, either copy the existing prompt, or set it to
      NEW_PROMPT.  */
@@ -331,7 +313,7 @@ display_gdb_prompt (char *new_prompt)
 	  strcat (actual_gdb_prompt, get_suffix (0));
 	}
       else
-	actual_gdb_prompt = new_prompt;;
+	actual_gdb_prompt = new_prompt;
     }
 
   if (async_command_editing_p)
@@ -473,7 +455,6 @@ async_enable_stdin (void)
 	 sync_execution.  Current target_terminal_ours() implementations
 	 check for sync_execution before switching the terminal.  */
       target_terminal_ours ();
-      pop_prompt ();
       sync_execution = 0;
     }
 }
@@ -487,7 +468,6 @@ async_disable_stdin (void)
   if (!sync_execution)
     {
       sync_execution = 1;
-      push_prompt ("", "", "");
     }
 }
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]