1 9b50d902SRodney W. Grimes /*-
2 8a16b7a1SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause
3 8a16b7a1SPedro F. Giffuni *
4 9b50d902SRodney W. Grimes * Copyright (c) 1988, 1993
5 9b50d902SRodney W. Grimes * The Regents of the University of California. All rights reserved.
6 9b50d902SRodney W. Grimes *
7 9b50d902SRodney W. Grimes * Redistribution and use in source and binary forms, with or without
8 9b50d902SRodney W. Grimes * modification, are permitted provided that the following conditions
9 9b50d902SRodney W. Grimes * are met:
10 9b50d902SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright
11 9b50d902SRodney W. Grimes * notice, this list of conditions and the following disclaimer.
12 9b50d902SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright
13 9b50d902SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the
14 9b50d902SRodney W. Grimes * documentation and/or other materials provided with the distribution.
15 fbbd9655SWarner Losh * 3. Neither the name of the University nor the names of its contributors
16 9b50d902SRodney W. Grimes * may be used to endorse or promote products derived from this software
17 9b50d902SRodney W. Grimes * without specific prior written permission.
18 9b50d902SRodney W. Grimes *
19 9b50d902SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 9b50d902SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 9b50d902SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 9b50d902SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 9b50d902SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 9b50d902SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 9b50d902SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 9b50d902SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 9b50d902SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 9b50d902SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 9b50d902SRodney W. Grimes * SUCH DAMAGE.
30 9b50d902SRodney W. Grimes */
31 9b50d902SRodney W. Grimes
32 9b50d902SRodney W. Grimes #include <sys/param.h>
33 9b50d902SRodney W. Grimes #include <sys/file.h>
34 9b50d902SRodney W. Grimes #include <sys/proc.h>
35 9b50d902SRodney W. Grimes #include <sys/time.h>
36 6004362eSDavid Schultz #include <sys/uio.h>
37 9b50d902SRodney W. Grimes #include <sys/ktrace.h>
38 0bff6132SJames Raynard
39 821df508SXin LI #include <stdio.h>
40 821df508SXin LI
41 9b50d902SRodney W. Grimes #include "ktrace.h"
42 9b50d902SRodney W. Grimes
43 ebdb213bSDavid Malone void timevaladd(struct timeval *, struct timeval *);
44 ebdb213bSDavid Malone void timevalsub(struct timeval *, struct timeval *);
45 ebdb213bSDavid Malone void timevalfix(struct timeval *);
46 ebdb213bSDavid Malone
47 ebdb213bSDavid Malone int
getpoints(char * s)48 01588bbdSMark Murray getpoints(char *s)
49 9b50d902SRodney W. Grimes {
50 9b50d902SRodney W. Grimes int facs = 0;
51 9b50d902SRodney W. Grimes
52 9b50d902SRodney W. Grimes while (*s) {
53 9b50d902SRodney W. Grimes switch(*s) {
54 9b50d902SRodney W. Grimes case 'c':
55 9b50d902SRodney W. Grimes facs |= KTRFAC_SYSCALL | KTRFAC_SYSRET;
56 9b50d902SRodney W. Grimes break;
57 c601ad8eSDag-Erling Smørgrav case 'i':
58 c601ad8eSDag-Erling Smørgrav facs |= KTRFAC_GENIO;
59 c601ad8eSDag-Erling Smørgrav break;
60 35818d2eSJohn Baldwin case 'f':
61 35818d2eSJohn Baldwin facs |= KTRFAC_FAULT | KTRFAC_FAULTEND;
62 35818d2eSJohn Baldwin break;
63 9b50d902SRodney W. Grimes case 'n':
64 9b50d902SRodney W. Grimes facs |= KTRFAC_NAMEI;
65 9b50d902SRodney W. Grimes break;
66 c601ad8eSDag-Erling Smørgrav case 'p':
67 c601ad8eSDag-Erling Smørgrav facs |= KTRFAC_CAPFAIL;
68 9b50d902SRodney W. Grimes break;
69 9b50d902SRodney W. Grimes case 's':
70 9b50d902SRodney W. Grimes facs |= KTRFAC_PSIG;
71 9b50d902SRodney W. Grimes break;
72 60e15db9SDag-Erling Smørgrav case 't':
73 *596ee234SMark Johnston facs |= KTRFAC_STRUCT | KTRFAC_STRUCT_ARRAY;
74 60e15db9SDag-Erling Smørgrav break;
75 09ac2438SPoul-Henning Kamp case 'u':
76 09ac2438SPoul-Henning Kamp facs |= KTRFAC_USER;
77 09ac2438SPoul-Henning Kamp break;
78 9b50d902SRodney W. Grimes case 'w':
79 9b50d902SRodney W. Grimes facs |= KTRFAC_CSW;
80 9b50d902SRodney W. Grimes break;
81 a56be37eSJohn Baldwin case 'y':
82 a56be37eSJohn Baldwin facs |= KTRFAC_SYSCTL;
83 a56be37eSJohn Baldwin break;
84 65a4daeaSArtem Hevorhian case 'a':
85 65a4daeaSArtem Hevorhian facs |= KTRFAC_ARGS;
86 65a4daeaSArtem Hevorhian break;
87 65a4daeaSArtem Hevorhian case 'e':
88 65a4daeaSArtem Hevorhian facs |= KTRFAC_ENVS;
89 65a4daeaSArtem Hevorhian break;
90 9b50d902SRodney W. Grimes case '+':
91 9b50d902SRodney W. Grimes facs |= DEF_POINTS;
92 9b50d902SRodney W. Grimes break;
93 9b50d902SRodney W. Grimes default:
94 9b50d902SRodney W. Grimes return (-1);
95 9b50d902SRodney W. Grimes }
96 9b50d902SRodney W. Grimes s++;
97 9b50d902SRodney W. Grimes }
98 9b50d902SRodney W. Grimes return (facs);
99 9b50d902SRodney W. Grimes }
100 9b50d902SRodney W. Grimes
101 ebdb213bSDavid Malone void
timevaladd(struct timeval * t1,struct timeval * t2)102 01588bbdSMark Murray timevaladd(struct timeval *t1, struct timeval *t2)
103 9b50d902SRodney W. Grimes {
104 9b50d902SRodney W. Grimes t1->tv_sec += t2->tv_sec;
105 9b50d902SRodney W. Grimes t1->tv_usec += t2->tv_usec;
106 9b50d902SRodney W. Grimes timevalfix(t1);
107 9b50d902SRodney W. Grimes }
108 9b50d902SRodney W. Grimes
109 ebdb213bSDavid Malone void
timevalsub(struct timeval * t1,struct timeval * t2)110 01588bbdSMark Murray timevalsub(struct timeval *t1, struct timeval *t2)
111 9b50d902SRodney W. Grimes {
112 9b50d902SRodney W. Grimes t1->tv_sec -= t2->tv_sec;
113 9b50d902SRodney W. Grimes t1->tv_usec -= t2->tv_usec;
114 9b50d902SRodney W. Grimes timevalfix(t1);
115 9b50d902SRodney W. Grimes }
116 9b50d902SRodney W. Grimes
117 ebdb213bSDavid Malone void
timevalfix(struct timeval * t1)118 01588bbdSMark Murray timevalfix(struct timeval *t1)
119 9b50d902SRodney W. Grimes {
120 9b50d902SRodney W. Grimes if (t1->tv_usec < 0) {
121 9b50d902SRodney W. Grimes t1->tv_sec--;
122 9b50d902SRodney W. Grimes t1->tv_usec += 1000000;
123 9b50d902SRodney W. Grimes }
124 9b50d902SRodney W. Grimes if (t1->tv_usec >= 1000000) {
125 9b50d902SRodney W. Grimes t1->tv_sec++;
126 9b50d902SRodney W. Grimes t1->tv_usec -= 1000000;
127 9b50d902SRodney W. Grimes }
128 9b50d902SRodney W. Grimes }
129