mirror of
https://github.com/bminor/binutils-gdb.git
synced 2025-12-26 01:07:52 +00:00
This patch adds a new convenience variable called "$_exitsignal", which
will hold the signal number when the inferior terminates due to the uncaught signal. I've made modifications on infrun.c:handle_inferior_event such that $_exitcode gets cleared when the inferior signalled, and vice-versa. This assumption was made because the variables are mutually exclusive, i.e., when the inferior terminates because of an uncaught signal it is not possible for it to return. I have also made modifications such that when a corefile is loaded, $_exitsignal gets set to the uncaught signal that "killed" the inferior, and $_exitcode is cleared. The patch also adds a NEWS entry, documentation bits, and a testcase. The documentation entry explains how to use $_exitsignal and $_exitcode in a GDB script, by making use of the new $_isvoid convenience function. gdb/ 2013-10-06 Sergio Durigan Junior <sergiodj@redhat.com> * NEWS: Mention new convenience variable $_exitsignal. * corelow.c (core_open): Reset exit convenience variables. Set $_exitsignal to the uncaught signal which generated the corefile. * infrun.c (handle_inferior_event): Reset exit convenience variables. Set $_exitsignal for TARGET_WAITKIND_SIGNALLED. (clear_exit_convenience_vars): New function. * inferior.h (clear_exit_convenience_vars): New prototype. gdb/testsuite/ 2013-10-06 Sergio Durigan Junior <sergiodj@redhat.com> * gdb.base/corefile.exp: Test whether $_exitsignal is set and $_exitcode is void when opening a corefile. * gdb.base/exitsignal.exp: New file. * gdb.base/segv.c: Likewise. * gdb.base/normal.c: Likewise. gdb/doc/ 2013-10-06 Sergio Durigan Junior <sergiodj@redhat.com> * gdb.texinfo (Convenience Variables): Document $_exitsignal. Update entry for $_exitcode.
This commit is contained in:
41
gdb/infrun.c
41
gdb/infrun.c
@@ -3426,6 +3426,9 @@ handle_inferior_event (struct execution_control_state *ecs)
|
||||
handle_vfork_child_exec_or_exit (0);
|
||||
target_terminal_ours (); /* Must do this before mourn anyway. */
|
||||
|
||||
/* Clearing any previous state of convenience variables. */
|
||||
clear_exit_convenience_vars ();
|
||||
|
||||
if (ecs->ws.kind == TARGET_WAITKIND_EXITED)
|
||||
{
|
||||
/* Record the exit code in the convenience variable $_exitcode, so
|
||||
@@ -3440,7 +3443,34 @@ handle_inferior_event (struct execution_control_state *ecs)
|
||||
print_exited_reason (ecs->ws.value.integer);
|
||||
}
|
||||
else
|
||||
print_signal_exited_reason (ecs->ws.value.sig);
|
||||
{
|
||||
struct regcache *regcache = get_thread_regcache (ecs->ptid);
|
||||
struct gdbarch *gdbarch = get_regcache_arch (regcache);
|
||||
|
||||
if (gdbarch_gdb_signal_to_target_p (gdbarch))
|
||||
{
|
||||
/* Set the value of the internal variable $_exitsignal,
|
||||
which holds the signal uncaught by the inferior. */
|
||||
set_internalvar_integer (lookup_internalvar ("_exitsignal"),
|
||||
gdbarch_gdb_signal_to_target (gdbarch,
|
||||
ecs->ws.value.sig));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* We don't have access to the target's method used for
|
||||
converting between signal numbers (GDB's internal
|
||||
representation <-> target's representation).
|
||||
Therefore, we cannot do a good job at displaying this
|
||||
information to the user. It's better to just warn
|
||||
her about it (if infrun debugging is enabled), and
|
||||
give up. */
|
||||
if (debug_infrun)
|
||||
fprintf_filtered (gdb_stdlog, _("\
|
||||
Cannot fill $_exitsignal with the correct signal number.\n"));
|
||||
}
|
||||
|
||||
print_signal_exited_reason (ecs->ws.value.sig);
|
||||
}
|
||||
|
||||
gdb_flush (gdb_stdout);
|
||||
target_mourn_inferior ();
|
||||
@@ -7061,6 +7091,15 @@ save_inferior_ptid (void)
|
||||
*saved_ptid_ptr = inferior_ptid;
|
||||
return make_cleanup (restore_inferior_ptid, saved_ptid_ptr);
|
||||
}
|
||||
|
||||
/* See inferior.h. */
|
||||
|
||||
void
|
||||
clear_exit_convenience_vars (void)
|
||||
{
|
||||
clear_internalvar (lookup_internalvar ("_exitsignal"));
|
||||
clear_internalvar (lookup_internalvar ("_exitcode"));
|
||||
}
|
||||
|
||||
|
||||
/* User interface for reverse debugging:
|
||||
|
||||
Reference in New Issue
Block a user