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 timespec_fmt[] = "{tv_sec=%jd, tv_nsec=%jd}";
47 static const char time_fmt[] = "{%jd, %jd}";
50 print_timespec_t(const timespec_t *t)
52 tprintf(timespec_fmt, (intmax_t) t->tv_sec, (intmax_t) t->tv_nsec);
56 print_timespec_t_utime(const timespec_t *t)
63 tprints("UTIME_OMIT");
72 print_timeval_t(const timeval_t *t)
74 tprintf(time_fmt, (intmax_t) t->tv_sec, (intmax_t) t->tv_usec);
77 MPERS_PRINTER_DECL(void, print_timespec,
78 struct tcb *tcp, const long addr)
82 if (umove_or_printaddr(tcp, addr, &t))
88 MPERS_PRINTER_DECL(const char *, sprint_timespec,
89 struct tcb *tcp, const long addr)
92 static char buf[sizeof(timespec_fmt) + 3 * sizeof(t)];
96 } else if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)) ||
97 umove(tcp, addr, &t)) {
98 snprintf(buf, sizeof(buf), "%#lx", addr);
100 snprintf(buf, sizeof(buf), timespec_fmt,
101 (intmax_t) t.tv_sec, (intmax_t) t.tv_nsec);
107 MPERS_PRINTER_DECL(void, print_timespec_utime_pair,
108 struct tcb *tcp, const long addr)
112 if (umove_or_printaddr(tcp, addr, &t))
116 print_timespec_t_utime(&t[0]);
118 print_timespec_t_utime(&t[1]);
122 MPERS_PRINTER_DECL(void, print_itimerspec,
123 struct tcb *tcp, const long addr)
127 if (umove_or_printaddr(tcp, addr, &t))
130 tprints("{it_interval=");
131 print_timespec_t(&t[0]);
132 tprints(", it_value=");
133 print_timespec_t(&t[1]);
137 MPERS_PRINTER_DECL(void, print_timeval,
138 struct tcb *tcp, const long addr)
142 if (umove_or_printaddr(tcp, addr, &t))
148 MPERS_PRINTER_DECL(void, print_timeval_pair,
149 struct tcb *tcp, const long addr)
153 if (umove_or_printaddr(tcp, addr, &t))
157 print_timeval_t(&t[0]);
159 print_timeval_t(&t[1]);
163 MPERS_PRINTER_DECL(const char *, sprint_timeval,
164 struct tcb *tcp, const long addr)
167 static char buf[sizeof(time_fmt) + 3 * sizeof(t)];
171 } else if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)) ||
172 umove(tcp, addr, &t)) {
173 snprintf(buf, sizeof(buf), "%#lx", addr);
175 snprintf(buf, sizeof(buf), time_fmt,
176 (intmax_t) t.tv_sec, (intmax_t) t.tv_usec);
182 MPERS_PRINTER_DECL(void, print_itimerval,
183 struct tcb *tcp, const long addr)
187 if (umove_or_printaddr(tcp, addr, &t))
190 tprints("{it_interval=");
191 print_timeval_t(&t[0]);
192 tprints(", it_value=");
193 print_timeval_t(&t[1]);
202 if (!umove_or_printaddr(tcp, tcp->u_arg[0], &t))
203 tprintf("[%jd]", (intmax_t) t);
216 print_timeval32_t(const timeval32_t *t)
218 tprintf(time_fmt, (intmax_t) t->tv_sec, (intmax_t) t->tv_usec);
222 print_timeval32(struct tcb *tcp, const long addr)
226 if (umove_or_printaddr(tcp, addr, &t))
229 print_timeval32_t(&t);
233 print_timeval32_pair(struct tcb *tcp, const long addr)
237 if (umove_or_printaddr(tcp, addr, &t))
241 print_timeval32_t(&t[0]);
243 print_timeval32_t(&t[1]);
248 print_itimerval32(struct tcb *tcp, const long addr)
252 if (umove_or_printaddr(tcp, addr, &t))
255 tprints("{it_interval=");
256 print_timeval32_t(&t[0]);
257 tprints(", it_value=");
258 print_timeval32_t(&t[1]);
263 sprint_timeval32(struct tcb *tcp, const long addr)
266 static char buf[sizeof(time_fmt) + 3 * sizeof(t)];
270 } else if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)) ||
271 umove(tcp, addr, &t)) {
272 snprintf(buf, sizeof(buf), "%#lx", addr);
274 snprintf(buf, sizeof(buf), time_fmt,
275 (intmax_t) t.tv_sec, (intmax_t) t.tv_usec);