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 2/4] Suppress repeated annotations until GDB is ready to accept input.


On 11/27/2012 06:48 PM, Tom Tromey wrote:
>>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:

> Pedro> [*] - though that could itself be considered a bug, the CLI
> Pedro> output is less than ideal here.  We should be able to keep the
> Pedro> bottom line reserved for the prompt, and scroll the rest of the
> Pedro> output without visually interfering with the prompt line.  E.g.,
> Pedro> we could be able to unwind the cursor to column 0, print whatever
> Pedro> while handling the event, and then redisplay the prompt as it
> Pedro> was, without the user noticing.  Or perhaps there's cleaner ways
> Pedro> even.
> 
> Do you mean, do this in Emacs or for the CLI itself?
> Either way I think it would be nice.

For the CLI itself.  I found an old prototype patch I had that still works.

Try e.g., a test program that has several threads, debug with target-async/non-stop
on, and do "interrupt -a".  With mainline, you get:

(gdb) c -a&
Continuing.
(gdb) [New Thread 0x7ffff7fd0700 (LWP 19273)]
[New Thread 0x7ffff77cf700 (LWP 19274)]
interrupt -a
(gdb)
[Thread 0x7ffff7fd1740 (LWP 19263)] #1 stopped.
0x0000003d26a08e60 in pthread_join (threadid=140737353942784, thread_return=0x7fffffffdb90) at pthread_join.c:93
93          lll_wait_tid (pd->tid);

[Thread 0x7ffff77cf700 (LWP 19274)] #3 stopped.
0x0000003d25eba6ed in nanosleep () at ../sysdeps/unix/syscall-template.S:82
82      T_PSEUDO (SYSCALL_SYMBOL, SYSCALL_NAME, SYSCALL_NARGS)

[Thread 0x7ffff7fd0700 (LWP 19273)] #2 stopped.
0x0000003d25eba6ed in nanosleep () at ../sysdeps/unix/syscall-template.S:82
82      T_PSEUDO (SYSCALL_SYMBOL, SYSCALL_NAME, SYSCALL_NARGS)


With the patch, you get:

(gdb) c -a&
Continuing.
[New Thread 0x7ffff7fd0700 (LWP 22367)]
During symbol reading, cannot get low and high bounds for subprogram DIE at 29519.
During symbol reading, Child DIE 0x7885 and its abstract origin 0x734f have different parents.
During symbol reading, Child DIE 0x7a01 and its abstract origin 0x7801 have different tags.
[New Thread 0x7ffff77cf700 (LWP 22368)]
(gdb) interrupt -a

[Thread 0x7ffff7fd0700 (LWP 22367)] #2 stopped.
0x0000003d25eba6ed in nanosleep () at ../sysdeps/unix/syscall-template.S:82
82      T_PSEUDO (SYSCALL_SYMBOL, SYSCALL_NAME, SYSCALL_NARGS)

[Thread 0x7ffff77cf700 (LWP 22368)] #3 stopped.
0x0000003d25eba6ed in nanosleep () at ../sysdeps/unix/syscall-template.S:82
82      T_PSEUDO (SYSCALL_SYMBOL, SYSCALL_NAME, SYSCALL_NARGS)

[Thread 0x7ffff7fd1740 (LWP 22357)] #1 stopped.
0x0000003d26a08e60 in pthread_join (threadid=140737353942784, thread_return=0x7fffffffdb90) at pthread_join.c:93
93          lll_wait_tid (pd->tid);
(gdb)

The difference above is in where "(gdb)" appears.  The latter is much neater.
But you really have to try it to and see for yourself in action.

The issue with this implementation is that it still flickers the prompt.
Not noticeable usually, unless you have a stream of gdb output while
the prompt is visible.  E.g., try a program that has a thread looping,
set a break in the loop, with condition 0 ("break someline if 0"), and
enable "set debug infrun 1".  Ideally, the prompt line would stay
always clearly visible, without flicker, with the other gdb output
scrolling starting at the line above the prompt.

So I'm not really sure of what's the proper way to handle this with
readline.  Maybe we need to handle this at a lower layer, say, make
the uiout level aware of the prompt buffer contents.

-- 
Pedro Alves

 gdb/infrun.c     |   28 ++++++++++++++++++++++++++++
 gdb/tui/tui-io.c |   11 +----------
 2 files changed, 29 insertions(+), 10 deletions(-)

diff --git a/gdb/infrun.c b/gdb/infrun.c
index e7c20e1..391ce12 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -59,6 +59,7 @@
 #include "objfiles.h"
 #include "completer.h"
 #include "target-descriptions.h"
+#include "readline/readline.h"

 /* Prototypes for local functions */

@@ -2743,6 +2744,29 @@ wait_for_inferior (void)
   do_cleanups (old_cleanups);
 }

+static void
+redisplay_prompt (void *old_prompt)
+{
+  rl_set_prompt (old_prompt);
+  xfree (old_prompt);
+  (*rl_redisplay_function) ();
+}
+
+static void
+hide_prompt_and_make_cleanup (void)
+{
+  char *prompt;
+
+  /* Don't rely on rl_save_prompt, as that doesn't handle nesting.  */
+
+  prompt = xstrdup (rl_prompt);
+
+  rl_set_prompt ("");
+  (*rl_redisplay_function) ();
+
+  make_cleanup (redisplay_prompt, prompt);
+}
+
 /* Asynchronous version of wait_for_inferior.  It is called by the
    event loop whenever a change of state is detected on the file
    descriptor corresponding to the target.  It can be called more than
@@ -2762,6 +2786,10 @@ fetch_inferior_event (void *client_data)
   int was_sync = sync_execution;
   int cmd_done = 0;

+  /* Hide the prompt while here, so that any message printed while
+     handling the event doesn't mess up with the prompt.  */
+  hide_prompt_and_make_cleanup ();
+
   memset (ecs, 0, sizeof (*ecs));

   /* We're handling a live event, so make sure we're doing live
diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c
index fe88f1a..77e8875 100644
--- a/gdb/tui/tui-io.c
+++ b/gdb/tui/tui-io.c
@@ -142,10 +142,6 @@ static FILE *tui_old_rl_outstream;
 static int tui_readline_pipe[2];
 #endif

-/* The last gdb prompt that was registered in readline.
-   This may be the main gdb prompt or a secondary prompt.  */
-static char *tui_rl_saved_prompt;
-
 static unsigned int tui_handle_resize_during_io (unsigned int);

 static void
@@ -221,7 +217,7 @@ tui_redisplay_readline (void)
   if (tui_current_key_mode == TUI_SINGLE_KEY_MODE)
     prompt = "";
   else
-    prompt = tui_rl_saved_prompt;
+    prompt = rl_display_prompt;

   c_pos = -1;
   c_line = -1;
@@ -288,11 +284,6 @@ tui_redisplay_readline (void)
 static void
 tui_prep_terminal (int notused1)
 {
-  /* Save the prompt registered in readline to correctly display it.
-     (we can't use gdb_prompt() due to secondary prompts and can't use
-     rl_prompt because it points to an alloca buffer).  */
-  xfree (tui_rl_saved_prompt);
-  tui_rl_saved_prompt = xstrdup (rl_prompt);
 }

 /* Readline callback to restore the terminal.  It is called once each


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