* [RFC] Never silently discard internal errors
@ 2006-09-25 18:42 Daniel Jacobowitz
2006-09-25 19:10 ` Michael Snyder
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: Daniel Jacobowitz @ 2006-09-25 18:42 UTC (permalink / raw)
To: gdb-patches
Here's a problem that one of our customers turned up. He runs GDB
from inside Emacs, which means that its standard input is considered
to be a pipe, which is not a terminal. Accordingly query is suppressed.
Whether this is right everywhere or not is a question for another day,
but one particular thing we discovered was that GDB would mysteriously
quit out from under him, without telling him what it was doing.
Eventually we tracked it down to an unrelated problem in the code he was
testing for me. Not too surprising - that's what all the gdb_assert's
and such are for, after all :-) But not only was it not asking permission
before it bailed, but it wasn't even leaving a useful message.
I think the attached patch is reasonable. It changes error handling
such that if query is a no-op - for instance, from a script file,
or from a pipe - we dump out a message to stdout anyway before quitting
or dumping core.
It's easy to see this behavior for yourself. Just put the line
"maint internal-error" in a text file, and start gdb with -x filename.
Watch it abort without saying goodbye.
Any thoughts on this patch? Shall I commit it?
--
Daniel Jacobowitz
CodeSourcery
2006-09-25 Daniel Jacobowitz <dan@codesourcery.com>
* utils.c (query_is_silent): New.
(internal_vproblem, query, defaulted_query): Use it.
Index: utils.c
===================================================================
RCS file: /cvs/src/src/gdb/utils.c,v
retrieving revision 1.169
diff -u -p -r1.169 utils.c
--- utils.c 21 Sep 2006 13:50:51 -0000 1.169
+++ utils.c 25 Sep 2006 18:31:50 -0000
@@ -81,6 +81,8 @@ void (*deprecated_error_begin_hook) (voi
/* Prototypes for local functions */
+static int query_is_silent (void);
+
static void vfprintf_maybe_filtered (struct ui_file *, const char *,
va_list, int) ATTR_FORMAT (printf, 2, 0);
@@ -750,6 +752,9 @@ further debugging may prove unreliable."
this lessens the likelhood of GDB going into an infinate
loop. */
quit_p = query (_("%s\nQuit this debugging session? "), reason);
+ if (query_is_silent ())
+ fprintf_unfiltered (gdb_stdout,
+ "%s\nQuitting this debugging session.\n", reason);
break;
case AUTO_BOOLEAN_TRUE:
quit_p = 1;
@@ -768,7 +773,9 @@ further debugging may prove unreliable."
`dropping' so that it is easier to see that something went
wrong in GDB. */
dump_core_p = query (_("%s\nCreate a core file of GDB? "), reason);
- break;
+ if (query_is_silent ())
+ fprintf_unfiltered (gdb_stdout,
+ "%s\nCreating a core file.\n", reason);
break;
case AUTO_BOOLEAN_TRUE:
dump_core_p = 1;
@@ -1128,6 +1135,24 @@ gdb_print_host_address (const void *addr
fprintf_filtered (stream, "0x%lx", (unsigned long) addr);
}
+/* Return whether query will not display anything. If it won't, the
+ caller may want to display an informative message that would otherwise
+ have been part of the query prompt. Also used to implement query
+ and defaulted_query, to assure they stay consistent. */
+
+static int
+query_is_silent (void)
+{
+ /* We will automatically answer the query if input is not from the
+ user directly (e.g. from a script file or a pipe), or if the user
+ did not want prompts. */
+ if (!input_from_terminal_p () || !caution)
+ return 1;
+
+ return 0;
+}
+
+
/* Ask user a y-or-n question and return 1 iff answer is yes.
Takes three args which are given to printf to print the question.
The first, a control string, should end in "? ".
@@ -1142,9 +1167,8 @@ 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)
+ /* Automatically answer "yes" if this query should not prompt. */
+ if (query_is_silent ())
return 1;
if (deprecated_query_hook)
@@ -1246,9 +1270,9 @@ 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)
+ /* Automatically answer the default value if this query should not
+ prompt. */
+ if (query_is_silent ())
return def_value;
if (deprecated_query_hook)
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RFC] Never silently discard internal errors
2006-09-25 18:42 [RFC] Never silently discard internal errors Daniel Jacobowitz
@ 2006-09-25 19:10 ` Michael Snyder
2006-09-25 19:37 ` Jim Blandy
2006-09-25 19:43 ` Eli Zaretskii
2 siblings, 0 replies; 11+ messages in thread
From: Michael Snyder @ 2006-09-25 19:10 UTC (permalink / raw)
To: Daniel Jacobowitz; +Cc: gdb-patches
On Mon, 2006-09-25 at 14:42 -0400, Daniel Jacobowitz wrote:
> Here's a problem that one of our customers turned up. He runs GDB
> from inside Emacs, which means that its standard input is considered
> to be a pipe, which is not a terminal. Accordingly query is suppressed.
> Whether this is right everywhere or not is a question for another day,
> but one particular thing we discovered was that GDB would mysteriously
> quit out from under him, without telling him what it was doing.
>
> Eventually we tracked it down to an unrelated problem in the code he was
> testing for me. Not too surprising - that's what all the gdb_assert's
> and such are for, after all :-) But not only was it not asking permission
> before it bailed, but it wasn't even leaving a useful message.
>
> I think the attached patch is reasonable. It changes error handling
> such that if query is a no-op - for instance, from a script file,
> or from a pipe - we dump out a message to stdout anyway before quitting
> or dumping core.
>
> It's easy to see this behavior for yourself. Just put the line
> "maint internal-error" in a text file, and start gdb with -x filename.
> Watch it abort without saying goodbye.
>
> Any thoughts on this patch? Shall I commit it?
I think the concept is sound. I absolutely hate when gdb terminates
unexpectedly and doesn't tell me why; anything that reduces the odds
of that happening is good.
> Daniel Jacobowitz
> CodeSourcery
>
> 2006-09-25 Daniel Jacobowitz <dan@codesourcery.com>
>
> * utils.c (query_is_silent): New.
> (internal_vproblem, query, defaulted_query): Use it.
>
> Index: utils.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/utils.c,v
> retrieving revision 1.169
> diff -u -p -r1.169 utils.c
> --- utils.c 21 Sep 2006 13:50:51 -0000 1.169
> +++ utils.c 25 Sep 2006 18:31:50 -0000
> @@ -81,6 +81,8 @@ void (*deprecated_error_begin_hook) (voi
>
> /* Prototypes for local functions */
>
> +static int query_is_silent (void);
> +
> static void vfprintf_maybe_filtered (struct ui_file *, const char *,
> va_list, int) ATTR_FORMAT (printf, 2, 0);
>
> @@ -750,6 +752,9 @@ further debugging may prove unreliable."
> this lessens the likelhood of GDB going into an infinate
> loop. */
> quit_p = query (_("%s\nQuit this debugging session? "), reason);
> + if (query_is_silent ())
> + fprintf_unfiltered (gdb_stdout,
> + "%s\nQuitting this debugging session.\n", reason);
> break;
> case AUTO_BOOLEAN_TRUE:
> quit_p = 1;
> @@ -768,7 +773,9 @@ further debugging may prove unreliable."
> `dropping' so that it is easier to see that something went
> wrong in GDB. */
> dump_core_p = query (_("%s\nCreate a core file of GDB? "), reason);
> - break;
> + if (query_is_silent ())
> + fprintf_unfiltered (gdb_stdout,
> + "%s\nCreating a core file.\n", reason);
> break;
> case AUTO_BOOLEAN_TRUE:
> dump_core_p = 1;
> @@ -1128,6 +1135,24 @@ gdb_print_host_address (const void *addr
> fprintf_filtered (stream, "0x%lx", (unsigned long) addr);
> }
>
> +/* Return whether query will not display anything. If it won't, the
> + caller may want to display an informative message that would otherwise
> + have been part of the query prompt. Also used to implement query
> + and defaulted_query, to assure they stay consistent. */
> +
> +static int
> +query_is_silent (void)
> +{
> + /* We will automatically answer the query if input is not from the
> + user directly (e.g. from a script file or a pipe), or if the user
> + did not want prompts. */
> + if (!input_from_terminal_p () || !caution)
> + return 1;
> +
> + return 0;
> +}
> +
> +
> /* Ask user a y-or-n question and return 1 iff answer is yes.
> Takes three args which are given to printf to print the question.
> The first, a control string, should end in "? ".
> @@ -1142,9 +1167,8 @@ 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)
> + /* Automatically answer "yes" if this query should not prompt. */
> + if (query_is_silent ())
> return 1;
>
> if (deprecated_query_hook)
> @@ -1246,9 +1270,9 @@ 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)
> + /* Automatically answer the default value if this query should not
> + prompt. */
> + if (query_is_silent ())
> return def_value;
>
> if (deprecated_query_hook)
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RFC] Never silently discard internal errors
2006-09-25 18:42 [RFC] Never silently discard internal errors Daniel Jacobowitz
2006-09-25 19:10 ` Michael Snyder
@ 2006-09-25 19:37 ` Jim Blandy
2006-09-25 20:03 ` Daniel Jacobowitz
2006-09-25 19:43 ` Eli Zaretskii
2 siblings, 1 reply; 11+ messages in thread
From: Jim Blandy @ 2006-09-25 19:37 UTC (permalink / raw)
To: gdb-patches
Daniel Jacobowitz <drow@false.org> writes:
> Here's a problem that one of our customers turned up. He runs GDB
> from inside Emacs, which means that its standard input is considered
> to be a pipe, which is not a terminal. Accordingly query is suppressed.
> Whether this is right everywhere or not is a question for another day,
> but one particular thing we discovered was that GDB would mysteriously
> quit out from under him, without telling him what it was doing.
>
> Eventually we tracked it down to an unrelated problem in the code he was
> testing for me. Not too surprising - that's what all the gdb_assert's
> and such are for, after all :-) But not only was it not asking permission
> before it bailed, but it wasn't even leaving a useful message.
>
> I think the attached patch is reasonable. It changes error handling
> such that if query is a no-op - for instance, from a script file,
> or from a pipe - we dump out a message to stdout anyway before quitting
> or dumping core.
>
> It's easy to see this behavior for yourself. Just put the line
> "maint internal-error" in a text file, and start gdb with -x filename.
> Watch it abort without saying goodbye.
>
> Any thoughts on this patch? Shall I commit it?
What if we simply had 'query' itself print out the prompt, followed by
"[answering 'y', since standard input is not a terminal]" (or
something more tasteful)? Then you wouldn't have to go around
decorating all the calls to query.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RFC] Never silently discard internal errors
2006-09-25 18:42 [RFC] Never silently discard internal errors Daniel Jacobowitz
2006-09-25 19:10 ` Michael Snyder
2006-09-25 19:37 ` Jim Blandy
@ 2006-09-25 19:43 ` Eli Zaretskii
2006-09-25 20:05 ` Daniel Jacobowitz
2 siblings, 1 reply; 11+ messages in thread
From: Eli Zaretskii @ 2006-09-25 19:43 UTC (permalink / raw)
To: Daniel Jacobowitz; +Cc: gdb-patches
> Date: Mon, 25 Sep 2006 14:42:23 -0400
> From: Daniel Jacobowitz <drow@false.org>
>
> I think the attached patch is reasonable. It changes error handling
> such that if query is a no-op - for instance, from a script file,
> or from a pipe - we dump out a message to stdout anyway before quitting
> or dumping core.
I agree with the principle that GDB should not silently quit.
> +/* Return whether query will not display anything. If it won't, the
> + caller may want to display an informative message that would otherwise
> + have been part of the query prompt. Also used to implement query
> + and defaulted_query, to assure they stay consistent. */
> +
> +static int
> +query_is_silent (void)
> +{
> + /* We will automatically answer the query if input is not from the
> + user directly (e.g. from a script file or a pipe), or if the user
> + did not want prompts. */
> + if (!input_from_terminal_p () || !caution)
> + return 1;
> +
> + return 0;
> +}
Can we do a bit better here? For example, if we are running under
Emacs, we could actually prompt, even though it's a pipe, right?
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RFC] Never silently discard internal errors
2006-09-25 19:37 ` Jim Blandy
@ 2006-09-25 20:03 ` Daniel Jacobowitz
2006-09-25 21:17 ` Jim Blandy
0 siblings, 1 reply; 11+ messages in thread
From: Daniel Jacobowitz @ 2006-09-25 20:03 UTC (permalink / raw)
To: Jim Blandy; +Cc: gdb-patches
On Mon, Sep 25, 2006 at 12:38:40PM -0700, Jim Blandy wrote:
> What if we simply had 'query' itself print out the prompt, followed by
> "[answering 'y', since standard input is not a terminal]" (or
> something more tasteful)? Then you wouldn't have to go around
> decorating all the calls to query.
I assume that would be wrong for "set confirm off"?
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RFC] Never silently discard internal errors
2006-09-25 19:43 ` Eli Zaretskii
@ 2006-09-25 20:05 ` Daniel Jacobowitz
2006-09-26 3:29 ` Eli Zaretskii
0 siblings, 1 reply; 11+ messages in thread
From: Daniel Jacobowitz @ 2006-09-25 20:05 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: gdb-patches
On Mon, Sep 25, 2006 at 10:43:20PM +0300, Eli Zaretskii wrote:
> > +/* Return whether query will not display anything. If it won't, the
> > + caller may want to display an informative message that would otherwise
> > + have been part of the query prompt. Also used to implement query
> > + and defaulted_query, to assure they stay consistent. */
> > +
> > +static int
> > +query_is_silent (void)
> > +{
> > + /* We will automatically answer the query if input is not from the
> > + user directly (e.g. from a script file or a pipe), or if the user
> > + did not want prompts. */
> > + if (!input_from_terminal_p () || !caution)
> > + return 1;
> > +
> > + return 0;
> > +}
>
> Can we do a bit better here? For example, if we are running under
> Emacs, we could actually prompt, even though it's a pipe, right?
From my original message:
> to be a pipe, which is not a terminal. Accordingly query is suppressed.
> Whether this is right everywhere or not is a question for another day,
I don't think we could start prompting on pipes; I'm sure it would
break some things, probably including the emacs mode in question.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RFC] Never silently discard internal errors
2006-09-25 20:03 ` Daniel Jacobowitz
@ 2006-09-25 21:17 ` Jim Blandy
2006-09-26 3:56 ` Daniel Jacobowitz
0 siblings, 1 reply; 11+ messages in thread
From: Jim Blandy @ 2006-09-25 21:17 UTC (permalink / raw)
To: gdb-patches
Daniel Jacobowitz <drow@false.org> writes:
> On Mon, Sep 25, 2006 at 12:38:40PM -0700, Jim Blandy wrote:
>> What if we simply had 'query' itself print out the prompt, followed by
>> "[answering 'y', since standard input is not a terminal]" (or
>> something more tasteful)? Then you wouldn't have to go around
>> decorating all the calls to query.
>
> I assume that would be wrong for "set confirm off"?
I don't want to turn this into a bikeshed discussion, but here's what
I had in mind:
*** utils.c 12 Jul 2006 11:50:18 -0700 1.168
--- utils.c 25 Sep 2006 14:17:20 -0700
***************
*** 1142,1152 ****
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);
--- 1142,1168 ----
int ans2;
int retval;
! /* If the user does not want prompts, answer "yes" automatically. */
! if (! caution)
return 1;
+ /* If input isn't coming from the user directly, just say what
+ question we're asking, and then answer "yes" automatically. This
+ way, important error messages don't get lost when talking to GDB
+ over a pipe. */
+ if (! input_from_terminal_p ())
+ {
+ wrap_here ("");
+
+ va_start (args, ctlstr);
+ vfprintf_filtered (gdb_stdout, ctlstr, args);
+ va_end (args);
+ printf_filtered (_("(y or n) [answered yes; input not from terminal]"));
+ gdb_flush (gdb_stdout);
+
+ return 1;
+ }
+
if (deprecated_query_hook)
{
va_start (args, ctlstr);
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RFC] Never silently discard internal errors
2006-09-25 20:05 ` Daniel Jacobowitz
@ 2006-09-26 3:29 ` Eli Zaretskii
2006-09-26 3:56 ` Daniel Jacobowitz
0 siblings, 1 reply; 11+ messages in thread
From: Eli Zaretskii @ 2006-09-26 3:29 UTC (permalink / raw)
To: Daniel Jacobowitz; +Cc: gdb-patches
> Date: Mon, 25 Sep 2006 16:05:34 -0400
> From: Daniel Jacobowitz <drow@false.org>
> Cc: gdb-patches@sourceware.org
>
> I don't think we could start prompting on pipes; I'm sure it would
> break some things, probably including the emacs mode in question.
Can you elaborate about the breakage?
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RFC] Never silently discard internal errors
2006-09-25 21:17 ` Jim Blandy
@ 2006-09-26 3:56 ` Daniel Jacobowitz
2006-10-18 22:21 ` Daniel Jacobowitz
0 siblings, 1 reply; 11+ messages in thread
From: Daniel Jacobowitz @ 2006-09-26 3:56 UTC (permalink / raw)
To: gdb-patches
On Mon, Sep 25, 2006 at 02:18:38PM -0700, Jim Blandy wrote:
>
> Daniel Jacobowitz <drow@false.org> writes:
> > On Mon, Sep 25, 2006 at 12:38:40PM -0700, Jim Blandy wrote:
> >> What if we simply had 'query' itself print out the prompt, followed by
> >> "[answering 'y', since standard input is not a terminal]" (or
> >> something more tasteful)? Then you wouldn't have to go around
> >> decorating all the calls to query.
> >
> > I assume that would be wrong for "set confirm off"?
>
> I don't want to turn this into a bikeshed discussion, but here's what
> I had in mind:
Hmm, I like this. Anyone else?
[defaulted_query needs similar treatment.]
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RFC] Never silently discard internal errors
2006-09-26 3:29 ` Eli Zaretskii
@ 2006-09-26 3:56 ` Daniel Jacobowitz
0 siblings, 0 replies; 11+ messages in thread
From: Daniel Jacobowitz @ 2006-09-26 3:56 UTC (permalink / raw)
To: gdb-patches
On Tue, Sep 26, 2006 at 06:29:12AM +0300, Eli Zaretskii wrote:
> > Date: Mon, 25 Sep 2006 16:05:34 -0400
> > From: Daniel Jacobowitz <drow@false.org>
> > Cc: gdb-patches@sourceware.org
> >
> > I don't think we could start prompting on pipes; I'm sure it would
> > break some things, probably including the emacs mode in question.
>
> Can you elaborate about the breakage?
I don't know what would break for sure, but I imagine that code which
has never before received any "(y or n)" prompts would not know what to
do when it got one, for any operations it conducted on behalf of the
user. This is the sort of thing that causes tests in the testsuite to
time out. The other likely problem is with line buffering; output over
a pipe is on many platforms block buffered rather than line buffered,
and the prompts might fail to show up when they were needed.
This is all speculation! Maybe it would just work, but it doesn't seem
like a great change unless someone who thinks it's a good idea
volunteers to test a bunch of different scenarios, and I'm not that
interested in the issue, I'm afraid.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RFC] Never silently discard internal errors
2006-09-26 3:56 ` Daniel Jacobowitz
@ 2006-10-18 22:21 ` Daniel Jacobowitz
0 siblings, 0 replies; 11+ messages in thread
From: Daniel Jacobowitz @ 2006-10-18 22:21 UTC (permalink / raw)
To: gdb-patches
On Mon, Sep 25, 2006 at 11:56:35PM -0400, Daniel Jacobowitz wrote:
> On Mon, Sep 25, 2006 at 02:18:38PM -0700, Jim Blandy wrote:
> >
> > Daniel Jacobowitz <drow@false.org> writes:
> > > On Mon, Sep 25, 2006 at 12:38:40PM -0700, Jim Blandy wrote:
> > >> What if we simply had 'query' itself print out the prompt, followed by
> > >> "[answering 'y', since standard input is not a terminal]" (or
> > >> something more tasteful)? Then you wouldn't have to go around
> > >> decorating all the calls to query.
> > >
> > > I assume that would be wrong for "set confirm off"?
> >
> > I don't want to turn this into a bikeshed discussion, but here's what
> > I had in mind:
>
> Hmm, I like this. Anyone else?
>
> [defaulted_query needs similar treatment.]
No one else had an opinion so Jim gets to paint the bikeshed :-)
I've tested and committed the attached. I took the opportunity to
combine query and defaulted_query, and fix a bug I encountered during
manual testing that could crash GDB if you hit <enter> a couple times
at the prompt.
--
Daniel Jacobowitz
CodeSourcery
2006-10-18 Jim Blandy <jimb@codesourcery.com>
Daniel Jacobowitz <dan@codesourcery.com>
* utils.c (query): Use defaulted_query.
(defaulted_query): Handle having no default answer. Print out
messages even if we have no terminal. Prevent memory corruption.
Index: utils.c
===================================================================
RCS file: /cvs/src/src/gdb/utils.c,v
retrieving revision 1.169
diff -u -p -r1.169 utils.c
--- utils.c 21 Sep 2006 13:50:51 -0000 1.169
+++ utils.c 18 Oct 2006 22:14:57 -0000
@@ -1127,92 +1127,13 @@ gdb_print_host_address (const void *addr
fprintf_filtered (stream, "0x%lx", (unsigned long) addr);
}
-
-/* Ask user a y-or-n question and return 1 iff answer is yes.
- Takes three args which are given to printf to print the question.
- The first, a control string, should end in "? ".
- It should not say how to answer, because we do that. */
-
-/* VARARGS */
-int
-query (const char *ctlstr, ...)
-{
- va_list args;
- int answer;
- 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);
- }
-
- while (1)
- {
- wrap_here (""); /* Flush any buffered output */
- gdb_flush (gdb_stdout);
-
- if (annotation_level > 1)
- printf_filtered (("\n\032\032pre-query\n"));
-
- va_start (args, ctlstr);
- vfprintf_filtered (gdb_stdout, ctlstr, args);
- va_end (args);
- printf_filtered (_("(y or n) "));
-
- if (annotation_level > 1)
- printf_filtered (("\n\032\032query\n"));
-
- wrap_here ("");
- gdb_flush (gdb_stdout);
-
- answer = fgetc (stdin);
- clearerr (stdin); /* in case of C-d */
- if (answer == EOF) /* C-d */
- {
- retval = 1;
- break;
- }
- /* Eat rest of input line, to EOF or newline */
- if (answer != '\n')
- do
- {
- ans2 = fgetc (stdin);
- clearerr (stdin);
- }
- while (ans2 != EOF && ans2 != '\n' && ans2 != '\r');
-
- if (answer >= 'a')
- answer -= 040;
- if (answer == 'Y')
- {
- retval = 1;
- break;
- }
- if (answer == 'N')
- {
- retval = 0;
- break;
- }
- printf_filtered (_("Please answer y or n.\n"));
- }
-
- if (annotation_level > 1)
- printf_filtered (("\n\032\032post-query\n"));
- return retval;
-}
\f
-/* This function supports the nquery() and yquery() functions.
+/* This function supports the query, nquery, and yquery functions.
Ask user a y-or-n question and return 0 if answer is no, 1 if
- answer is yes, or default the answer to the specified default.
- DEFCHAR is either 'y' or 'n' and refers to the default answer.
+ answer is yes, or default the answer to the specified default
+ (for yquery or nquery). DEFCHAR may be 'y' or 'n' to provide a
+ default answer, or '\0' for no default.
CTLSTR is the control string and should end in "? ". It should
not say how to answer, because we do that.
ARGS are the arguments passed along with the CTLSTR argument to
@@ -1226,10 +1147,18 @@ defaulted_query (const char *ctlstr, con
int retval;
int def_value;
char def_answer, not_def_answer;
- char *y_string, *n_string;
+ char *y_string, *n_string, *question;
/* Set up according to which answer is the default. */
- if (defchar == 'y')
+ if (defchar == '\0')
+ {
+ def_value = 1;
+ def_answer = 'Y';
+ not_def_answer = 'N';
+ y_string = "y";
+ n_string = "n";
+ }
+ else if (defchar == 'y')
{
def_value = 1;
def_answer = 'Y';
@@ -1246,6 +1175,27 @@ defaulted_query (const char *ctlstr, con
n_string = "[n]";
}
+ /* Automatically answer the default value if the user did not want
+ prompts. */
+ if (! caution)
+ return def_value;
+
+ /* If input isn't coming from the user directly, just say what
+ question we're asking, and then answer "yes" automatically. This
+ way, important error messages don't get lost when talking to GDB
+ over a pipe. */
+ if (! input_from_terminal_p ())
+ {
+ wrap_here ("");
+ vfprintf_filtered (gdb_stdout, ctlstr, args);
+
+ printf_filtered (_("(%s or %s) [answered %c; input not from terminal]\n"),
+ y_string, n_string, def_answer);
+ gdb_flush (gdb_stdout);
+
+ return def_value;
+ }
+
/* 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)
@@ -1256,6 +1206,9 @@ defaulted_query (const char *ctlstr, con
return deprecated_query_hook (ctlstr, args);
}
+ /* Format the question outside of the loop, to avoid reusing args. */
+ question = xstrvprintf (ctlstr, args);
+
while (1)
{
wrap_here (""); /* Flush any buffered output */
@@ -1264,7 +1217,7 @@ defaulted_query (const char *ctlstr, con
if (annotation_level > 1)
printf_filtered (("\n\032\032pre-query\n"));
- vfprintf_filtered (gdb_stdout, ctlstr, args);
+ fputs_filtered (question, gdb_stdout);
printf_filtered (_("(%s or %s) "), y_string, n_string);
if (annotation_level > 1)
@@ -1298,10 +1251,12 @@ defaulted_query (const char *ctlstr, con
retval = !def_value;
break;
}
- /* Otherwise, for the default, the user may either specify
- the required input or have it default by entering nothing. */
- if (answer == def_answer || answer == '\n' ||
- answer == '\r' || answer == EOF)
+ /* Otherwise, if a default was specified, the user may either
+ specify the required input or have it default by entering
+ nothing. */
+ if (answer == def_answer
+ || (defchar != '\0' &&
+ (answer == '\n' || answer == '\r' || answer == EOF)))
{
retval = def_value;
break;
@@ -1311,6 +1266,7 @@ defaulted_query (const char *ctlstr, con
y_string, n_string);
}
+ xfree (question);
if (annotation_level > 1)
printf_filtered (("\n\032\032post-query\n"));
return retval;
@@ -1349,6 +1305,21 @@ yquery (const char *ctlstr, ...)
va_end (args);
}
+/* Ask user a y-or-n question and return 1 iff answer is yes.
+ Takes three args which are given to printf to print the question.
+ The first, a control string, should end in "? ".
+ It should not say how to answer, because we do that. */
+
+int
+query (const char *ctlstr, ...)
+{
+ va_list args;
+
+ va_start (args, ctlstr);
+ return defaulted_query (ctlstr, '\0', args);
+ va_end (args);
+}
+
/* Print an error message saying that we couldn't make sense of a
\^mumble sequence in a string or character constant. START and END
indicate a substring of some larger string that contains the
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2006-10-18 22:21 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-09-25 18:42 [RFC] Never silently discard internal errors Daniel Jacobowitz
2006-09-25 19:10 ` Michael Snyder
2006-09-25 19:37 ` Jim Blandy
2006-09-25 20:03 ` Daniel Jacobowitz
2006-09-25 21:17 ` Jim Blandy
2006-09-26 3:56 ` Daniel Jacobowitz
2006-10-18 22:21 ` Daniel Jacobowitz
2006-09-25 19:43 ` Eli Zaretskii
2006-09-25 20:05 ` Daniel Jacobowitz
2006-09-26 3:29 ` Eli Zaretskii
2006-09-26 3:56 ` Daniel Jacobowitz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox