[2/3,v4] Refactor and expose core-dumping functionality
Commit Message
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 <gbenson@redhat.com>
* 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.
Comments
On Thu, Jun 5, 2014 at 6:03 AM, Gary Benson <gbenson@redhat.com> wrote:
> 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 <gbenson@redhat.com>
>
> * 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.
check_can_dump_core feels a bit clumsy over the original can_dump_core.
can_dump_core (or can_dump_core_p) reads better to me.
[And now it does what it says it does, without the side-effect of the printf.]
Not sure if I'd rename check_can_dump_core_warn (or delete it).
Doug Evans wrote:
> On Thu, Jun 5, 2014 at 6:03 AM, Gary Benson <gbenson@redhat.com> wrote:
> > 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.
>
> check_can_dump_core feels a bit clumsy over the original
> can_dump_core. can_dump_core (or can_dump_core_p) reads better to
> me. [And now it does what it says it does, without the side-effect
> of the printf.]
>
> Not sure if I'd rename check_can_dump_core_warn (or delete it).
Ok, I renamed check_can_dump_core back to the original can_dump_core,
and I renamed check_can_dump_core_warn as can_dump_core_warn (it's
called twice, so there would be duplication if I removed it).
I won't post another patch series for such a small change but the
updated patches are in my github (http://tinyurl.com/dmcc-v4-2 and
http://tinyurl.com/dmcc-v4-3) if you would like to take a look.
Patch 2 is the important one, patch 3 only has a couple of lines
changed.
Thanks,
Gary
@@ -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 */
@@ -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