From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12485 invoked by alias); 25 Mar 2006 00:04:35 -0000 Received: (qmail 12469 invoked by uid 22791); 25 Mar 2006 00:04:34 -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; Sat, 25 Mar 2006 00:04:32 +0000 Received: from drow by nevyn.them.org with local (Exim 4.54) id 1FMwGa-0004wE-GF; Fri, 24 Mar 2006 19:04:28 -0500 Date: Sat, 25 Mar 2006 07:00: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: <20060325000428.GH26748@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> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <44115FE2.4070206@st.com> User-Agent: Mutt/1.5.8i X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2006-03/txt/msg00284.txt.bz2 On Fri, Mar 10, 2006 at 11:15:46AM +0000, Andrew STUBBS wrote: > Daniel Jacobowitz wrote: > >On Thu, Mar 09, 2006 at 08:10:56PM +0100, Mark Kettenis wrote: > >>>Date: Thu, 09 Mar 2006 15:37:22 +0000 > >>>From: Andrew STUBBS > >>> > >>>2006-03-09 Andrew Stubbs > >>> > >>> * cli/cli-script.c (execute_user_command): Set instream to -1, not 0. > >>> (read_command_lines): Check instream before calling the prompt hook. > >>I think this usage of -1 is a bad idea. > > > >Me too. We're already using a global variable; why not just add > >another and restore it in the same cleanup? > > I don't really mind, as long as it works. > > How would you like it done? Does something like this work? Fixes a nasty cleanups bug in user commands at the same time. 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 25 Mar 2006 00:03:23 -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; 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 25 Mar 2006 00:03:23 -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: 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 25 Mar 2006 00:03:23 -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 Index: gdbtk/generic/gdbtk-hooks.c =================================================================== RCS file: /cvs/src/src/gdb/gdbtk/generic/gdbtk-hooks.c,v retrieving revision 1.41 diff -u -p -r1.41 gdbtk-hooks.c --- gdbtk/generic/gdbtk-hooks.c 23 Dec 2005 18:23:16 -0000 1.41 +++ gdbtk/generic/gdbtk-hooks.c 25 Mar 2006 00:03:23 -0000 @@ -486,6 +486,9 @@ gdbtk_readline_begin (char *format,...) va_list args; char *buf; + if (instream != NULL || in_user_command) + return; + va_start (args, format); xvasprintf (&buf, format, args); gdbtk_two_elem_cmd ("gdbtk_tcl_readline_begin", buf); @@ -497,6 +500,9 @@ gdbtk_readline (char *prompt) { int result; + if (instream != NULL || in_user_command) + return; + #ifdef _WIN32 close_bfds (); #endif @@ -518,6 +524,9 @@ gdbtk_readline (char *prompt) static void gdbtk_readline_end () { + if (instream != NULL || in_user_command) + return; + if (Tcl_Eval (gdbtk_interp, "gdbtk_tcl_readline_end") != TCL_OK) report_error (); } @@ -682,6 +691,9 @@ gdbtk_query (const char *query, va_list char *buf; long val; + if (instream != NULL || in_user_command) + return; + xvasprintf (&buf, query, args); gdbtk_two_elem_cmd ("gdbtk_tcl_query", buf); free(buf); -- Daniel Jacobowitz CodeSourcery