From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: Tristan Gingold <gingold@adacore.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [patch] Do not disappoint on "Create a core file of GDB?"
Date: Mon, 11 Jan 2010 16:18:00 -0000 [thread overview]
Message-ID: <20100111161734.GA13820@host0.dyn.jankratochvil.net> (raw)
In-Reply-To: <CE8566E5-5C9A-4532-93EE-5A806DBEE511@adacore.com>
On Mon, 11 Jan 2010 17:07:30 +0100, Tristan Gingold wrote:
>
> On Jan 11, 2010, at 5:02 PM, Jan Kratochvil wrote:
> Hi,
>
> sorry for the nit but:
>
> > setrlimit is a POSIX function so I hope it does not need autoconf magic:
> > http://www.opengroup.org/onlinepubs/009695399/functions/setrlimit.html
>
> Sure, but windows is not POSIX compliant, so I think you can't avoid some
> autoconf stuff.
OK.
The patch has now no effect on platforms without setrlimit / getrlimit.
Thanks,
Jan
2010-01-11 Jan Kratochvil <jan.kratochvil@redhat.com>
* 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.
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -801,7 +801,8 @@ AC_FUNC_VFORK
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
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -26,6 +26,9 @@
#include "event-top.h"
#include "exceptions.h"
#include "gdbthread.h"
+#ifdef HAVE_SYS_RESOURCE_H
+#include <sys/resource.h>
+#endif /* HAVE_SYS_RESOURCE_H */
#ifdef TUI
#include "tui/tui.h" /* For tui_get_command_dimension. */
@@ -843,6 +844,44 @@ 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)
+{
+#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 +932,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 +941,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 +990,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 +1010,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 +1020,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
}
}
next prev parent reply other threads:[~2010-01-11 16:18 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-11 16:03 Jan Kratochvil
2010-01-11 16:06 ` Tristan Gingold
2010-01-11 16:18 ` Jan Kratochvil [this message]
2010-01-11 19:15 ` Eli Zaretskii
2010-01-12 8:44 ` Tristan Gingold
2010-01-12 19:37 ` Eli Zaretskii
2010-01-15 0:28 ` Jan Kratochvil
2010-01-15 8:24 ` Eli Zaretskii
2010-01-12 16:58 ` Tom Tromey
2010-01-15 0:35 ` Jan Kratochvil
2010-01-30 13:05 ` Mark Kettenis
2010-01-30 14:47 ` Jan Kratochvil
2010-01-31 14:13 ` Mark Kettenis
2010-03-31 13:38 ` Pierre Muller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100111161734.GA13820@host0.dyn.jankratochvil.net \
--to=jan.kratochvil@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=gingold@adacore.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox