From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17113 invoked by alias); 30 Apr 2012 14:49:19 -0000 Received: (qmail 17100 invoked by uid 22791); 30 Apr 2012 14:49:16 -0000 X-SWARE-Spam-Status: No, hits=-3.5 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,RCVD_IN_HOSTKARMA_NO,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 30 Apr 2012 14:49:03 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 712401C62D3; Mon, 30 Apr 2012 10:49:02 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id VBn1btuVlLod; Mon, 30 Apr 2012 10:49:02 -0400 (EDT) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 3BB851C62B2; Mon, 30 Apr 2012 10:49:02 -0400 (EDT) Received: by joel.gnat.com (Postfix, from userid 1000) id 2E544145616; Mon, 30 Apr 2012 07:48:56 -0700 (PDT) Date: Mon, 30 Apr 2012 16:26:00 -0000 From: Joel Brobecker To: Eli Zaretskii Cc: gdb-patches@sourceware.org Subject: Re: GDB/MI and ">" prompts Message-ID: <20120430144856.GU10958@adacore.com> References: <83vckviv3b.fsf@gnu.org> <20120419154853.GM25623@adacore.com> <83sjfzitxx.fsf@gnu.org> <83r4vjitnj.fsf@gnu.org> <20120419185329.GO25623@adacore.com> <83mx67ikxm.fsf@gnu.org> <837gx7hhxa.fsf@gnu.org> <83lilg6ysn.fsf@gnu.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <83lilg6ysn.fsf@gnu.org> User-Agent: Mutt/1.5.20 (2009-06-14) 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-04/txt/msg01076.txt.bz2 On Sat, Apr 28, 2012 at 11:33:28AM +0300, Eli Zaretskii wrote: > > Ping! Is the patch below OK for committing? I don't really know what the consequences would be to switch temporarily to the CLI interpreter. I am hoping someone else might. If not, there's only going to be one way to know, which it to give it a try. Right now is a good time for this sort of attempt, as we are still about 4 weeks away from 7.5 branching. > > > Date: Sun, 22 Apr 2012 19:04:17 +0300 > > From: Eli Zaretskii > > Cc: gdb-patches@sourceware.org > > > > [I moved this to gdb-patches, since I propose a patch below.] > > > > > Date: Thu, 19 Apr 2012 22:24:53 +0300 > > > From: Eli Zaretskii > > > Cc: gdb@sourceware.org > > > > > > The crux of my question was why non-interactive mode does display a > > > prompt while the interactive one doesn't. > > > > To answer my own question, here's why: > > > > char * > > command_line_input (char *prompt_arg, int repeat, char *annotation_suffix) > > { > > ... > > /* Don't use fancy stuff if not talking to stdin. */ > > if (deprecated_readline_hook && input_from_terminal_p ()) > > { > > rl = (*deprecated_readline_hook) (local_prompt); > > } > > else if (command_editing_p && input_from_terminal_p ()) > > { > > rl = gdb_readline_wrapper (local_prompt); > > } > > else > > { > > rl = gdb_readline (local_prompt); > > } > > > > Now, the code is clear, but I cannot say I understand the logic. If > > the input is from terminal, we ask (inside gdb_readline_wrapper) the > > current interpreter whether to show the prompt. But if input is _not_ > > from terminal, we display the prompt unconditionally (inside > > gdb_readline). How does this make sense? > > > > > Date: Thu, 19 Apr 2012 11:53:29 -0700 > > > From: Joel Brobecker > > > Cc: gdb@sourceware.org > > > > > > The other thing that occured to me was that, perhaps, we should instead > > > be switching the interpreter while executing the console command, > > > > I arrived to the same conclusion, eventually. See below. > > > > > but I doubt that would be correct. > > > > Why not? The patch below works for me. > > > > --- gdb/interps.c~0 2012-01-06 06:43:17.000000000 +0200 > > +++ gdb/interps.c 2012-04-22 08:55:27.056588400 +0300 > > @@ -253,6 +253,18 @@ interp_ui_out (struct interp *interp) > > return current_interpreter->procs->ui_out_proc (current_interpreter); > > } > > > > +/* Temporarily overrides the current interpreter. */ > > +struct interp * > > +interp_set_temp (const char *name) > > +{ > > + struct interp *interp = interp_lookup (name); > > + struct interp *old_interp = current_interpreter; > > + > > + if (interp) > > + current_interpreter = interp; > > + return old_interp; > > +} > > + > > /* Returns the interpreter's cookie. */ > > > > void * > > --- gdb/interps.h~0 2012-01-06 06:43:17.000000000 +0200 > > +++ gdb/interps.h 2012-04-22 08:42:05.687879800 +0300 > > @@ -69,6 +69,7 @@ > > extern struct ui_out *interp_ui_out (struct interp *interp); > > extern void *interp_data (struct interp *interp); > > extern const char *interp_name (struct interp *interp); > > +extern struct interp *interp_set_temp (const char *name); > > > > extern int current_interp_named_p (const char *name); > > extern int current_interp_display_prompt_p (void); > > --- gdb/cli/cli-script.c~0 2012-01-06 06:43:32.000000000 +0200 > > +++ gdb/cli/cli-script.c 2012-04-22 09:04:23.533807200 +0300 > > @@ -1178,6 +1178,12 @@ recurse_read_control_structure (char * ( > > return ret; > > } > > > > +static void > > +restore_interp (void *arg) > > +{ > > + interp_set_temp (interp_name ((struct interp *)arg)); > > +} > > + > > /* Read lines from the input stream and accumulate them in a chain of > > struct command_line's, which is then returned. For input from a > > terminal, the special command "end" is used to mark the end of the > > @@ -1210,8 +1216,21 @@ read_command_lines (char *prompt_arg, in > > } > > } > > > > - head = read_command_lines_1 (read_next_line, parse_commands, > > - validator, closure); > > + > > + /* Reading commands assumes the CLI behavior, so temporarily > > + override the current interpreter with CLI. */ > > + if (current_interp_named_p (INTERP_CONSOLE)) > > + head = read_command_lines_1 (read_next_line, parse_commands, > > + validator, closure); > > + else > > + { > > + struct interp *old_interp = interp_set_temp (INTERP_CONSOLE); > > + struct cleanup *old_chain = make_cleanup (restore_interp, old_interp); > > + > > + head = read_command_lines_1 (read_next_line, parse_commands, > > + validator, closure); > > + do_cleanups (old_chain); > > + } > > > > if (deprecated_readline_end_hook && from_tty && input_from_terminal_p ()) > > { > > -- Joel