2 * Copyright (c) 2015-2017 Dmitry V. Levin <ldv@altlinux.org>
3 * Copyright (c) 2016-2018 The strace developers.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include DEF_MPERS_TYPE(timeval_t)
33 typedef struct timeval timeval_t;
39 static const char timeval_fmt[] = "{tv_sec=%lld, tv_usec=%llu}";
42 print_timeval_t(const timeval_t *t)
44 tprintf(timeval_fmt, (long long) t->tv_sec,
45 zero_extend_signed_to_ull(t->tv_usec));
49 print_timeval_t_utime(const timeval_t *t)
52 tprints_comment(sprinttime_usec(t->tv_sec,
53 zero_extend_signed_to_ull(t->tv_usec)));
56 MPERS_PRINTER_DECL(void, print_struct_timeval, const void *arg)
61 MPERS_PRINTER_DECL(bool, print_struct_timeval_data_size,
62 const void *arg, const size_t size)
64 if (size < sizeof(timeval_t)) {
73 MPERS_PRINTER_DECL(void, print_timeval,
74 struct tcb *const tcp, const kernel_ulong_t addr)
78 if (umove_or_printaddr(tcp, addr, &t))
84 MPERS_PRINTER_DECL(void, print_timeval_utimes,
85 struct tcb *const tcp, const kernel_ulong_t addr)
89 if (umove_or_printaddr(tcp, addr, &t))
93 print_timeval_t_utime(&t[0]);
95 print_timeval_t_utime(&t[1]);
99 MPERS_PRINTER_DECL(const char *, sprint_timeval,
100 struct tcb *const tcp, const kernel_ulong_t addr)
103 static char buf[sizeof(timeval_fmt) + 3 * sizeof(t)];
107 } else if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)) ||
108 umove(tcp, addr, &t)) {
109 xsprintf(buf, "%#" PRI_klx, addr);
111 xsprintf(buf, timeval_fmt,
112 (long long) t.tv_sec,
113 zero_extend_signed_to_ull(t.tv_usec));
119 MPERS_PRINTER_DECL(void, print_itimerval,
120 struct tcb *const tcp, const kernel_ulong_t addr)
124 if (umove_or_printaddr(tcp, addr, &t))
127 tprints("{it_interval=");
128 print_timeval_t(&t[0]);
129 tprints(", it_value=");
130 print_timeval_t(&t[1]);
137 print_timeval32_t(const timeval32_t *t)
139 tprintf(timeval_fmt, (long long) t->tv_sec,
140 zero_extend_signed_to_ull(t->tv_usec));
144 print_timeval32_t_utime(const timeval32_t *t)
146 print_timeval32_t(t);
147 tprints_comment(sprinttime_usec(t->tv_sec,
148 zero_extend_signed_to_ull(t->tv_usec)));
152 print_timeval32(struct tcb *const tcp, const kernel_ulong_t addr)
156 if (umove_or_printaddr(tcp, addr, &t))
159 print_timeval32_t(&t);
163 print_timeval32_utimes(struct tcb *const tcp, const kernel_ulong_t addr)
167 if (umove_or_printaddr(tcp, addr, &t))
171 print_timeval32_t_utime(&t[0]);
173 print_timeval32_t_utime(&t[1]);
178 print_itimerval32(struct tcb *const tcp, const kernel_ulong_t addr)
182 if (umove_or_printaddr(tcp, addr, &t))
185 tprints("{it_interval=");
186 print_timeval32_t(&t[0]);
187 tprints(", it_value=");
188 print_timeval32_t(&t[1]);
193 sprint_timeval32(struct tcb *const tcp, const kernel_ulong_t addr)
196 static char buf[sizeof(timeval_fmt) + 3 * sizeof(t)];
200 } else if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)) ||
201 umove(tcp, addr, &t)) {
202 xsprintf(buf, "%#" PRI_klx, addr);
204 xsprintf(buf, timeval_fmt,
205 (long long) t.tv_sec,
206 zero_extend_signed_to_ull(t.tv_usec));