Refactor and expose core-dumping functionality
This commit exposes the functions that dump core outside utils.c. can_dump_core gains a new parameter, "limit_kind", to allow either the soft or hard limit to be checked, and its printing has separated into the new function warn_cant_dump_core. The new function can_dump_core_warn does what can_dump_core previously did (print and warn). gdb/ 2014-06-19 Gary Benson <gbenson@redhat.com> * utils.h (resource_limit_kind): New enum. (can_dump_core): New declaration. (warn_cant_dump_core): Likewise. (dump_core): Likewise. * utils.c (dump_core): Made nonstatic. Added new parameter "limit_kind". (can_dump_core): Made nonstatic. Moved printing code to... (warn_cant_dump_core): New function. (can_dump_core_warn): Likewise. (internal_vproblem): Replace calls to can_dump_core with calls to can_dump_core_warn. Supply new argument to each.
This commit is contained in:
parent
57fcfb1b20
commit
eae7090bea
3 changed files with 80 additions and 12 deletions
|
@ -1,3 +1,17 @@
|
||||||
|
2014-06-19 Gary Benson <gbenson@redhat.com>
|
||||||
|
|
||||||
|
* utils.h (resource_limit_kind): New enum.
|
||||||
|
(can_dump_core): New declaration.
|
||||||
|
(warn_cant_dump_core): Likewise.
|
||||||
|
(dump_core): Likewise.
|
||||||
|
* utils.c (dump_core): Made nonstatic. Added new
|
||||||
|
parameter "limit_kind".
|
||||||
|
(can_dump_core): Made nonstatic. Moved printing code to...
|
||||||
|
(warn_cant_dump_core): New function.
|
||||||
|
(can_dump_core_warn): Likewise.
|
||||||
|
(internal_vproblem): Replace calls to can_dump_core with
|
||||||
|
calls to can_dump_core_warn. Supply new argument to each.
|
||||||
|
|
||||||
2014-06-19 Gary Benson <gbenson@redhat.com>
|
2014-06-19 Gary Benson <gbenson@redhat.com>
|
||||||
|
|
||||||
* utils.h (demangler_vwarning): New declaration.
|
* utils.h (demangler_vwarning): New declaration.
|
||||||
|
|
52
gdb/utils.c
52
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. */
|
/* Dump core trying to increase the core soft limit to hard limit first. */
|
||||||
|
|
||||||
static void
|
void
|
||||||
dump_core (void)
|
dump_core (void)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_SETRLIMIT
|
#ifdef HAVE_SETRLIMIT
|
||||||
|
@ -613,10 +613,12 @@ dump_core (void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check whether GDB will be able to dump core using the dump_core
|
/* Check whether GDB will be able to dump core using the dump_core
|
||||||
function. */
|
function. Returns zero if GDB cannot or should not dump core.
|
||||||
|
If LIMIT_KIND is LIMIT_CUR the user's soft limit will be respected.
|
||||||
|
If LIMIT_KIND is LIMIT_MAX only the hard limit will be respected. */
|
||||||
|
|
||||||
static int
|
int
|
||||||
can_dump_core (const char *reason)
|
can_dump_core (enum resource_limit_kind limit_kind)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_GETRLIMIT
|
#ifdef HAVE_GETRLIMIT
|
||||||
struct rlimit rlim;
|
struct rlimit rlim;
|
||||||
|
@ -625,12 +627,14 @@ can_dump_core (const char *reason)
|
||||||
if (getrlimit (RLIMIT_CORE, &rlim) != 0)
|
if (getrlimit (RLIMIT_CORE, &rlim) != 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (rlim.rlim_max == 0)
|
switch (limit_kind)
|
||||||
{
|
{
|
||||||
fprintf_unfiltered (gdb_stderr,
|
case LIMIT_CUR:
|
||||||
_("%s\nUnable to dump core, use `ulimit -c"
|
if (rlim.rlim_cur == 0)
|
||||||
" unlimited' before executing GDB next time.\n"),
|
return 0;
|
||||||
reason);
|
|
||||||
|
case LIMIT_MAX:
|
||||||
|
if (rlim.rlim_max == 0)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif /* HAVE_GETRLIMIT */
|
#endif /* HAVE_GETRLIMIT */
|
||||||
|
@ -638,6 +642,32 @@ can_dump_core (const char *reason)
|
||||||
return 1;
|
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
|
||||||
|
can_dump_core_warn (enum resource_limit_kind limit_kind,
|
||||||
|
const char *reason)
|
||||||
|
{
|
||||||
|
int core_dump_allowed = can_dump_core (limit_kind);
|
||||||
|
|
||||||
|
if (!core_dump_allowed)
|
||||||
|
warn_cant_dump_core (reason);
|
||||||
|
|
||||||
|
return core_dump_allowed;
|
||||||
|
}
|
||||||
|
|
||||||
/* Allow the user to configure the debugger behavior with respect to
|
/* Allow the user to configure the debugger behavior with respect to
|
||||||
what to do when an internal problem is detected. */
|
what to do when an internal problem is detected. */
|
||||||
|
|
||||||
|
@ -756,7 +786,7 @@ internal_vproblem (struct internal_problem *problem,
|
||||||
|
|
||||||
if (problem->should_dump_core == internal_problem_ask)
|
if (problem->should_dump_core == internal_problem_ask)
|
||||||
{
|
{
|
||||||
if (!can_dump_core (reason))
|
if (!can_dump_core_warn (LIMIT_MAX, reason))
|
||||||
dump_core_p = 0;
|
dump_core_p = 0;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -767,7 +797,7 @@ internal_vproblem (struct internal_problem *problem,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (problem->should_dump_core == internal_problem_yes)
|
else if (problem->should_dump_core == internal_problem_yes)
|
||||||
dump_core_p = can_dump_core (reason);
|
dump_core_p = can_dump_core_warn (LIMIT_MAX, reason);
|
||||||
else if (problem->should_dump_core == internal_problem_no)
|
else if (problem->should_dump_core == internal_problem_no)
|
||||||
dump_core_p = 0;
|
dump_core_p = 0;
|
||||||
else
|
else
|
||||||
|
|
24
gdb/utils.h
24
gdb/utils.h
|
@ -372,4 +372,28 @@ extern ULONGEST align_down (ULONGEST v, int n);
|
||||||
|
|
||||||
extern LONGEST gdb_sign_extend (LONGEST value, int bit);
|
extern LONGEST gdb_sign_extend (LONGEST value, int bit);
|
||||||
|
|
||||||
|
/* Resource limits used by getrlimit and setrlimit. */
|
||||||
|
|
||||||
|
enum resource_limit_kind
|
||||||
|
{
|
||||||
|
LIMIT_CUR,
|
||||||
|
LIMIT_MAX
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Check whether GDB will be able to dump core using the dump_core
|
||||||
|
function. Returns zero if GDB cannot or should not dump core.
|
||||||
|
If LIMIT_KIND is LIMIT_CUR the user's soft limit will be respected.
|
||||||
|
If LIMIT_KIND is LIMIT_MAX only the hard limit will be respected. */
|
||||||
|
|
||||||
|
extern int can_dump_core (enum resource_limit_kind limit_kind);
|
||||||
|
|
||||||
|
/* 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 */
|
#endif /* UTILS_H */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue