From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25803 invoked by alias); 25 Sep 2006 18:42:38 -0000 Received: (qmail 25775 invoked by uid 22791); 25 Sep 2006 18:42: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; Mon, 25 Sep 2006 18:42:28 +0000 Received: from drow by nevyn.them.org with local (Exim 4.54) id 1GRvPM-00046H-0I for gdb-patches@sourceware.org; Mon, 25 Sep 2006 14:42:24 -0400 Date: Mon, 25 Sep 2006 18:42:00 -0000 From: Daniel Jacobowitz To: gdb-patches@sourceware.org Subject: [RFC] Never silently discard internal errors Message-ID: <20060925184223.GA15314@nevyn.them.org> Mail-Followup-To: gdb-patches@sourceware.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.13 (2006-08-11) 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-09/txt/msg00168.txt.bz2 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 * 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)