From patchwork Thu Jun 5 13:03:22 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gary Benson X-Patchwork-Id: 1334 Received: (qmail 22140 invoked by alias); 5 Jun 2014 13:03:39 -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 22126 invoked by uid 89); 5 Jun 2014 13:03:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 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 ESMTP; Thu, 05 Jun 2014 13:03:31 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s55D3O3H021454 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 5 Jun 2014 09:03:24 -0400 Received: from blade.nx (ovpn-116-110.ams2.redhat.com [10.36.116.110]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s55D3MZg011317; Thu, 5 Jun 2014 09:03:23 -0400 Received: by blade.nx (Postfix, from userid 1000) id 36D3726243D; Thu, 5 Jun 2014 14:03:22 +0100 (BST) Date: Thu, 5 Jun 2014 14:03:22 +0100 From: Gary Benson To: gdb-patches@sourceware.org Cc: Andrew Burgess , Doug Evans , Eli Zaretskii , Florian Weimer , Mark Kettenis , Pedro Alves , Tom Tromey Subject: [PATCH 2/3 v4] Refactor and expose core-dumping functionality Message-ID: <20140605130322.GC20572@blade.nx> References: <20140605130140.GA20572@blade.nx> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20140605130140.GA20572@blade.nx> X-IsSubscribed: yes This patch exposes the functions that dump core outside utils.c. The function can_dump_core has been split into two new functions, check_can_dump_core and warn_cant_dump_core so that the check and the printed warning can be separated. A new function check_can_dump_core_warn replaces the original can_dump_core. gdb/ 2014-06-05 Gary Benson * utils.h (check_can_dump_core): New declaration. (warn_cant_dump_core): Likewise. (dump_core): Likewise. * utils.c (dump_core): Made nonstatic. (can_dump_core): Removed function. (check_can_dump_core): New function. (warn_cant_dump_core): Likewise. (check_can_dump_core_warn): Likewise. (internal_vproblem): Replace calls to can_dump_core with calls to check_can_dump_core_warn. diff --git a/gdb/utils.h b/gdb/utils.h index 0ba7879..a6115c1 100644 --- a/gdb/utils.h +++ b/gdb/utils.h @@ -374,4 +374,18 @@ extern ULONGEST align_down (ULONGEST v, int n); extern LONGEST gdb_sign_extend (LONGEST value, int bit); +/* Check whether GDB will be able to dump core using the dump_core + function. */ + +extern int check_can_dump_core (void); + +/* Print a warning that we cannot dump core. */ + +extern void warn_cant_dump_core (const char *reason); + +/* Dump core trying to increase the core soft limit to hard limit + first. */ + +extern void dump_core (void); + #endif /* UTILS_H */ diff --git a/gdb/utils.c b/gdb/utils.c index a72f3bd..0f25436 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -600,7 +600,7 @@ error_stream (struct ui_file *stream) /* Dump core trying to increase the core soft limit to hard limit first. */ -static void +void dump_core (void) { #ifdef HAVE_SETRLIMIT @@ -615,8 +615,8 @@ dump_core (void) /* Check whether GDB will be able to dump core using the dump_core function. */ -static int -can_dump_core (const char *reason) +int +check_can_dump_core (void) { #ifdef HAVE_GETRLIMIT struct rlimit rlim; @@ -626,18 +626,37 @@ can_dump_core (const char *reason) return 1; if (rlim.rlim_max == 0) - { - fprintf_unfiltered (gdb_stderr, - _("%s\nUnable to dump core, use `ulimit -c" - " unlimited' before executing GDB next time.\n"), - reason); - return 0; - } + return 0; #endif /* HAVE_GETRLIMIT */ return 1; } +/* Print a warning that we cannot dump core. */ + +void +warn_cant_dump_core (const char *reason) +{ + fprintf_unfiltered (gdb_stderr, + _("%s\nUnable to dump core, use `ulimit -c" + " unlimited' before executing GDB next time.\n"), + reason); +} + +/* Check whether GDB will be able to dump core using the dump_core + function, and print a warning if we cannot. */ + +static int +check_can_dump_core_warn (const char *reason) +{ + int can_dump_core = check_can_dump_core (); + + if (!can_dump_core) + warn_cant_dump_core (reason); + + return can_dump_core; +} + /* Allow the user to configure the debugger behavior with respect to what to do when an internal problem is detected. */ @@ -756,7 +775,7 @@ internal_vproblem (struct internal_problem *problem, if (problem->should_dump_core == internal_problem_ask) { - if (!can_dump_core (reason)) + if (!check_can_dump_core_warn (reason)) dump_core_p = 0; else { @@ -767,7 +786,7 @@ internal_vproblem (struct internal_problem *problem, } } else if (problem->should_dump_core == internal_problem_yes) - dump_core_p = can_dump_core (reason); + dump_core_p = check_can_dump_core_warn (reason); else if (problem->should_dump_core == internal_problem_no) dump_core_p = 0; else