]> granicus.if.org Git - strace/commitdiff
Rewrite qual_signal using bit sets
authorDmitry V. Levin <ldv@altlinux.org>
Sat, 3 Dec 2016 22:37:19 +0000 (22:37 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Mon, 5 Dec 2016 20:49:59 +0000 (20:49 +0000)
* 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.

defs.h
qualify.c
strace.c
syscall.c

diff --git a/defs.h b/defs.h
index 2976c52f6b6daf4416d2e5c298c2336f38f29fe8..7998a16de3175408728afd140eaa661725773d0b 100644 (file)
--- 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);
index 157565177a3fca762ff32c9ebb1c2a8d277fa9fb..30e7ac997f4496c248ea140a2b01bdd7cfb00a77 100644 (file)
--- 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");
+}
index df1ec3e39e27dc764200e97e12c9385d60661667..1b8b5cca312d94a543900e7ee24c6ea373717a7f 100644 (file)
--- 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));
index 590a8a652b3be774cc951995cee81d9e14111a5e..1f01adbb9408460846cf227a6cd6604652664da9 100644 (file)
--- 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;