Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Tom Tromey <tromey@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 2/4] Suppress repeated annotations until GDB is ready to accept input.
Date: Tue, 27 Nov 2012 23:53:00 -0000	[thread overview]
Message-ID: <50B5524F.7040509@redhat.com> (raw)
In-Reply-To: <87sj7udgrj.fsf@fleche.redhat.com>

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


  reply	other threads:[~2012-11-27 23:53 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <50ACF672.7060607@redhat.com>
2012-11-21 20:14 ` [PATCH 0/4] Misc annotations changes Pedro Alves
2012-11-21 20:14   ` [PATCH 4/4] Skip breakpoints-invalid annotations for internal|momentary breakpoints Pedro Alves
2012-11-21 20:14   ` [PATCH 3/4] Fully move the breakpoints-invalid annotation to observers Pedro Alves
2012-11-26 15:23     ` Tom Tromey
2012-11-21 20:14   ` [PATCH 2/4] Suppress repeated annotations until GDB is ready to accept input Pedro Alves
2012-11-26 15:50     ` Tom Tromey
2012-11-26 18:28       ` Pedro Alves
2012-11-27 18:48         ` Tom Tromey
2012-11-27 23:53           ` Pedro Alves [this message]
2013-01-22 19:59           ` Pedro Alves
2012-11-27 18:56         ` Eli Zaretskii
2012-11-21 20:14   ` [PATCH 1/4] Remove (alleged) "breakpoints-changed" annotation suppression on ignore count changes Pedro Alves
2012-11-26 15:42   ` [PATCH 0/4] Misc annotations changes Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=50B5524F.7040509@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tromey@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox