| @@ -1,807 +1,807 @@ | | | @@ -1,807 +1,807 @@ |
1 | /* $NetBSD: dump.c,v 1.34 2009/05/02 18:26:53 christos Exp $ */ | | 1 | /* $NetBSD: dump.c,v 1.35 2009/05/02 21:01:01 mlelstv Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 1988, 1993 | | 4 | * Copyright (c) 1988, 1993 |
5 | * The Regents of the University of California. All rights reserved. | | 5 | * The Regents of the University of California. All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
15 | * 3. Neither the name of the University nor the names of its contributors | | 15 | * 3. Neither the name of the University nor the names of its contributors |
16 | * may be used to endorse or promote products derived from this software | | 16 | * may be used to endorse or promote products derived from this software |
17 | * without specific prior written permission. | | 17 | * without specific prior written permission. |
18 | * | | 18 | * |
19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | | 19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | | 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
29 | * SUCH DAMAGE. | | 29 | * SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | #include <sys/cdefs.h> | | 32 | #include <sys/cdefs.h> |
33 | #ifndef lint | | 33 | #ifndef lint |
34 | __COPYRIGHT("@(#) Copyright (c) 1988, 1993\ | | 34 | __COPYRIGHT("@(#) Copyright (c) 1988, 1993\ |
35 | The Regents of the University of California. All rights reserved."); | | 35 | The Regents of the University of California. All rights reserved."); |
36 | #endif /* not lint */ | | 36 | #endif /* not lint */ |
37 | | | 37 | |
38 | #ifndef lint | | 38 | #ifndef lint |
39 | #if 0 | | 39 | #if 0 |
40 | static char sccsid[] = "@(#)kdump.c 8.4 (Berkeley) 4/28/95"; | | 40 | static char sccsid[] = "@(#)kdump.c 8.4 (Berkeley) 4/28/95"; |
41 | #endif | | 41 | #endif |
42 | __RCSID("$NetBSD: dump.c,v 1.34 2009/05/02 18:26:53 christos Exp $"); | | 42 | __RCSID("$NetBSD: dump.c,v 1.35 2009/05/02 21:01:01 mlelstv Exp $"); |
43 | #endif /* not lint */ | | 43 | #endif /* not lint */ |
44 | | | 44 | |
45 | #include <sys/param.h> | | 45 | #include <sys/param.h> |
46 | #define _KERNEL | | 46 | #define _KERNEL |
47 | #include <sys/errno.h> | | 47 | #include <sys/errno.h> |
48 | #undef _KERNEL | | 48 | #undef _KERNEL |
49 | #include <sys/ioctl.h> | | 49 | #include <sys/ioctl.h> |
50 | #include <sys/time.h> | | 50 | #include <sys/time.h> |
51 | #include <sys/uio.h> | | 51 | #include <sys/uio.h> |
52 | #include <sys/ktrace.h> | | 52 | #include <sys/ktrace.h> |
53 | #include <sys/ptrace.h> | | 53 | #include <sys/ptrace.h> |
54 | #include <sys/queue.h> | | 54 | #include <sys/queue.h> |
55 | | | 55 | |
56 | #include <err.h> | | 56 | #include <err.h> |
57 | #include <signal.h> | | 57 | #include <signal.h> |
58 | #include <stdarg.h> | | 58 | #include <stdarg.h> |
59 | #include <stddef.h> | | 59 | #include <stddef.h> |
60 | #include <stdio.h> | | 60 | #include <stdio.h> |
61 | #include <stdlib.h> | | 61 | #include <stdlib.h> |
62 | #include <string.h> | | 62 | #include <string.h> |
63 | #include <unistd.h> | | 63 | #include <unistd.h> |
64 | #include <vis.h> | | 64 | #include <vis.h> |
65 | | | 65 | |
66 | #include "ktrace.h" | | 66 | #include "ktrace.h" |
67 | #include "misc.h" | | 67 | #include "misc.h" |
68 | #include "setemul.h" | | 68 | #include "setemul.h" |
69 | | | 69 | |
70 | int timestamp, decimal, fancy = 1, tail, maxdata; | | 70 | int timestamp, decimal, fancy = 1, tail, maxdata; |
71 | | | 71 | |
72 | int width; /* Keep track of current columns. */ | | 72 | int width; /* Keep track of current columns. */ |
73 | | | 73 | |
74 | #include <sys/syscall.h> | | 74 | #include <sys/syscall.h> |
75 | | | 75 | |
76 | static const char *const ptrace_ops[] = { | | 76 | static const char *const ptrace_ops[] = { |
77 | "PT_TRACE_ME", "PT_READ_I", "PT_READ_D", "PT_READ_U", | | 77 | "PT_TRACE_ME", "PT_READ_I", "PT_READ_D", "PT_READ_U", |
78 | "PT_WRITE_I", "PT_WRITE_D", "PT_WRITE_U", "PT_CONTINUE", | | 78 | "PT_WRITE_I", "PT_WRITE_D", "PT_WRITE_U", "PT_CONTINUE", |
79 | "PT_KILL", "PT_ATTACH", "PT_DETACH", | | 79 | "PT_KILL", "PT_ATTACH", "PT_DETACH", |
80 | }; | | 80 | }; |
81 | | | 81 | |
82 | struct ktr_entry { | | 82 | struct ktr_entry { |
83 | TAILQ_ENTRY(ktr_entry) kte_list; | | 83 | TAILQ_ENTRY(ktr_entry) kte_list; |
84 | struct ktr_header kte_kth; | | 84 | struct ktr_header kte_kth; |
85 | }; | | 85 | }; |
86 | | | 86 | |
87 | TAILQ_HEAD(kteq, ktr_entry) ktependq = TAILQ_HEAD_INITIALIZER(ktependq); | | 87 | TAILQ_HEAD(kteq, ktr_entry) ktependq = TAILQ_HEAD_INITIALIZER(ktependq); |
88 | | | 88 | |
89 | void argprint(const char *, register_t **, int *); | | 89 | void argprint(const char *, register_t **, int *); |
90 | void dumpheader(struct ktr_header *); | | 90 | void dumpheader(struct ktr_header *); |
91 | int dumprecord(int, FILE *); | | 91 | int dumprecord(int, FILE *); |
92 | void flushpendq(struct ktr_entry *); | | 92 | void flushpendq(struct ktr_entry *); |
93 | int fread_tail(void *, int, int, FILE *); | | 93 | int fread_tail(void *, int, int, FILE *); |
94 | void genioprint(struct ktr_header *); | | 94 | void genioprint(struct ktr_header *); |
95 | struct ktr_entry * | | 95 | struct ktr_entry * |
96 | getpendq(struct ktr_header *, int, struct kteq *); | | 96 | getpendq(struct ktr_header *, int, struct kteq *); |
97 | struct ktr_entry * | | 97 | struct ktr_entry * |
98 | getrecord(FILE *); | | 98 | getrecord(FILE *); |
99 | void indent(int); | | 99 | void indent(int); |
100 | void ioctldecode(u_long); | | 100 | void ioctldecode(u_long); |
101 | void ktrcsw(struct ktr_entry *); | | 101 | void ktrcsw(struct ktr_entry *); |
102 | void ktremul(struct ktr_entry *); | | 102 | void ktremul(struct ktr_entry *); |
103 | void ktrgenio(struct ktr_entry *); | | 103 | void ktrgenio(struct ktr_entry *); |
104 | void ktrnamei(struct ktr_entry *); | | 104 | void ktrnamei(struct ktr_entry *); |
105 | void ktrpsig(struct ktr_entry *); | | 105 | void ktrpsig(struct ktr_entry *); |
106 | void ktrsyscall(struct ktr_entry *); | | 106 | void ktrsyscall(struct ktr_entry *); |
107 | void ktrsysret(struct ktr_entry *); | | 107 | void ktrsysret(struct ktr_entry *); |
108 | void nameiargprint(const char *, struct ktr_header *, register_t **, int *); | | 108 | void nameiargprint(const char *, struct ktr_header *, register_t **, int *); |
109 | void nameiprint(struct ktr_header *); | | 109 | void nameiprint(struct ktr_header *); |
110 | void newline(void); | | 110 | void newline(void); |
111 | void putpendq(struct ktr_entry *); | | 111 | void putpendq(struct ktr_entry *); |
112 | void syscallnameprint(int); | | 112 | void syscallnameprint(int); |
113 | void syscallprint(struct ktr_header *); | | 113 | void syscallprint(struct ktr_header *); |
114 | void sysretprint(struct ktr_header *); | | 114 | void sysretprint(struct ktr_header *); |
115 | int wprintf(const char *, ...); | | 115 | int wprintf(const char *, ...); |
116 | void *xrealloc(void *, size_t *, size_t); | | 116 | void *xrealloc(void *, size_t *, size_t); |
117 | | | 117 | |
118 | int | | 118 | int |
119 | wprintf(const char *fmt, ...) | | 119 | wprintf(const char *fmt, ...) |
120 | { | | 120 | { |
121 | va_list ap; | | 121 | va_list ap; |
122 | int w; | | 122 | int w; |
123 | | | 123 | |
124 | va_start(ap, fmt); | | 124 | va_start(ap, fmt); |
125 | w = vprintf(fmt, ap); | | 125 | w = vprintf(fmt, ap); |
126 | if (w == -1) | | 126 | if (w == -1) |
127 | warn("vprintf"); | | 127 | warn("vprintf"); |
128 | else | | 128 | else |
129 | width += w; | | 129 | width += w; |
130 | va_end(ap); | | 130 | va_end(ap); |
131 | return (w); | | 131 | return (w); |
132 | } | | 132 | } |
133 | | | 133 | |
134 | void | | 134 | void |
135 | newline(void) | | 135 | newline(void) |
136 | { | | 136 | { |
137 | | | 137 | |
138 | if (width > 0) { | | 138 | if (width > 0) { |
139 | printf("\n"); | | 139 | printf("\n"); |
140 | width = 0; | | 140 | width = 0; |
141 | } | | 141 | } |
142 | } | | 142 | } |
143 | | | 143 | |
144 | void | | 144 | void |
145 | indent(int col) | | 145 | indent(int col) |
146 | { | | 146 | { |
147 | | | 147 | |
148 | while (width < col) | | 148 | while (width < col) |
149 | if (wprintf(" ") < 0) | | 149 | if (wprintf(" ") < 0) |
150 | break; | | 150 | break; |
151 | } | | 151 | } |
152 | | | 152 | |
153 | void * | | 153 | void * |
154 | xrealloc(void *p, size_t *siz, size_t req) | | 154 | xrealloc(void *p, size_t *siz, size_t req) |
155 | { | | 155 | { |
156 | | | 156 | |
157 | if (*siz < req) { | | 157 | if (*siz < req) { |
158 | if (*siz == 0) | | 158 | if (*siz == 0) |
159 | *siz = 1; | | 159 | *siz = 1; |
160 | while (*siz < req) | | 160 | while (*siz < req) |
161 | *siz <<= 1; | | 161 | *siz <<= 1; |
162 | p = realloc(p, *siz); | | 162 | p = realloc(p, *siz); |
163 | if (p == NULL) | | 163 | if (p == NULL) |
164 | err(EXIT_FAILURE, "realloc: %lu bytes", | | 164 | err(EXIT_FAILURE, "realloc: %lu bytes", |
165 | (u_long)*siz); | | 165 | (u_long)*siz); |
166 | } | | 166 | } |
167 | return (p); | | 167 | return (p); |
168 | } | | 168 | } |
169 | | | 169 | |
170 | struct ktr_entry * | | 170 | struct ktr_entry * |
171 | getrecord(FILE *fp) | | 171 | getrecord(FILE *fp) |
172 | { | | 172 | { |
173 | struct ktr_entry *kte; | | 173 | struct ktr_entry *kte; |
174 | struct ktr_header *kth; | | 174 | struct ktr_header *kth; |
175 | char *cp; | | 175 | char *cp; |
176 | size_t siz, len; | | 176 | size_t siz, len; |
177 | | | 177 | |
178 | siz = 0; | | 178 | siz = 0; |
179 | kte = xrealloc(NULL, &siz, sizeof(struct ktr_entry)); | | 179 | kte = xrealloc(NULL, &siz, sizeof(struct ktr_entry)); |
180 | kth = &kte->kte_kth; | | 180 | kth = &kte->kte_kth; |
181 | if (fread_tail(kth, sizeof(struct ktr_header), 1, fp) == 0) { | | 181 | if (fread_tail(kth, sizeof(struct ktr_header), 1, fp) == 0) { |
182 | free(kte); | | 182 | free(kte); |
183 | return (NULL); | | 183 | return (NULL); |
184 | } | | 184 | } |
185 | | | 185 | |
186 | if (kth->ktr_len < 0) | | 186 | if (kth->ktr_len < 0) |
187 | errx(EXIT_FAILURE, "bogus length 0x%x", kth->ktr_len); | | 187 | errx(EXIT_FAILURE, "bogus length 0x%x", kth->ktr_len); |
188 | len = kth->ktr_len; | | 188 | len = kth->ktr_len; |
189 | if (len > 0) { | | 189 | if (len > 0) { |
190 | /* + 1 to ensure room for NUL terminate */ | | 190 | /* + 1 to ensure room for NUL terminate */ |
191 | kte = xrealloc(kte, &siz, sizeof(struct ktr_entry) + len + 1); | | 191 | kte = xrealloc(kte, &siz, sizeof(struct ktr_entry) + len + 1); |
192 | if (fread_tail(cp = (char *)(&kte->kte_kth + 1), | | 192 | if (fread_tail(cp = (char *)(&kte->kte_kth + 1), |
193 | len, 1, fp) == 0) | | 193 | len, 1, fp) == 0) |
194 | errx(EXIT_FAILURE, "data too short"); | | 194 | errx(EXIT_FAILURE, "data too short"); |
195 | cp[len] = 0; | | 195 | cp[len] = 0; |
196 | } | | 196 | } |
197 | | | 197 | |
198 | return (kte); | | 198 | return (kte); |
199 | } | | 199 | } |
200 | | | 200 | |
201 | #define KTE_TYPE(kte) ((kte)->kte_kth.ktr_type) | | 201 | #define KTE_TYPE(kte) ((kte)->kte_kth.ktr_type) |
202 | #define KTE_PID(kte) ((kte)->kte_kth.ktr_pid) | | 202 | #define KTE_PID(kte) ((kte)->kte_kth.ktr_pid) |
203 | #define KTE_LID(kte) ((kte)->kte_kth.ktr_lid) | | 203 | #define KTE_LID(kte) ((kte)->kte_kth.ktr_lid) |
204 | #define KTE_MATCH(kte, type, pid, lid) \ | | 204 | #define KTE_MATCH(kte, type, pid, lid) \ |
205 | (KTE_TYPE(kte) == (type) && KTE_PID(kte) == (pid) && \ | | 205 | (KTE_TYPE(kte) == (type) && KTE_PID(kte) == (pid) && \ |
206 | KTE_LID(kte) == (lid)) | | 206 | KTE_LID(kte) == (lid)) |
207 | | | 207 | |
208 | void | | 208 | void |
209 | putpendq(struct ktr_entry *kte) | | 209 | putpendq(struct ktr_entry *kte) |
210 | { | | 210 | { |
211 | | | 211 | |
212 | TAILQ_INSERT_TAIL(&ktependq, kte, kte_list); | | 212 | TAILQ_INSERT_TAIL(&ktependq, kte, kte_list); |
213 | } | | 213 | } |
214 | | | 214 | |
215 | void | | 215 | void |
216 | flushpendq(struct ktr_entry *us) | | 216 | flushpendq(struct ktr_entry *us) |
217 | { | | 217 | { |
218 | struct ktr_entry *kte, *kte_next; | | 218 | struct ktr_entry *kte, *kte_next; |
219 | int pid = KTE_PID(us); | | 219 | int pid = KTE_PID(us), lid = KTE_LID(us); |
220 | | | 220 | |
221 | for (kte = TAILQ_FIRST(&ktependq); kte != NULL; kte = kte_next) { | | 221 | for (kte = TAILQ_FIRST(&ktependq); kte != NULL; kte = kte_next) { |
222 | kte_next = TAILQ_NEXT(kte, kte_list); | | 222 | kte_next = TAILQ_NEXT(kte, kte_list); |
223 | if (KTE_PID(kte) == pid) { | | 223 | if (KTE_PID(kte) == pid || KTE_LID(kte) == lid) { |
224 | TAILQ_REMOVE(&ktependq, kte, kte_list); | | 224 | TAILQ_REMOVE(&ktependq, kte, kte_list); |
225 | free(kte); | | 225 | free(kte); |
226 | } | | 226 | } |
227 | } | | 227 | } |
228 | } | | 228 | } |
229 | | | 229 | |
230 | struct ktr_entry * | | 230 | struct ktr_entry * |
231 | getpendq(struct ktr_header *us, int type, struct kteq *kteq) | | 231 | getpendq(struct ktr_header *us, int type, struct kteq *kteq) |
232 | { | | 232 | { |
233 | struct ktr_entry *kte, *kte_next; | | 233 | struct ktr_entry *kte, *kte_next; |
234 | int pid = us->ktr_pid, lid = us->ktr_lid; | | 234 | int pid = us->ktr_pid, lid = us->ktr_lid; |
235 | | | 235 | |
236 | if (kteq != NULL) | | 236 | if (kteq != NULL) |
237 | TAILQ_INIT(kteq); | | 237 | TAILQ_INIT(kteq); |
238 | for (kte = TAILQ_FIRST(&ktependq); kte != NULL; kte = kte_next) { | | 238 | for (kte = TAILQ_FIRST(&ktependq); kte != NULL; kte = kte_next) { |
239 | kte_next = TAILQ_NEXT(kte, kte_list); | | 239 | kte_next = TAILQ_NEXT(kte, kte_list); |
240 | if (KTE_MATCH(kte, type, pid, lid)) { | | 240 | if (KTE_MATCH(kte, type, pid, lid)) { |
241 | TAILQ_REMOVE(&ktependq, kte, kte_list); | | 241 | TAILQ_REMOVE(&ktependq, kte, kte_list); |
242 | if (kteq != NULL) | | 242 | if (kteq != NULL) |
243 | TAILQ_INSERT_TAIL(kteq, kte, kte_list); | | 243 | TAILQ_INSERT_TAIL(kteq, kte, kte_list); |
244 | else | | 244 | else |
245 | break; | | 245 | break; |
246 | } | | 246 | } |
247 | } | | 247 | } |
248 | | | 248 | |
249 | return (kteq ? TAILQ_FIRST(kteq) : kte); | | 249 | return (kteq ? TAILQ_FIRST(kteq) : kte); |
250 | } | | 250 | } |
251 | | | 251 | |
252 | int | | 252 | int |
253 | dumprecord(int trpoints, FILE *fp) | | 253 | dumprecord(int trpoints, FILE *fp) |
254 | { | | 254 | { |
255 | struct ktr_entry *kte; | | 255 | struct ktr_entry *kte; |
256 | struct ktr_header *kth; | | 256 | struct ktr_header *kth; |
257 | | | 257 | |
258 | kte = getrecord(fp); | | 258 | kte = getrecord(fp); |
259 | if (kte == NULL) | | 259 | if (kte == NULL) |
260 | return (0); | | 260 | return (0); |
261 | | | 261 | |
262 | kth = &kte->kte_kth; | | 262 | kth = &kte->kte_kth; |
263 | if ((trpoints & (1 << kth->ktr_type)) == 0) { | | 263 | if ((trpoints & (1 << kth->ktr_type)) == 0) { |
264 | free(kte); | | 264 | free(kte); |
265 | goto out; | | 265 | goto out; |
266 | } | | 266 | } |
267 | | | 267 | |
268 | /* Update context to match currently processed record. */ | | 268 | /* Update context to match currently processed record. */ |
269 | ectx_sanify(kth->ktr_pid); | | 269 | ectx_sanify(kth->ktr_pid); |
270 | | | 270 | |
271 | switch (kth->ktr_type) { | | 271 | switch (kth->ktr_type) { |
272 | case KTR_SYSCALL: | | 272 | case KTR_SYSCALL: |
273 | ktrsyscall(kte); | | 273 | ktrsyscall(kte); |
274 | break; | | 274 | break; |
275 | case KTR_SYSRET: | | 275 | case KTR_SYSRET: |
276 | ktrsysret(kte); | | 276 | ktrsysret(kte); |
277 | break; | | 277 | break; |
278 | case KTR_NAMEI: | | 278 | case KTR_NAMEI: |
279 | putpendq(kte); | | 279 | putpendq(kte); |
280 | break; | | 280 | break; |
281 | case KTR_GENIO: | | 281 | case KTR_GENIO: |
282 | putpendq(kte); | | 282 | putpendq(kte); |
283 | break; | | 283 | break; |
284 | case KTR_PSIG: | | 284 | case KTR_PSIG: |
285 | ktrpsig(kte); | | 285 | ktrpsig(kte); |
286 | break; | | 286 | break; |
287 | case KTR_CSW: | | 287 | case KTR_CSW: |
288 | ktrcsw(kte); | | 288 | ktrcsw(kte); |
289 | break; | | 289 | break; |
290 | case KTR_EMUL: | | 290 | case KTR_EMUL: |
291 | ktremul(kte); | | 291 | ktremul(kte); |
292 | break; | | 292 | break; |
293 | default: | | 293 | default: |
294 | /* | | 294 | /* |
295 | * XXX: Other types added recently. | | 295 | * XXX: Other types added recently. |
296 | */ | | 296 | */ |
297 | free(kte); | | 297 | free(kte); |
298 | break; | | 298 | break; |
299 | } | | 299 | } |
300 | newline(); | | 300 | newline(); |
301 | | | 301 | |
302 | out: | | 302 | out: |
303 | return (1); | | 303 | return (1); |
304 | } | | 304 | } |
305 | | | 305 | |
306 | void | | 306 | void |
307 | dumpfile(const char *file, int fd, int trpoints) | | 307 | dumpfile(const char *file, int fd, int trpoints) |
308 | { | | 308 | { |
309 | FILE *fp; | | 309 | FILE *fp; |
310 | | | 310 | |
311 | if (file == NULL || *file == 0) { | | 311 | if (file == NULL || *file == 0) { |
312 | if ((fp = fdopen(fd, "r")) == NULL) | | 312 | if ((fp = fdopen(fd, "r")) == NULL) |
313 | err(EXIT_FAILURE, "fdopen(%d)", fd); | | 313 | err(EXIT_FAILURE, "fdopen(%d)", fd); |
314 | } else if (strcmp(file, "-") == 0) | | 314 | } else if (strcmp(file, "-") == 0) |
315 | fp = stdin; | | 315 | fp = stdin; |
316 | else if ((fp = fopen(file, "r")) == NULL) | | 316 | else if ((fp = fopen(file, "r")) == NULL) |
317 | err(EXIT_FAILURE, "fopen: %s", file); | | 317 | err(EXIT_FAILURE, "fopen: %s", file); |
318 | | | 318 | |
319 | for (width = 0; dumprecord(trpoints, fp) != 0;) | | 319 | for (width = 0; dumprecord(trpoints, fp) != 0;) |
320 | if (tail) | | 320 | if (tail) |
321 | (void)fflush(stdout); | | 321 | (void)fflush(stdout); |
322 | | | 322 | |
323 | newline(); | | 323 | newline(); |
324 | | | 324 | |
325 | /* | | 325 | /* |
326 | * XXX: Dump pending KTR_SYSCALL if any? | | 326 | * XXX: Dump pending KTR_SYSCALL if any? |
327 | */ | | 327 | */ |
328 | } | | 328 | } |
329 | | | 329 | |
330 | int | | 330 | int |
331 | fread_tail(void *buf, int size, int num, FILE *fp) | | 331 | fread_tail(void *buf, int size, int num, FILE *fp) |
332 | { | | 332 | { |
333 | int i; | | 333 | int i; |
334 | | | 334 | |
335 | while ((i = fread(buf, size, num, fp)) == 0 && tail) { | | 335 | while ((i = fread(buf, size, num, fp)) == 0 && tail) { |
336 | (void)sleep(1); | | 336 | (void)sleep(1); |
337 | clearerr(fp); | | 337 | clearerr(fp); |
338 | } | | 338 | } |
339 | return (i); | | 339 | return (i); |
340 | } | | 340 | } |
341 | | | 341 | |
342 | void | | 342 | void |
343 | dumpheader(struct ktr_header *kth) | | 343 | dumpheader(struct ktr_header *kth) |
344 | { | | 344 | { |
345 | union timeholder { | | 345 | union timeholder { |
346 | struct timeval tv; | | 346 | struct timeval tv; |
347 | struct timespec ts; | | 347 | struct timespec ts; |
348 | }; | | 348 | }; |
349 | static union timeholder prevtime; | | 349 | static union timeholder prevtime; |
350 | union timeholder temp; | | 350 | union timeholder temp; |
351 | | | 351 | |
352 | wprintf("%6d ", kth->ktr_pid); | | 352 | wprintf("%6d ", kth->ktr_pid); |
353 | if (kth->ktr_version > KTRFAC_VERSION(KTRFACv0)) | | 353 | if (kth->ktr_version > KTRFAC_VERSION(KTRFACv0)) |
354 | wprintf("%6d ", kth->ktr_lid); | | 354 | wprintf("%6d ", kth->ktr_lid); |
355 | wprintf("%-8.*s ", MAXCOMLEN, kth->ktr_comm); | | 355 | wprintf("%-8.*s ", MAXCOMLEN, kth->ktr_comm); |
356 | if (timestamp) { | | 356 | if (timestamp) { |
357 | if (timestamp == 2) { | | 357 | if (timestamp == 2) { |
358 | switch (kth->ktr_version) { | | 358 | switch (kth->ktr_version) { |
359 | case KTRFAC_VERSION(KTRFACv0): | | 359 | case KTRFAC_VERSION(KTRFACv0): |
360 | if (prevtime.tv.tv_sec == 0) | | 360 | if (prevtime.tv.tv_sec == 0) |
361 | temp.tv.tv_sec = temp.tv.tv_usec = 0; | | 361 | temp.tv.tv_sec = temp.tv.tv_usec = 0; |
362 | else | | 362 | else |
363 | timersub(&kth->ktr_otv, | | 363 | timersub(&kth->ktr_otv, |
364 | &prevtime.tv, &temp.tv); | | 364 | &prevtime.tv, &temp.tv); |
365 | prevtime.tv.tv_sec = kth->ktr_otv.tv_sec; | | 365 | prevtime.tv.tv_sec = kth->ktr_otv.tv_sec; |
366 | prevtime.tv.tv_usec = kth->ktr_otv.tv_usec; | | 366 | prevtime.tv.tv_usec = kth->ktr_otv.tv_usec; |
367 | break; | | 367 | break; |
368 | | | 368 | |
369 | case KTRFAC_VERSION(KTRFACv1): | | 369 | case KTRFAC_VERSION(KTRFACv1): |
370 | if (prevtime.ts.tv_sec == 0) | | 370 | if (prevtime.ts.tv_sec == 0) |
371 | temp.ts.tv_sec = temp.ts.tv_nsec = 0; | | 371 | temp.ts.tv_sec = temp.ts.tv_nsec = 0; |
372 | else | | 372 | else |
373 | timespecsub(&kth->ktr_time, | | 373 | timespecsub(&kth->ktr_time, |
374 | &prevtime.ts, &temp.ts); | | 374 | &prevtime.ts, &temp.ts); |
375 | prevtime.ts.tv_sec = kth->ktr_ots.tv_sec; | | 375 | prevtime.ts.tv_sec = kth->ktr_ots.tv_sec; |
376 | prevtime.ts.tv_nsec = kth->ktr_ots.tv_nsec; | | 376 | prevtime.ts.tv_nsec = kth->ktr_ots.tv_nsec; |
377 | break; | | 377 | break; |
378 | | | 378 | |
379 | case KTRFAC_VERSION(KTRFACv2): | | 379 | case KTRFAC_VERSION(KTRFACv2): |
380 | if (prevtime.ts.tv_sec == 0) | | 380 | if (prevtime.ts.tv_sec == 0) |
381 | temp.ts.tv_sec = temp.ts.tv_nsec = 0; | | 381 | temp.ts.tv_sec = temp.ts.tv_nsec = 0; |
382 | else | | 382 | else |
383 | timespecsub(&kth->ktr_time, | | 383 | timespecsub(&kth->ktr_time, |
384 | &prevtime.ts, &temp.ts); | | 384 | &prevtime.ts, &temp.ts); |
385 | prevtime.ts.tv_sec = kth->ktr_ts.tv_sec; | | 385 | prevtime.ts.tv_sec = kth->ktr_ts.tv_sec; |
386 | prevtime.ts.tv_nsec = kth->ktr_ts.tv_nsec; | | 386 | prevtime.ts.tv_nsec = kth->ktr_ts.tv_nsec; |
387 | break; | | 387 | break; |
388 | } | | 388 | } |
389 | } else { | | 389 | } else { |
390 | switch (kth->ktr_version) { | | 390 | switch (kth->ktr_version) { |
391 | case KTRFAC_VERSION(KTRFACv0): | | 391 | case KTRFAC_VERSION(KTRFACv0): |
392 | temp.tv.tv_sec = kth->ktr_otv.tv_sec; | | 392 | temp.tv.tv_sec = kth->ktr_otv.tv_sec; |
393 | temp.tv.tv_usec = kth->ktr_otv.tv_usec; | | 393 | temp.tv.tv_usec = kth->ktr_otv.tv_usec; |
394 | break; | | 394 | break; |
395 | case KTRFAC_VERSION(KTRFACv1): | | 395 | case KTRFAC_VERSION(KTRFACv1): |
396 | temp.ts.tv_sec = kth->ktr_ots.tv_sec; | | 396 | temp.ts.tv_sec = kth->ktr_ots.tv_sec; |
397 | temp.ts.tv_nsec = kth->ktr_ots.tv_nsec; | | 397 | temp.ts.tv_nsec = kth->ktr_ots.tv_nsec; |
398 | break; | | 398 | break; |
399 | case KTRFAC_VERSION(KTRFACv2): | | 399 | case KTRFAC_VERSION(KTRFACv2): |
400 | temp.ts.tv_sec = kth->ktr_ts.tv_sec; | | 400 | temp.ts.tv_sec = kth->ktr_ts.tv_sec; |
401 | temp.ts.tv_nsec = kth->ktr_ts.tv_nsec; | | 401 | temp.ts.tv_nsec = kth->ktr_ts.tv_nsec; |
402 | break; | | 402 | break; |
403 | } | | 403 | } |
404 | } | | 404 | } |
405 | if (kth->ktr_version == KTRFAC_VERSION(KTRFACv0)) | | 405 | if (kth->ktr_version == KTRFAC_VERSION(KTRFACv0)) |
406 | wprintf("%lld.%06ld ", | | 406 | wprintf("%lld.%06ld ", |
407 | (long long)temp.tv.tv_sec, (long)temp.tv.tv_usec); | | 407 | (long long)temp.tv.tv_sec, (long)temp.tv.tv_usec); |
408 | else | | 408 | else |
409 | wprintf("%lld.%09ld ", | | 409 | wprintf("%lld.%09ld ", |
410 | (long long)temp.ts.tv_sec, (long)temp.ts.tv_nsec); | | 410 | (long long)temp.ts.tv_sec, (long)temp.ts.tv_nsec); |
411 | } | | 411 | } |
412 | } | | 412 | } |
413 | | | 413 | |
414 | void | | 414 | void |
415 | ioctldecode(u_long cmd) | | 415 | ioctldecode(u_long cmd) |
416 | { | | 416 | { |
417 | char dirbuf[4], *dir = dirbuf; | | 417 | char dirbuf[4], *dir = dirbuf; |
418 | | | 418 | |
419 | if (cmd & IOC_OUT) | | 419 | if (cmd & IOC_OUT) |
420 | *dir++ = 'W'; | | 420 | *dir++ = 'W'; |
421 | if (cmd & IOC_IN) | | 421 | if (cmd & IOC_IN) |
422 | *dir++ = 'R'; | | 422 | *dir++ = 'R'; |
423 | *dir = '\0'; | | 423 | *dir = '\0'; |
424 | | | 424 | |
425 | wprintf(decimal ? ", _IO%s('%c',%ld" : ", _IO%s('%c',%#lx", | | 425 | wprintf(decimal ? ", _IO%s('%c',%ld" : ", _IO%s('%c',%#lx", |
426 | dirbuf, (int) ((cmd >> 8) & 0xff), cmd & 0xff); | | 426 | dirbuf, (int) ((cmd >> 8) & 0xff), cmd & 0xff); |
427 | if ((cmd & IOC_VOID) == 0) | | 427 | if ((cmd & IOC_VOID) == 0) |
428 | wprintf(decimal ? ",%ld)" : ",%#lx)", | | 428 | wprintf(decimal ? ",%ld)" : ",%#lx)", |
429 | (cmd >> 16) & 0xff); | | 429 | (cmd >> 16) & 0xff); |
430 | else | | 430 | else |
431 | wprintf(")"); | | 431 | wprintf(")"); |
432 | } | | 432 | } |
433 | | | 433 | |
434 | void | | 434 | void |
435 | nameiargprint(const char *prefix, struct ktr_header *kth, | | 435 | nameiargprint(const char *prefix, struct ktr_header *kth, |
436 | register_t **ap, int *argsize) | | 436 | register_t **ap, int *argsize) |
437 | { | | 437 | { |
438 | struct ktr_entry *kte; | | 438 | struct ktr_entry *kte; |
439 | | | 439 | |
440 | if (*argsize == 0) | | 440 | if (*argsize == 0) |
441 | errx(EXIT_FAILURE, "argument expected"); | | 441 | errx(EXIT_FAILURE, "argument expected"); |
442 | /* | | 442 | /* |
443 | * XXX: binary emulation mode. | | 443 | * XXX: binary emulation mode. |
444 | */ | | 444 | */ |
445 | kte = getpendq(kth, KTR_NAMEI, NULL); | | 445 | kte = getpendq(kth, KTR_NAMEI, NULL); |
446 | if (kte == NULL) | | 446 | if (kte == NULL) |
447 | argprint(prefix, ap, argsize); | | 447 | argprint(prefix, ap, argsize); |
448 | else { | | 448 | else { |
449 | wprintf("%s", prefix); | | 449 | wprintf("%s", prefix); |
450 | nameiprint(&kte->kte_kth); | | 450 | nameiprint(&kte->kte_kth); |
451 | free(kte); | | 451 | free(kte); |
452 | (*ap)++; | | 452 | (*ap)++; |
453 | *argsize -= sizeof(register_t); | | 453 | *argsize -= sizeof(register_t); |
454 | } | | 454 | } |
455 | } | | 455 | } |
456 | | | 456 | |
457 | void | | 457 | void |
458 | syscallnameprint(int code) | | 458 | syscallnameprint(int code) |
459 | { | | 459 | { |
460 | | | 460 | |
461 | if (code >= cur_emul->nsysnames || code < 0) | | 461 | if (code >= cur_emul->nsysnames || code < 0) |
462 | wprintf("[%d]", code); | | 462 | wprintf("[%d]", code); |
463 | else | | 463 | else |
464 | wprintf("%s", cur_emul->sysnames[code]); | | 464 | wprintf("%s", cur_emul->sysnames[code]); |
465 | } | | 465 | } |
466 | | | 466 | |
467 | void | | 467 | void |
468 | argprint(const char *prefix, register_t **ap, int *argsize) | | 468 | argprint(const char *prefix, register_t **ap, int *argsize) |
469 | { | | 469 | { |
470 | | | 470 | |
471 | if (decimal) | | 471 | if (decimal) |
472 | wprintf("%s%ld", prefix, (long)**ap); | | 472 | wprintf("%s%ld", prefix, (long)**ap); |
473 | else | | 473 | else |
474 | wprintf("%s%#lx", prefix, (long)**ap); | | 474 | wprintf("%s%#lx", prefix, (long)**ap); |
475 | (*ap)++; | | 475 | (*ap)++; |
476 | *argsize -= sizeof(register_t); | | 476 | *argsize -= sizeof(register_t); |
477 | } | | 477 | } |
478 | | | 478 | |
479 | void | | 479 | void |
480 | syscallprint(struct ktr_header *kth) | | 480 | syscallprint(struct ktr_header *kth) |
481 | { | | 481 | { |
482 | struct ktr_syscall *ktr = (struct ktr_syscall *)(kth + 1); | | 482 | struct ktr_syscall *ktr = (struct ktr_syscall *)(kth + 1); |
483 | register_t *ap; | | 483 | register_t *ap; |
484 | const char *s; | | 484 | const char *s; |
485 | int argsize; | | 485 | int argsize; |
486 | | | 486 | |
487 | syscallnameprint(ktr->ktr_code); | | 487 | syscallnameprint(ktr->ktr_code); |
488 | | | 488 | |
489 | /* | | 489 | /* |
490 | * Arguments processing. | | 490 | * Arguments processing. |
491 | */ | | 491 | */ |
492 | argsize = ktr->ktr_argsize; | | 492 | argsize = ktr->ktr_argsize; |
493 | if (argsize == 0) { | | 493 | if (argsize == 0) { |
494 | wprintf("("); | | 494 | wprintf("("); |
495 | goto noargument; | | 495 | goto noargument; |
496 | } | | 496 | } |
497 | | | 497 | |
498 | ap = (register_t *)(ktr + 1); | | 498 | ap = (register_t *)(ktr + 1); |
499 | if (!fancy) | | 499 | if (!fancy) |
500 | goto print_first; | | 500 | goto print_first; |
501 | | | 501 | |
502 | switch (ktr->ktr_code) { | | 502 | switch (ktr->ktr_code) { |
503 | /* | | 503 | /* |
504 | * All these have a path as the first param. | | 504 | * All these have a path as the first param. |
505 | * The order is same as syscalls.master. | | 505 | * The order is same as syscalls.master. |
506 | */ | | 506 | */ |
507 | case SYS_open: | | 507 | case SYS_open: |
508 | case SYS_link: | | 508 | case SYS_link: |
509 | case SYS_unlink: | | 509 | case SYS_unlink: |
510 | case SYS_chdir: | | 510 | case SYS_chdir: |
511 | case SYS___mknod50: | | 511 | case SYS___mknod50: |
512 | case SYS_chmod: | | 512 | case SYS_chmod: |
513 | case SYS_chown: | | 513 | case SYS_chown: |
514 | case SYS_unmount: | | 514 | case SYS_unmount: |
515 | case SYS_access: | | 515 | case SYS_access: |
516 | case SYS_chflags: | | 516 | case SYS_chflags: |
517 | case SYS_acct: | | 517 | case SYS_acct: |
518 | case SYS_revoke: | | 518 | case SYS_revoke: |
519 | case SYS_symlink: | | 519 | case SYS_symlink: |
520 | case SYS_readlink: | | 520 | case SYS_readlink: |
521 | case SYS_execve: | | 521 | case SYS_execve: |
522 | case SYS_chroot: | | 522 | case SYS_chroot: |
523 | case SYS_rename: | | 523 | case SYS_rename: |
524 | case SYS_mkfifo: | | 524 | case SYS_mkfifo: |
525 | case SYS_mkdir: | | 525 | case SYS_mkdir: |
526 | case SYS_rmdir: | | 526 | case SYS_rmdir: |
527 | case SYS___utimes50: | | 527 | case SYS___utimes50: |
528 | case SYS_quotactl: | | 528 | case SYS_quotactl: |
529 | case SYS_statvfs1: | | 529 | case SYS_statvfs1: |
530 | case SYS_compat_30_getfh: | | 530 | case SYS_compat_30_getfh: |
531 | case SYS_pathconf: | | 531 | case SYS_pathconf: |
532 | case SYS_truncate: | | 532 | case SYS_truncate: |
533 | case SYS_undelete: | | 533 | case SYS_undelete: |
534 | case SYS___posix_rename: | | 534 | case SYS___posix_rename: |
535 | case SYS_lchmod: | | 535 | case SYS_lchmod: |
536 | case SYS_lchown: | | 536 | case SYS_lchown: |
537 | case SYS___lutimes50: | | 537 | case SYS___lutimes50: |
538 | case SYS___stat50: | | 538 | case SYS___stat50: |
539 | case SYS___lstat50: | | 539 | case SYS___lstat50: |
540 | case SYS___posix_chown: | | 540 | case SYS___posix_chown: |
541 | case SYS___posix_lchown: | | 541 | case SYS___posix_lchown: |
542 | case SYS_lchflags: | | 542 | case SYS_lchflags: |
543 | case SYS___getfh30: | | 543 | case SYS___getfh30: |
544 | nameiargprint("(", kth, &ap, &argsize); | | 544 | nameiargprint("(", kth, &ap, &argsize); |
545 | | | 545 | |
546 | /* | | 546 | /* |
547 | * 2nd argument is also pathname. | | 547 | * 2nd argument is also pathname. |
548 | */ | | 548 | */ |
549 | switch (ktr->ktr_code) { | | 549 | switch (ktr->ktr_code) { |
550 | case SYS_link: | | 550 | case SYS_link: |
551 | case SYS_rename: | | 551 | case SYS_rename: |
552 | case SYS___posix_rename: | | 552 | case SYS___posix_rename: |
553 | nameiargprint(", ", kth, &ap, &argsize); | | 553 | nameiargprint(", ", kth, &ap, &argsize); |
554 | break; | | 554 | break; |
555 | } | | 555 | } |
556 | break; | | 556 | break; |
557 | | | 557 | |
558 | case SYS_compat_16___sigaction14 : | | 558 | case SYS_compat_16___sigaction14 : |
559 | wprintf("(%s", signals[(int)*ap].name); | | 559 | wprintf("(%s", signals[(int)*ap].name); |
560 | ap++; | | 560 | ap++; |
561 | argsize -= sizeof(register_t); | | 561 | argsize -= sizeof(register_t); |
562 | break; | | 562 | break; |
563 | | | 563 | |
564 | case SYS_ioctl : | | 564 | case SYS_ioctl : |
565 | argprint("(", &ap, &argsize); | | 565 | argprint("(", &ap, &argsize); |
566 | if ((s = ioctlname(*ap)) != NULL) | | 566 | if ((s = ioctlname(*ap)) != NULL) |
567 | wprintf(", %s", s); | | 567 | wprintf(", %s", s); |
568 | else | | 568 | else |
569 | ioctldecode(*ap); | | 569 | ioctldecode(*ap); |
570 | ap++; | | 570 | ap++; |
571 | argsize -= sizeof(register_t); | | 571 | argsize -= sizeof(register_t); |
572 | break; | | 572 | break; |
573 | | | 573 | |
574 | case SYS_ptrace : | | 574 | case SYS_ptrace : |
575 | if ((long)*ap >= 0 && | | 575 | if ((long)*ap >= 0 && |
576 | *ap < (register_t)(sizeof(ptrace_ops) / sizeof(ptrace_ops[0]))) | | 576 | *ap < (register_t)(sizeof(ptrace_ops) / sizeof(ptrace_ops[0]))) |
577 | wprintf("(%s", ptrace_ops[*ap]); | | 577 | wprintf("(%s", ptrace_ops[*ap]); |
578 | else | | 578 | else |
579 | wprintf("(%ld", (long)*ap); | | 579 | wprintf("(%ld", (long)*ap); |
580 | ap++; | | 580 | ap++; |
581 | argsize -= sizeof(register_t); | | 581 | argsize -= sizeof(register_t); |
582 | break; | | 582 | break; |
583 | | | 583 | |
584 | default: | | 584 | default: |
585 | print_first: | | 585 | print_first: |
586 | argprint("(", &ap, &argsize); | | 586 | argprint("(", &ap, &argsize); |
587 | break; | | 587 | break; |
588 | } | | 588 | } |
589 | | | 589 | |
590 | /* Print rest of argument. */ | | 590 | /* Print rest of argument. */ |
591 | while (argsize > 0) | | 591 | while (argsize > 0) |
592 | argprint(", ", &ap, &argsize); | | 592 | argprint(", ", &ap, &argsize); |
593 | | | 593 | |
594 | noargument: | | 594 | noargument: |
595 | wprintf(")"); | | 595 | wprintf(")"); |
596 | } | | 596 | } |
597 | | | 597 | |
598 | void | | 598 | void |
599 | ktrsyscall(struct ktr_entry *kte) | | 599 | ktrsyscall(struct ktr_entry *kte) |
600 | { | | 600 | { |
601 | struct ktr_header *kth = &kte->kte_kth; | | 601 | struct ktr_header *kth = &kte->kte_kth; |
602 | struct ktr_syscall *ktr = (struct ktr_syscall *)(kth + 1); | | 602 | struct ktr_syscall *ktr = (struct ktr_syscall *)(kth + 1); |
603 | | | 603 | |
604 | switch (ktr->ktr_code) { | | 604 | switch (ktr->ktr_code) { |
605 | case SYS_exit: | | 605 | case SYS_exit: |
606 | dumpheader(kth); | | 606 | dumpheader(kth); |
607 | syscallprint(kth); | | 607 | syscallprint(kth); |
608 | break; | | 608 | break; |
609 | default: | | 609 | default: |
610 | putpendq(kte); | | 610 | putpendq(kte); |
611 | return; | | 611 | return; |
612 | } | | 612 | } |
613 | | | 613 | |
614 | free(kte); | | 614 | free(kte); |
615 | } | | 615 | } |
616 | | | 616 | |
617 | void | | 617 | void |
618 | sysretprint(struct ktr_header *kth) | | 618 | sysretprint(struct ktr_header *kth) |
619 | { | | 619 | { |
620 | struct ktr_sysret *ktr = (struct ktr_sysret *)(kth + 1); | | 620 | struct ktr_sysret *ktr = (struct ktr_sysret *)(kth + 1); |
621 | register_t ret = ktr->ktr_retval; | | 621 | register_t ret = ktr->ktr_retval; |
622 | int error = ktr->ktr_error; | | 622 | int error = ktr->ktr_error; |
623 | | | 623 | |
624 | indent(50); | | 624 | indent(50); |
625 | if (error == EJUSTRETURN) | | 625 | if (error == EJUSTRETURN) |
626 | wprintf(" JUSTRETURN"); | | 626 | wprintf(" JUSTRETURN"); |
627 | else if (error == ERESTART) | | 627 | else if (error == ERESTART) |
628 | wprintf(" RESTART"); | | 628 | wprintf(" RESTART"); |
629 | else if (error) { | | 629 | else if (error) { |
630 | wprintf(" Err#%d", error); | | 630 | wprintf(" Err#%d", error); |
631 | if (error < MAXERRNOS && error >= -2) | | 631 | if (error < MAXERRNOS && error >= -2) |
632 | wprintf(" %s", errnos[error].name); | | 632 | wprintf(" %s", errnos[error].name); |
633 | } else | | 633 | } else |
634 | switch (ktr->ktr_code) { | | 634 | switch (ktr->ktr_code) { |
635 | case SYS_mmap: | | 635 | case SYS_mmap: |
636 | wprintf(" = %p", (long)ret); | | 636 | wprintf(" = %p", (long)ret); |
637 | break; | | 637 | break; |
638 | default: | | 638 | default: |
639 | wprintf(" = %ld", (long)ret); | | 639 | wprintf(" = %ld", (long)ret); |
640 | if (kth->ktr_len > (int)offsetof(struct ktr_sysret, | | 640 | if (kth->ktr_len > (int)offsetof(struct ktr_sysret, |
641 | ktr_retval_1) && ktr->ktr_retval_1 != 0) | | 641 | ktr_retval_1) && ktr->ktr_retval_1 != 0) |
642 | wprintf(", %ld", (long)ktr->ktr_retval_1); | | 642 | wprintf(", %ld", (long)ktr->ktr_retval_1); |
643 | break; | | 643 | break; |
644 | } | | 644 | } |
645 | } | | 645 | } |
646 | | | 646 | |
647 | void | | 647 | void |
648 | ktrsysret(struct ktr_entry *kte) | | 648 | ktrsysret(struct ktr_entry *kte) |
649 | { | | 649 | { |
650 | struct ktr_header *kth = &kte->kte_kth; | | 650 | struct ktr_header *kth = &kte->kte_kth; |
651 | struct ktr_sysret *ktr = (struct ktr_sysret *)(kth + 1); | | 651 | struct ktr_sysret *ktr = (struct ktr_sysret *)(kth + 1); |
652 | struct ktr_entry *genio; | | 652 | struct ktr_entry *genio; |
653 | struct ktr_entry *syscall_ent; | | 653 | struct ktr_entry *syscall_ent; |
654 | | | 654 | |
655 | dumpheader(kth); | | 655 | dumpheader(kth); |
656 | | | 656 | |
657 | /* Print syscall name and arguments. */ | | 657 | /* Print syscall name and arguments. */ |
658 | syscall_ent = getpendq(kth, KTR_SYSCALL, NULL); | | 658 | syscall_ent = getpendq(kth, KTR_SYSCALL, NULL); |
659 | if (syscall_ent == NULL) { | | 659 | if (syscall_ent == NULL) { |
660 | /* | | 660 | /* |
661 | * Possibilly a child of fork/vfork, or tracing of | | 661 | * Possibilly a child of fork/vfork, or tracing of |
662 | * process started during system call. | | 662 | * process started during system call. |
663 | */ | | 663 | */ |
664 | syscallnameprint(ktr->ktr_code); | | 664 | syscallnameprint(ktr->ktr_code); |
665 | } else { | | 665 | } else { |
666 | syscallprint(&syscall_ent->kte_kth); | | 666 | syscallprint(&syscall_ent->kte_kth); |
667 | free(syscall_ent); | | 667 | free(syscall_ent); |
668 | } | | 668 | } |
669 | | | 669 | |
670 | /* Print return value and an error if any. */ | | 670 | /* Print return value and an error if any. */ |
671 | sysretprint(kth); | | 671 | sysretprint(kth); |
672 | | | 672 | |
673 | genio = getpendq(kth, KTR_GENIO, NULL); | | 673 | genio = getpendq(kth, KTR_GENIO, NULL); |
674 | if (genio != NULL) { | | 674 | if (genio != NULL) { |
675 | genioprint(&genio->kte_kth); | | 675 | genioprint(&genio->kte_kth); |
676 | free(genio); | | 676 | free(genio); |
677 | } | | 677 | } |
678 | | | 678 | |
679 | flushpendq(kte); | | 679 | flushpendq(kte); |
680 | free(kte); | | 680 | free(kte); |
681 | } | | 681 | } |
682 | | | 682 | |
683 | void | | 683 | void |
684 | nameiprint(struct ktr_header *kth) | | 684 | nameiprint(struct ktr_header *kth) |
685 | { | | 685 | { |
686 | | | 686 | |
687 | wprintf("\"%.*s\"", kth->ktr_len, (char *)(kth + 1)); | | 687 | wprintf("\"%.*s\"", kth->ktr_len, (char *)(kth + 1)); |
688 | } | | 688 | } |
689 | | | 689 | |
690 | #ifdef notused | | 690 | #ifdef notused |
691 | void | | 691 | void |
692 | ktrnamei(struct ktr_entry *kte) | | 692 | ktrnamei(struct ktr_entry *kte) |
693 | { | | 693 | { |
694 | struct ktr_header *kth = &kte->kte_kth; | | 694 | struct ktr_header *kth = &kte->kte_kth; |
695 | | | 695 | |
696 | dumpheader(kth); | | 696 | dumpheader(kth); |
697 | wprintf("namei("); | | 697 | wprintf("namei("); |
698 | nameiprint(kth); | | 698 | nameiprint(kth); |
699 | wprintf(")"); | | 699 | wprintf(")"); |
700 | | | 700 | |
701 | free(kte); | | 701 | free(kte); |
702 | } | | 702 | } |
703 | #endif | | 703 | #endif |
704 | | | 704 | |
705 | void | | 705 | void |
706 | ktremul(struct ktr_entry *kte) | | 706 | ktremul(struct ktr_entry *kte) |
707 | { | | 707 | { |
708 | struct ktr_header *kth = &kte->kte_kth; | | 708 | struct ktr_header *kth = &kte->kte_kth; |
709 | char *emul = (char *)(kth + 1); | | 709 | char *emul = (char *)(kth + 1); |
710 | | | 710 | |
711 | dumpheader(kth); | | 711 | dumpheader(kth); |
712 | wprintf("emul(%s)", emul); | | 712 | wprintf("emul(%s)", emul); |
713 | setemul(emul, kth->ktr_pid, 1); | | 713 | setemul(emul, kth->ktr_pid, 1); |
714 | | | 714 | |
715 | free(kte); | | 715 | free(kte); |
716 | } | | 716 | } |
717 | | | 717 | |
718 | void | | 718 | void |
719 | genioprint(struct ktr_header *kth) | | 719 | genioprint(struct ktr_header *kth) |
720 | { | | 720 | { |
721 | struct ktr_genio *ktr = (struct ktr_genio *)(kth + 1); | | 721 | struct ktr_genio *ktr = (struct ktr_genio *)(kth + 1); |
722 | static int screenwidth = 0; | | 722 | static int screenwidth = 0; |
723 | int datalen = kth->ktr_len - sizeof(struct ktr_genio); | | 723 | int datalen = kth->ktr_len - sizeof(struct ktr_genio); |
724 | /* | | 724 | /* |
725 | * Need to be unsigned type so that positive value is passed | | 725 | * Need to be unsigned type so that positive value is passed |
726 | * to vis(), which will call isgraph(). | | 726 | * to vis(), which will call isgraph(). |
727 | */ | | 727 | */ |
728 | unsigned char *dp = (unsigned char *)(ktr + 1); | | 728 | unsigned char *dp = (unsigned char *)(ktr + 1); |
729 | int w; | | 729 | int w; |
730 | char visbuf[5]; | | 730 | char visbuf[5]; |
731 | | | 731 | |
732 | if (screenwidth == 0) { | | 732 | if (screenwidth == 0) { |
733 | struct winsize ws; | | 733 | struct winsize ws; |
734 | | | 734 | |
735 | if (fancy && ioctl(fileno(stderr), TIOCGWINSZ, &ws) != -1 && | | 735 | if (fancy && ioctl(fileno(stderr), TIOCGWINSZ, &ws) != -1 && |
736 | ws.ws_col > 8) | | 736 | ws.ws_col > 8) |
737 | screenwidth = ws.ws_col; | | 737 | screenwidth = ws.ws_col; |
738 | else | | 738 | else |
739 | screenwidth = 80; | | 739 | screenwidth = 80; |
740 | } | | 740 | } |
741 | | | 741 | |
742 | if (maxdata && datalen > maxdata) | | 742 | if (maxdata && datalen > maxdata) |
743 | datalen = maxdata; | | 743 | datalen = maxdata; |
744 | newline(); | | 744 | newline(); |
745 | wprintf(" \""); | | 745 | wprintf(" \""); |
746 | for (; datalen > 0; datalen--, dp++) { | | 746 | for (; datalen > 0; datalen--, dp++) { |
747 | (void) vis(visbuf, *dp, VIS_NL|VIS_TAB|VIS_CSTYLE, | | 747 | (void) vis(visbuf, *dp, VIS_NL|VIS_TAB|VIS_CSTYLE, |
748 | /* We put NUL at the end of buffer when reading */ | | 748 | /* We put NUL at the end of buffer when reading */ |
749 | *(dp + 1)); | | 749 | *(dp + 1)); |
750 | visbuf[4] = '\0'; | | 750 | visbuf[4] = '\0'; |
751 | w = strlen(visbuf); | | 751 | w = strlen(visbuf); |
752 | if (width + w + 2 >= screenwidth) | | 752 | if (width + w + 2 >= screenwidth) |
753 | break; | | 753 | break; |
754 | wprintf("%s", visbuf); | | 754 | wprintf("%s", visbuf); |
755 | if (width + 2 >= screenwidth) | | 755 | if (width + 2 >= screenwidth) |
756 | break; | | 756 | break; |
757 | } | | 757 | } |
758 | wprintf("\""); | | 758 | wprintf("\""); |
759 | } | | 759 | } |
760 | | | 760 | |
761 | #ifdef notused | | 761 | #ifdef notused |
762 | void | | 762 | void |
763 | ktrgenio(struct ktr_entry *kte) | | 763 | ktrgenio(struct ktr_entry *kte) |
764 | { | | 764 | { |
765 | struct ktr_header *kth = &kte->kte_kth; | | 765 | struct ktr_header *kth = &kte->kte_kth; |
766 | struct ktr_genio *ktr = (struct ktr_genio *)(kth + 1); | | 766 | struct ktr_genio *ktr = (struct ktr_genio *)(kth + 1); |
767 | | | 767 | |
768 | dumpheader(kth); | | 768 | dumpheader(kth); |
769 | wprintf("genio fd %d %s", | | 769 | wprintf("genio fd %d %s", |
770 | ktr->ktr_fd, ktr->ktr_rw ? "write" : "read"); | | 770 | ktr->ktr_fd, ktr->ktr_rw ? "write" : "read"); |
771 | genioprint(kth); | | 771 | genioprint(kth); |
772 | | | 772 | |
773 | free(kte); | | 773 | free(kte); |
774 | } | | 774 | } |
775 | #endif | | 775 | #endif |
776 | | | 776 | |
777 | void | | 777 | void |
778 | ktrpsig(struct ktr_entry *kte) | | 778 | ktrpsig(struct ktr_entry *kte) |
779 | { | | 779 | { |
780 | struct ktr_header *kth = &kte->kte_kth; | | 780 | struct ktr_header *kth = &kte->kte_kth; |
781 | struct ktr_psig *psig = (struct ktr_psig *)(kth + 1); | | 781 | struct ktr_psig *psig = (struct ktr_psig *)(kth + 1); |
782 | | | 782 | |
783 | dumpheader(kth); | | 783 | dumpheader(kth); |
784 | wprintf("SIG%s ", sys_signame[psig->signo]); | | 784 | wprintf("SIG%s ", sys_signame[psig->signo]); |
785 | if (psig->action == SIG_DFL) | | 785 | if (psig->action == SIG_DFL) |
786 | wprintf("SIG_DFL"); | | 786 | wprintf("SIG_DFL"); |
787 | else { | | 787 | else { |
788 | wprintf("caught handler=0x%lx mask=0x%lx code=0x%x", | | 788 | wprintf("caught handler=0x%lx mask=0x%lx code=0x%x", |
789 | (u_long)psig->action, (unsigned long)psig->mask.__bits[0], | | 789 | (u_long)psig->action, (unsigned long)psig->mask.__bits[0], |
790 | psig->code); | | 790 | psig->code); |
791 | } | | 791 | } |
792 | | | 792 | |
793 | free(kte); | | 793 | free(kte); |
794 | } | | 794 | } |
795 | | | 795 | |
796 | void | | 796 | void |
797 | ktrcsw(struct ktr_entry *kte) | | 797 | ktrcsw(struct ktr_entry *kte) |
798 | { | | 798 | { |
799 | struct ktr_header *kth = &kte->kte_kth; | | 799 | struct ktr_header *kth = &kte->kte_kth; |
800 | struct ktr_csw *cs = (struct ktr_csw *)(kth + 1); | | 800 | struct ktr_csw *cs = (struct ktr_csw *)(kth + 1); |
801 | | | 801 | |
802 | dumpheader(kth); | | 802 | dumpheader(kth); |
803 | wprintf("%s %s", cs->out ? "stop" : "resume", | | 803 | wprintf("%s %s", cs->out ? "stop" : "resume", |
804 | cs->user ? "user" : "kernel"); | | 804 | cs->user ? "user" : "kernel"); |
805 | | | 805 | |
806 | free(kte); | | 806 | free(kte); |
807 | } | | 807 | } |