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;
36 static const char timeval_fmt[] = "{tv_sec=%lld, tv_usec=%llu}";
39 print_timeval_t(const timeval_t *t)
41 tprintf(timeval_fmt, (long long) t->tv_sec,
42 zero_extend_signed_to_ull(t->tv_usec));
46 print_timeval_t_utime(const timeval_t *t)
49 tprints_comment(sprinttime_usec(t->tv_sec,
50 zero_extend_signed_to_ull(t->tv_usec)));
53 MPERS_PRINTER_DECL(void, print_struct_timeval, const void *arg)
58 MPERS_PRINTER_DECL(bool, print_struct_timeval_data_size,
59 const void *arg, const size_t size)
61 if (size < sizeof(timeval_t)) {
70 MPERS_PRINTER_DECL(void, print_timeval,
71 struct tcb *const tcp, const kernel_ulong_t addr)
75 if (umove_or_printaddr(tcp, addr, &t))
81 MPERS_PRINTER_DECL(void, print_timeval_utimes,
82 struct tcb *const tcp, const kernel_ulong_t addr)
86 if (umove_or_printaddr(tcp, addr, &t))
90 print_timeval_t_utime(&t[0]);
92 print_timeval_t_utime(&t[1]);
96 MPERS_PRINTER_DECL(const char *, sprint_timeval,
97 struct tcb *const tcp, const kernel_ulong_t addr)
100 static char buf[sizeof(timeval_fmt) + 3 * sizeof(t)];
104 } else if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)) ||
105 umove(tcp, addr, &t)) {
106 snprintf(buf, sizeof(buf), "%#" PRI_klx, addr);
108 snprintf(buf, sizeof(buf), timeval_fmt,
109 (long long) t.tv_sec,
110 zero_extend_signed_to_ull(t.tv_usec));
116 MPERS_PRINTER_DECL(void, print_itimerval,
117 struct tcb *const tcp, const kernel_ulong_t addr)
121 if (umove_or_printaddr(tcp, addr, &t))
124 tprints("{it_interval=");
125 print_timeval_t(&t[0]);
126 tprints(", it_value=");
127 print_timeval_t(&t[1]);
134 print_timeval32_t(const timeval32_t *t)
136 tprintf(timeval_fmt, (long long) t->tv_sec,
137 zero_extend_signed_to_ull(t->tv_usec));
141 print_timeval32_t_utime(const timeval32_t *t)
143 print_timeval32_t(t);
144 tprints_comment(sprinttime_usec(t->tv_sec,
145 zero_extend_signed_to_ull(t->tv_usec)));
149 print_timeval32(struct tcb *const tcp, const kernel_ulong_t addr)
153 if (umove_or_printaddr(tcp, addr, &t))
156 print_timeval32_t(&t);
160 print_timeval32_utimes(struct tcb *const tcp, const kernel_ulong_t addr)
164 if (umove_or_printaddr(tcp, addr, &t))
168 print_timeval32_t_utime(&t[0]);
170 print_timeval32_t_utime(&t[1]);
175 print_itimerval32(struct tcb *const tcp, const kernel_ulong_t addr)
179 if (umove_or_printaddr(tcp, addr, &t))
182 tprints("{it_interval=");
183 print_timeval32_t(&t[0]);
184 tprints(", it_value=");
185 print_timeval32_t(&t[1]);
190 sprint_timeval32(struct tcb *const tcp, const kernel_ulong_t addr)
193 static char buf[sizeof(timeval_fmt) + 3 * sizeof(t)];
197 } else if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)) ||
198 umove(tcp, addr, &t)) {
199 snprintf(buf, sizeof(buf), "%#" PRI_klx, addr);
201 snprintf(buf, sizeof(buf), timeval_fmt,
202 (long long) t.tv_sec,
203 zero_extend_signed_to_ull(t.tv_usec));