From patchwork Wed Aug 6 10:12:21 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gary Benson X-Patchwork-Id: 2321 Received: (qmail 22147 invoked by alias); 6 Aug 2014 10:34:34 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 22136 invoked by uid 89); 6 Aug 2014 10:34:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 06 Aug 2014 10:34:31 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s76ACawQ003849 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 6 Aug 2014 06:12:36 -0400 Received: from blade.nx (ovpn-116-90.ams2.redhat.com [10.36.116.90]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s76ACZBM001265 for ; Wed, 6 Aug 2014 06:12:35 -0400 Received: from blade.nx (localhost [127.0.0.1]) by blade.nx (Postfix) with ESMTP id C80CA2640DE for ; Wed, 6 Aug 2014 11:12:34 +0100 (BST) From: Gary Benson To: gdb-patches@sourceware.org Subject: [PATCH 1/8] Make internal_vproblem always work Date: Wed, 6 Aug 2014 11:12:21 +0100 Message-Id: <1407319948-2264-2-git-send-email-gbenson@redhat.com> In-Reply-To: <1407319948-2264-1-git-send-email-gbenson@redhat.com> References: <1407319948-2264-1-git-send-email-gbenson@redhat.com> X-IsSubscribed: yes internal_vproblem can be called (via malloc_failure) from almost the first line of captured_main, but it will crash if called before the first call to set_width. This commit makes internal_vproblem work at any time. There are two parts to this. If called before gdb_stderr is set up, internal_vproblem will fall back to printing the message on regular stderr and aborting. If called after gdb_stderr is set up but before filtered printing is set up, internal_vproblem will operate as usual except that it can not query whether to quit and/or dump core so it defaults to doing both. gdb/ 2014-08-05 Gary Benson * utils.h (filtered_printing_initialized): New declaration. * utils.c (abort_with_message): New function. (internal_vproblem): Use abort_with_message for first level recursive internal problems, and if gdb_stderr is not set up. Protect calls to target_terminal_ours, begin_line and query. --- gdb/ChangeLog | 8 ++++++++ gdb/utils.c | 48 ++++++++++++++++++++++++++++++++++++++++-------- gdb/utils.h | 3 +++ 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/gdb/utils.c b/gdb/utils.c index 3f753bb..fce5baa 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -577,6 +577,19 @@ error_stream (struct ui_file *stream) error (("%s"), message); } +/* Emit a message and abort. */ + +static void ATTRIBUTE_NORETURN +abort_with_message (const char *msg) +{ + if (gdb_stderr == NULL) + fputs (msg, stderr); + else + fputs_unfiltered (msg, gdb_stderr); + + abort (); /* NOTE: GDB has only three calls to abort(). */ +} + /* Dump core trying to increase the core soft limit to hard limit first. */ void @@ -699,8 +712,7 @@ internal_vproblem (struct internal_problem *problem, break; case 1: dejavu = 2; - fputs_unfiltered (msg, gdb_stderr); - abort (); /* NOTE: GDB has only three calls to abort(). */ + abort_with_message (msg); default: dejavu = 3; /* Newer GLIBC versions put the warn_unused_result attribute @@ -714,10 +726,6 @@ internal_vproblem (struct internal_problem *problem, } } - /* Try to get the message out and at the start of a new line. */ - target_terminal_ours (); - begin_line (); - /* Create a string containing the full error/warning message. Need to call query with this full string, as otherwize the reason (error/warning) and question become separated. Format using a @@ -735,8 +743,23 @@ internal_vproblem (struct internal_problem *problem, make_cleanup (xfree, reason); } + /* Fall back to abort_with_message if gdb_stderr is not set up. */ + if (gdb_stderr == NULL) + { + fputs (reason, stderr); + abort_with_message ("\n"); + } + + /* Try to get the message out and at the start of a new line. */ + if (target_supports_terminal_ours ()) + target_terminal_ours (); + if (filtered_printing_initialized ()) + begin_line (); + /* Emit the message unless query will emit it below. */ - if (problem->should_quit != internal_problem_ask || !confirm) + if (problem->should_quit != internal_problem_ask + || !confirm + || !filtered_printing_initialized ()) fprintf_unfiltered (gdb_stderr, "%s\n", reason); if (problem->should_quit == internal_problem_ask) @@ -744,7 +767,7 @@ internal_vproblem (struct internal_problem *problem, /* Default (yes/batch case) is to quit GDB. When in batch mode this lessens the likelihood of GDB going into an infinite loop. */ - if (!confirm) + if (!confirm || !filtered_printing_initialized ()) quit_p = 1; else quit_p = query (_("%s\nQuit this debugging session? "), reason); @@ -766,6 +789,8 @@ internal_vproblem (struct internal_problem *problem, { if (!can_dump_core_warn (LIMIT_MAX, reason)) dump_core_p = 0; + else if (!filtered_printing_initialized ()) + dump_core_p = 1; else { /* Default (yes/batch case) is to dump core. This leaves a GDB @@ -1738,6 +1763,13 @@ init_page_info (void) set_width (); } +/* Return nonzero if filtered printing is initialized. */ +int +filtered_printing_initialized (void) +{ + return wrap_buffer != NULL; +} + /* Helper for make_cleanup_restore_page_info. */ static void diff --git a/gdb/utils.h b/gdb/utils.h index cc79562..0fddecb 100644 --- a/gdb/utils.h +++ b/gdb/utils.h @@ -245,6 +245,9 @@ extern void fputstrn_filtered (const char *str, int n, int quotr, extern void fputstrn_unfiltered (const char *str, int n, int quotr, struct ui_file * stream); +/* Return nonzero if filtered printing is initialized. */ +extern int filtered_printing_initialized (void); + /* Display the host ADDR on STREAM formatted as ``0x%x''. */ extern void gdb_print_host_address (const void *addr, struct ui_file *stream);