2 * Copyright (c) 2015 Dmitry V. Levin <ldv@altlinux.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include DEF_MPERS_TYPE(time_t)
31 #include DEF_MPERS_TYPE(timespec_t)
32 #include DEF_MPERS_TYPE(timeval_t)
34 typedef struct timespec timespec_t;
35 typedef struct timeval timeval_t;
40 # define UTIME_NOW ((1l << 30) - 1l)
43 # define UTIME_OMIT ((1l << 30) - 2l)
46 static const char time_fmt[] = "{%jd, %jd}";
49 print_timespec_t(const timespec_t *t)
51 tprintf(time_fmt, (intmax_t) t->tv_sec, (intmax_t) t->tv_nsec);
55 print_timespec_t_utime(const timespec_t *t)
62 tprints("UTIME_OMIT");
71 print_timeval_t(const timeval_t *t)
73 tprintf(time_fmt, (intmax_t) t->tv_sec, (intmax_t) t->tv_usec);
76 MPERS_PRINTER_DECL(void, print_timespec)(struct tcb *tcp, const long addr)
80 if (umove_or_printaddr(tcp, addr, &t))
86 MPERS_PRINTER_DECL(const char *, sprint_timespec)(struct tcb *tcp, const long addr)
89 static char buf[sizeof(time_fmt) + 3 * sizeof(t)];
93 } else if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)) ||
94 umove(tcp, addr, &t)) {
95 snprintf(buf, sizeof(buf), "%#lx", addr);
97 snprintf(buf, sizeof(buf), time_fmt,
98 (intmax_t) t.tv_sec, (intmax_t) t.tv_nsec);
104 MPERS_PRINTER_DECL(void, print_timespec_utime_pair)(struct tcb *tcp, const long addr)
108 if (umove_or_printaddr(tcp, addr, &t))
112 print_timespec_t_utime(&t[0]);
114 print_timespec_t_utime(&t[1]);
118 MPERS_PRINTER_DECL(void, print_itimerspec)(struct tcb *tcp, const long addr)
122 if (umove_or_printaddr(tcp, addr, &t))
125 tprints("{it_interval=");
126 print_timespec_t(&t[0]);
127 tprints(", it_value=");
128 print_timespec_t(&t[1]);
132 MPERS_PRINTER_DECL(void, print_timeval)(struct tcb *tcp, const long addr)
136 if (umove_or_printaddr(tcp, addr, &t))
142 MPERS_PRINTER_DECL(void, print_timeval_pair)(struct tcb *tcp, const long addr)
146 if (umove_or_printaddr(tcp, addr, &t))
150 print_timeval_t(&t[0]);
152 print_timeval_t(&t[1]);
156 MPERS_PRINTER_DECL(const char *, sprint_timeval)(struct tcb *tcp, const long addr)
159 static char buf[sizeof(time_fmt) + 3 * sizeof(t)];
163 } else if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)) ||
164 umove(tcp, addr, &t)) {
165 snprintf(buf, sizeof(buf), "%#lx", addr);
167 snprintf(buf, sizeof(buf), time_fmt,
168 (intmax_t) t.tv_sec, (intmax_t) t.tv_usec);
174 MPERS_PRINTER_DECL(void, print_itimerval)(struct tcb *tcp, const long addr)
178 if (umove_or_printaddr(tcp, addr, &t))
181 tprints("{it_interval=");
182 print_timeval_t(&t[0]);
183 tprints(", it_value=");
184 print_timeval_t(&t[1]);
193 if (!umove_or_printaddr(tcp, tcp->u_arg[0], &t))
194 tprintf("[%jd]", (intmax_t) t);
207 print_timeval32_t(const timeval32_t *t)
209 tprintf(time_fmt, (intmax_t) t->tv_sec, (intmax_t) t->tv_usec);
213 print_timeval32(struct tcb *tcp, const long addr)
217 if (umove_or_printaddr(tcp, addr, &t))
220 print_timeval32_t(&t);
224 print_timeval32_pair(struct tcb *tcp, const long addr)
228 if (umove_or_printaddr(tcp, addr, &t))
232 print_timeval32_t(&t[0]);
234 print_timeval32_t(&t[1]);
239 print_itimerval32(struct tcb *tcp, const long addr)
243 if (umove_or_printaddr(tcp, addr, &t))
246 tprints("{it_interval=");
247 print_timeval32_t(&t[0]);
248 tprints(", it_value=");
249 print_timeval32_t(&t[1]);
254 sprint_timeval32(struct tcb *tcp, const long addr)
257 static char buf[sizeof(time_fmt) + 3 * sizeof(t)];
261 } else if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)) ||
262 umove(tcp, addr, &t)) {
263 snprintf(buf, sizeof(buf), "%#lx", addr);
265 snprintf(buf, sizeof(buf), time_fmt,
266 (intmax_t) t.tv_sec, (intmax_t) t.tv_usec);