From patchwork Fri Jun 6 13:32:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gary Benson X-Patchwork-Id: 1352 Received: (qmail 1595 invoked by alias); 6 Jun 2014 13:32:38 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 1584 invoked by uid 89); 6 Jun 2014 13:32:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 06 Jun 2014 13:32:36 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s56DWXhk006970 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 6 Jun 2014 09:32:33 -0400 Received: from blade.nx (ovpn-116-93.ams2.redhat.com [10.36.116.93]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s56DWVVO019664; Fri, 6 Jun 2014 09:32:31 -0400 Received: by blade.nx (Postfix, from userid 1000) id B130B2622D4; Fri, 6 Jun 2014 14:32:30 +0100 (BST) Date: Fri, 6 Jun 2014 14:32:30 +0100 From: Gary Benson To: gdb-patches@sourceware.org Cc: Doug Evans , Eli Zaretskii Subject: [PATCH v2] Separate out ANSI-standard signals Message-ID: <20140606133230.GB1769@blade.nx> MIME-Version: 1.0 Content-Disposition: inline X-IsSubscribed: yes Hi all, This patch reorders various pieces of code to separate ANSI-standard signals from other signals that need checking. Comments are added to document this. This patch differs from the first version in that extra comments have been added to document the ordering of the signals. Ok to commit? Cheers, Gary --- gdb/ 2014-06-06 Gary Benson * 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-06 Gary Benson * 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. diff --git a/gdb/common/signals.c b/gdb/common/signals.c index ea0c19a..3c9cd41 100644 --- a/gdb/common/signals.c +++ b/gdb/common/signals.c @@ -121,36 +121,47 @@ gdb_signal_from_name (const char *name) enum gdb_signal gdb_signal_from_host (int hostsig) { - /* A switch statement would make sense but would require special kludges - to deal with the cases where more than one signal has the same number. */ + /* A switch statement would make sense but would require special + 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) 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 (hostsig == SIGHUP) return GDB_SIGNAL_HUP; #endif - if (hostsig == SIGINT) - return GDB_SIGNAL_INT; #if defined (SIGQUIT) if (hostsig == SIGQUIT) return GDB_SIGNAL_QUIT; #endif - if (hostsig == SIGILL) - return GDB_SIGNAL_ILL; #if defined (SIGTRAP) if (hostsig == SIGTRAP) return GDB_SIGNAL_TRAP; #endif - if (hostsig == SIGABRT) - return GDB_SIGNAL_ABRT; #if defined (SIGEMT) if (hostsig == SIGEMT) return GDB_SIGNAL_EMT; #endif - if (hostsig == SIGFPE) - return GDB_SIGNAL_FPE; #if defined (SIGKILL) if (hostsig == SIGKILL) return GDB_SIGNAL_KILL; @@ -159,8 +170,6 @@ gdb_signal_from_host (int hostsig) if (hostsig == SIGBUS) return GDB_SIGNAL_BUS; #endif - if (hostsig == SIGSEGV) - return GDB_SIGNAL_SEGV; #if defined (SIGSYS) if (hostsig == SIGSYS) return GDB_SIGNAL_SYS; @@ -173,8 +182,6 @@ gdb_signal_from_host (int hostsig) if (hostsig == SIGALRM) return GDB_SIGNAL_ALRM; #endif - if (hostsig == SIGTERM) - return GDB_SIGNAL_TERM; #if defined (SIGUSR1) if (hostsig == SIGUSR1) return GDB_SIGNAL_USR1; @@ -366,36 +373,48 @@ do_gdb_signal_to_host (enum gdb_signal oursig, do not support signals. */ (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; switch (oursig) { case GDB_SIGNAL_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) case GDB_SIGNAL_HUP: return SIGHUP; #endif - case GDB_SIGNAL_INT: - return SIGINT; #if defined (SIGQUIT) case GDB_SIGNAL_QUIT: return SIGQUIT; #endif - case GDB_SIGNAL_ILL: - return SIGILL; #if defined (SIGTRAP) case GDB_SIGNAL_TRAP: return SIGTRAP; #endif - case GDB_SIGNAL_ABRT: - return SIGABRT; #if defined (SIGEMT) case GDB_SIGNAL_EMT: return SIGEMT; #endif - case GDB_SIGNAL_FPE: - return SIGFPE; #if defined (SIGKILL) case GDB_SIGNAL_KILL: return SIGKILL; @@ -404,8 +423,6 @@ do_gdb_signal_to_host (enum gdb_signal oursig, case GDB_SIGNAL_BUS: return SIGBUS; #endif - case GDB_SIGNAL_SEGV: - return SIGSEGV; #if defined (SIGSYS) case GDB_SIGNAL_SYS: return SIGSYS; @@ -418,8 +435,6 @@ do_gdb_signal_to_host (enum gdb_signal oursig, case GDB_SIGNAL_ALRM: return SIGALRM; #endif - case GDB_SIGNAL_TERM: - return SIGTERM; #if defined (SIGUSR1) case GDB_SIGNAL_USR1: return SIGUSR1; diff --git a/gdb/proc-events.c b/gdb/proc-events.c index 9bd7b31..68f004f 100644 --- a/gdb/proc-events.c +++ b/gdb/proc-events.c @@ -1396,37 +1396,47 @@ proc_prettyprint_syscalls (sysset_t *sysset, int verbose) /* 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[] = { { 0, "", "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 { SIGHUP, "SIGHUP", "Hangup" }, #endif - { SIGINT, "SIGINT", "Interrupt (rubout)" }, #ifdef SIGQUIT { SIGQUIT, "SIGQUIT", "Quit (ASCII FS)" }, #endif - { SIGILL, "SIGILL", "Illegal instruction" }, /* not reset when caught */ #ifdef SIGTRAP { SIGTRAP, "SIGTRAP", "Trace trap" }, /* not reset when caught */ #endif - { SIGABRT, "SIGABRT", "used by abort()" }, /* replaces SIGIOT */ #ifdef SIGIOT { SIGIOT, "SIGIOT", "IOT instruction" }, #endif #ifdef SIGEMT { SIGEMT, "SIGEMT", "EMT instruction" }, #endif - { SIGFPE, "SIGFPE", "Floating point exception" }, #ifdef SIGKILL { SIGKILL, "SIGKILL", "Kill" }, /* Solaris: cannot be caught/ignored */ #endif #ifdef SIGBUS { SIGBUS, "SIGBUS", "Bus error" }, #endif - { SIGSEGV, "SIGSEGV", "Segmentation violation" }, #ifdef SIGSYS { SIGSYS, "SIGSYS", "Bad argument to system call" }, #endif @@ -1436,7 +1446,6 @@ static struct trans signal_table[] = #ifdef SIGALRM { SIGALRM, "SIGALRM", "Alarm clock" }, #endif - { SIGTERM, "SIGTERM", "Software termination signal from kill" }, #ifdef SIGUSR1 { SIGUSR1, "SIGUSR1", "User defined signal 1" }, #endif diff --git a/gdb/testsuite/gdb.base/sigall.c b/gdb/testsuite/gdb.base/sigall.c index 7a7610e..283cef3 100644 --- a/gdb/testsuite/gdb.base/sigall.c +++ b/gdb/testsuite/gdb.base/sigall.c @@ -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 gen_ABRT () { @@ -794,6 +808,44 @@ gen_ABRT () 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 gen_HUP () { @@ -817,13 +869,6 @@ return 0; } int -gen_ILL () -{ - kill (getpid (), SIGILL); -return 0; -} - -int gen_EMT () { #ifdef SIGEMT @@ -834,28 +879,6 @@ gen_EMT () 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_BUS () { @@ -868,13 +891,6 @@ return 0; } int -gen_SEGV () -{ - kill (getpid (), SIGSEGV); -return 0; -} - -int gen_SYS () { #ifdef SIGSYS @@ -1555,13 +1571,6 @@ gen_63 () #endif return 0; } - -int -gen_TERM () -{ - kill (getpid (), SIGTERM); -return 0; -} int main () @@ -1578,22 +1587,31 @@ main () } #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 (SIGFPE, handle_FPE); + signal (SIGSEGV, handle_SEGV); + signal (SIGTERM, handle_TERM); + + /* All other signals need preprocessor conditionals. */ #ifdef SIGHUP signal (SIGHUP, handle_HUP); #endif #ifdef SIGQUIT signal (SIGQUIT, handle_QUIT); #endif - signal (SIGILL, handle_ILL); #ifdef SIGEMT signal (SIGEMT, handle_EMT); #endif - signal (SIGFPE, handle_FPE); #ifdef SIGBUS signal (SIGBUS, handle_BUS); #endif - signal (SIGSEGV, handle_SEGV); #ifdef SIGSYS signal (SIGSYS, handle_SYS); #endif @@ -1721,7 +1739,6 @@ main () signal (62, handle_62); signal (63, handle_63); #endif /* lynx */ - signal (SIGTERM, handle_TERM); x = 0; diff --git a/gdb/testsuite/gdb.reverse/sigall-reverse.c b/gdb/testsuite/gdb.reverse/sigall-reverse.c index 6ccea42..9053163 100644 --- a/gdb/testsuite/gdb.reverse/sigall-reverse.c +++ b/gdb/testsuite/gdb.reverse/sigall-reverse.c @@ -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 gen_ABRT (void) { @@ -385,6 +399,44 @@ gen_ABRT (void) 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 gen_HUP (void) { @@ -408,13 +460,6 @@ return 0; } int -gen_ILL (void) -{ - kill (getpid (), SIGILL); -return 0; -} - -int gen_EMT (void) { #ifdef SIGEMT @@ -425,28 +470,6 @@ gen_EMT (void) 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_BUS (void) { @@ -459,13 +482,6 @@ return 0; } int -gen_SEGV (void) -{ - kill (getpid (), SIGSEGV); -return 0; -} - -int gen_SYS (void) { #ifdef SIGSYS @@ -1146,13 +1162,6 @@ gen_63 (void) #endif return 0; } - -int -gen_TERM (void) -{ - kill (getpid (), SIGTERM); -return 0; -} int main () @@ -1168,22 +1177,31 @@ main () } #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 (SIGFPE, handle_FPE); + signal (SIGSEGV, handle_SEGV); + signal (SIGTERM, handle_TERM); + + /* All other signals need preprocessor conditionals. */ #ifdef SIGHUP signal (SIGHUP, handle_HUP); #endif #ifdef SIGQUIT signal (SIGQUIT, handle_QUIT); #endif - signal (SIGILL, handle_ILL); #ifdef SIGEMT signal (SIGEMT, handle_EMT); #endif - signal (SIGFPE, handle_FPE); #ifdef SIGBUS signal (SIGBUS, handle_BUS); #endif - signal (SIGSEGV, handle_SEGV); #ifdef SIGSYS signal (SIGSYS, handle_SYS); #endif @@ -1311,7 +1329,6 @@ main () signal (62, handle_62); signal (63, handle_63); #endif /* lynx */ - signal (SIGTERM, handle_TERM); x = 0;