Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Daniel Jacobowitz <drow@false.org>
To: gdb-patches@sourceware.org
Subject: [RFC] Never silently discard internal errors
Date: Mon, 25 Sep 2006 18:42:00 -0000	[thread overview]
Message-ID: <20060925184223.GA15314@nevyn.them.org> (raw)

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)


             reply	other threads:[~2006-09-25 18:42 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-25 18:42 Daniel Jacobowitz [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060925184223.GA15314@nevyn.them.org \
    --to=drow@false.org \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox