2 * Copyright (c) 2015-2016 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=%jd, tv_usec=%jd}";
39 print_timeval_t(const timeval_t *t)
41 tprintf(timeval_fmt, (intmax_t) t->tv_sec, (intmax_t) t->tv_usec);
44 MPERS_PRINTER_DECL(void, print_struct_timeval, const void *arg)
49 MPERS_PRINTER_DECL(void, print_timeval,
50 struct tcb *tcp, const long addr)
54 if (umove_or_printaddr(tcp, addr, &t))
60 MPERS_PRINTER_DECL(void, print_timeval_pair,
61 struct tcb *tcp, const long addr)
65 if (umove_or_printaddr(tcp, addr, &t))
69 print_timeval_t(&t[0]);
71 print_timeval_t(&t[1]);
75 MPERS_PRINTER_DECL(const char *, sprint_timeval,
76 struct tcb *tcp, const long addr)
79 static char buf[sizeof(timeval_fmt) + 3 * sizeof(t)];
83 } else if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)) ||
84 umove(tcp, addr, &t)) {
85 snprintf(buf, sizeof(buf), "%#lx", addr);
87 snprintf(buf, sizeof(buf), timeval_fmt,
88 (intmax_t) t.tv_sec, (intmax_t) t.tv_usec);
94 MPERS_PRINTER_DECL(void, print_itimerval,
95 struct tcb *tcp, const long addr)
99 if (umove_or_printaddr(tcp, addr, &t))
102 tprints("{it_interval=");
103 print_timeval_t(&t[0]);
104 tprints(", it_value=");
105 print_timeval_t(&t[1]);
116 print_timeval32_t(const timeval32_t *t)
118 tprintf(timeval_fmt, (intmax_t) t->tv_sec, (intmax_t) t->tv_usec);
122 print_timeval32(struct tcb *tcp, const long addr)
126 if (umove_or_printaddr(tcp, addr, &t))
129 print_timeval32_t(&t);
133 print_timeval32_pair(struct tcb *tcp, const long addr)
137 if (umove_or_printaddr(tcp, addr, &t))
141 print_timeval32_t(&t[0]);
143 print_timeval32_t(&t[1]);
148 print_itimerval32(struct tcb *tcp, const long addr)
152 if (umove_or_printaddr(tcp, addr, &t))
155 tprints("{it_interval=");
156 print_timeval32_t(&t[0]);
157 tprints(", it_value=");
158 print_timeval32_t(&t[1]);
163 sprint_timeval32(struct tcb *tcp, const long addr)
166 static char buf[sizeof(timeval_fmt) + 3 * sizeof(t)];
170 } else if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)) ||
171 umove(tcp, addr, &t)) {
172 snprintf(buf, sizeof(buf), "%#lx", addr);
174 snprintf(buf, sizeof(buf), timeval_fmt,
175 (intmax_t) t.tv_sec, (intmax_t) t.tv_usec);