2 * Copyright (c) 2015-2017 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(timeval_t)
32 typedef struct timeval timeval_t;
38 static const char timeval_fmt[] = "{tv_sec=%lld, tv_usec=%llu}";
41 print_timeval_t(const timeval_t *t)
43 tprintf(timeval_fmt, (long long) t->tv_sec,
44 zero_extend_signed_to_ull(t->tv_usec));
48 print_timeval_t_utime(const timeval_t *t)
51 tprints_comment(sprinttime_usec(t->tv_sec,
52 zero_extend_signed_to_ull(t->tv_usec)));
55 MPERS_PRINTER_DECL(void, print_struct_timeval, const void *arg)
60 MPERS_PRINTER_DECL(bool, print_struct_timeval_data_size,
61 const void *arg, const size_t size)
63 if (size < sizeof(timeval_t)) {
72 MPERS_PRINTER_DECL(void, print_timeval,
73 struct tcb *const tcp, const kernel_ulong_t addr)
77 if (umove_or_printaddr(tcp, addr, &t))
83 MPERS_PRINTER_DECL(void, print_timeval_utimes,
84 struct tcb *const tcp, const kernel_ulong_t addr)
88 if (umove_or_printaddr(tcp, addr, &t))
92 print_timeval_t_utime(&t[0]);
94 print_timeval_t_utime(&t[1]);
98 MPERS_PRINTER_DECL(const char *, sprint_timeval,
99 struct tcb *const tcp, const kernel_ulong_t addr)
102 static char buf[sizeof(timeval_fmt) + 3 * sizeof(t)];
106 } else if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)) ||
107 umove(tcp, addr, &t)) {
108 xsprintf(buf, "%#" PRI_klx, addr);
110 xsprintf(buf, timeval_fmt,
111 (long long) t.tv_sec,
112 zero_extend_signed_to_ull(t.tv_usec));
118 MPERS_PRINTER_DECL(void, print_itimerval,
119 struct tcb *const tcp, const kernel_ulong_t addr)
123 if (umove_or_printaddr(tcp, addr, &t))
126 tprints("{it_interval=");
127 print_timeval_t(&t[0]);
128 tprints(", it_value=");
129 print_timeval_t(&t[1]);
136 print_timeval32_t(const timeval32_t *t)
138 tprintf(timeval_fmt, (long long) t->tv_sec,
139 zero_extend_signed_to_ull(t->tv_usec));
143 print_timeval32_t_utime(const timeval32_t *t)
145 print_timeval32_t(t);
146 tprints_comment(sprinttime_usec(t->tv_sec,
147 zero_extend_signed_to_ull(t->tv_usec)));
151 print_timeval32(struct tcb *const tcp, const kernel_ulong_t addr)
155 if (umove_or_printaddr(tcp, addr, &t))
158 print_timeval32_t(&t);
162 print_timeval32_utimes(struct tcb *const tcp, const kernel_ulong_t addr)
166 if (umove_or_printaddr(tcp, addr, &t))
170 print_timeval32_t_utime(&t[0]);
172 print_timeval32_t_utime(&t[1]);
177 print_itimerval32(struct tcb *const tcp, const kernel_ulong_t addr)
181 if (umove_or_printaddr(tcp, addr, &t))
184 tprints("{it_interval=");
185 print_timeval32_t(&t[0]);
186 tprints(", it_value=");
187 print_timeval32_t(&t[1]);
192 sprint_timeval32(struct tcb *const tcp, const kernel_ulong_t addr)
195 static char buf[sizeof(timeval_fmt) + 3 * sizeof(t)];
199 } else if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)) ||
200 umove(tcp, addr, &t)) {
201 xsprintf(buf, "%#" PRI_klx, addr);
203 xsprintf(buf, timeval_fmt,
204 (long long) t.tv_sec,
205 zero_extend_signed_to_ull(t.tv_usec));