From: Dmitry V. Levin Date: Sat, 3 Dec 2016 22:37:19 +0000 (+0000) Subject: Rewrite qual_signal using bit sets X-Git-Tag: v4.15~28 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=11abfb422a9dc2cd1d44500bad62464fe09b6fb0;p=strace Rewrite qual_signal using bit sets * defs.h (signal_set): New variable prototypes. (qualify_signals): New function prototypes. (QUAL_SIGNAL): Change to a value greater than 0xff. (QUAL_FAULT): Change to a lower value. * qualify.c (signal_set): New variable. (sigstr_to_uint, qualify_signals): New functions. * syscall.c (qual_signal): Remove. (qual_options): Replace qual_signal with NULL. (qualify): Use qualify_signals. * strace.c (print_signalled, print_stopped): Use is_number_in_set with signal_set argument. --- diff --git a/defs.h b/defs.h index 2976c52f..7998a16d 100644 --- a/defs.h +++ b/defs.h @@ -288,10 +288,10 @@ struct tcb { #define QUAL_ABBREV 0x002 /* abbreviate the structures of this syscall */ #define QUAL_VERBOSE 0x004 /* decode the structures of this syscall */ #define QUAL_RAW 0x008 /* print all args in hex for this syscall */ -#define QUAL_SIGNAL 0x010 /* report events with this signal */ +#define QUAL_FAULT 0x010 /* fail this system call on purpose */ +#define QUAL_SIGNAL 0x100 /* report events with this signal */ #define QUAL_READ 0x200 /* dump data read from this file descriptor */ #define QUAL_WRITE 0x400 /* dump data written to this file descriptor */ -#define QUAL_FAULT 0x080 /* fail this system call on purpose */ typedef uint8_t qualbits_t; #define DEFAULT_QUAL_FLAGS (QUAL_TRACE | QUAL_ABBREV | QUAL_VERBOSE) @@ -667,10 +667,12 @@ extern void print_ifindex(unsigned int); struct number_set; extern struct number_set read_set; extern struct number_set write_set; +extern struct number_set signal_set; extern bool is_number_in_set(unsigned int number, const struct number_set *); extern void qualify_read(const char *); extern void qualify_write(const char *); +extern void qualify_signals(const char *); extern int dm_ioctl(struct tcb *, const unsigned int, long); extern int file_ioctl(struct tcb *, const unsigned int, long); diff --git a/qualify.c b/qualify.c index 15756517..30e7ac99 100644 --- a/qualify.c +++ b/qualify.c @@ -38,6 +38,7 @@ struct number_set { struct number_set read_set; struct number_set write_set; +struct number_set signal_set; static void number_setbit(const unsigned int i, number_slot_t *const vec) @@ -152,3 +153,37 @@ qualify_write(const char *const str) { qualify_tokens(str, &write_set, string_to_uint, "descriptor"); } + +static int +sigstr_to_uint(const char *s) +{ + int i; + + if (*s >= '0' && *s <= '9') + return string_to_uint_upto(s, 255); + + if (strncasecmp(s, "SIG", 3) == 0) + s += 3; + + for (i = 0; i <= 255; ++i) { + const char *name = signame(i); + + if (strncasecmp(name, "SIG", 3) != 0) + continue; + + name += 3; + + if (strcasecmp(name, s) != 0) + continue; + + return i; + } + + return -1; +} + +void +qualify_signals(const char *const str) +{ + qualify_tokens(str, &signal_set, sigstr_to_uint, "signal"); +} diff --git a/strace.c b/strace.c index df1ec3e3..1b8b5cca 100644 --- a/strace.c +++ b/strace.c @@ -2094,8 +2094,7 @@ print_signalled(struct tcb *tcp, const int pid, int status) } if (cflag != CFLAG_ONLY_STATS - && (qual_flags[WTERMSIG(status)] & QUAL_SIGNAL) - ) { + && is_number_in_set(WTERMSIG(status), &signal_set)) { printleader(tcp); #ifdef WCOREDUMP tprintf("+++ killed by %s %s+++\n", @@ -2130,8 +2129,7 @@ print_stopped(struct tcb *tcp, const siginfo_t *si, const unsigned int sig) { if (cflag != CFLAG_ONLY_STATS && !hide_log(tcp) - && (qual_flags[sig] & QUAL_SIGNAL) - ) { + && is_number_in_set(sig, &signal_set)) { printleader(tcp); if (si) { tprintf("--- %s ", signame(sig)); diff --git a/syscall.c b/syscall.c index 590a8a65..1f01adbb 100644 --- a/syscall.c +++ b/syscall.c @@ -360,7 +360,6 @@ update_personality(struct tcb *tcp, unsigned int personality) #endif static int qual_fault(const char *, unsigned int, int); -static int qual_signal(const char *, unsigned int, int); static int qual_syscall(const char *, unsigned int, int); static const struct qual_options { @@ -377,9 +376,9 @@ static const struct qual_options { { QUAL_VERBOSE, "v", qual_syscall, "system call" }, { QUAL_RAW, "raw", qual_syscall, "system call" }, { QUAL_RAW, "x", qual_syscall, "system call" }, - { QUAL_SIGNAL, "signal", qual_signal, "signal" }, - { QUAL_SIGNAL, "signals", qual_signal, "signal" }, - { QUAL_SIGNAL, "s", qual_signal, "signal" }, + { QUAL_SIGNAL, "signal", NULL, "signal" }, + { QUAL_SIGNAL, "signals", NULL, "signal" }, + { QUAL_SIGNAL, "s", NULL, "signal" }, { QUAL_READ, "read", NULL, "descriptor" }, { QUAL_READ, "reads", NULL, "descriptor" }, { QUAL_READ, "r", NULL, "descriptor" }, @@ -700,34 +699,6 @@ qual_fault(const char *const s, const unsigned int bitflag, const int not) return rc; } -static int -qual_signal(const char *s, const unsigned int bitflag, const int not) -{ - int i; - - if (*s >= '0' && *s <= '9') { - i = string_to_uint_upto(s, 255); - if (i < 0) - return -1; - qualify_one(i, bitflag, not, -1, NULL); - return 0; - } - if (strncasecmp(s, "SIG", 3) == 0) - s += 3; - for (i = 0; i <= NSIG; ++i) { - const char *name = signame(i); - if (strncasecmp(name, "SIG", 3) != 0) - continue; - name += 3; - - if (strcasecmp(name, s) != 0) - continue; - qualify_one(i, bitflag, not, -1, NULL); - return 0; - } - return -1; -} - void qualify(const char *s) { @@ -753,6 +724,9 @@ qualify(const char *s) } switch (opt->bitflag) { + case QUAL_SIGNAL: + qualify_signals(s); + return; case QUAL_READ: qualify_read(s); return;