From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3995 invoked by alias); 28 Mar 2006 21:59:08 -0000 Received: (qmail 3955 invoked by uid 22791); 28 Mar 2006 21:59:06 -0000 X-Spam-Check-By: sourceware.org Received: from nevyn.them.org (HELO nevyn.them.org) (66.93.172.17) by sourceware.org (qpsmtpd/0.31.1) with ESMTP; Tue, 28 Mar 2006 21:59:04 +0000 Received: from drow by nevyn.them.org with local (Exim 4.54) id 1FOMDK-0002y9-SP; Tue, 28 Mar 2006 16:58:58 -0500 Date: Tue, 28 Mar 2006 21:59:00 -0000 From: Daniel Jacobowitz To: Andrew STUBBS Cc: Mark Kettenis , gdb-patches@sourceware.org, insight@sourceware.org Subject: Re: [PATCH] Don't call Insight hooks when not appropriate Message-ID: <20060328215858.GC10392@nevyn.them.org> Mail-Followup-To: Andrew STUBBS , Mark Kettenis , gdb-patches@sourceware.org, insight@sourceware.org References: <44104BB2.6000108@st.com> <200603091910.k29JAucq014442@elgar.sibelius.xs4all.nl> <20060309191304.GA31165@nevyn.them.org> <44115FE2.4070206@st.com> <20060325000428.GH26748@nevyn.them.org> <4427CCAC.3030800@st.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4427CCAC.3030800@st.com> User-Agent: Mutt/1.5.8i Mailing-List: contact insight-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: insight-owner@sourceware.org X-SW-Source: 2006-q1/txt/msg00112.txt.bz2 On Mon, Mar 27, 2006 at 12:29:48PM +0100, Andrew STUBBS wrote: > Daniel Jacobowitz wrote: > >>How would you like it done? > > > >Does something like this work? Fixes a nasty cleanups bug in user > >commands at the same time. > > I haven't actually tested it, but shouldn't gdbtk_readline() and > gdbtk_query() return values? In particular, gdbtk_query() should return > 1 (yes) as the default answer, just as query() does in utils.c. You're right; my patch won't work. How about this one instead? Make input_from_terminal_p do something sensible for Insight. Index: top.c =================================================================== RCS file: /cvs/src/src/gdb/top.c,v retrieving revision 1.113 diff -u -p -r1.113 top.c --- top.c 10 Feb 2006 22:01:43 -0000 1.113 +++ top.c 28 Mar 2006 21:58:18 -0000 @@ -112,6 +112,10 @@ Whether to confirm potentially dangerous FILE *instream; +/* Flag to indicate whether a user defined command is currently running. */ + +int in_user_command; + /* Current working directory. */ char *current_directory; @@ -909,11 +913,11 @@ command_line_input (char *prompt_arg, in } /* Don't use fancy stuff if not talking to stdin. */ - if (deprecated_readline_hook && instream == NULL) + if (deprecated_readline_hook && input_from_terminal_p ()) { rl = (*deprecated_readline_hook) (local_prompt); } - else if (command_editing_p && instream == stdin && ISATTY (instream)) + else if (command_editing_p && input_from_terminal_p ()) { rl = gdb_readline_wrapper (local_prompt); } @@ -1197,13 +1201,22 @@ quit_force (char *args, int from_tty) exit (exit_code); } -/* Returns whether GDB is running on a terminal and whether the user - desires that questions be asked of them on that terminal. */ +/* Returns whether GDB is running on a terminal and input is + currently coming from that terminal. */ int input_from_terminal_p (void) { - return gdb_has_a_terminal () && (instream == stdin) & caution; + if (gdb_has_a_terminal () && instream == stdin) + return 1; + + /* If INSTREAM is unset, and we are not in a user command, we + must be in Insight. That's like having a terminal, for our + purposes. */ + if (instream == NULL && !in_user_command) + return 1; + + return 0; } static void Index: top.h =================================================================== RCS file: /cvs/src/src/gdb/top.h,v retrieving revision 1.12 diff -u -p -r1.12 top.h --- top.h 17 Dec 2005 22:34:03 -0000 1.12 +++ top.h 28 Mar 2006 21:58:18 -0000 @@ -27,6 +27,7 @@ extern char *line; extern int linesize; extern FILE *instream; +extern int in_user_command; extern char gdb_dirbuf[1024]; extern int inhibit_gdbinit; extern int epoch_interface; Index: utils.c =================================================================== RCS file: /cvs/src/src/gdb/utils.c,v retrieving revision 1.166 diff -u -p -r1.166 utils.c --- utils.c 10 Feb 2006 21:53:51 -0000 1.166 +++ utils.c 28 Mar 2006 21:58:19 -0000 @@ -1141,16 +1141,17 @@ query (const char *ctlstr, ...) int ans2; int retval; + /* Automatically answer "yes" if input is not from the user + directly, or if the user did not want prompts. */ + if (!input_from_terminal_p () || !caution) + return 1; + if (deprecated_query_hook) { va_start (args, ctlstr); return deprecated_query_hook (ctlstr, args); } - /* Automatically answer "yes" if input is not from a terminal. */ - if (!input_from_terminal_p ()) - return 1; - while (1) { wrap_here (""); /* Flush any buffered output */ @@ -1244,15 +1245,16 @@ defaulted_query (const char *ctlstr, con n_string = "[n]"; } + /* Automatically answer "yes" if input is not from the user + directly, or if the user did not want prompts. */ + if (!input_from_terminal_p () || !caution) + return 1; + if (deprecated_query_hook) { return deprecated_query_hook (ctlstr, args); } - /* Automatically answer default value if input is not from a terminal. */ - if (!input_from_terminal_p ()) - return def_value; - while (1) { wrap_here (""); /* Flush any buffered output */ Index: cli/cli-script.c =================================================================== RCS file: /cvs/src/src/gdb/cli/cli-script.c,v retrieving revision 1.32 diff -u -p -r1.32 cli-script.c --- cli/cli-script.c 17 Dec 2005 22:40:17 -0000 1.32 +++ cli/cli-script.c 28 Mar 2006 21:58:19 -0000 @@ -241,9 +241,9 @@ static void do_restore_user_call_depth (void * call_depth) { int * depth = call_depth; - /* We will be returning_to_top_level() at this point, so we want to - reset our depth. */ - (*depth) = 0; + (*depth)--; + if ((*depth) == 0) + in_user_command = 0; } @@ -266,12 +266,17 @@ execute_user_command (struct cmd_list_el if (++user_call_depth > max_user_call_depth) error (_("Max user call depth exceeded -- command aborted.")); - old_chain = make_cleanup (do_restore_user_call_depth, &user_call_depth); + make_cleanup (do_restore_user_call_depth, &user_call_depth); /* Set the instream to 0, indicating execution of a user-defined function. */ - old_chain = make_cleanup (do_restore_instream_cleanup, instream); + make_cleanup (do_restore_instream_cleanup, instream); instream = (FILE *) 0; + + /* Also set the global in_user_command, so that NULL instream is + not confused with Insight. */ + in_user_command = 1; + while (cmdlines) { ret = execute_control_command (cmdlines); @@ -283,8 +288,6 @@ execute_user_command (struct cmd_list_el cmdlines = cmdlines->next; } do_cleanups (old_chain); - - user_call_depth--; } enum command_control_type @@ -920,15 +923,19 @@ read_command_lines (char *prompt_arg, in enum misc_command_type val; control_level = 0; - if (deprecated_readline_begin_hook) - { - /* Note - intentional to merge messages with no newline */ - (*deprecated_readline_begin_hook) ("%s %s\n", prompt_arg, END_MESSAGE); - } - else if (from_tty && input_from_terminal_p ()) + + if (from_tty && input_from_terminal_p ()) { - printf_unfiltered ("%s\n%s\n", prompt_arg, END_MESSAGE); - gdb_flush (gdb_stdout); + if (deprecated_readline_begin_hook) + { + /* Note - intentional to merge messages with no newline */ + (*deprecated_readline_begin_hook) ("%s %s\n", prompt_arg, END_MESSAGE); + } + else + { + printf_unfiltered ("%s\n%s\n", prompt_arg, END_MESSAGE); + gdb_flush (gdb_stdout); + } } head = tail = NULL; @@ -989,7 +996,7 @@ read_command_lines (char *prompt_arg, in do_cleanups (old_chain); } - if (deprecated_readline_end_hook) + if (deprecated_readline_end_hook && from_tty && input_from_terminal_p ()) { (*deprecated_readline_end_hook) (); } Index: tui/tui-hooks.c =================================================================== RCS file: /cvs/src/src/gdb/tui/tui-hooks.c,v retrieving revision 1.26 diff -u -p -r1.26 tui-hooks.c --- tui/tui-hooks.c 23 Dec 2005 19:10:02 -0000 1.26 +++ tui/tui-hooks.c 28 Mar 2006 21:58:21 -0000 @@ -77,10 +77,6 @@ tui_query_hook (const char * msg, va_lis int ans2; int answer; - /* Automatically answer "yes" if input is not from a terminal. */ - if (!input_from_terminal_p ()) - return 1; - echo (); while (1) { -- Daniel Jacobowitz CodeSourcery