From: Dmitry V. Levin Date: Sat, 21 May 2016 22:53:06 +0000 (+0000) Subject: mpers: add support of conditionally compiled printers X-Git-Tag: v4.12~110 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a8fce09e344a644aa0279f0efe54e4faeb64ca29;p=strace mpers: add support of conditionally compiled printers We used to declare and define all printers marked with MPERS_PRINTER_DECL, including ifdef'ed ones. That approach left us no way to conditionally compile mpersified printers, which was not a problem until btrfs ioctls appeared on the horizon. With this change, those mpersified printers that are not going to be compiled are also won't be declared and won't be added to struct_printers. This is implemented by filtering all source files containing MPERS_PRINTER_DECL markers through CPP. As a nice side effect, this also lifts an ugly requirement of writing all MPERS_PRINTER_DECL declarations in a single line. * README-mpers: Update description of MPERS_PRINTER_DECL syntax. * defs.h [IN_MPERS_BOOTSTRAP] (MPERS_PRINTER_DECL): Turn into a recursive variadic macro. [!IN_MPERS_BOOTSTRAP] (MPERS_PRINTER_DECL): Turn into a variadic macro. All callers changed. * Makefile.am (mpers_preproc_files, mpers_printer_decl_pattern): New variables. (CLEANFILES): Add $(mpers_preproc_files). (%.c.mpers.i): New rule. (printers.h, %_printer_decls.h, %_printer_defs.h): Use mpers_preproc_files instead of srcdir_mpers_source_files, use mpers_printer_decl_pattern. * .gitignore: Add /*.mpers.i. --- diff --git a/.gitignore b/.gitignore index f3609403..122e197f 100644 --- a/.gitignore +++ b/.gitignore @@ -67,3 +67,4 @@ Makefile.in /native_printer_decls.h /native_printer_defs.h /printers.h +/*.mpers.i diff --git a/Makefile.am b/Makefile.am index 4b66b045..1585a7cf 100644 --- a/Makefile.am +++ b/Makefile.am @@ -718,13 +718,14 @@ ioctls_all%.h: $(srcdir)/$(OS)/$(ARCH)/ioctls_inc%.h $(srcdir)/$(OS)/$(ARCH)/ioc BUILT_SOURCES = $(ioctl_redefs_h) $(ioctlent_h) \ native_printer_decls.h native_printer_defs.h printers.h sen.h sys_func.h .version -CLEANFILES = $(ioctl_redefs_h) $(ioctlent_h) \ +CLEANFILES = $(ioctl_redefs_h) $(ioctlent_h) $(mpers_preproc_files) \ native_printer_decls.h native_printer_defs.h printers.h sen.h sys_func.h DISTCLEANFILES = gnu/stubs-32.h gnu/stubs-x32.h # defines mpers_source_files include mpers.am srcdir_mpers_source_files = $(patsubst %,$(srcdir)/%,$(mpers_source_files)) +mpers_preproc_files = $(mpers_source_files:.c=.c.mpers.i) mpers_NAME = mpers_PREFIX = $(mpers_NAME)_ @@ -764,28 +765,36 @@ m%_funcs.h: $(srcdir_mpers_source_files) # printers -printers.h: $(srcdir_mpers_source_files) +%.c.mpers.i: $(srcdir)/%.c + $(CPP) -P $(mpers_sh_opts) -DIN_MPERS_BOOTSTRAP $< -o $@ + +mpers_printer_decl_pattern = ^MPERS_PRINTER_DECL(\([^,)]\+\),[[:space:]]*\([^,)]\+\),[[:space:]]*\([^)]\+\))$$ + +printers.h: $(mpers_preproc_files) echo '/* Generated by Makefile from $^; do not edit. */' > $@-t echo 'typedef struct {' >> $@-t for f in $^; do \ - sed -n 's/^MPERS_PRINTER_DECL(\([^,]\+\),[[:space:]]*\([^)]\+\))\(.*\)/ \1 (*\2) \3;\n#define \2 MPERS_PRINTER_NAME(\2)\n/p' $$f || exit; \ + sed -n 's/$(mpers_printer_decl_pattern)/ \1 (*\2)(\3);\n#define \2 MPERS_PRINTER_NAME(\2)\n/p' $$f \ + || exit; \ done >> $@-t echo '} struct_printers;' >> $@-t echo 'extern const struct_printers *printers;' >> $@-t echo '#define MPERS_PRINTER_NAME(printer_name) printers->printer_name' >> $@-t mv $@-t $@ -%_printer_decls.h: $(srcdir_mpers_source_files) +%_printer_decls.h: $(mpers_preproc_files) echo '/* Generated by Makefile from $^; do not edit. */' > $@-t for f in $^; do \ - sed -n 's/^MPERS_PRINTER_DECL(\([^,]\+\),[[:space:]]*\([^)]\+\))\(.*\)/extern \1 $(mpers_PREFIX)\2\3;/p' $$f || exit; \ + sed -n 's/$(mpers_printer_decl_pattern)/extern \1 $(mpers_PREFIX)\2(\3);/p' $$f \ + || exit; \ done >> $@-t mv $@-t $@ -%_printer_defs.h: $(srcdir_mpers_source_files) +%_printer_defs.h: $(mpers_preproc_files) echo '/* Generated by Makefile from $^; do not edit. */' > $@-t for f in $^; do \ - sed -n 's/^MPERS_PRINTER_DECL(\([^,]\+\),[[:space:]]*\([^)]\+\))\(.*\)/\.\2 = $(mpers_PREFIX)\2,/p' $$f || exit; \ + sed -n 's/$(mpers_printer_decl_pattern)/\.\2 = $(mpers_PREFIX)\2,/p' $$f \ + || exit; \ done >> $@-t mv $@-t $@ diff --git a/README-mpers b/README-mpers index 8ae418df..ad1ca181 100644 --- a/README-mpers +++ b/README-mpers @@ -8,7 +8,7 @@ be included conditionally; (containing definitions of these types or other behaviour-affecting defines); * printers should be defined -as MPERS_PRINTER_DECL(return_type, function_name)(args), +as MPERS_PRINTER_DECL(return_type, function_name, args), inside files that include MPERS_DEFS these printers should be called as MPERS_FUNC_NAME(function_name)(args), in other files they should be called just as function_name(args). diff --git a/defs.h b/defs.h index f693da1a..3cde1450 100644 --- a/defs.h +++ b/defs.h @@ -795,11 +795,17 @@ extern unsigned nsignals; extern unsigned nioctlents; extern unsigned num_quals; -#if SUPPORTED_PERSONALITIES > 1 -# include "printers.h" -#else -# include "native_printer_decls.h" -#endif +#ifdef IN_MPERS_BOOTSTRAP +/* Transform multi-line MPERS_PRINTER_DECL statements to one-liners. */ +# define MPERS_PRINTER_DECL(type, name, ...) MPERS_PRINTER_DECL(type, name, __VA_ARGS__) +#else /* !IN_MPERS_BOOTSTRAP */ +# if SUPPORTED_PERSONALITIES > 1 +# include "printers.h" +# else +# include "native_printer_decls.h" +# endif +# define MPERS_PRINTER_DECL(type, name, ...) type MPERS_FUNC_NAME(name)(__VA_ARGS__) +#endif /* !IN_MPERS_BOOTSTRAP */ /* * If you need non-NULL sysent[scno].sys_func and sysent[scno].sys_name @@ -819,8 +825,6 @@ extern unsigned num_quals; #define SYS_FUNC(syscall_name) int SYS_FUNC_NAME(sys_ ## syscall_name)(struct tcb *tcp) -#define MPERS_PRINTER_DECL(type, name) type MPERS_FUNC_NAME(name) - /* * The kernel used to define 64-bit types on 64-bit systems on a per-arch * basis. Some architectures would use unsigned long and others would use diff --git a/fetch_seccomp_fprog.c b/fetch_seccomp_fprog.c index dbaf83a7..d54b9796 100644 --- a/fetch_seccomp_fprog.c +++ b/fetch_seccomp_fprog.c @@ -34,7 +34,8 @@ typedef struct seccomp_fprog seccomp_fprog_t; #include MPERS_DEFS -MPERS_PRINTER_DECL(bool, fetch_seccomp_fprog)(struct tcb *tcp, const long addr, void *p) +MPERS_PRINTER_DECL(bool, fetch_seccomp_fprog, + struct tcb *tcp, const long addr, void *p) { struct seccomp_fprog *pfp = p; seccomp_fprog_t mfp; diff --git a/fetch_struct_flock.c b/fetch_struct_flock.c index cd195e2f..b5713f4f 100644 --- a/fetch_struct_flock.c +++ b/fetch_struct_flock.c @@ -51,7 +51,8 @@ typedef struct_kernel_flock64 struct_flock64; && FLOCK_MEMBERS_EQ(type, l_len) \ && FLOCK_MEMBERS_EQ(type, l_pid)) -MPERS_PRINTER_DECL(bool, fetch_struct_flock)(struct tcb *tcp, const long addr, void *p) +MPERS_PRINTER_DECL(bool, fetch_struct_flock, + struct tcb *tcp, const long addr, void *p) { struct_kernel_flock64 *pfl = p; struct_flock mfl; @@ -70,7 +71,8 @@ MPERS_PRINTER_DECL(bool, fetch_struct_flock)(struct tcb *tcp, const long addr, v return true; } -MPERS_PRINTER_DECL(bool, fetch_struct_flock64)(struct tcb *tcp, const long addr, void *p) +MPERS_PRINTER_DECL(bool, fetch_struct_flock64, + struct tcb *tcp, const long addr, void *p) { struct_kernel_flock64 *pfl = p; struct_flock64 mfl; diff --git a/fetch_struct_statfs.c b/fetch_struct_statfs.c index 7c8b0885..0717e4b2 100644 --- a/fetch_struct_statfs.c +++ b/fetch_struct_statfs.c @@ -47,7 +47,8 @@ typedef struct statfs64 struct_statfs64; else \ dst = (unsigned long long) (src) -MPERS_PRINTER_DECL(bool, fetch_struct_statfs)(struct tcb *tcp, const long addr, struct strace_statfs *p) +MPERS_PRINTER_DECL(bool, fetch_struct_statfs, + struct tcb *tcp, const long addr, struct strace_statfs *p) { struct_statfs b; @@ -84,7 +85,9 @@ MPERS_PRINTER_DECL(bool, fetch_struct_statfs)(struct tcb *tcp, const long addr, # define COMPAT_STATFS64_PADDED_SIZE (sizeof(struct_statfs64) + 4) #endif -MPERS_PRINTER_DECL(bool, fetch_struct_statfs64)(struct tcb *tcp, const long addr, const unsigned long size, struct strace_statfs *p) +MPERS_PRINTER_DECL(bool, fetch_struct_statfs64, + struct tcb *tcp, const long addr, const unsigned long size, + struct strace_statfs *p) { struct_statfs64 b; diff --git a/mpers_type.h b/mpers_type.h index adbefd57..4ce569bb 100644 --- a/mpers_type.h +++ b/mpers_type.h @@ -39,5 +39,9 @@ #else # define MPERS_PREFIX # define DEF_MPERS_TYPE(args) "empty.h" -# define MPERS_DEFS "native_defs.h" +# if IN_MPERS_BOOTSTRAP +# define MPERS_DEFS "empty.h" +# else +# define MPERS_DEFS "native_defs.h" +# endif #endif diff --git a/print_mq_attr.c b/print_mq_attr.c index a43d4376..18078346 100644 --- a/print_mq_attr.c +++ b/print_mq_attr.c @@ -41,7 +41,7 @@ typedef struct mq_attr mq_attr_t; #include MPERS_DEFS -MPERS_PRINTER_DECL(void, printmqattr)(struct tcb *tcp, const long addr) +MPERS_PRINTER_DECL(void, printmqattr, struct tcb *tcp, const long addr) { #if defined HAVE_MQUEUE_H || defined HAVE_LINUX_MQUEUE_H mq_attr_t attr; diff --git a/print_msgbuf.c b/print_msgbuf.c index c7e87e49..68d8741b 100644 --- a/print_msgbuf.c +++ b/print_msgbuf.c @@ -38,7 +38,8 @@ typedef struct msgbuf msgbuf_t; #include MPERS_DEFS -MPERS_PRINTER_DECL(void, tprint_msgbuf)(struct tcb *tcp, const long addr, const unsigned long count) +MPERS_PRINTER_DECL(void, tprint_msgbuf, + struct tcb *tcp, const long addr, const unsigned long count) { msgbuf_t msg; diff --git a/print_sigevent.c b/print_sigevent.c index f8eb8a0f..1c2b1748 100644 --- a/print_sigevent.c +++ b/print_sigevent.c @@ -35,7 +35,7 @@ #include #include "xlat/sigev_value.h" -MPERS_PRINTER_DECL(void, print_sigevent)(struct tcb *tcp, const long addr) +MPERS_PRINTER_DECL(void, print_sigevent, struct tcb *tcp, const long addr) { struct_sigevent sev; diff --git a/print_time.c b/print_time.c index dddb3f16..500ce8e5 100644 --- a/print_time.c +++ b/print_time.c @@ -73,7 +73,8 @@ print_timeval_t(const timeval_t *t) tprintf(time_fmt, (intmax_t) t->tv_sec, (intmax_t) t->tv_usec); } -MPERS_PRINTER_DECL(void, print_timespec)(struct tcb *tcp, const long addr) +MPERS_PRINTER_DECL(void, print_timespec, + struct tcb *tcp, const long addr) { timespec_t t; @@ -83,7 +84,8 @@ MPERS_PRINTER_DECL(void, print_timespec)(struct tcb *tcp, const long addr) print_timespec_t(&t); } -MPERS_PRINTER_DECL(const char *, sprint_timespec)(struct tcb *tcp, const long addr) +MPERS_PRINTER_DECL(const char *, sprint_timespec, + struct tcb *tcp, const long addr) { timespec_t t; static char buf[sizeof(time_fmt) + 3 * sizeof(t)]; @@ -101,7 +103,8 @@ MPERS_PRINTER_DECL(const char *, sprint_timespec)(struct tcb *tcp, const long ad return buf; } -MPERS_PRINTER_DECL(void, print_timespec_utime_pair)(struct tcb *tcp, const long addr) +MPERS_PRINTER_DECL(void, print_timespec_utime_pair, + struct tcb *tcp, const long addr) { timespec_t t[2]; @@ -115,7 +118,8 @@ MPERS_PRINTER_DECL(void, print_timespec_utime_pair)(struct tcb *tcp, const long tprints("]"); } -MPERS_PRINTER_DECL(void, print_itimerspec)(struct tcb *tcp, const long addr) +MPERS_PRINTER_DECL(void, print_itimerspec, + struct tcb *tcp, const long addr) { timespec_t t[2]; @@ -129,7 +133,8 @@ MPERS_PRINTER_DECL(void, print_itimerspec)(struct tcb *tcp, const long addr) tprints("}"); } -MPERS_PRINTER_DECL(void, print_timeval)(struct tcb *tcp, const long addr) +MPERS_PRINTER_DECL(void, print_timeval, + struct tcb *tcp, const long addr) { timeval_t t; @@ -139,7 +144,8 @@ MPERS_PRINTER_DECL(void, print_timeval)(struct tcb *tcp, const long addr) print_timeval_t(&t); } -MPERS_PRINTER_DECL(void, print_timeval_pair)(struct tcb *tcp, const long addr) +MPERS_PRINTER_DECL(void, print_timeval_pair, + struct tcb *tcp, const long addr) { timeval_t t[2]; @@ -153,7 +159,8 @@ MPERS_PRINTER_DECL(void, print_timeval_pair)(struct tcb *tcp, const long addr) tprints("]"); } -MPERS_PRINTER_DECL(const char *, sprint_timeval)(struct tcb *tcp, const long addr) +MPERS_PRINTER_DECL(const char *, sprint_timeval, + struct tcb *tcp, const long addr) { timeval_t t; static char buf[sizeof(time_fmt) + 3 * sizeof(t)]; @@ -171,7 +178,8 @@ MPERS_PRINTER_DECL(const char *, sprint_timeval)(struct tcb *tcp, const long add return buf; } -MPERS_PRINTER_DECL(void, print_itimerval)(struct tcb *tcp, const long addr) +MPERS_PRINTER_DECL(void, print_itimerval, + struct tcb *tcp, const long addr) { timeval_t t[2]; diff --git a/print_timex.c b/print_timex.c index 4eac54df..ad6a7114 100644 --- a/print_timex.c +++ b/print_timex.c @@ -40,7 +40,7 @@ typedef struct timex struct_timex; #include "xlat/adjtimex_modes.h" #include "xlat/adjtimex_status.h" -MPERS_PRINTER_DECL(int, print_timex)(struct tcb *tcp, const long addr) +MPERS_PRINTER_DECL(int, print_timex, struct tcb *tcp, const long addr) { struct_timex tx; diff --git a/printrusage.c b/printrusage.c index be56e66f..0375f8fd 100644 --- a/printrusage.c +++ b/printrusage.c @@ -37,7 +37,7 @@ typedef struct rusage rusage_t; #include MPERS_DEFS -MPERS_PRINTER_DECL(void, printrusage)(struct tcb *tcp, long addr) +MPERS_PRINTER_DECL(void, printrusage, struct tcb *tcp, long addr) { rusage_t ru; diff --git a/printsiginfo.c b/printsiginfo.c index 78508df3..a14ebb49 100644 --- a/printsiginfo.c +++ b/printsiginfo.c @@ -228,7 +228,8 @@ printsiginfo(const siginfo_t *sip) tprints("}"); } -MPERS_PRINTER_DECL(void, printsiginfo_at)(struct tcb *tcp, long addr) +MPERS_PRINTER_DECL(void, printsiginfo_at, + struct tcb *tcp, long addr) { siginfo_t si; @@ -243,7 +244,8 @@ print_siginfo_t(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data) return true; } -MPERS_PRINTER_DECL(void, print_siginfo_array)(struct tcb *tcp, unsigned long addr, unsigned long len) +MPERS_PRINTER_DECL(void, print_siginfo_array, + struct tcb *tcp, unsigned long addr, unsigned long len) { siginfo_t si; diff --git a/v4l2.c b/v4l2.c index ab9a69c6..c0cda21c 100644 --- a/v4l2.c +++ b/v4l2.c @@ -846,7 +846,8 @@ print_v4l2_create_buffers(struct tcb *tcp, const long arg) } #endif /* VIDIOC_CREATE_BUFS */ -MPERS_PRINTER_DECL(int, v4l2_ioctl)(struct tcb *tcp, const unsigned int code, const long arg) +MPERS_PRINTER_DECL(int, v4l2_ioctl, + struct tcb *tcp, const unsigned int code, const long arg) { if (!verbose(tcp)) return RVAL_DECODED;