* basic_actions.c (apply_read, apply_write): New functions.
* basic_filters.c (parse_fd_filter, run_fd_filter, free_fd_filter): Likewise.
* defs.h (QUAL_READ, QUAL_WRITE): Add new flags.
(dump_read, dump_write): Add macros for these flags.
* filter.c (filter_types): Add fd filter type.
* filter.h (DECL_FILTER): Add fd filter declaration.
(DECL_FILTER_ACTION): Add read and write filter action declarations.
* filter_action.c (action_types): Add read and write filter action types.
* filter_qualify.c (read_set, write_set): Remove set variables.
(qualify_read, qualify_write): Use new filtering API.
* number_set.h (read_set, write_set): Remove set variable declarations.
* syscall.c (dumpio): Check dump_read, dump_write macros
instead of global sets.
---
 basic_actions.c  | 12 ++++++++++++
 basic_filters.c  | 30 ++++++++++++++++++++++++++++++
 defs.h           |  4 ++++
 filter.c         |  1 +
 filter.h         |  3 +++
 filter_action.c  |  2 ++
 filter_qualify.c | 18 ++++++++++--------
 number_set.h     |  2 --
 syscall.c        |  4 ++--
 9 files changed, 64 insertions(+), 12 deletions(-)

diff --git a/basic_actions.c b/basic_actions.c
index 42394494..004b1844 100644
--- a/basic_actions.c
+++ b/basic_actions.c
@@ -116,3 +116,15 @@ parse_fault(const char *str)
 {
        return parse_inject_common(str, true, "fault");
 }
+
+void
+apply_read(struct tcb *tcp, void *_priv_data)
+{
+       tcp->qual_flg |= QUAL_READ;
+}
+
+void
+apply_write(struct tcb *tcp, void *_priv_data)
+{
+       tcp->qual_flg |= QUAL_WRITE;
+}
diff --git a/basic_filters.c b/basic_filters.c
index 99c6e714..54b52fed 100644
--- a/basic_filters.c
+++ b/basic_filters.c
@@ -345,3 +345,33 @@ handle_inversion:
                error_msg_and_die("invalid %s '%s'", name, str);
        }
 }
+
+void *
+parse_fd_filter(const char *str)
+{
+       struct number_set *set;
+
+       set = alloc_number_set_array(1);
+       qualify_tokens(str, set, string_to_uint, "descriptor");
+       return set;
+}
+
+bool
+run_fd_filter(struct tcb *tcp, void *priv_data)
+{
+       int fd = tcp->u_arg[0];
+       struct number_set *set = priv_data;
+
+       if (fd < 0)
+               return false;
+       return is_number_in_set(fd, set);
+}
+
+void
+free_fd_filter(void *priv_data)
+{
+       struct number_set *set = priv_data;
+
+       free_number_set_array(set, 1);
+       return;
+}
diff --git a/defs.h b/defs.h
index 6354d90f..c03010b5 100644
--- a/defs.h
+++ b/defs.h
@@ -254,6 +254,8 @@ struct tcb {
 #define QUAL_VERBOSE   0x004   /* decode the structures of this syscall */
 #define QUAL_RAW       0x008   /* print all args in hex for this syscall */
 #define QUAL_INJECT    0x010   /* tamper with this system call on purpose */
+#define QUAL_READ      0x020   /* dump data read in this syscall */
+#define QUAL_WRITE     0x040   /* dump data written in this syscall */
 
 #define DEFAULT_QUAL_FLAGS (QUAL_TRACE | QUAL_ABBREV | QUAL_VERBOSE)
 
@@ -263,6 +265,8 @@ struct tcb {
 #define traced(tcp)    ((tcp)->qual_flg & QUAL_TRACE)
 #define verbose(tcp)   ((tcp)->qual_flg & QUAL_VERBOSE)
 #define abbrev(tcp)    ((tcp)->qual_flg & QUAL_ABBREV)
+#define dump_read(tcp) ((tcp)->qual_flg & QUAL_READ)
+#define dump_write(tcp)        ((tcp)->qual_flg & QUAL_WRITE)
 #define raw(tcp)       ((tcp)->qual_flg & QUAL_RAW)
 #define inject(tcp)    ((tcp)->qual_flg & QUAL_INJECT)
 #define filtered(tcp)  ((tcp)->flags & TCB_FILTERED)
diff --git a/filter.c b/filter.c
index d2bc1bfa..a7d93de7 100644
--- a/filter.c
+++ b/filter.c
@@ -40,6 +40,7 @@ static const struct filter_type {
        void (*free_priv_data)(void *);
 } filter_types[] = {
        FILTER_TYPE(syscall),
+       FILTER_TYPE(fd),
 };
 #undef FILTER_TYPE
 
diff --git a/filter.h b/filter.h
index c66bf443..886da1b4 100644
--- a/filter.h
+++ b/filter.h
@@ -78,6 +78,7 @@ free_ ## name ## _filter(void *)                              
        \
 /* End of DECL_FILTER definition. */
 
 DECL_FILTER(syscall);
+DECL_FILTER(fd);
 #undef DECL_FILTER
 
 #define DECL_FILTER_ACTION(name)                                       \
@@ -91,6 +92,8 @@ DECL_FILTER_ACTION(abbrev);
 DECL_FILTER_ACTION(verbose);
 DECL_FILTER_ACTION(inject);
 DECL_FILTER_ACTION(fault);
+DECL_FILTER_ACTION(read);
+DECL_FILTER_ACTION(write);
 #undef DECL_FILTER_ACTION
 
 #define DECL_FILTER_ACTION_PARSER(name)                                        
\
diff --git a/filter_action.c b/filter_action.c
index da329380..b403ca3a 100644
--- a/filter_action.c
+++ b/filter_action.c
@@ -47,6 +47,8 @@ static const struct filter_action_type {
        FILTER_ACTION_TYPE(raw,         2, QUAL_RAW,            null,   
is_traced),
        FILTER_ACTION_TYPE(abbrev,      2, QUAL_ABBREV,         null,   
is_traced),
        FILTER_ACTION_TYPE(verbose,     2, QUAL_VERBOSE,        null,   
is_traced),
+       FILTER_ACTION_TYPE(read,        2, QUAL_READ,           null,   
is_traced),
+       FILTER_ACTION_TYPE(write,       2, QUAL_WRITE,          null,   
is_traced),
 };
 #undef FILTER_ACTION_TYPE
 
diff --git a/filter_qualify.c b/filter_qualify.c
index ffeeb498..18efdd9d 100644
--- a/filter_qualify.c
+++ b/filter_qualify.c
@@ -31,8 +31,6 @@
 #include "number_set.h"
 #include "filter.h"
 
-struct number_set *read_set;
-struct number_set *write_set;
 struct number_set *signal_set;
 
 static int
@@ -179,17 +177,21 @@ parse_inject_common_args(char *str, struct inject_opts 
*const opts,
 static void
 qualify_read(const char *const str)
 {
-       if (!read_set)
-               read_set = alloc_number_set_array(1);
-       qualify_tokens(str, read_set, string_to_uint, "descriptor");
+       struct filter_action *action = find_or_add_action("read");
+       struct filter *filter = create_filter(action, "fd");
+
+       parse_filter(filter, str);
+       set_qualify_mode(action, 1);
 }
 
 static void
 qualify_write(const char *const str)
 {
-       if (!write_set)
-               write_set = alloc_number_set_array(1);
-       qualify_tokens(str, write_set, string_to_uint, "descriptor");
+       struct filter_action *action = find_or_add_action("write");
+       struct filter *filter = create_filter(action, "fd");
+
+       parse_filter(filter, str);
+       set_qualify_mode(action, 1);
 }
 
 static void
diff --git a/number_set.h b/number_set.h
index ec53bc1b..f3b9f312 100644
--- a/number_set.h
+++ b/number_set.h
@@ -59,8 +59,6 @@ alloc_number_set_array(unsigned int nmemb) ATTRIBUTE_MALLOC;
 extern void
 free_number_set_array(struct number_set *, unsigned int nmemb);
 
-extern struct number_set *read_set;
-extern struct number_set *write_set;
 extern struct number_set *signal_set;
 
 #endif /* !STRACE_NUMBER_SET_H */
diff --git a/syscall.c b/syscall.c
index b3893d00..96726497 100644
--- a/syscall.c
+++ b/syscall.c
@@ -425,7 +425,7 @@ dumpio(struct tcb *tcp)
        if (fd < 0)
                return;
 
-       if (is_number_in_set(fd, read_set)) {
+       if (dump_read(tcp)) {
                switch (tcp->s_ent->sen) {
                case SEN_read:
                case SEN_pread:
@@ -448,7 +448,7 @@ dumpio(struct tcb *tcp)
                        return;
                }
        }
-       if (is_number_in_set(fd, write_set)) {
+       if (dump_write(tcp)) {
                switch (tcp->s_ent->sen) {
                case SEN_write:
                case SEN_pwrite:
-- 
2.11.0


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Strace-devel mailing list
Strace-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/strace-devel

Reply via email to