Introduce macros.h
Introduce a separate header file for generic macros shared between strace and its tests. Start this unification with ARRAY_SIZE macro. * defs.h: Include "macros.h". (ARRAY_SIZE): Move ... * macros.h: ... to new file. * Makefile.am (strace_SOURCES): Add it. * tests/tests.h: Include "macros.h". (ARRAY_SIZE): Remove. All callers updated.
This commit is contained in:
parent
5f4842dee1
commit
38198609df
@ -159,6 +159,7 @@ strace_SOURCES = \
|
||||
lookup_dcookie.c \
|
||||
loop.c \
|
||||
lseek.c \
|
||||
macros.h \
|
||||
mem.c \
|
||||
membarrier.c \
|
||||
memfd_create.c \
|
||||
|
5
defs.h
5
defs.h
@ -54,8 +54,9 @@
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "kernel_types.h"
|
||||
#include "mpers_type.h"
|
||||
#include "gcc_compat.h"
|
||||
#include "macros.h"
|
||||
#include "mpers_type.h"
|
||||
#include "sysent.h"
|
||||
|
||||
#ifndef HAVE_STRERROR
|
||||
@ -75,8 +76,6 @@ extern char *stpcpy(char *dst, const char *src);
|
||||
(offsetof(type, member) + sizeof(((type *)NULL)->member))
|
||||
#endif
|
||||
|
||||
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]) + MUST_BE_ARRAY(a))
|
||||
|
||||
/* macros */
|
||||
#ifndef MAX
|
||||
# define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||
|
35
macros.h
Normal file
35
macros.h
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2001-2017 The strace developers.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef STRACE_MACROS_H
|
||||
#define STRACE_MACROS_H
|
||||
|
||||
#include "gcc_compat.h"
|
||||
|
||||
#define ARRAY_SIZE(a_) (sizeof(a_) / sizeof((a_)[0]) + MUST_BE_ARRAY(a_))
|
||||
|
||||
#endif /* !STRACE_MACROS_H */
|
21
tests/mmsg.c
21
tests/mmsg.c
@ -113,14 +113,16 @@ main(void)
|
||||
" | 00000 %-49s %-16s |\n",
|
||||
w0_c, LENGTH_OF(w0_c),
|
||||
w1_c, LENGTH_OF(w1_c),
|
||||
ARRAY_SIZE(w0_iov_),
|
||||
(unsigned int) ARRAY_SIZE(w0_iov_),
|
||||
LENGTH_OF(w0_c) + LENGTH_OF(w1_c),
|
||||
w2_c, LENGTH_OF(w2_c), ARRAY_SIZE(w1_iov_),
|
||||
w2_c, LENGTH_OF(w2_c), (unsigned int) ARRAY_SIZE(w1_iov_),
|
||||
LENGTH_OF(w2_c),
|
||||
n_w_mmh, r,
|
||||
ARRAY_SIZE(w0_iov_), LENGTH_OF(w0_c), w0_d, w0_c,
|
||||
(unsigned int) ARRAY_SIZE(w0_iov_),
|
||||
LENGTH_OF(w0_c), w0_d, w0_c,
|
||||
LENGTH_OF(w1_c), w1_d, w1_c,
|
||||
ARRAY_SIZE(w1_iov_), LENGTH_OF(w2_c), w2_d, w2_c);
|
||||
(unsigned int) ARRAY_SIZE(w1_iov_),
|
||||
LENGTH_OF(w2_c), w2_d, w2_c);
|
||||
|
||||
const unsigned int w_len =
|
||||
LENGTH_OF(w0_c) + LENGTH_OF(w1_c) + LENGTH_OF(w2_c);
|
||||
@ -184,11 +186,14 @@ main(void)
|
||||
" = %u buffers in vector 1\n"
|
||||
" * %u bytes in buffer 0\n"
|
||||
" | 00000 %-49s %-16s |\n",
|
||||
r0_c, r_len, ARRAY_SIZE(r0_iov_), LENGTH_OF(r0_c),
|
||||
r1_c, r_len, r_len, ARRAY_SIZE(r1_iov_), LENGTH_OF(r1_c),
|
||||
r0_c, r_len, (unsigned int) ARRAY_SIZE(r0_iov_),
|
||||
LENGTH_OF(r0_c), r1_c, r_len, r_len,
|
||||
(unsigned int) ARRAY_SIZE(r1_iov_), LENGTH_OF(r1_c),
|
||||
n_r_mmh, r,
|
||||
ARRAY_SIZE(r0_iov_), LENGTH_OF(r0_c), r0_d, r0_c,
|
||||
ARRAY_SIZE(r1_iov_), LENGTH_OF(r1_c), r1_d, r1_c);
|
||||
(unsigned int) ARRAY_SIZE(r0_iov_), LENGTH_OF(r0_c),
|
||||
r0_d, r0_c,
|
||||
(unsigned int) ARRAY_SIZE(r1_iov_), LENGTH_OF(r1_c),
|
||||
r1_d, r1_c);
|
||||
|
||||
tprintf("+++ exited with 0 +++\n");
|
||||
return 0;
|
||||
|
12
tests/poll.c
12
tests/poll.c
@ -194,7 +194,8 @@ main(int ac, char **av)
|
||||
tprintf("poll(");
|
||||
print_pollfd_array_entering(tail_fds0, ARRAY_SIZE(pfds0),
|
||||
ARRAY_SIZE(pfds0), abbrev);
|
||||
tprintf(", %u, %d) = %d (", ARRAY_SIZE(pfds0), timeout, rc);
|
||||
tprintf(", %u, %d) = %d (",
|
||||
(unsigned int) ARRAY_SIZE(pfds0), timeout, rc);
|
||||
print_pollfd_array_exiting(tail_fds0, ARRAY_SIZE(pfds0), abbrev);
|
||||
tprintf(")\n");
|
||||
|
||||
@ -207,7 +208,8 @@ main(int ac, char **av)
|
||||
tprintf("poll(");
|
||||
print_pollfd_array_entering(tail_fds0, ARRAY_SIZE(pfds0),
|
||||
ARRAY_SIZE(pfds0), abbrev);
|
||||
tprintf(", %u, %d) = %d (", ARRAY_SIZE(pfds0), timeout, rc);
|
||||
tprintf(", %u, %d) = %d (",
|
||||
(unsigned int) ARRAY_SIZE(pfds0), timeout, rc);
|
||||
print_pollfd_array_exiting(tail_fds0, ARRAY_SIZE(pfds0), abbrev);
|
||||
tprintf(")\n");
|
||||
|
||||
@ -219,7 +221,8 @@ main(int ac, char **av)
|
||||
tprintf("poll(");
|
||||
print_pollfd_array_entering(tail_fds0, ARRAY_SIZE(pfds0),
|
||||
ARRAY_SIZE(pfds0), abbrev);
|
||||
tprintf(", %u, %d) = %d (", ARRAY_SIZE(pfds0), timeout, rc);
|
||||
tprintf(", %u, %d) = %d (",
|
||||
(unsigned int) ARRAY_SIZE(pfds0), timeout, rc);
|
||||
print_pollfd_array_exiting(tail_fds0, ARRAY_SIZE(pfds0), abbrev);
|
||||
tprintf(")\n");
|
||||
|
||||
@ -234,7 +237,8 @@ main(int ac, char **av)
|
||||
tprintf("poll(");
|
||||
print_pollfd_array_entering(tail_fds1, ARRAY_SIZE(pfds1),
|
||||
ARRAY_SIZE(pfds1), abbrev);
|
||||
tprintf(", %u, %d) = %d (Timeout)\n", ARRAY_SIZE(pfds1), timeout, rc);
|
||||
tprintf(", %u, %d) = %d (Timeout)\n",
|
||||
(unsigned int) ARRAY_SIZE(pfds1), timeout, rc);
|
||||
|
||||
const void *const efault = tail_fds0 + ARRAY_SIZE(pfds0);
|
||||
rc = syscall(__NR_poll, efault, 1, 0);
|
||||
|
@ -121,7 +121,7 @@ main(void)
|
||||
" * %u bytes in buffer 2\n"
|
||||
" | 00000 %-49s %-16s |\n",
|
||||
w0_c, LENGTH_OF(w0_c), w1_c, LENGTH_OF(w1_c),
|
||||
w2_c, LENGTH_OF(w2_c), ARRAY_SIZE(w_iov_), w_len,
|
||||
w2_c, LENGTH_OF(w2_c), (unsigned int) ARRAY_SIZE(w_iov_), w_len,
|
||||
LENGTH_OF(w0_c), w0_d, w0_c,
|
||||
LENGTH_OF(w1_c), w1_d, w1_c, LENGTH_OF(w2_c), w2_d, w2_c);
|
||||
|
||||
@ -142,7 +142,8 @@ main(void)
|
||||
tprintf("preadv(0, [{iov_base=\"%s\", iov_len=%u}], %u, 0) = %u\n"
|
||||
" * %u bytes in buffer 0\n"
|
||||
" | 00000 %-49s %-16s |\n",
|
||||
r0_c, r_len, ARRAY_SIZE(r0_iov_), r_len, r_len, r0_d, r0_c);
|
||||
r0_c, r_len, (unsigned int) ARRAY_SIZE(r0_iov_),
|
||||
r_len, r_len, r0_d, r0_c);
|
||||
|
||||
void *r1 = tail_alloc(r_len);
|
||||
void *r2 = tail_alloc(w_len);
|
||||
@ -166,7 +167,7 @@ main(void)
|
||||
", {iov_base=\"\", iov_len=%u}], %u, %u) = %u\n"
|
||||
" * %u bytes in buffer 0\n"
|
||||
" | 00000 %-49s %-16s |\n",
|
||||
r1_c, r_len, w_len, ARRAY_SIZE(r1_iov_),
|
||||
r1_c, r_len, w_len, (unsigned int) ARRAY_SIZE(r1_iov_),
|
||||
r_len, w_len - r_len,
|
||||
w_len - r_len, r1_d, r1_c);
|
||||
close(0);
|
||||
|
@ -125,7 +125,7 @@ main(void)
|
||||
perror_msg_and_fail("preadv: expected %u, returned %ld",
|
||||
r_len, rc);
|
||||
printf("preadv(%d, [{iov_base=\"%s\", iov_len=%u}], %u, 0) = %u\n",
|
||||
fd, r0_c, r_len, ARRAY_SIZE(r0_iov_), r_len);
|
||||
fd, r0_c, r_len, (unsigned int) ARRAY_SIZE(r0_iov_), r_len);
|
||||
|
||||
void *r1 = tail_alloc(r_len);
|
||||
void *r2 = tail_alloc(LENGTH_OF(w));
|
||||
@ -147,8 +147,9 @@ main(void)
|
||||
(int) LENGTH_OF(w) - r_len, rc);
|
||||
printf("preadv(%d, [{iov_base=\"%s\", iov_len=%u}"
|
||||
", {iov_base=\"\", iov_len=%u}], %u, %u) = %u\n",
|
||||
fd, r1_c, r_len, LENGTH_OF(w), ARRAY_SIZE(r1_iov_),
|
||||
r_len, LENGTH_OF(w) - r_len);
|
||||
fd, r1_c, r_len, LENGTH_OF(w),
|
||||
(unsigned int) ARRAY_SIZE(r1_iov_),
|
||||
r_len, LENGTH_OF(w) - r_len);
|
||||
|
||||
puts("+++ exited with 0 +++");
|
||||
return 0;
|
||||
|
@ -127,7 +127,7 @@ dumpio(void)
|
||||
" * %u bytes in buffer 2\n"
|
||||
" | 00000 %-49s %-16s |\n",
|
||||
w0_c, LENGTH_OF(w0_c), w1_c, LENGTH_OF(w1_c),
|
||||
w2_c, LENGTH_OF(w2_c), ARRAY_SIZE(w_iov_), w_len,
|
||||
w2_c, LENGTH_OF(w2_c), (unsigned int) ARRAY_SIZE(w_iov_), w_len,
|
||||
LENGTH_OF(w0_c), w0_d, w0_c,
|
||||
LENGTH_OF(w1_c), w1_d, w1_c, LENGTH_OF(w2_c), w2_d, w2_c);
|
||||
|
||||
@ -148,7 +148,8 @@ dumpio(void)
|
||||
tprintf("preadv2(0, [{iov_base=\"%s\", iov_len=%u}], %u, 0, 0) = %u\n"
|
||||
" * %u bytes in buffer 0\n"
|
||||
" | 00000 %-49s %-16s |\n",
|
||||
r0_c, r_len, ARRAY_SIZE(r0_iov_), r_len, r_len, r0_d, r0_c);
|
||||
r0_c, r_len, (unsigned int) ARRAY_SIZE(r0_iov_),
|
||||
r_len, r_len, r0_d, r0_c);
|
||||
|
||||
void *r1 = tail_alloc(r_len);
|
||||
void *r2 = tail_alloc(w_len);
|
||||
@ -172,7 +173,7 @@ dumpio(void)
|
||||
", {iov_base=\"\", iov_len=%u}], %u, %u, 0) = %u\n"
|
||||
" * %u bytes in buffer 0\n"
|
||||
" | 00000 %-49s %-16s |\n",
|
||||
r1_c, r_len, w_len, ARRAY_SIZE(r1_iov_),
|
||||
r1_c, r_len, w_len, (unsigned int) ARRAY_SIZE(r1_iov_),
|
||||
r_len, w_len - r_len,
|
||||
w_len - r_len, r1_d, r1_c);
|
||||
close(0);
|
||||
|
@ -108,7 +108,7 @@ main(void)
|
||||
" * %u bytes in buffer 2\n"
|
||||
" | 00000 %-49s %-16s |\n",
|
||||
fds[1], w0_c, LENGTH_OF(w0_c), w1_c, LENGTH_OF(w1_c),
|
||||
w2_c, LENGTH_OF(w2_c), ARRAY_SIZE(w_iov_), w_len,
|
||||
w2_c, LENGTH_OF(w2_c), (unsigned int) ARRAY_SIZE(w_iov_), w_len,
|
||||
LENGTH_OF(w0_c), w0_d, w0_c,
|
||||
LENGTH_OF(w1_c), w1_d, w1_c, LENGTH_OF(w2_c), w2_d, w2_c);
|
||||
|
||||
@ -126,8 +126,8 @@ main(void)
|
||||
tprintf("readv(%d, [{iov_base=\"%s\", iov_len=%u}], %u) = %u\n"
|
||||
" * %u bytes in buffer 0\n"
|
||||
" | 00000 %-49s %-16s |\n",
|
||||
fds[0],
|
||||
r0_c, r_len, ARRAY_SIZE(r0_iov_), r_len, r_len, r0_d, r0_c);
|
||||
fds[0], r0_c, r_len, (unsigned int) ARRAY_SIZE(r0_iov_),
|
||||
r_len, r_len, r0_d, r0_c);
|
||||
|
||||
void *r1 = tail_alloc(r_len);
|
||||
void *r2 = tail_alloc(w_len);
|
||||
@ -148,8 +148,8 @@ main(void)
|
||||
", {iov_base=\"\", iov_len=%u}], %u) = %u\n"
|
||||
" * %u bytes in buffer 0\n"
|
||||
" | 00000 %-49s %-16s |\n",
|
||||
fds[0], r1_c, r_len, w_len, ARRAY_SIZE(r1_iov_), w_len - r_len,
|
||||
w_len - r_len, r1_d, r1_c);
|
||||
fds[0], r1_c, r_len, w_len, (unsigned int) ARRAY_SIZE(r1_iov_),
|
||||
w_len - r_len, w_len - r_len, r1_d, r1_c);
|
||||
close(fds[0]);
|
||||
|
||||
tprintf("+++ exited with 0 +++\n");
|
||||
|
@ -100,7 +100,7 @@ main(void)
|
||||
w0_c, LENGTH_OF(w0_c),
|
||||
w1_c, LENGTH_OF(w1_c),
|
||||
w2_c, LENGTH_OF(w2_c),
|
||||
ARRAY_SIZE(w_iov_), w_len,
|
||||
(unsigned int) ARRAY_SIZE(w_iov_), w_len,
|
||||
LENGTH_OF(w0_c), w0_d, w0_c,
|
||||
LENGTH_OF(w1_c), w1_d, w1_c,
|
||||
LENGTH_OF(w2_c), w2_d, w2_c);
|
||||
@ -127,7 +127,8 @@ main(void)
|
||||
", msg_controllen=0, msg_flags=0}, 0) = %u\n"
|
||||
" * %u bytes in buffer 0\n"
|
||||
" | 00000 %-49s %-16s |\n",
|
||||
r0_c, r_len, ARRAY_SIZE(r0_iov_), r_len, r_len, r0_d, r0_c);
|
||||
r0_c, r_len, (unsigned int) ARRAY_SIZE(r0_iov_),
|
||||
r_len, r_len, r0_d, r0_c);
|
||||
|
||||
void *r1 = tail_alloc(r_len);
|
||||
void *r2 = tail_alloc(w_len);
|
||||
@ -151,8 +152,8 @@ main(void)
|
||||
", msg_iovlen=%u, msg_controllen=0, msg_flags=0}, 0) = %u\n"
|
||||
" * %u bytes in buffer 0\n"
|
||||
" | 00000 %-49s %-16s |\n",
|
||||
r1_c, r_len, w_len, ARRAY_SIZE(r1_iov_), w_len - r_len,
|
||||
w_len - r_len, r1_d, r1_c);
|
||||
r1_c, r_len, w_len, (unsigned int) ARRAY_SIZE(r1_iov_),
|
||||
w_len - r_len, w_len - r_len, r1_d, r1_c);
|
||||
close(0);
|
||||
|
||||
tprintf("+++ exited with 0 +++\n");
|
||||
|
@ -36,6 +36,7 @@
|
||||
# include <sys/types.h>
|
||||
# include "kernel_types.h"
|
||||
# include "gcc_compat.h"
|
||||
# include "macros.h"
|
||||
|
||||
/*
|
||||
* The printf-like function to use in header files
|
||||
@ -198,7 +199,6 @@ f8ill_ptr_to_kulong(const void *const ptr)
|
||||
? F8ILL_KULONG_MASK | uptr : (kernel_ulong_t) uptr;
|
||||
}
|
||||
|
||||
# define ARRAY_SIZE(arg) ((unsigned int) (sizeof(arg) / sizeof((arg)[0])))
|
||||
# define LENGTH_OF(arg) ((unsigned int) sizeof(arg) - 1)
|
||||
|
||||
/* Zero-extend a signed integer type to unsigned long long. */
|
||||
|
@ -86,7 +86,7 @@ main(void)
|
||||
" * %u bytes in buffer 2\n"
|
||||
" | 00000 %-49s %-16s |\n",
|
||||
w0_c, LENGTH_OF(w0_c), w1_c, LENGTH_OF(w1_c),
|
||||
w2_c, LENGTH_OF(w2_c), ARRAY_SIZE(iov_),
|
||||
w2_c, LENGTH_OF(w2_c), (unsigned int) ARRAY_SIZE(iov_),
|
||||
"SPLICE_F_NONBLOCK", len,
|
||||
LENGTH_OF(w0_c), w0_d, w0_c,
|
||||
LENGTH_OF(w1_c), w1_d, w1_c, LENGTH_OF(w2_c), w2_d, w2_c);
|
||||
|
Loading…
x
Reference in New Issue
Block a user