From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8720 invoked by alias); 27 Nov 2012 23:53:04 -0000 Received: (qmail 8712 invoked by uid 22791); 27 Nov 2012 23:53:03 -0000 X-SWARE-Spam-Status: No, hits=-7.9 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,KHOP_THREADED,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,RP_MATCHES_RCVD,SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 27 Nov 2012 23:52:50 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qARNqneJ016555 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 27 Nov 2012 18:52:49 -0500 Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id qARNqlSA011472; Tue, 27 Nov 2012 18:52:48 -0500 Message-ID: <50B5524F.7040509@redhat.com> Date: Tue, 27 Nov 2012 23:53:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: Tom Tromey CC: gdb-patches@sourceware.org Subject: Re: [PATCH 2/4] Suppress repeated annotations until GDB is ready to accept input. References: <20121121201416.1015.36832.stgit@brno.lan> <20121121201429.1015.6037.stgit@brno.lan> <87vccsics1.fsf@fleche.redhat.com> <50B3B4BC.2010108@redhat.com> <87sj7udgrj.fsf@fleche.redhat.com> In-Reply-To: <87sj7udgrj.fsf@fleche.redhat.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-11/txt/msg00786.txt.bz2 On 11/27/2012 06:48 PM, Tom Tromey wrote: >>>>>> "Pedro" == Pedro Alves 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