Separate out ANSI-standard signals

This commit reorders various pieces of code to separate ANSI-standard
signals from other signals that need checking.  Comments are added to
document this, and to document the ordering of the signals.

gdb/
2014-06-09  Gary Benson  <gbenson@redhat.com>

	* common/signals.c (gdb_signal_from_host): Reorder to separate
	the always-available ANSI-standard signals from the signals that
	require checking.
	(do_gdb_signal_to_host): Likewise.
	* proc-events.c (signal_table): Likewise.

gdb/testsuite/
2014-06-09  Gary Benson  <gbenson@redhat.com>

	* gdb.base/sigall.c [Functions to send signals]: Reorder to
	separate the always-available ANSI-standard signals from the
	signals that require checking.
	(main): Likewise.
	* gdb.reverse/sigall-reverse.c [Functions to send signals]:
	Likewise.
	(main): Likewise.
This commit is contained in:
Gary Benson
2014-06-09 10:34:33 +01:00
parent c261090765
commit 3657956bf8
6 changed files with 205 additions and 129 deletions

View File

@ -1,3 +1,11 @@
2014-06-09 Gary Benson <gbenson@redhat.com>
* common/signals.c (gdb_signal_from_host): Reorder to separate
the always-available ANSI-standard signals from the signals that
require checking.
(do_gdb_signal_to_host): Likewise.
* proc-events.c (signal_table): Likewise.
2014-06-08 Hui Zhu <hui@codesourcery.com> 2014-06-08 Hui Zhu <hui@codesourcery.com>
* common/linux-ptrace.c (linux_disable_event_reporting): New * common/linux-ptrace.c (linux_disable_event_reporting): New

View File

@ -121,36 +121,47 @@ gdb_signal_from_name (const char *name)
enum gdb_signal enum gdb_signal
gdb_signal_from_host (int hostsig) gdb_signal_from_host (int hostsig)
{ {
/* A switch statement would make sense but would require special kludges /* A switch statement would make sense but would require special
to deal with the cases where more than one signal has the same number. */ kludges to deal with the cases where more than one signal has the
same number. Signals are ordered ANSI-standard signals first,
other signals second, with signals in each block ordered by their
numerical values on a typical POSIX platform. */
if (hostsig == 0) if (hostsig == 0)
return GDB_SIGNAL_0; return GDB_SIGNAL_0;
/* SIGINT, SIGILL, SIGABRT, SIGFPE, SIGSEGV and SIGTERM
are ANSI-standard signals and are always available. */
if (hostsig == SIGINT)
return GDB_SIGNAL_INT;
if (hostsig == SIGILL)
return GDB_SIGNAL_ILL;
if (hostsig == SIGABRT)
return GDB_SIGNAL_ABRT;
if (hostsig == SIGFPE)
return GDB_SIGNAL_FPE;
if (hostsig == SIGSEGV)
return GDB_SIGNAL_SEGV;
if (hostsig == SIGTERM)
return GDB_SIGNAL_TERM;
/* All other signals need preprocessor conditionals. */
#if defined (SIGHUP) #if defined (SIGHUP)
if (hostsig == SIGHUP) if (hostsig == SIGHUP)
return GDB_SIGNAL_HUP; return GDB_SIGNAL_HUP;
#endif #endif
if (hostsig == SIGINT)
return GDB_SIGNAL_INT;
#if defined (SIGQUIT) #if defined (SIGQUIT)
if (hostsig == SIGQUIT) if (hostsig == SIGQUIT)
return GDB_SIGNAL_QUIT; return GDB_SIGNAL_QUIT;
#endif #endif
if (hostsig == SIGILL)
return GDB_SIGNAL_ILL;
#if defined (SIGTRAP) #if defined (SIGTRAP)
if (hostsig == SIGTRAP) if (hostsig == SIGTRAP)
return GDB_SIGNAL_TRAP; return GDB_SIGNAL_TRAP;
#endif #endif
if (hostsig == SIGABRT)
return GDB_SIGNAL_ABRT;
#if defined (SIGEMT) #if defined (SIGEMT)
if (hostsig == SIGEMT) if (hostsig == SIGEMT)
return GDB_SIGNAL_EMT; return GDB_SIGNAL_EMT;
#endif #endif
if (hostsig == SIGFPE)
return GDB_SIGNAL_FPE;
#if defined (SIGKILL) #if defined (SIGKILL)
if (hostsig == SIGKILL) if (hostsig == SIGKILL)
return GDB_SIGNAL_KILL; return GDB_SIGNAL_KILL;
@ -159,8 +170,6 @@ gdb_signal_from_host (int hostsig)
if (hostsig == SIGBUS) if (hostsig == SIGBUS)
return GDB_SIGNAL_BUS; return GDB_SIGNAL_BUS;
#endif #endif
if (hostsig == SIGSEGV)
return GDB_SIGNAL_SEGV;
#if defined (SIGSYS) #if defined (SIGSYS)
if (hostsig == SIGSYS) if (hostsig == SIGSYS)
return GDB_SIGNAL_SYS; return GDB_SIGNAL_SYS;
@ -173,8 +182,6 @@ gdb_signal_from_host (int hostsig)
if (hostsig == SIGALRM) if (hostsig == SIGALRM)
return GDB_SIGNAL_ALRM; return GDB_SIGNAL_ALRM;
#endif #endif
if (hostsig == SIGTERM)
return GDB_SIGNAL_TERM;
#if defined (SIGUSR1) #if defined (SIGUSR1)
if (hostsig == SIGUSR1) if (hostsig == SIGUSR1)
return GDB_SIGNAL_USR1; return GDB_SIGNAL_USR1;
@ -366,36 +373,48 @@ do_gdb_signal_to_host (enum gdb_signal oursig,
do not support signals. */ do not support signals. */
(void) retsig; (void) retsig;
/* Signals are ordered ANSI-standard signals first, other signals
second, with signals in each block ordered by their numerical
values on a typical POSIX platform. */
*oursig_ok = 1; *oursig_ok = 1;
switch (oursig) switch (oursig)
{ {
case GDB_SIGNAL_0: case GDB_SIGNAL_0:
return 0; return 0;
/* SIGINT, SIGILL, SIGABRT, SIGFPE, SIGSEGV and SIGTERM
are ANSI-standard signals and are always available. */
case GDB_SIGNAL_INT:
return SIGINT;
case GDB_SIGNAL_ILL:
return SIGILL;
case GDB_SIGNAL_ABRT:
return SIGABRT;
case GDB_SIGNAL_FPE:
return SIGFPE;
case GDB_SIGNAL_SEGV:
return SIGSEGV;
case GDB_SIGNAL_TERM:
return SIGTERM;
/* All other signals need preprocessor conditionals. */
#if defined (SIGHUP) #if defined (SIGHUP)
case GDB_SIGNAL_HUP: case GDB_SIGNAL_HUP:
return SIGHUP; return SIGHUP;
#endif #endif
case GDB_SIGNAL_INT:
return SIGINT;
#if defined (SIGQUIT) #if defined (SIGQUIT)
case GDB_SIGNAL_QUIT: case GDB_SIGNAL_QUIT:
return SIGQUIT; return SIGQUIT;
#endif #endif
case GDB_SIGNAL_ILL:
return SIGILL;
#if defined (SIGTRAP) #if defined (SIGTRAP)
case GDB_SIGNAL_TRAP: case GDB_SIGNAL_TRAP:
return SIGTRAP; return SIGTRAP;
#endif #endif
case GDB_SIGNAL_ABRT:
return SIGABRT;
#if defined (SIGEMT) #if defined (SIGEMT)
case GDB_SIGNAL_EMT: case GDB_SIGNAL_EMT:
return SIGEMT; return SIGEMT;
#endif #endif
case GDB_SIGNAL_FPE:
return SIGFPE;
#if defined (SIGKILL) #if defined (SIGKILL)
case GDB_SIGNAL_KILL: case GDB_SIGNAL_KILL:
return SIGKILL; return SIGKILL;
@ -404,8 +423,6 @@ do_gdb_signal_to_host (enum gdb_signal oursig,
case GDB_SIGNAL_BUS: case GDB_SIGNAL_BUS:
return SIGBUS; return SIGBUS;
#endif #endif
case GDB_SIGNAL_SEGV:
return SIGSEGV;
#if defined (SIGSYS) #if defined (SIGSYS)
case GDB_SIGNAL_SYS: case GDB_SIGNAL_SYS:
return SIGSYS; return SIGSYS;
@ -418,8 +435,6 @@ do_gdb_signal_to_host (enum gdb_signal oursig,
case GDB_SIGNAL_ALRM: case GDB_SIGNAL_ALRM:
return SIGALRM; return SIGALRM;
#endif #endif
case GDB_SIGNAL_TERM:
return SIGTERM;
#if defined (SIGUSR1) #if defined (SIGUSR1)
case GDB_SIGNAL_USR1: case GDB_SIGNAL_USR1:
return SIGUSR1; return SIGUSR1;

View File

@ -1396,37 +1396,47 @@ proc_prettyprint_syscalls (sysset_t *sysset, int verbose)
/* Prettyprint signals. */ /* Prettyprint signals. */
/* Signal translation table. */ /* Signal translation table, ordered ANSI-standard signals first,
other signals second, with signals in each block ordered by their
numerical values on a typical POSIX platform. */
static struct trans signal_table[] = static struct trans signal_table[] =
{ {
{ 0, "<no signal>", "no signal" }, { 0, "<no signal>", "no signal" },
/* SIGINT, SIGILL, SIGABRT, SIGFPE, SIGSEGV and SIGTERM
are ANSI-standard signals and are always available. */
{ SIGINT, "SIGINT", "Interrupt (rubout)" },
{ SIGILL, "SIGILL", "Illegal instruction" }, /* not reset when caught */
{ SIGABRT, "SIGABRT", "used by abort()" }, /* replaces SIGIOT */
{ SIGFPE, "SIGFPE", "Floating point exception" },
{ SIGSEGV, "SIGSEGV", "Segmentation violation" },
{ SIGTERM, "SIGTERM", "Software termination signal from kill" },
/* All other signals need preprocessor conditionals. */
#ifdef SIGHUP #ifdef SIGHUP
{ SIGHUP, "SIGHUP", "Hangup" }, { SIGHUP, "SIGHUP", "Hangup" },
#endif #endif
{ SIGINT, "SIGINT", "Interrupt (rubout)" },
#ifdef SIGQUIT #ifdef SIGQUIT
{ SIGQUIT, "SIGQUIT", "Quit (ASCII FS)" }, { SIGQUIT, "SIGQUIT", "Quit (ASCII FS)" },
#endif #endif
{ SIGILL, "SIGILL", "Illegal instruction" }, /* not reset when caught */
#ifdef SIGTRAP #ifdef SIGTRAP
{ SIGTRAP, "SIGTRAP", "Trace trap" }, /* not reset when caught */ { SIGTRAP, "SIGTRAP", "Trace trap" }, /* not reset when caught */
#endif #endif
{ SIGABRT, "SIGABRT", "used by abort()" }, /* replaces SIGIOT */
#ifdef SIGIOT #ifdef SIGIOT
{ SIGIOT, "SIGIOT", "IOT instruction" }, { SIGIOT, "SIGIOT", "IOT instruction" },
#endif #endif
#ifdef SIGEMT #ifdef SIGEMT
{ SIGEMT, "SIGEMT", "EMT instruction" }, { SIGEMT, "SIGEMT", "EMT instruction" },
#endif #endif
{ SIGFPE, "SIGFPE", "Floating point exception" },
#ifdef SIGKILL #ifdef SIGKILL
{ SIGKILL, "SIGKILL", "Kill" }, /* Solaris: cannot be caught/ignored */ { SIGKILL, "SIGKILL", "Kill" }, /* Solaris: cannot be caught/ignored */
#endif #endif
#ifdef SIGBUS #ifdef SIGBUS
{ SIGBUS, "SIGBUS", "Bus error" }, { SIGBUS, "SIGBUS", "Bus error" },
#endif #endif
{ SIGSEGV, "SIGSEGV", "Segmentation violation" },
#ifdef SIGSYS #ifdef SIGSYS
{ SIGSYS, "SIGSYS", "Bad argument to system call" }, { SIGSYS, "SIGSYS", "Bad argument to system call" },
#endif #endif
@ -1436,7 +1446,6 @@ static struct trans signal_table[] =
#ifdef SIGALRM #ifdef SIGALRM
{ SIGALRM, "SIGALRM", "Alarm clock" }, { SIGALRM, "SIGALRM", "Alarm clock" },
#endif #endif
{ SIGTERM, "SIGTERM", "Software termination signal from kill" },
#ifdef SIGUSR1 #ifdef SIGUSR1
{ SIGUSR1, "SIGUSR1", "User defined signal 1" }, { SIGUSR1, "SIGUSR1", "User defined signal 1" },
#endif #endif

View File

@ -1,3 +1,13 @@
2014-06-09 Gary Benson <gbenson@redhat.com>
* gdb.base/sigall.c [Functions to send signals]: Reorder to
separate the always-available ANSI-standard signals from the
signals that require checking.
(main): Likewise.
* gdb.reverse/sigall-reverse.c [Functions to send signals]:
Likewise.
(main): Likewise.
2014-06-07 Keith Seitz <keiths@redhat.com> 2014-06-07 Keith Seitz <keiths@redhat.com>
Revert: Revert:

View File

@ -786,7 +786,21 @@ handle_TERM (sig)
{ {
} }
/* Functions to send signals. These also serve as markers. */ /* Functions to send signals. These also serve as markers.
Ordered ANSI-standard signals first, other signals second,
with signals in each block ordered by their numerical values
on a typical POSIX platform. */
/* SIGINT, SIGILL, SIGABRT, SIGFPE, SIGSEGV and SIGTERM
are ANSI-standard signals and are always available. */
int
gen_ILL ()
{
kill (getpid (), SIGILL);
return 0;
}
int int
gen_ABRT () gen_ABRT ()
{ {
@ -794,6 +808,44 @@ gen_ABRT ()
return 0; return 0;
} }
int x;
int
gen_FPE ()
{
/* The intent behind generating SIGFPE this way is to check the mapping
from the CPU exception itself to the signals. It would be nice to
do the same for SIGBUS, SIGSEGV, etc., but I suspect that even this
test might turn out to be insufficiently portable. */
#if 0
/* Loses on the PA because after the signal handler executes we try to
re-execute the failing instruction again. Perhaps we could siglongjmp
out of the signal handler? */
/* The expect script looks for the word "kill"; don't delete it. */
return 5 / x; /* and we both started jumping up and down yelling kill */
#else
kill (getpid (), SIGFPE);
#endif
return 0;
}
int
gen_SEGV ()
{
kill (getpid (), SIGSEGV);
return 0;
}
int
gen_TERM ()
{
kill (getpid (), SIGTERM);
return 0;
}
/* All other signals need preprocessor conditionals. */
int int
gen_HUP () gen_HUP ()
{ {
@ -816,13 +868,6 @@ gen_QUIT ()
return 0; return 0;
} }
int
gen_ILL ()
{
kill (getpid (), SIGILL);
return 0;
}
int int
gen_EMT () gen_EMT ()
{ {
@ -834,28 +879,6 @@ gen_EMT ()
return 0; return 0;
} }
int x;
int
gen_FPE ()
{
/* The intent behind generating SIGFPE this way is to check the mapping
from the CPU exception itself to the signals. It would be nice to
do the same for SIGBUS, SIGSEGV, etc., but I suspect that even this
test might turn out to be insufficiently portable. */
#if 0
/* Loses on the PA because after the signal handler executes we try to
re-execute the failing instruction again. Perhaps we could siglongjmp
out of the signal handler? */
/* The expect script looks for the word "kill"; don't delete it. */
return 5 / x; /* and we both started jumping up and down yelling kill */
#else
kill (getpid (), SIGFPE);
#endif
return 0;
}
int int
gen_BUS () gen_BUS ()
{ {
@ -867,13 +890,6 @@ gen_BUS ()
return 0; return 0;
} }
int
gen_SEGV ()
{
kill (getpid (), SIGSEGV);
return 0;
}
int int
gen_SYS () gen_SYS ()
{ {
@ -1555,13 +1571,6 @@ gen_63 ()
#endif #endif
return 0; return 0;
} }
int
gen_TERM ()
{
kill (getpid (), SIGTERM);
return 0;
}
int int
main () main ()
@ -1578,22 +1587,31 @@ main ()
} }
#endif #endif
/* Signals are ordered ANSI-standard signals first, other signals
second, with signals in each block ordered by their numerical
values on a typical POSIX platform. */
/* SIGINT, SIGILL, SIGABRT, SIGFPE, SIGSEGV and SIGTERM
are ANSI-standard signals and are always available. */
signal (SIGILL, handle_ILL);
signal (SIGABRT, handle_ABRT); signal (SIGABRT, handle_ABRT);
signal (SIGFPE, handle_FPE);
signal (SIGSEGV, handle_SEGV);
signal (SIGTERM, handle_TERM);
/* All other signals need preprocessor conditionals. */
#ifdef SIGHUP #ifdef SIGHUP
signal (SIGHUP, handle_HUP); signal (SIGHUP, handle_HUP);
#endif #endif
#ifdef SIGQUIT #ifdef SIGQUIT
signal (SIGQUIT, handle_QUIT); signal (SIGQUIT, handle_QUIT);
#endif #endif
signal (SIGILL, handle_ILL);
#ifdef SIGEMT #ifdef SIGEMT
signal (SIGEMT, handle_EMT); signal (SIGEMT, handle_EMT);
#endif #endif
signal (SIGFPE, handle_FPE);
#ifdef SIGBUS #ifdef SIGBUS
signal (SIGBUS, handle_BUS); signal (SIGBUS, handle_BUS);
#endif #endif
signal (SIGSEGV, handle_SEGV);
#ifdef SIGSYS #ifdef SIGSYS
signal (SIGSYS, handle_SYS); signal (SIGSYS, handle_SYS);
#endif #endif
@ -1721,7 +1739,6 @@ main ()
signal (62, handle_62); signal (62, handle_62);
signal (63, handle_63); signal (63, handle_63);
#endif /* lynx */ #endif /* lynx */
signal (SIGTERM, handle_TERM);
x = 0; x = 0;

View File

@ -377,7 +377,21 @@ handle_TERM (int sig)
{ {
} }
/* Functions to send signals. These also serve as markers. */ /* Functions to send signals. These also serve as markers.
Ordered ANSI-standard signals first, other signals second,
with signals in each block ordered by their numerical values
on a typical POSIX platform. */
/* SIGINT, SIGILL, SIGABRT, SIGFPE, SIGSEGV and SIGTERM
are ANSI-standard signals and are always available. */
int
gen_ILL (void)
{
kill (getpid (), SIGILL);
return 0;
}
int int
gen_ABRT (void) gen_ABRT (void)
{ {
@ -385,6 +399,44 @@ gen_ABRT (void)
return 0; return 0;
} }
int x;
int
gen_FPE (void)
{
/* The intent behind generating SIGFPE this way is to check the mapping
from the CPU exception itself to the signals. It would be nice to
do the same for SIGBUS, SIGSEGV, etc., but I suspect that even this
test might turn out to be insufficiently portable. */
#if 0
/* Loses on the PA because after the signal handler executes we try to
re-execute the failing instruction again. Perhaps we could siglongjmp
out of the signal handler? */
/* The expect script looks for the word "kill"; don't delete it. */
return 5 / x; /* and we both started jumping up and down yelling kill */
#else
kill (getpid (), SIGFPE);
#endif
return 0;
}
int
gen_SEGV (void)
{
kill (getpid (), SIGSEGV);
return 0;
}
int
gen_TERM (void)
{
kill (getpid (), SIGTERM);
return 0;
}
/* All other signals need preprocessor conditionals. */
int int
gen_HUP (void) gen_HUP (void)
{ {
@ -407,13 +459,6 @@ gen_QUIT (void)
return 0; return 0;
} }
int
gen_ILL (void)
{
kill (getpid (), SIGILL);
return 0;
}
int int
gen_EMT (void) gen_EMT (void)
{ {
@ -425,28 +470,6 @@ gen_EMT (void)
return 0; return 0;
} }
int x;
int
gen_FPE (void)
{
/* The intent behind generating SIGFPE this way is to check the mapping
from the CPU exception itself to the signals. It would be nice to
do the same for SIGBUS, SIGSEGV, etc., but I suspect that even this
test might turn out to be insufficiently portable. */
#if 0
/* Loses on the PA because after the signal handler executes we try to
re-execute the failing instruction again. Perhaps we could siglongjmp
out of the signal handler? */
/* The expect script looks for the word "kill"; don't delete it. */
return 5 / x; /* and we both started jumping up and down yelling kill */
#else
kill (getpid (), SIGFPE);
#endif
return 0;
}
int int
gen_BUS (void) gen_BUS (void)
{ {
@ -458,13 +481,6 @@ gen_BUS (void)
return 0; return 0;
} }
int
gen_SEGV (void)
{
kill (getpid (), SIGSEGV);
return 0;
}
int int
gen_SYS (void) gen_SYS (void)
{ {
@ -1146,13 +1162,6 @@ gen_63 (void)
#endif #endif
return 0; return 0;
} }
int
gen_TERM (void)
{
kill (getpid (), SIGTERM);
return 0;
}
int int
main () main ()
@ -1168,22 +1177,31 @@ main ()
} }
#endif #endif
/* Signals are ordered ANSI-standard signals first, other signals
second, with signals in each block ordered by their numerical
values on a typical POSIX platform. */
/* SIGINT, SIGILL, SIGABRT, SIGFPE, SIGSEGV and SIGTERM
are ANSI-standard signals and are always available. */
signal (SIGILL, handle_ILL);
signal (SIGABRT, handle_ABRT); signal (SIGABRT, handle_ABRT);
signal (SIGFPE, handle_FPE);
signal (SIGSEGV, handle_SEGV);
signal (SIGTERM, handle_TERM);
/* All other signals need preprocessor conditionals. */
#ifdef SIGHUP #ifdef SIGHUP
signal (SIGHUP, handle_HUP); signal (SIGHUP, handle_HUP);
#endif #endif
#ifdef SIGQUIT #ifdef SIGQUIT
signal (SIGQUIT, handle_QUIT); signal (SIGQUIT, handle_QUIT);
#endif #endif
signal (SIGILL, handle_ILL);
#ifdef SIGEMT #ifdef SIGEMT
signal (SIGEMT, handle_EMT); signal (SIGEMT, handle_EMT);
#endif #endif
signal (SIGFPE, handle_FPE);
#ifdef SIGBUS #ifdef SIGBUS
signal (SIGBUS, handle_BUS); signal (SIGBUS, handle_BUS);
#endif #endif
signal (SIGSEGV, handle_SEGV);
#ifdef SIGSYS #ifdef SIGSYS
signal (SIGSYS, handle_SYS); signal (SIGSYS, handle_SYS);
#endif #endif
@ -1311,7 +1329,6 @@ main ()
signal (62, handle_62); signal (62, handle_62);
signal (63, handle_63); signal (63, handle_63);
#endif /* lynx */ #endif /* lynx */
signal (SIGTERM, handle_TERM);
x = 0; x = 0;