public inbox for insight@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Don't call Insight hooks when not appropriate
@ 2006-03-09 15:42 Andrew STUBBS
  2006-03-09 19:11 ` Mark Kettenis
  0 siblings, 1 reply; 18+ messages in thread
From: Andrew STUBBS @ 2006-03-09 15:42 UTC (permalink / raw)
  To: GDB Patches, insight

[-- Attachment #1: Type: text/plain, Size: 887 bytes --]

Hi all,

I'm not really sure whether this should go to GDB patches or Insight so 
you've both got it.

The attached patch prevents annoying messages and dialogue boxes when 
sourcing command scripts and running user-defined commands. It stops all 
yes/no questions and all 'Type commands for ...' messages.

Output and prompts from these scripts are normally suppressed by GDB, 
but not by Insight.

In order to achieve this I had to find a way to tell the difference 
between the normal Insight input state, and the state when executing 
user commands - both were previously identified by instream==NULL. I 
have changed instream to -1 when running user-defined commands. An 
inspection of the uses of instream suggests this will not have any 
detrimental affects, but it is hard to be totally sure.

I know these hooks are marked deprecated, but we're still using them.

Andrew Stubbs

[-- Attachment #2: insight-dialogue.patch --]
[-- Type: text/plain, Size: 2185 bytes --]

2006-03-09  Andrew Stubbs  <andrew.stubbs@st.com>

	* cli/cli-script.c (execute_user_command): Set instream to -1, not 0.
	(read_command_lines): Check instream before calling the prompt hook.
	* utils.c: Include top.h.
	(query): Check instream before calling the query hook.

Index: src/gdb/cli/cli-script.c
===================================================================
--- src.orig/gdb/cli/cli-script.c	2006-02-20 18:19:58.000000000 +0000
+++ src/gdb/cli/cli-script.c	2006-03-09 15:21:40.000000000 +0000
@@ -268,10 +268,11 @@ execute_user_command (struct cmd_list_el
 
   old_chain = make_cleanup (do_restore_user_call_depth, &user_call_depth);
 
-  /* Set the instream to 0, indicating execution of a
-     user-defined function.  */
+  /* Set the instream to -1, indicating execution of a
+     user-defined function.  Don't use 0 any more, because this is
+     the same as NULL, which is the instream value used by insight.  */
   old_chain = make_cleanup (do_restore_instream_cleanup, instream);
-  instream = (FILE *) 0;
+  instream = (FILE *) -1;
   while (cmdlines)
     {
       ret = execute_control_command (cmdlines);
@@ -920,7 +921,7 @@ read_command_lines (char *prompt_arg, in
   enum misc_command_type val;
 
   control_level = 0;
-  if (deprecated_readline_begin_hook)
+  if ((instream == stdin || instream == NULL) && deprecated_readline_begin_hook)
     {
       /* Note - intentional to merge messages with no newline */
       (*deprecated_readline_begin_hook) ("%s  %s\n", prompt_arg, END_MESSAGE);
Index: src/gdb/utils.c
===================================================================
--- src.orig/gdb/utils.c	2006-02-20 18:12:38.000000000 +0000
+++ src/gdb/utils.c	2006-03-09 15:17:43.000000000 +0000
@@ -54,6 +54,7 @@
 #include "filenames.h"
 #include "symfile.h"
 #include "gdb_obstack.h"
+#include "top.h"
 
 #include "inferior.h"		/* for signed_pointer_to_address */
 
@@ -1141,7 +1142,7 @@ query (const char *ctlstr, ...)
   int ans2;
   int retval;
 
-  if (deprecated_query_hook)
+  if ((instream == stdin || instream == NULL) && deprecated_query_hook)
     {
       va_start (args, ctlstr);
       return deprecated_query_hook (ctlstr, args);

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] Don't call Insight hooks when not appropriate
  2006-03-09 15:42 [PATCH] Don't call Insight hooks when not appropriate Andrew STUBBS
@ 2006-03-09 19:11 ` Mark Kettenis
  2006-03-09 19:13   ` Daniel Jacobowitz
  0 siblings, 1 reply; 18+ messages in thread
From: Mark Kettenis @ 2006-03-09 19:11 UTC (permalink / raw)
  To: andrew.stubbs; +Cc: gdb-patches, insight

> Date: Thu, 09 Mar 2006 15:37:22 +0000
> From: Andrew STUBBS <andrew.stubbs@st.com>
> 
> 2006-03-09  Andrew Stubbs  <andrew.stubbs@st.com>
> 
> 	* 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.

Mark

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] Don't call Insight hooks when not appropriate
  2006-03-09 19:11 ` Mark Kettenis
@ 2006-03-09 19:13   ` Daniel Jacobowitz
  2006-03-09 19:14     ` Daniel Jacobowitz
                       ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: Daniel Jacobowitz @ 2006-03-09 19:13 UTC (permalink / raw)
  To: Mark Kettenis; +Cc: andrew.stubbs, gdb-patches, insight

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 <andrew.stubbs@st.com>
> > 
> > 2006-03-09  Andrew Stubbs  <andrew.stubbs@st.com>
> > 
> > 	* 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?

-- 
Daniel Jacobowitz
CodeSourcery

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] Don't call Insight hooks when not appropriate
  2006-03-09 19:13   ` Daniel Jacobowitz
@ 2006-03-09 19:14     ` Daniel Jacobowitz
  2006-03-09 20:20     ` Michael Snyder
  2006-03-10 11:18     ` Andrew STUBBS
  2 siblings, 0 replies; 18+ messages in thread
From: Daniel Jacobowitz @ 2006-03-09 19:14 UTC (permalink / raw)
  To: Mark Kettenis, andrew.stubbs, gdb-patches, insight

On Thu, Mar 09, 2006 at 02:13:04PM -0500, 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 <andrew.stubbs@st.com>
> > > 
> > > 2006-03-09  Andrew Stubbs  <andrew.stubbs@st.com>
> > > 
> > > 	* 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?

Or maybe make the existing user_call_depth global.

-- 
Daniel Jacobowitz
CodeSourcery

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] Don't call Insight hooks when not appropriate
  2006-03-09 19:13   ` Daniel Jacobowitz
  2006-03-09 19:14     ` Daniel Jacobowitz
@ 2006-03-09 20:20     ` Michael Snyder
  2006-03-10 11:15       ` Andrew STUBBS
  2006-03-10 11:18     ` Andrew STUBBS
  2 siblings, 1 reply; 18+ messages in thread
From: Michael Snyder @ 2006-03-09 20:20 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: Mark Kettenis, andrew.stubbs, gdb-patches, insight

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 <andrew.stubbs@st.com>
>>>
>>>2006-03-09  Andrew Stubbs  <andrew.stubbs@st.com>
>>>
>>>	* 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?
> 

It might not be so bad, if replaced with a constant...
#define INVALID_USER 0
#define INVALID_INSIGHT -1

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] Don't call Insight hooks when not appropriate
  2006-03-09 20:20     ` Michael Snyder
@ 2006-03-10 11:15       ` Andrew STUBBS
  0 siblings, 0 replies; 18+ messages in thread
From: Andrew STUBBS @ 2006-03-10 11:15 UTC (permalink / raw)
  To: Michael Snyder; +Cc: Daniel Jacobowitz, Mark Kettenis, gdb-patches, insight

Michael Snyder wrote:
> It might not be so bad, if replaced with a constant...
> #define INVALID_USER 0
> #define INVALID_INSIGHT -1

Just so we are clear; I did it the other way round.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] Don't call Insight hooks when not appropriate
  2006-03-09 19:13   ` Daniel Jacobowitz
  2006-03-09 19:14     ` Daniel Jacobowitz
  2006-03-09 20:20     ` Michael Snyder
@ 2006-03-10 11:18     ` Andrew STUBBS
  2006-03-25  0:04       ` Daniel Jacobowitz
  2 siblings, 1 reply; 18+ messages in thread
From: Andrew STUBBS @ 2006-03-10 11:18 UTC (permalink / raw)
  To: Mark Kettenis, andrew.stubbs, gdb-patches, insight

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 <andrew.stubbs@st.com>
>>>
>>> 2006-03-09  Andrew Stubbs  <andrew.stubbs@st.com>
>>>
>>> 	* 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?

Andrew

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] Don't call Insight hooks when not appropriate
  2006-03-10 11:18     ` Andrew STUBBS
@ 2006-03-25  0:04       ` Daniel Jacobowitz
  2006-03-27 11:32         ` Andrew STUBBS
  0 siblings, 1 reply; 18+ messages in thread
From: Daniel Jacobowitz @ 2006-03-25  0:04 UTC (permalink / raw)
  To: Andrew STUBBS; +Cc: Mark Kettenis, gdb-patches, insight

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 <andrew.stubbs@st.com>
> >>>
> >>>2006-03-09  Andrew Stubbs  <andrew.stubbs@st.com>
> >>>
> >>>	* 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

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] Don't call Insight hooks when not appropriate
  2006-03-25  0:04       ` Daniel Jacobowitz
@ 2006-03-27 11:32         ` Andrew STUBBS
  2006-03-28 21:59           ` Daniel Jacobowitz
  0 siblings, 1 reply; 18+ messages in thread
From: Andrew STUBBS @ 2006-03-27 11:32 UTC (permalink / raw)
  To: Andrew STUBBS, Mark Kettenis, gdb-patches, insight

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.

Andrew

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] Don't call Insight hooks when not appropriate
  2006-03-27 11:32         ` Andrew STUBBS
@ 2006-03-28 21:59           ` Daniel Jacobowitz
  2006-03-29 15:43             ` Andrew STUBBS
  0 siblings, 1 reply; 18+ messages in thread
From: Daniel Jacobowitz @ 2006-03-28 21:59 UTC (permalink / raw)
  To: Andrew STUBBS; +Cc: Mark Kettenis, gdb-patches, insight

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;
 }
 \f
 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

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] Don't call Insight hooks when not appropriate
  2006-03-28 21:59           ` Daniel Jacobowitz
@ 2006-03-29 15:43             ` Andrew STUBBS
  2006-03-29 15:49               ` Daniel Jacobowitz
  0 siblings, 1 reply; 18+ messages in thread
From: Andrew STUBBS @ 2006-03-29 15:43 UTC (permalink / raw)
  To: Mark Kettenis, gdb-patches, insight

[-- Attachment #1: Type: text/plain, Size: 888 bytes --]

Daniel Jacobowitz wrote:
>> 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.

I'm a little confused now. I assume you meant to retain the cli-script.c
and top.h patches from your previous posting, but, even so, your patch
doesn't even attempt to tackle the problems with query() and
read_command_lines().

I think you are getting at the attached patch. I have tested this and it 
does what I want it to. It produces no extra failures in the test suite.

I'm still a little concerned that input_from_terminal_p no longer seems
to take 'caution' into account. Is that deliberate?

Andrew Stubbs


[-- Attachment #2: insight-dialogue-2.patch --]
[-- Type: text/plain, Size: 5946 bytes --]

2006-03-29  Daniel Jacobowitz  <dan@codesourcery.com>
	    Andrew Stubbs  <andrew.stubbs@st.com>

	* top.h: Declare in_user_command variable.
	* cli/cli-script.c (do_restore_user_call_depth): Unset in_user_command.
	(execute_user_command): Only set old_chain once.
	Set in_user_command.
	Decrement user_call_depth on return.
	(read_command_lines): Use input_from_terminal_p() to guard the
	deprecated_readline_begin_hook() call in addition to the non-hook.
	* top.c (in_user_command): New global variable.
	(command_line_input): use only input_from_terminal_p() to determine
	interactive state.
	(input_from_terminal_p): Take in_user_command into account.
	* utils.c (query): Move automatic 'yes' test before
	deprecated_query_hook() call.


Index: src/gdb/cli/cli-script.c
===================================================================
--- src.orig/gdb/cli/cli-script.c	2006-03-27 13:55:48.000000000 +0100
+++ src/gdb/cli/cli-script.c	2006-03-29 11:25:52.000000000 +0100
@@ -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 (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 if (from_tty)
+	{
+	  printf_unfiltered ("%s\n%s\n", prompt_arg, END_MESSAGE);
+	  gdb_flush (gdb_stdout);
+	}
     }
 
   head = tail = NULL;
Index: src/gdb/top.c
===================================================================
--- src.orig/gdb/top.c	2006-02-20 18:39:55.000000000 +0000
+++ src/gdb/top.c	2006-03-29 11:22:47.000000000 +0100
@@ -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;
 }
 \f
 static void
Index: src/gdb/top.h
===================================================================
--- src.orig/gdb/top.h	2005-12-17 22:34:03.000000000 +0000
+++ src/gdb/top.h	2006-03-29 11:22:29.000000000 +0100
@@ -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: src/gdb/utils.c
===================================================================
--- src.orig/gdb/utils.c	2006-03-27 13:55:48.000000000 +0100
+++ src/gdb/utils.c	2006-03-29 11:26:18.000000000 +0100
@@ -1141,16 +1141,16 @@ query (const char *ctlstr, ...)
   int ans2;
   int retval;
 
+  /* Automatically answer "yes" if input is not from a terminal.  */
+  if (!input_from_terminal_p ())
+    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 */

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] Don't call Insight hooks when not appropriate
  2006-03-29 15:43             ` Andrew STUBBS
@ 2006-03-29 15:49               ` Daniel Jacobowitz
  2006-03-29 15:58                 ` Andrew STUBBS
  0 siblings, 1 reply; 18+ messages in thread
From: Daniel Jacobowitz @ 2006-03-29 15:49 UTC (permalink / raw)
  To: Andrew STUBBS; +Cc: Mark Kettenis, gdb-patches, insight

On Wed, Mar 29, 2006 at 04:40:15PM +0100, Andrew STUBBS wrote:
> Daniel Jacobowitz wrote:
> >>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.
> 
> I'm a little confused now. I assume you meant to retain the cli-script.c
> and top.h patches from your previous posting, but, even so, your patch
> doesn't even attempt to tackle the problems with query() and
> read_command_lines().

I'm confused - did you try the same patch I posted?  There was a top.h
diff in what I posted, and a cli-script.c patch.

I changed the behavior of input_from_terminal_p (yes, removal of the
caution check was deliberate - I audited all the callers), and moved it
above the calls to deprecated_query_hook.  That should have fixed the
query case.  Similarly read_command_lines's call to the deprecated
hooks is now guarded by input_from_terminal_p ().

It looked much like what you've posted below, except more thorough
(e.g. you missed defaulted_query).  I can see the whole patch in the
list archives, so I wonder if your mail client ate it.

-- 
Daniel Jacobowitz
CodeSourcery

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] Don't call Insight hooks when not appropriate
  2006-03-29 15:49               ` Daniel Jacobowitz
@ 2006-03-29 15:58                 ` Andrew STUBBS
  2006-03-29 16:29                   ` Daniel Jacobowitz
  0 siblings, 1 reply; 18+ messages in thread
From: Andrew STUBBS @ 2006-03-29 15:58 UTC (permalink / raw)
  To: Mark Kettenis, gdb-patches, insight

Daniel Jacobowitz wrote:
> It looked much like what you've posted below, except more thorough
> (e.g. you missed defaulted_query).  I can see the whole patch in the
> list archives, so I wonder if your mail client ate it.

I see what's happened; there's a form-feed, or something, in it and that 
has caused the confusion.

Sorry, I'll try your patch properly.

Andrew

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] Don't call Insight hooks when not appropriate
  2006-03-29 15:58                 ` Andrew STUBBS
@ 2006-03-29 16:29                   ` Daniel Jacobowitz
  2006-03-29 16:38                     ` Andrew STUBBS
  0 siblings, 1 reply; 18+ messages in thread
From: Daniel Jacobowitz @ 2006-03-29 16:29 UTC (permalink / raw)
  To: Andrew STUBBS; +Cc: Mark Kettenis, gdb-patches, insight

On Wed, Mar 29, 2006 at 04:55:35PM +0100, Andrew STUBBS wrote:
> Daniel Jacobowitz wrote:
> >It looked much like what you've posted below, except more thorough
> >(e.g. you missed defaulted_query).  I can see the whole patch in the
> >list archives, so I wonder if your mail client ate it.
> 
> I see what's happened; there's a form-feed, or something, in it and that 
> has caused the confusion.
> 
> Sorry, I'll try your patch properly.

D'oh!  Thanks.  A lot of GDB code uses those for page breaks.

-- 
Daniel Jacobowitz
CodeSourcery

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] Don't call Insight hooks when not appropriate
  2006-03-29 16:29                   ` Daniel Jacobowitz
@ 2006-03-29 16:38                     ` Andrew STUBBS
  2006-03-29 16:45                       ` Dave Korn
                                         ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: Andrew STUBBS @ 2006-03-29 16:38 UTC (permalink / raw)
  To: Mark Kettenis, gdb-patches, insight

Daniel Jacobowitz wrote:
> On Wed, Mar 29, 2006 at 04:55:35PM +0100, Andrew STUBBS wrote:
>> Daniel Jacobowitz wrote:
>>> It looked much like what you've posted below, except more thorough
>>> (e.g. you missed defaulted_query).  I can see the whole patch in the
>>> list archives, so I wonder if your mail client ate it.
>> I see what's happened; there's a form-feed, or something, in it and that 
>> has caused the confusion.
>>
>> Sorry, I'll try your patch properly.
> 
> D'oh!  Thanks.  A lot of GDB code uses those for page breaks.

Yes, it is irritating, but I'm sure somebody likes them.

I have now tested your full patch. I could not get it to compile without 
adding 'caution' to top.h and including top.h in utils.c.

With that one change it does what I want. Thanks.

One small query: defaulted_query() used to return def_value, but now 
always returns 1. This does not seem to be the same thing. The new text 
is identical to that in query(), which smells like a paste-o to me.

Andrew

^ permalink raw reply	[flat|nested] 18+ messages in thread

* RE: [PATCH] Don't call Insight hooks when not appropriate
  2006-03-29 16:38                     ` Andrew STUBBS
@ 2006-03-29 16:45                       ` Dave Korn
  2006-03-29 18:01                       ` Eli Zaretskii
  2006-03-29 22:53                       ` Daniel Jacobowitz
  2 siblings, 0 replies; 18+ messages in thread
From: Dave Korn @ 2006-03-29 16:45 UTC (permalink / raw)
  To: 'Andrew STUBBS', 'Mark Kettenis', gdb-patches, insight

On 29 March 2006 17:36, Andrew STUBBS wrote:

> Daniel Jacobowitz wrote:
>> On Wed, Mar 29, 2006 at 04:55:35PM +0100, Andrew STUBBS wrote:
>>> Daniel Jacobowitz wrote:
>>>> It looked much like what you've posted below, except more thorough
>>>> (e.g. you missed defaulted_query).  I can see the whole patch in the
>>>> list archives, so I wonder if your mail client ate it.
>>> I see what's happened; there's a form-feed, or something, in it and that
>>> has caused the confusion. 
>>> 
>>> Sorry, I'll try your patch properly.
>> 
>> D'oh!  Thanks.  A lot of GDB code uses those for page breaks.
> 
> Yes, it is irritating, but I'm sure somebody likes them.

  I remembered seeing it in the gnu coding standards: it's at

http://www.gnu.org/prep/standards/standards.html#index-formfeed-61

  Just FYI.

    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] Don't call Insight hooks when not appropriate
  2006-03-29 16:38                     ` Andrew STUBBS
  2006-03-29 16:45                       ` Dave Korn
@ 2006-03-29 18:01                       ` Eli Zaretskii
  2006-03-29 22:53                       ` Daniel Jacobowitz
  2 siblings, 0 replies; 18+ messages in thread
From: Eli Zaretskii @ 2006-03-29 18:01 UTC (permalink / raw)
  To: Andrew STUBBS; +Cc: mark.kettenis, gdb-patches, insight

> Date: Wed, 29 Mar 2006 17:36:19 +0100
> From: Andrew STUBBS <andrew.stubbs@st.com>
> 
> > D'oh!  Thanks.  A lot of GDB code uses those for page breaks.
> 
> Yes, it is irritating, but I'm sure somebody likes them.

Emacs users do.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] Don't call Insight hooks when not appropriate
  2006-03-29 16:38                     ` Andrew STUBBS
  2006-03-29 16:45                       ` Dave Korn
  2006-03-29 18:01                       ` Eli Zaretskii
@ 2006-03-29 22:53                       ` Daniel Jacobowitz
  2 siblings, 0 replies; 18+ messages in thread
From: Daniel Jacobowitz @ 2006-03-29 22:53 UTC (permalink / raw)
  To: Andrew STUBBS; +Cc: Mark Kettenis, gdb-patches, insight

On Wed, Mar 29, 2006 at 05:36:19PM +0100, Andrew STUBBS wrote:
> I have now tested your full patch. I could not get it to compile without 
> adding 'caution' to top.h and including top.h in utils.c.
> 
> With that one change it does what I want. Thanks.
> 
> One small query: defaulted_query() used to return def_value, but now 
> always returns 1. This does not seem to be the same thing. The new text 
> is identical to that in query(), which smells like a paste-o to me.

Thank you for testing.  I've made those changes, tested GDB, and
checked it in - you're right about the paste-o, I had it right the
first time I did that and then I edited the comment and busted it...

Here's the final patch.

-- 
Daniel Jacobowitz
CodeSourcery

2006-03-29  Daniel Jacobowitz  <dan@codesourcery.com>

	* Makefile.in (utils.o): Update.
	* top.c (in_user_command): New.
	(command_line_input): Use input_from_terminal_p.
	(input_from_terminal_p): Don't check caution.  Handle
	stdin == NULL for Insight.
	* top.h (in_user_command, caution): New declarations.
	* utils.c: Include "top.h".
	(query, defaulted_query): Check caution here.  Move the call
	to input_from_terminal_p higher.
	* cli/cli-script.c (do_restore_user_call_depth): Only decrement
	the depth.  Update in_user_command if necessary.
	(execute_user_command): Don't clobber old_chain.  Set
	in_user_command.  Let do_restore_user_call_depth handle
	user_call_depth.
	(read_command_lines): Check whether to prompt before calling
	Insight hooks.
	* tui/tui-hooks.c (tui_query_hook): Remove newly unnecessary
	input_from_terminal_p check.

Index: gdb/Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.796
diff -u -p -r1.796 Makefile.in
--- gdb/Makefile.in	28 Mar 2006 19:19:16 -0000	1.796
+++ gdb/Makefile.in	29 Mar 2006 22:52:04 -0000
@@ -2744,7 +2744,7 @@ user-regs.o: user-regs.c $(defs_h) $(use
 utils.o: utils.c $(defs_h) $(gdb_assert_h) $(gdb_string_h) $(event_top_h) \
 	$(exceptions_h) $(tui_h) $(gdbcmd_h) $(serial_h) $(bfd_h) \
 	$(target_h) $(demangle_h) $(expression_h) $(language_h) $(charset_h) \
-	$(annotate_h) $(filenames_h) $(symfile_h) $(inferior_h) \
+	$(annotate_h) $(filenames_h) $(symfile_h) $(inferior_h) $(top_h) \
 	$(gdb_curses_h) $(readline_h) $(gdb_obstack_h)
 uw-thread.o: uw-thread.c $(defs_h) $(gdbthread_h) $(target_h) $(inferior_h) \
 	$(regcache_h) $(gregset_h)
Index: gdb/top.c
===================================================================
RCS file: /cvs/src/src/gdb/top.c,v
retrieving revision 1.113
diff -u -p -r1.113 top.c
--- gdb/top.c	10 Feb 2006 22:01:43 -0000	1.113
+++ gdb/top.c	29 Mar 2006 22:52:04 -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;
 }
 \f
 static void
Index: gdb/top.h
===================================================================
RCS file: /cvs/src/src/gdb/top.h,v
retrieving revision 1.12
diff -u -p -r1.12 top.h
--- gdb/top.h	17 Dec 2005 22:34:03 -0000	1.12
+++ gdb/top.h	29 Mar 2006 22:52:04 -0000
@@ -1,7 +1,7 @@
 /* Top level stuff for GDB, the GNU debugger.
 
    Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
-   1996, 1997, 1998, 1999, 2000, 2005 Free Software Foundation, Inc.
+   1996, 1997, 1998, 1999, 2000, 2005, 2006 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -27,6 +27,8 @@
 extern char *line;
 extern int linesize;
 extern FILE *instream;
+extern int in_user_command;
+extern int caution;
 extern char gdb_dirbuf[1024];
 extern int inhibit_gdbinit;
 extern int epoch_interface;
Index: gdb/utils.c
===================================================================
RCS file: /cvs/src/src/gdb/utils.c,v
retrieving revision 1.166
diff -u -p -r1.166 utils.c
--- gdb/utils.c	10 Feb 2006 21:53:51 -0000	1.166
+++ gdb/utils.c	29 Mar 2006 22:52:04 -0000
@@ -54,6 +54,7 @@
 #include "filenames.h"
 #include "symfile.h"
 #include "gdb_obstack.h"
+#include "top.h"
 
 #include "inferior.h"		/* for signed_pointer_to_address */
 
@@ -1141,16 +1142,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 +1246,16 @@ defaulted_query (const char *ctlstr, con
       n_string = "[n]";
     }
 
+  /* Automatically answer the default value if input is not from the user
+     directly, or if the user did not want prompts.  */
+  if (!input_from_terminal_p () || !caution)
+    return def_value;
+
   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: gdb/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
--- gdb/cli/cli-script.c	17 Dec 2005 22:40:17 -0000	1.32
+++ gdb/cli/cli-script.c	29 Mar 2006 22:52:05 -0000
@@ -1,8 +1,8 @@
 /* GDB CLI command scripting.
 
    Copyright (c) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
-   1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2004, 2005 Free
-   Software Foundation, Inc.
+   1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2004, 2005, 2006
+   Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -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: gdb/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
--- gdb/tui/tui-hooks.c	23 Dec 2005 19:10:02 -0000	1.26
+++ gdb/tui/tui-hooks.c	29 Mar 2006 22:52:05 -0000
@@ -1,6 +1,7 @@
 /* GDB hooks for TUI.
 
-   Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+   Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006
+   Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -77,10 +78,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)
     {

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2006-03-29 22:53 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-03-09 15:42 [PATCH] Don't call Insight hooks when not appropriate Andrew STUBBS
2006-03-09 19:11 ` Mark Kettenis
2006-03-09 19:13   ` Daniel Jacobowitz
2006-03-09 19:14     ` Daniel Jacobowitz
2006-03-09 20:20     ` Michael Snyder
2006-03-10 11:15       ` Andrew STUBBS
2006-03-10 11:18     ` Andrew STUBBS
2006-03-25  0:04       ` Daniel Jacobowitz
2006-03-27 11:32         ` Andrew STUBBS
2006-03-28 21:59           ` Daniel Jacobowitz
2006-03-29 15:43             ` Andrew STUBBS
2006-03-29 15:49               ` Daniel Jacobowitz
2006-03-29 15:58                 ` Andrew STUBBS
2006-03-29 16:29                   ` Daniel Jacobowitz
2006-03-29 16:38                     ` Andrew STUBBS
2006-03-29 16:45                       ` Dave Korn
2006-03-29 18:01                       ` Eli Zaretskii
2006-03-29 22:53                       ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).