From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14152 invoked by alias); 15 Jan 2010 00:35:42 -0000 Received: (qmail 14135 invoked by uid 22791); 15 Jan 2010 00:35:41 -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; Fri, 15 Jan 2010 00:35:34 +0000 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o0F0ZXCF026314 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 14 Jan 2010 19:35:33 -0500 Received: from host0.dyn.jankratochvil.net (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o0F0ZUKw004692 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 14 Jan 2010 19:35:32 -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 o0F0ZUXB026792; Fri, 15 Jan 2010 01:35:30 +0100 Received: (from jkratoch@localhost) by host0.dyn.jankratochvil.net (8.14.3/8.14.3/Submit) id o0F0ZTX8026791; Fri, 15 Jan 2010 01:35:29 +0100 Date: Fri, 15 Jan 2010 00:35:00 -0000 From: Jan Kratochvil To: Tom Tromey Cc: gdb-patches@sourceware.org Subject: Re: [patch] Do not disappoint on "Create a core file of GDB?" Message-ID: <20100115003529.GA26561@host0.dyn.jankratochvil.net> References: <20100111160241.GA12356@host0.dyn.jankratochvil.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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/msg00396.txt.bz2 On Tue, 12 Jan 2010 17:58:48 +0100, Tom Tromey wrote: > Jan> 2010-01-11 Jan Kratochvil > Jan> * configure.ac (AC_CHECK_FUNCS): Check for setrlimit and getrlimit. > Jan> * configure: Regenerate. > Jan> * config.in: Regenerate. > Jan> * utils.c: Include sys/resource.h. > Jan> (dump_core, can_dump_core): New. > Jan> (internal_vproblem): Update the comment. Check can_dump_core while > Jan> setting dump_core_p. Replace two abort calls by dump_core calls. > > Looks good to me. > Ok. Checked-in. Thanks, Jan http://sourceware.org/ml/gdb-cvs/2010-01/msg00131.html --- src/gdb/ChangeLog 2010/01/14 21:24:04 1.11253 +++ src/gdb/ChangeLog 2010/01/15 00:34:37 1.11254 @@ -1,3 +1,13 @@ +2010-01-15 Jan Kratochvil + + * configure.ac (AC_CHECK_FUNCS): Check for setrlimit and getrlimit. + * configure: Regenerate. + * config.in: Regenerate. + * 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. + 2010-01-14 Jan Kratochvil Eli Zaretskii --- src/gdb/config.in 2009/11/11 04:42:39 1.114 +++ src/gdb/config.in 2010/01/15 00:34:37 1.115 @@ -165,6 +165,9 @@ /* Define to 1 if you have the `getpagesize' function. */ #undef HAVE_GETPAGESIZE +/* Define to 1 if you have the `getrlimit' function. */ +#undef HAVE_GETRLIMIT + /* Define to 1 if you have the `getrusage' function. */ #undef HAVE_GETRUSAGE @@ -366,6 +369,9 @@ /* Define to 1 if you have the `setpgrp' function. */ #undef HAVE_SETPGRP +/* Define to 1 if you have the `setrlimit' function. */ +#undef HAVE_SETRLIMIT + /* Define to 1 if you have the `setsid' function. */ #undef HAVE_SETSID --- src/gdb/configure 2010/01/12 12:22:52 1.296 +++ src/gdb/configure 2010/01/15 00:34:37 1.297 @@ -11233,7 +11233,8 @@ for ac_func in canonicalize_file_name realpath getrusage getuid \ getgid pipe poll pread64 sbrk setpgid setpgrp setsid \ sigaction sigprocmask sigsetmask socketpair syscall \ - ttrace wborder setlocale iconvlist libiconvlist btowc + ttrace wborder setlocale iconvlist libiconvlist btowc \ + setrlimit getrlimit do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" --- src/gdb/configure.ac 2010/01/01 09:44:06 1.111 +++ src/gdb/configure.ac 2010/01/15 00:34:37 1.112 @@ -801,7 +801,8 @@ AC_CHECK_FUNCS([canonicalize_file_name realpath getrusage getuid \ getgid pipe poll pread64 sbrk setpgid setpgrp setsid \ sigaction sigprocmask sigsetmask socketpair syscall \ - ttrace wborder setlocale iconvlist libiconvlist btowc]) + ttrace wborder setlocale iconvlist libiconvlist btowc \ + setrlimit getrlimit]) AM_LANGINFO_CODESET # Check the return and argument types of ptrace. No canned test for --- src/gdb/utils.c 2010/01/12 21:40:24 1.221 +++ src/gdb/utils.c 2010/01/15 00:34:37 1.222 @@ -26,6 +26,9 @@ #include "event-top.h" #include "exceptions.h" #include "gdbthread.h" +#ifdef HAVE_SYS_RESOURCE_H +#include +#endif /* HAVE_SYS_RESOURCE_H */ #ifdef TUI #include "tui/tui.h" /* For tui_get_command_dimension. */ @@ -843,6 +846,44 @@ error (("%s"), message); } +/* Dump core trying to increase the core soft limit to hard limit first. */ + +static void +dump_core (void) +{ +#ifdef HAVE_SETRLIMIT + struct rlimit rlim = { RLIM_INFINITY, RLIM_INFINITY }; + + setrlimit (RLIMIT_CORE, &rlim); +#endif /* HAVE_SETRLIMIT */ + + 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) +{ +#ifdef HAVE_GETRLIMIT + 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; + } +#endif /* HAVE_GETRLIMIT */ + + return 1; +} + /* Allow the user to configure the debugger behavior with respect to what to do when an internal problem is detected. */ @@ -893,7 +934,7 @@ 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 +943,7 @@ 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 +992,18 @@ 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 +1012,7 @@ if (quit_p) { if (dump_core_p) - abort (); /* NOTE: GDB has only four calls to abort(). */ + dump_core (); else exit (1); } @@ -976,7 +1022,7 @@ { #ifdef HAVE_WORKING_FORK if (fork () == 0) - abort (); /* NOTE: GDB has only four calls to abort(). */ + dump_core (); #endif } }