Ignore machine-check MSRs
[freebsd-src/fkvm-freebsd.git] / sys / kern / uipc_debug.c
blobc2a0937ab9160c756b298cc2ba6a8cfd3b862566
1 /*-
2 * Copyright (c) 2007 Robert N. M. Watson
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
28 * Debugger routines relating to sockets, protocols, etc, for use in DDB.
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
34 #include "opt_ddb.h"
36 #include <sys/param.h>
37 #include <sys/domain.h>
38 #include <sys/kernel.h>
39 #include <sys/protosw.h>
40 #include <sys/socket.h>
41 #include <sys/socketvar.h>
43 #ifdef DDB
44 #include <ddb/ddb.h>
46 static void
47 db_print_sotype(short so_type)
50 switch (so_type) {
51 case SOCK_STREAM:
52 db_printf("SOCK_STREAM");
53 break;
55 case SOCK_DGRAM:
56 db_printf("SOCK_DGRAM");
57 break;
59 case SOCK_RAW:
60 db_printf("SOCK_RAW");
61 break;
63 case SOCK_RDM:
64 db_printf("SOCK_RDM");
65 break;
67 case SOCK_SEQPACKET:
68 db_printf("SOCK_SEQPACKET");
69 break;
71 default:
72 db_printf("unknown");
73 break;
77 static void
78 db_print_sooptions(short so_options)
80 int comma;
82 comma = 0;
83 if (so_options & SO_DEBUG) {
84 db_printf("%sSO_DEBUG", comma ? ", " : "");
85 comma = 1;
87 if (so_options & SO_ACCEPTCONN) {
88 db_printf("%sSO_ACCEPTCONN", comma ? ", " : "");
89 comma = 1;
91 if (so_options & SO_REUSEADDR) {
92 db_printf("%sSO_REUSEADDR", comma ? ", " : "");
93 comma = 1;
95 if (so_options & SO_KEEPALIVE) {
96 db_printf("%sSO_KEEPALIVE", comma ? ", " : "");
97 comma = 1;
99 if (so_options & SO_DONTROUTE) {
100 db_printf("%sSO_DONTROUTE", comma ? ", " : "");
101 comma = 1;
103 if (so_options & SO_BROADCAST) {
104 db_printf("%sSO_BROADCAST", comma ? ", " : "");
105 comma = 1;
107 if (so_options & SO_USELOOPBACK) {
108 db_printf("%sSO_USELOOPBACK", comma ? ", " : "");
109 comma = 1;
111 if (so_options & SO_LINGER) {
112 db_printf("%sSO_LINGER", comma ? ", " : "");
113 comma = 1;
115 if (so_options & SO_OOBINLINE) {
116 db_printf("%sSO_OOBINLINE", comma ? ", " : "");
117 comma = 1;
119 if (so_options & SO_REUSEPORT) {
120 db_printf("%sSO_REUSEPORT", comma ? ", " : "");
121 comma = 1;
123 if (so_options & SO_TIMESTAMP) {
124 db_printf("%sSO_TIMESTAMP", comma ? ", " : "");
125 comma = 1;
127 if (so_options & SO_NOSIGPIPE) {
128 db_printf("%sSO_NOSIGPIPE", comma ? ", " : "");
129 comma = 1;
131 if (so_options & SO_ACCEPTFILTER) {
132 db_printf("%sSO_ACCEPTFILTER", comma ? ", " : "");
133 comma = 1;
135 if (so_options & SO_BINTIME) {
136 db_printf("%sSO_BINTIME", comma ? ", " : "");
137 comma = 1;
141 static void
142 db_print_sostate(short so_state)
144 int comma;
146 comma = 0;
147 if (so_state & SS_NOFDREF) {
148 db_printf("%sSS_FDREF", comma ? ", " : "");
149 comma = 1;
151 if (so_state & SS_ISCONNECTED) {
152 db_printf("%sSS_ISCONNECTED", comma ? ", " : "");
153 comma = 1;
155 if (so_state & SS_ISCONNECTING) {
156 db_printf("%sSS_ISCONNECTING", comma ? ", " : "");
157 comma = 1;
159 if (so_state & SS_ISDISCONNECTING) {
160 db_printf("%sSS_ISDISCONNECTING", comma ? ", " : "");
161 comma = 1;
163 if (so_state & SS_NBIO) {
164 db_printf("%sSS_NBIO", comma ? ", " : "");
165 comma = 1;
167 if (so_state & SS_ASYNC) {
168 db_printf("%sSS_ASYNC", comma ? ", " : "");
169 comma = 1;
171 if (so_state & SS_ISCONFIRMING) {
172 db_printf("%sSS_ISCONFIRMING", comma ? ", " : "");
173 comma = 1;
175 comma = 0;
176 if (so_state & SS_PROTOREF) {
177 db_printf("%sSS_PROTOREF", comma ? ", " : "");
178 comma = 1;
182 static void
183 db_print_soqstate(int so_qstate)
185 int comma;
187 comma = 0;
188 if (so_qstate & SQ_INCOMP) {
189 db_printf("%sSQ_INCOMP", comma ? ", " : "");
190 comma = 1;
192 if (so_qstate & SQ_COMP) {
193 db_printf("%sSQ_COMP", comma ? ", " : "");
194 comma = 1;
198 static void
199 db_print_sbstate(short sb_state)
201 int comma;
203 comma = 0;
204 if (sb_state & SBS_CANTSENDMORE) {
205 db_printf("%sSS_CANTSENDMORE", comma ? ", " : "");
206 comma = 1;
208 if (sb_state & SBS_CANTRCVMORE) {
209 db_printf("%sSS_CANTRCVMORE", comma ? ", " : "");
210 comma = 1;
212 if (sb_state & SBS_RCVATMARK) {
213 db_printf("%sSS_RCVATMARK", comma ? ", " : "");
214 comma = 1;
218 static void
219 db_print_indent(int indent)
221 int i;
223 for (i = 0; i < indent; i++)
224 db_printf(" ");
227 static void
228 db_print_domain(struct domain *d, const char *domain_name, int indent)
231 db_print_indent(indent);
232 db_printf("%s at %p\n", domain_name, d);
234 indent += 2;
236 db_print_indent(indent);
237 db_printf("dom_family: %d ", d->dom_family);
238 db_printf("dom_name: %s\n", d->dom_name);
240 db_print_indent(indent);
241 db_printf("dom_init: %p ", d->dom_init);
242 db_printf("dom_externalize: %p ", d->dom_externalize);
243 db_printf("dom_dispose: %p\n", d->dom_dispose);
245 db_print_indent(indent);
246 db_printf("dom_protosw: %p ", d->dom_protosw);
247 db_printf("dom_next: %p\n", d->dom_next);
249 db_print_indent(indent);
250 db_printf("dom_rtattach: %p ", d->dom_rtattach);
251 db_printf("dom_rtoffset: %d ", d->dom_rtoffset);
252 db_printf("dom_maxrtkey: %d\n", d->dom_maxrtkey);
254 db_print_indent(indent);
255 db_printf("dom_ifattach: %p ", d->dom_ifattach);
256 db_printf("dom_ifdetach: %p\n", d->dom_ifdetach);
259 static void
260 db_print_prflags(short pr_flags)
262 int comma;
264 comma = 0;
265 if (pr_flags & PR_ATOMIC) {
266 db_printf("%sPR_ATOMIC", comma ? ", " : "");
267 comma = 1;
269 if (pr_flags & PR_ADDR) {
270 db_printf("%sPR_ADDR", comma ? ", " : "");
271 comma = 1;
273 if (pr_flags & PR_CONNREQUIRED) {
274 db_printf("%sPR_CONNREQUIRED", comma ? ", " : "");
275 comma = 1;
277 if (pr_flags & PR_WANTRCVD) {
278 db_printf("%sPR_WANTRCVD", comma ? ", " : "");
279 comma = 1;
281 if (pr_flags & PR_RIGHTS) {
282 db_printf("%sPR_RIGHTS", comma ? ", " : "");
283 comma = 1;
285 if (pr_flags & PR_IMPLOPCL) {
286 db_printf("%sPR_IMPLOPCL", comma ? ", " : "");
287 comma = 1;
289 if (pr_flags & PR_LASTHDR) {
290 db_printf("%sPR_LASTHDR", comma ? ", " : "");
291 comma = 1;
295 static void
296 db_print_protosw(struct protosw *pr, const char *prname, int indent)
299 db_print_indent(indent);
300 db_printf("%s at %p\n", prname, pr);
302 indent += 2;
304 db_print_indent(indent);
305 db_printf("pr_type: %d ", pr->pr_type);
306 db_printf("pr_domain: %p\n", pr->pr_domain);
307 if (pr->pr_domain != NULL)
308 db_print_domain(pr->pr_domain, "pr_domain", indent);
310 db_print_indent(indent);
311 db_printf("pr_protocol: %d\n", pr->pr_protocol);
313 db_print_indent(indent);
314 db_printf("pr_flags: %d (", pr->pr_flags);
315 db_print_prflags(pr->pr_flags);
316 db_printf(")\n");
318 db_print_indent(indent);
319 db_printf("pr_input: %p ", pr->pr_input);
320 db_printf("pr_output: %p ", pr->pr_output);
321 db_printf("pr_ctlinput: %p\n", pr->pr_ctlinput);
323 db_print_indent(indent);
324 db_printf("pr_ctloutput: %p ", pr->pr_ctloutput);
325 db_printf("pr_ousrreq: %p ", pr->pr_ousrreq);
326 db_printf("pr_init: %p\n", pr->pr_init);
328 db_print_indent(indent);
329 db_printf("pr_fasttimo: %p ", pr->pr_fasttimo);
330 db_printf("pr_slowtimo: %p ", pr->pr_slowtimo);
331 db_printf("pr_drain: %p\n", pr->pr_drain);
333 db_print_indent(indent);
334 db_printf("pr_ousrreq: %p\n", pr->pr_ousrreq);
337 static void
338 db_print_sbflags(short sb_flags)
340 int comma;
342 comma = 0;
343 if (sb_flags & SB_WAIT) {
344 db_printf("%sSB_WAIT", comma ? ", " : "");
345 comma = 1;
347 if (sb_flags & SB_SEL) {
348 db_printf("%sSB_SEL", comma ? ", " : "");
349 comma = 1;
351 if (sb_flags & SB_ASYNC) {
352 db_printf("%sSB_ASYNC", comma ? ", " : "");
353 comma = 1;
355 if (sb_flags & SB_UPCALL) {
356 db_printf("%sSB_UPCALL", comma ? ", " : "");
357 comma = 1;
359 if (sb_flags & SB_NOINTR) {
360 db_printf("%sSB_NOINTR", comma ? ", " : "");
361 comma = 1;
363 if (sb_flags & SB_AIO) {
364 db_printf("%sSB_AIO", comma ? ", " : "");
365 comma = 1;
367 if (sb_flags & SB_KNOTE) {
368 db_printf("%sSB_KNOTE", comma ? ", " : "");
369 comma = 1;
371 if (sb_flags & SB_AUTOSIZE) {
372 db_printf("%sSB_AUTOSIZE", comma ? ", " : "");
373 comma = 1;
377 static void
378 db_print_sockbuf(struct sockbuf *sb, const char *sockbufname, int indent)
381 db_print_indent(indent);
382 db_printf("%s at %p\n", sockbufname, sb);
384 indent += 2;
386 db_print_indent(indent);
387 db_printf("sb_state: 0x%x (", sb->sb_state);
388 db_print_sbstate(sb->sb_state);
389 db_printf(")\n");
391 db_print_indent(indent);
392 db_printf("sb_mb: %p ", sb->sb_mb);
393 db_printf("sb_mbtail: %p ", sb->sb_mbtail);
394 db_printf("sb_lastrecord: %p\n", sb->sb_lastrecord);
396 db_print_indent(indent);
397 db_printf("sb_sndptr: %p ", sb->sb_sndptr);
398 db_printf("sb_sndptroff: %u\n", sb->sb_sndptroff);
400 db_print_indent(indent);
401 db_printf("sb_cc: %u ", sb->sb_cc);
402 db_printf("sb_hiwat: %u ", sb->sb_hiwat);
403 db_printf("sb_mbcnt: %u ", sb->sb_mbcnt);
404 db_printf("sb_mbmax: %u\n", sb->sb_mbmax);
406 db_print_indent(indent);
407 db_printf("sb_ctl: %u ", sb->sb_ctl);
408 db_printf("sb_lowat: %d ", sb->sb_lowat);
409 db_printf("sb_timeo: %d\n", sb->sb_timeo);
411 db_print_indent(indent);
412 db_printf("sb_flags: 0x%x (", sb->sb_flags);
413 db_print_sbflags(sb->sb_flags);
414 db_printf(")\n");
417 static void
418 db_print_socket(struct socket *so, const char *socketname, int indent)
421 db_print_indent(indent);
422 db_printf("%s at %p\n", socketname, so);
424 indent += 2;
426 db_print_indent(indent);
427 db_printf("so_count: %d ", so->so_count);
428 db_printf("so_type: %d (", so->so_type);
429 db_print_sotype(so->so_type);
430 db_printf(")\n");
432 db_print_indent(indent);
433 db_printf("so_options: 0x%x (", so->so_options);
434 db_print_sooptions(so->so_options);
435 db_printf(")\n");
437 db_print_indent(indent);
438 db_printf("so_linger: %d ", so->so_linger);
439 db_printf("so_state: 0x%x (", so->so_state);
440 db_print_sostate(so->so_state);
441 db_printf(")\n");
443 db_print_indent(indent);
444 db_printf("so_qstate: 0x%x (", so->so_qstate);
445 db_print_soqstate(so->so_qstate);
446 db_printf(") ");
447 db_printf("so_pcb: %p ", so->so_pcb);
448 db_printf("so_proto: %p\n", so->so_proto);
450 if (so->so_proto != NULL)
451 db_print_protosw(so->so_proto, "so_proto", indent);
453 db_print_indent(indent);
454 db_printf("so_head: %p ", so->so_head);
455 db_printf("so_incomp first: %p ", TAILQ_FIRST(&so->so_incomp));
456 db_printf("so_comp first: %p\n", TAILQ_FIRST(&so->so_comp));
458 db_print_indent(indent);
459 /* so_list skipped */
460 db_printf("so_qlen: %d ", so->so_qlen);
461 db_printf("so_incqlen: %d ", so->so_incqlen);
462 db_printf("so_qlimit: %d ", so->so_qlimit);
463 db_printf("so_timeo: %d ", so->so_timeo);
464 db_printf("so_error: %d\n", so->so_error);
466 db_print_indent(indent);
467 db_printf("so_sigio: %p ", so->so_sigio);
468 db_printf("so_oobmark: %lu ", so->so_oobmark);
469 db_printf("so_aiojobq first: %p\n", TAILQ_FIRST(&so->so_aiojobq));
471 db_print_sockbuf(&so->so_rcv, "so_rcv", indent);
472 db_print_sockbuf(&so->so_snd, "so_snd", indent);
475 DB_SHOW_COMMAND(socket, db_show_socket)
477 struct socket *so;
479 if (!have_addr) {
480 db_printf("usage: show socket <addr>\n");
481 return;
483 so = (struct socket *)addr;
485 db_print_socket(so, "socket", 0);
488 DB_SHOW_COMMAND(sockbuf, db_show_sockbuf)
490 struct sockbuf *sb;
492 if (!have_addr) {
493 db_printf("usage: show sockbuf <addr>\n");
494 return;
496 sb = (struct sockbuf *)addr;
498 db_print_sockbuf(sb, "sockbuf", 0);
501 DB_SHOW_COMMAND(protosw, db_show_protosw)
503 struct protosw *pr;
505 if (!have_addr) {
506 db_printf("usage: show protosw <addr>\n");
507 return;
509 pr = (struct protosw *)addr;
511 db_print_protosw(pr, "protosw", 0);
514 DB_SHOW_COMMAND(domain, db_show_domain)
516 struct domain *d;
518 if (!have_addr) {
519 db_printf("usage: show protosw <addr>\n");
520 return;
522 d = (struct domain *)addr;
524 db_print_domain(d, "domain", 0);
526 #endif