From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13312 invoked by alias); 11 Jan 2010 16:03:08 -0000 Received: (qmail 13196 invoked by uid 22791); 11 Jan 2010 16:03:06 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 11 Jan 2010 16:03:02 +0000 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o0BG30rI006932 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 11 Jan 2010 11:03:01 -0500 Received: from host0.dyn.jankratochvil.net (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o0BG2lVw026888 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 11 Jan 2010 11:02:54 -0500 Received: from host0.dyn.jankratochvil.net (localhost [127.0.0.1]) by host0.dyn.jankratochvil.net (8.14.3/8.14.3) with ESMTP id o0BG2iTn013156 for ; Mon, 11 Jan 2010 17:02:44 +0100 Received: (from jkratoch@localhost) by host0.dyn.jankratochvil.net (8.14.3/8.14.3/Submit) id o0BG2f6j013152 for gdb-patches@sourceware.org; Mon, 11 Jan 2010 17:02:41 +0100 Date: Mon, 11 Jan 2010 16:03:00 -0000 From: Jan Kratochvil To: gdb-patches@sourceware.org Subject: [patch] Do not disappoint on "Create a core file of GDB?" Message-ID: <20100111160241.GA12356@host0.dyn.jankratochvil.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-08-17) X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-01/txt/msg00252.txt.bz2 Hi, this is a FAQ, GDB asks "Create a core file of GDB?", user types "y" but a core file is never created. It is because distros (at least Fedora) commonly have: ulimit -S -c 0 ulimit -H -c unlimited and GDB does not raise its soft limit to hard limit. But common applications also do not raise it so why should GDB? Soft limit is there to act as default value for the application. GDB is different as it explicitly asks the user - in such case it should IMO raise the core limit. Even in the case of "maint set internal-error corefile yes" it had to be set explicitly by the user as the default is "ask", therefore it should override the soft core limit. setrlimit is a POSIX function so I hope it does not need autoconf magic: http://www.opengroup.org/onlinepubs/009695399/functions/setrlimit.html No regressions on {x86_64,x86_64-m32,i686}-fedora12-linux-gnu. Thanks, Jan 2010-01-11 Jan Kratochvil * utils.c: Include sys/resource.h. (dump_core, can_dump_core): New. (internal_vproblem): Update the comment. Check can_dump_core while setting dump_core_p. Replace two abort calls by dump_core calls. --- a/gdb/utils.c +++ b/gdb/utils.c @@ -26,6 +26,7 @@ #include "event-top.h" #include "exceptions.h" #include "gdbthread.h" +#include #ifdef TUI #include "tui/tui.h" /* For tui_get_command_dimension. */ @@ -843,6 +844,40 @@ error_stream (struct ui_file *stream) error (("%s"), message); } +/* Dump core trying to increase the core soft limit to hard limit first. */ + +static void +dump_core (void) +{ + struct rlimit rlim = { RLIM_INFINITY, RLIM_INFINITY }; + + setrlimit (RLIMIT_CORE, &rlim); + + abort (); /* NOTE: GDB has only three calls to abort(). */ +} + +/* Check whether GDB will be able to dump core using the dump_core function. */ + +static int +can_dump_core (const char *reason) +{ + struct rlimit rlim; + + /* Be quiet and assume we can dump if an error is returned. */ + if (getrlimit (RLIMIT_CORE, &rlim) != 0) + 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 1; +} + /* Allow the user to configure the debugger behavior with respect to what to do when an internal problem is detected. */ @@ -893,7 +928,7 @@ internal_vproblem (struct internal_problem *problem, case 1: dejavu = 2; fputs_unfiltered (msg, gdb_stderr); - abort (); /* NOTE: GDB has only four calls to abort(). */ + abort (); /* NOTE: GDB has only three calls to abort(). */ default: dejavu = 3; /* Newer GLIBC versions put the warn_unused_result attribute @@ -902,7 +937,7 @@ internal_vproblem (struct internal_problem *problem, does not fix this problem. This is the solution suggested at http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25509. */ if (write (STDERR_FILENO, msg, sizeof (msg)) != sizeof (msg)) - abort (); /* NOTE: GDB has only four calls to abort(). */ + abort (); /* NOTE: GDB has only three calls to abort(). */ exit (1); } } @@ -951,13 +986,18 @@ further debugging may prove unreliable.", file, line, problem->name, msg); if (problem->should_dump_core == internal_problem_ask) { - /* Default (yes/batch case) is to dump core. This leaves a GDB - `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); + if (!can_dump_core (reason)) + dump_core_p = 0; + else + { + /* Default (yes/batch case) is to dump core. This leaves a GDB + `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); + } } else if (problem->should_dump_core == internal_problem_yes) - dump_core_p = 1; + dump_core_p = can_dump_core (reason); else if (problem->should_dump_core == internal_problem_no) dump_core_p = 0; else @@ -966,7 +1006,7 @@ further debugging may prove unreliable.", file, line, problem->name, msg); if (quit_p) { if (dump_core_p) - abort (); /* NOTE: GDB has only four calls to abort(). */ + dump_core (); else exit (1); } @@ -976,7 +1016,7 @@ further debugging may prove unreliable.", file, line, problem->name, msg); { #ifdef HAVE_WORKING_FORK if (fork () == 0) - abort (); /* NOTE: GDB has only four calls to abort(). */ + dump_core (); #endif } }