On Tue, May 31, 2016 at 02:13:57PM +0800, Fei Jie wrote: > * tests/tests.h (signal2name): New prototype. > * tests/signal2name.c: New file. > * tests/Makefile.am (libtests_a_SOURCES): Add it. > --- > tests/Makefile.am | 1 + > tests/signal2name.c | 125 > ++++++++++++++++++++++++++++++++++++++++++++++++++++ > tests/tests.h | 3 ++ > 3 files changed, 129 insertions(+) > create mode 100644 tests/signal2name.c > > diff --git a/tests/Makefile.am b/tests/Makefile.am > index 9eba306..ac527ec 100644 > --- a/tests/Makefile.am > +++ b/tests/Makefile.am > @@ -51,6 +51,7 @@ libtests_a_SOURCES = \ > print_quoted_string.c \ > printflags.c \ > printxval.c \ > + signal2name.c \ > tail_alloc.c \ > tests.h \ > tprintf.c \ > diff --git a/tests/signal2name.c b/tests/signal2name.c > new file mode 100644 > index 0000000..906e821 > --- /dev/null > +++ b/tests/signal2name.c > @@ -0,0 +1,125 @@ > +#include "tests.h" > +#include <signal.h> > + > +#define CASE(x) case x: return #x > + > +const char * > +signal2name(int sig) > +{ > + switch (sig) { > +#ifdef SIGALRM > + CASE(SIGALRM); > +#endif > +#ifdef SIGBUS > + CASE(SIGBUS); > +#endif > +#ifdef SIGCHLD > + CASE(SIGCHLD); > +#endif > +#ifdef SIGCONT > + CASE(SIGCONT); > +#endif > +#ifdef SIGFPE > + CASE(SIGFPE); > +#endif > +#ifdef SIGHUP > + CASE(SIGHUP); > +#endif > +#ifdef SIGILL > + CASE(SIGILL); > +#endif > +#ifdef SIGINT > + CASE(SIGINT); > +#endif > +#ifdef SIGIO > + CASE(SIGIO); > +#endif > +#ifdef SIGPIPE > + CASE(SIGPIPE); > +#endif > +#ifdef SIGPROF > + CASE(SIGPROF); > +#endif > +#ifdef SIGQUIT > + CASE(SIGQUIT); > +#endif > +#ifdef SIGSEGV > + CASE(SIGSEGV); > +#endif > +#ifdef SIGSYS > + CASE(SIGSYS); > +#endif > +#ifdef SIGTERM > + CASE(SIGTERM); > +#endif > +#ifdef SIGTRAP > + CASE(SIGTRAP); > +#endif > +#ifdef SIGTSTP > + CASE(SIGTSTP); > +#endif > +#ifdef SIGTTIN > + CASE(SIGTTIN); > +#endif > +#ifdef SIGTTOU > + CASE(SIGTTOU); > +#endif > +#ifdef SIGURG > + CASE(SIGURG); > +#endif > +#ifdef SIGUSR1 > + CASE(SIGUSR1); > +#endif > +#ifdef SIGUSR2 > + CASE(SIGUSR2); > +#endif > +#ifdef SIGVTALRM > + CASE(SIGVTALRM); > +#endif > +#ifdef SIGWINCH > + CASE(SIGWINCH); > +#endif > +#ifdef SIGXCPU > + CASE(SIGXCPU); > +#endif > +#ifdef SIGXFSZ > + CASE(SIGXFSZ); > +#endif
I don't see any benefits in ifdef'ing signal constants. A test is going to try them all anyway, so if something is wrong, let's detect it at compile time. > +#if !defined MIPS > +# ifdef SIGABRT > + CASE(SIGABRT); > +# endif > +#endif This could be merged with SIGIOT, e.g. #ifdef MIPS CASE(SIGIOT); #else CASE(SIGABRT); #endif > +#if defined ALPHA || defined MIPS || defined SPARC > +# ifdef SIGEMT > + CASE(SIGEMT); > +# endif > +#endif > +#ifdef ALPHA > +# ifdef SIGINFO > + CASE(SIGINFO); > +# endif > +#endif This could be merged with SIGPWR and SIGLOST, e.g. #if defined ALPHA CASE(SIGINFO); #elif defined SPARC || defined SPARC64 CASE(SIGLOST); #else CASE(SIGPWR); #endif > +#ifdef MIPS > +# ifdef SIGIOT > + CASE(SIGIOT); > +# endif > +#endif > +#ifdef SPARC > +# ifdef SIGLOST > + CASE(SIGLOST); > +# endif > +#endif > +#if !defined ALPHA && !defined SPARC > +# ifdef SIGPWR > + CASE(SIGPWR); > +# endif > +#endif > +#if !defined ALPHA && !defined SPARC && !defined MIPS > +# ifdef SIGSTKFLT > + CASE(SIGSTKFLT); > +# endif > +#endif SPARC64 behaves the same way as SPARC wrt signal constants. > + default: perror_msg_and_fail("unknown signal number %d", sig); > + } > +} Alternatively, arch specific cases could be organized this way: #if defined ALPHA CASE(SIGABRT); CASE(SIGEMT); CASE(SIGINFO); #elif defined SPARC || defined SPARC64 CASE(SIGABRT); CASE(SIGEMT); CASE(SIGLOST); #elif defined MIPS CASE(SIGEMT); CASE(SIGIOT); CASE(SIGPWR); #else CASE(SIGABRT); CASE(SIGPWR); CASE(SIGSTKFLT); #endif -- ldv
pgpJ1OTcGErLS.pgp
Description: PGP signature
------------------------------------------------------------------------------ What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic patterns at an interface-level. Reveals which users, apps, and protocols are consuming the most bandwidth. Provides multi-vendor support for NetFlow, J-Flow, sFlow and other flows. Make informed decisions using capacity planning reports. http://pubads.g.doubleclick.net/gampad/clk?id=1444514421&iu=/41014381
_______________________________________________ Strace-devel mailing list Strace-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/strace-devel