]> granicus.if.org Git - strace/commitdiff
mpers: add support of conditionally compiled printers
authorDmitry V. Levin <ldv@altlinux.org>
Sat, 21 May 2016 22:53:06 +0000 (22:53 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Sat, 21 May 2016 22:53:06 +0000 (22:53 +0000)
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.

16 files changed:
.gitignore
Makefile.am
README-mpers
defs.h
fetch_seccomp_fprog.c
fetch_struct_flock.c
fetch_struct_statfs.c
mpers_type.h
print_mq_attr.c
print_msgbuf.c
print_sigevent.c
print_time.c
print_timex.c
printrusage.c
printsiginfo.c
v4l2.c

index f36094034974d0fbe520a33811af51758491a37f..122e197ff2adeaf72234e34017961061d784ba1a 100644 (file)
@@ -67,3 +67,4 @@ Makefile.in
 /native_printer_decls.h
 /native_printer_defs.h
 /printers.h
+/*.mpers.i
index 4b66b0453d672eb4508668c7ee23c24fc5de23d7..1585a7cf982cac47dd4ddd7e64e2c00464d36569 100644 (file)
@@ -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 $@
 
index 8ae418dff4f24d98f411ebe5dbc7044c841a9600..ad1ca1816a8392265134e267bbca2f353eedbbaf 100644 (file)
@@ -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_nameargs),
 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 f693da1a866f46c8a8061e414cac61a92d6fde4d..3cde1450eb5fdc8380da341425dc20770cdf75cd 100644 (file)
--- 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
index dbaf83a7113d7ae282a048502cd7398eecf61b87..d54b9796c8b47790ef959175f02e77ca81d802e0 100644 (file)
@@ -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;
index cd195e2f3040a7cdf5d97eb05b695f50f032281d..b5713f4f7ad9c6d78f0ec87a4a4a6857fded7303 100644 (file)
@@ -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;
index 7c8b088538a98ec522b7b565b2ee34cddaed516f..0717e4b2d9d6f2b921039c2ca8b234dda6ac1519 100644 (file)
@@ -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;
 
index adbefd57831eb4b86f131171b7f9ad4a5ff9b56e..4ce569bb3fc75b24f09d6372d45259627c1590cb 100644 (file)
@@ -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
index a43d4376815e7b23c83cfbfada978e7c604df233..18078346a119724f513e4cb89cf79269b1b49c44 100644 (file)
@@ -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, printmqattrstruct tcb *tcp, const long addr)
 {
 #if defined HAVE_MQUEUE_H || defined HAVE_LINUX_MQUEUE_H
        mq_attr_t attr;
index c7e87e495f64578ab83653f971ef548aec597403..68d8741be045d5828dce7e9c14e30ea9f50d988a 100644 (file)
@@ -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;
 
index f8eb8a0f4765bec2e8cb0007bf378875fcd9ca76..1c2b17486b2073d86d36c43f8113b3e88a1bac68 100644 (file)
@@ -35,7 +35,7 @@
 #include <signal.h>
 #include "xlat/sigev_value.h"
 
-MPERS_PRINTER_DECL(void, print_sigevent)(struct tcb *tcp, const long addr)
+MPERS_PRINTER_DECL(void, print_sigeventstruct tcb *tcp, const long addr)
 {
        struct_sigevent sev;
 
index dddb3f16a6980f7547b98cfd93c764caec7a7610..500ce8e5b1683eb52ef5ba3c18f8793688e629ae 100644 (file)
@@ -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];
 
index 4eac54df8976166cc41486e78a5533b6a6449707..ad6a7114c1a91f0c1f491426ab5f3abfcf23b15d 100644 (file)
@@ -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_timexstruct tcb *tcp, const long addr)
 {
        struct_timex tx;
 
index be56e66ff9c56020d1d7218befa0b209636699c8..0375f8fd8f617569d21142e3546d5a928f0c2383 100644 (file)
@@ -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, printrusagestruct tcb *tcp, long addr)
 {
        rusage_t ru;
 
index 78508df31abdb7b5adb2e16056d428686a9ca5e2..a14ebb49012452d6997fb1f31a93d233712ffdb3 100644 (file)
@@ -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 ab9a69c6df00fecf438b30d6d21306c582a2f84b..c0cda21c4a73a121a24fd6fb6b032db1f5206840 100644 (file)
--- 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;