]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/kern/uipc_debug.c
Merge in support for Xen HVM on amd64 architecture.
[FreeBSD/FreeBSD.git] / sys / kern / uipc_debug.c
1 /*-
2  * Copyright (c) 2007 Robert N. M. Watson
3  * All rights reserved.
4  *
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.
13  *
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.
25  */
26
27 /*
28  * Debugger routines relating to sockets, protocols, etc, for use in DDB.
29  */
30
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
33
34 #include "opt_ddb.h"
35
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>
42
43 #ifdef DDB
44 #include <ddb/ddb.h>
45
46 static void
47 db_print_sotype(short so_type)
48 {
49
50         switch (so_type) {
51         case SOCK_STREAM:
52                 db_printf("SOCK_STREAM");
53                 break;
54
55         case SOCK_DGRAM:
56                 db_printf("SOCK_DGRAM");
57                 break;
58
59         case SOCK_RAW:
60                 db_printf("SOCK_RAW");
61                 break;
62
63         case SOCK_RDM:
64                 db_printf("SOCK_RDM");
65                 break;
66
67         case SOCK_SEQPACKET:
68                 db_printf("SOCK_SEQPACKET");
69                 break;
70
71         default:
72                 db_printf("unknown");
73                 break;
74         }
75 }
76
77 static void
78 db_print_sooptions(short so_options)
79 {
80         int comma;
81
82         comma = 0;
83         if (so_options & SO_DEBUG) {
84                 db_printf("%sSO_DEBUG", comma ? ", " : "");
85                 comma = 1;
86         }
87         if (so_options & SO_ACCEPTCONN) {
88                 db_printf("%sSO_ACCEPTCONN", comma ? ", " : "");
89                 comma = 1;
90         }
91         if (so_options & SO_REUSEADDR) {
92                 db_printf("%sSO_REUSEADDR", comma ? ", " : "");
93                 comma = 1;
94         }
95         if (so_options & SO_KEEPALIVE) {
96                 db_printf("%sSO_KEEPALIVE", comma ? ", " : "");
97                 comma = 1;
98         }
99         if (so_options & SO_DONTROUTE) {
100                 db_printf("%sSO_DONTROUTE", comma ? ", " : "");
101                 comma = 1;
102         }
103         if (so_options & SO_BROADCAST) {
104                 db_printf("%sSO_BROADCAST", comma ? ", " : "");
105                 comma = 1;
106         }
107         if (so_options & SO_USELOOPBACK) {
108                 db_printf("%sSO_USELOOPBACK", comma ? ", " : "");
109                 comma = 1;
110         }
111         if (so_options & SO_LINGER) {
112                 db_printf("%sSO_LINGER", comma ? ", " : "");
113                 comma = 1;
114         }
115         if (so_options & SO_OOBINLINE) {
116                 db_printf("%sSO_OOBINLINE", comma ? ", " : "");
117                 comma = 1;
118         }
119         if (so_options & SO_REUSEPORT) {
120                 db_printf("%sSO_REUSEPORT", comma ? ", " : "");
121                 comma = 1;
122         }
123         if (so_options & SO_TIMESTAMP) {
124                 db_printf("%sSO_TIMESTAMP", comma ? ", " : "");
125                 comma = 1;
126         }
127         if (so_options & SO_NOSIGPIPE) {
128                 db_printf("%sSO_NOSIGPIPE", comma ? ", " : "");
129                 comma = 1;
130         }
131         if (so_options & SO_ACCEPTFILTER) {
132                 db_printf("%sSO_ACCEPTFILTER", comma ? ", " : "");
133                 comma = 1;
134         }
135         if (so_options & SO_BINTIME) {
136                 db_printf("%sSO_BINTIME", comma ? ", " : "");
137                 comma = 1;
138         }
139 }
140
141 static void
142 db_print_sostate(short so_state)
143 {
144         int comma;
145
146         comma = 0;
147         if (so_state & SS_NOFDREF) {
148                 db_printf("%sSS_NOFDREF", comma ? ", " : "");
149                 comma = 1;
150         }
151         if (so_state & SS_ISCONNECTED) {
152                 db_printf("%sSS_ISCONNECTED", comma ? ", " : "");
153                 comma = 1;
154         }
155         if (so_state & SS_ISCONNECTING) {
156                 db_printf("%sSS_ISCONNECTING", comma ? ", " : "");
157                 comma = 1;
158         }
159         if (so_state & SS_ISDISCONNECTING) {
160                 db_printf("%sSS_ISDISCONNECTING", comma ? ", " : "");
161                 comma = 1;
162         }
163         if (so_state & SS_NBIO) {
164                 db_printf("%sSS_NBIO", comma ? ", " : "");
165                 comma = 1;
166         }
167         if (so_state & SS_ASYNC) {
168                 db_printf("%sSS_ASYNC", comma ? ", " : "");
169                 comma = 1;
170         }
171         if (so_state & SS_ISCONFIRMING) {
172                 db_printf("%sSS_ISCONFIRMING", comma ? ", " : "");
173                 comma = 1;
174         }
175         if (so_state & SS_PROTOREF) {
176                 db_printf("%sSS_PROTOREF", comma ? ", " : "");
177                 comma = 1;
178         }
179 }
180
181 static void
182 db_print_soqstate(int so_qstate)
183 {
184         int comma;
185
186         comma = 0;
187         if (so_qstate & SQ_INCOMP) {
188                 db_printf("%sSQ_INCOMP", comma ? ", " : "");
189                 comma = 1;
190         }
191         if (so_qstate & SQ_COMP) {
192                 db_printf("%sSQ_COMP", comma ? ", " : "");
193                 comma = 1;
194         }
195 }
196
197 static void
198 db_print_sbstate(short sb_state)
199 {
200         int comma;
201
202         comma = 0;
203         if (sb_state & SBS_CANTSENDMORE) {
204                 db_printf("%sSS_CANTSENDMORE", comma ? ", " : "");
205                 comma = 1;
206         }
207         if (sb_state & SBS_CANTRCVMORE) {
208                 db_printf("%sSS_CANTRCVMORE", comma ? ", " : "");
209                 comma = 1;
210         }
211         if (sb_state & SBS_RCVATMARK) {
212                 db_printf("%sSS_RCVATMARK", comma ? ", " : "");
213                 comma = 1;
214         }
215 }
216
217 static void
218 db_print_indent(int indent)
219 {
220         int i;
221
222         for (i = 0; i < indent; i++)
223                 db_printf(" ");
224 }
225
226 static void
227 db_print_domain(struct domain *d, const char *domain_name, int indent)
228 {
229
230         db_print_indent(indent);
231         db_printf("%s at %p\n", domain_name, d);
232
233         indent += 2;
234
235         db_print_indent(indent);
236         db_printf("dom_family: %d   ", d->dom_family);
237         db_printf("dom_name: %s\n", d->dom_name);
238
239         db_print_indent(indent);
240         db_printf("dom_init: %p   ", d->dom_init);
241         db_printf("dom_externalize: %p   ", d->dom_externalize);
242         db_printf("dom_dispose: %p\n", d->dom_dispose);
243
244         db_print_indent(indent);
245         db_printf("dom_protosw: %p   ", d->dom_protosw);
246         db_printf("dom_next: %p\n", d->dom_next);
247
248         db_print_indent(indent);
249         db_printf("dom_rtattach: %p   ", d->dom_rtattach);
250         db_printf("dom_rtoffset: %d   ", d->dom_rtoffset);
251         db_printf("dom_maxrtkey: %d\n", d->dom_maxrtkey);
252
253         db_print_indent(indent);
254         db_printf("dom_ifattach: %p   ", d->dom_ifattach);
255         db_printf("dom_ifdetach: %p\n", d->dom_ifdetach);
256 }
257
258 static void
259 db_print_prflags(short pr_flags)
260 {
261         int comma;
262
263         comma = 0;
264         if (pr_flags & PR_ATOMIC) {
265                 db_printf("%sPR_ATOMIC", comma ? ", " : "");
266                 comma = 1;
267         }
268         if (pr_flags & PR_ADDR) {
269                 db_printf("%sPR_ADDR", comma ? ", " : "");
270                 comma = 1;
271         }
272         if (pr_flags & PR_CONNREQUIRED) {
273                 db_printf("%sPR_CONNREQUIRED", comma ? ", " : "");
274                 comma = 1;
275         }
276         if (pr_flags & PR_WANTRCVD) {
277                 db_printf("%sPR_WANTRCVD", comma ? ", " : "");
278                 comma = 1;
279         }
280         if (pr_flags & PR_RIGHTS) {
281                 db_printf("%sPR_RIGHTS", comma ? ", " : "");
282                 comma = 1;
283         }
284         if (pr_flags & PR_IMPLOPCL) {
285                 db_printf("%sPR_IMPLOPCL", comma ? ", " : "");
286                 comma = 1;
287         }
288         if (pr_flags & PR_LASTHDR) {
289                 db_printf("%sPR_LASTHDR", comma ? ", " : "");
290                 comma = 1;
291         }
292 }
293
294 static void
295 db_print_protosw(struct protosw *pr, const char *prname, int indent)
296 {
297
298         db_print_indent(indent);
299         db_printf("%s at %p\n", prname, pr);
300
301         indent += 2;
302
303         db_print_indent(indent);
304         db_printf("pr_type: %d   ", pr->pr_type);
305         db_printf("pr_domain: %p\n", pr->pr_domain);
306         if (pr->pr_domain != NULL)
307                 db_print_domain(pr->pr_domain, "pr_domain", indent);
308
309         db_print_indent(indent);
310         db_printf("pr_protocol: %d\n", pr->pr_protocol);
311
312         db_print_indent(indent);
313         db_printf("pr_flags: %d (", pr->pr_flags);
314         db_print_prflags(pr->pr_flags);
315         db_printf(")\n");
316
317         db_print_indent(indent);
318         db_printf("pr_input: %p   ", pr->pr_input);
319         db_printf("pr_output: %p   ", pr->pr_output);
320         db_printf("pr_ctlinput: %p\n", pr->pr_ctlinput);
321
322         db_print_indent(indent);
323         db_printf("pr_ctloutput: %p   ", pr->pr_ctloutput);
324         db_printf("pr_init: %p\n", pr->pr_init);
325
326         db_print_indent(indent);
327         db_printf("pr_fasttimo: %p   ", pr->pr_fasttimo);
328         db_printf("pr_slowtimo: %p   ", pr->pr_slowtimo);
329         db_printf("pr_drain: %p\n", pr->pr_drain);
330
331         db_print_indent(indent);
332 }
333
334 static void
335 db_print_sbflags(short sb_flags)
336 {
337         int comma;
338
339         comma = 0;
340         if (sb_flags & SB_WAIT) {
341                 db_printf("%sSB_WAIT", comma ? ", " : "");
342                 comma = 1;
343         }
344         if (sb_flags & SB_SEL) {
345                 db_printf("%sSB_SEL", comma ? ", " : "");
346                 comma = 1;
347         }
348         if (sb_flags & SB_ASYNC) {
349                 db_printf("%sSB_ASYNC", comma ? ", " : "");
350                 comma = 1;
351         }
352         if (sb_flags & SB_UPCALL) {
353                 db_printf("%sSB_UPCALL", comma ? ", " : "");
354                 comma = 1;
355         }
356         if (sb_flags & SB_NOINTR) {
357                 db_printf("%sSB_NOINTR", comma ? ", " : "");
358                 comma = 1;
359         }
360         if (sb_flags & SB_AIO) {
361                 db_printf("%sSB_AIO", comma ? ", " : "");
362                 comma = 1;
363         }
364         if (sb_flags & SB_KNOTE) {
365                 db_printf("%sSB_KNOTE", comma ? ", " : "");
366                 comma = 1;
367         }
368         if (sb_flags & SB_AUTOSIZE) {
369                 db_printf("%sSB_AUTOSIZE", comma ? ", " : "");
370                 comma = 1;
371         }
372 }
373
374 static void
375 db_print_sockbuf(struct sockbuf *sb, const char *sockbufname, int indent)
376 {
377
378         db_print_indent(indent);
379         db_printf("%s at %p\n", sockbufname, sb);
380
381         indent += 2;
382
383         db_print_indent(indent);
384         db_printf("sb_state: 0x%x (", sb->sb_state);
385         db_print_sbstate(sb->sb_state);
386         db_printf(")\n");
387
388         db_print_indent(indent);
389         db_printf("sb_mb: %p   ", sb->sb_mb);
390         db_printf("sb_mbtail: %p   ", sb->sb_mbtail);
391         db_printf("sb_lastrecord: %p\n", sb->sb_lastrecord);
392
393         db_print_indent(indent);
394         db_printf("sb_sndptr: %p   ", sb->sb_sndptr);
395         db_printf("sb_sndptroff: %u\n", sb->sb_sndptroff);
396
397         db_print_indent(indent);
398         db_printf("sb_cc: %u   ", sb->sb_cc);
399         db_printf("sb_hiwat: %u   ", sb->sb_hiwat);
400         db_printf("sb_mbcnt: %u   ", sb->sb_mbcnt);
401         db_printf("sb_mbmax: %u\n", sb->sb_mbmax);
402
403         db_print_indent(indent);
404         db_printf("sb_ctl: %u   ", sb->sb_ctl);
405         db_printf("sb_lowat: %d   ", sb->sb_lowat);
406         db_printf("sb_timeo: %d\n", sb->sb_timeo);
407
408         db_print_indent(indent);
409         db_printf("sb_flags: 0x%x (", sb->sb_flags);
410         db_print_sbflags(sb->sb_flags);
411         db_printf(")\n");
412 }
413
414 static void
415 db_print_socket(struct socket *so, const char *socketname, int indent)
416 {
417
418         db_print_indent(indent);
419         db_printf("%s at %p\n", socketname, so);
420
421         indent += 2;
422
423         db_print_indent(indent);
424         db_printf("so_count: %d   ", so->so_count);
425         db_printf("so_type: %d (", so->so_type);
426         db_print_sotype(so->so_type);
427         db_printf(")\n");
428
429         db_print_indent(indent);
430         db_printf("so_options: 0x%x (", so->so_options);
431         db_print_sooptions(so->so_options);
432         db_printf(")\n");
433
434         db_print_indent(indent);
435         db_printf("so_linger: %d   ", so->so_linger);
436         db_printf("so_state: 0x%x (", so->so_state);
437         db_print_sostate(so->so_state);
438         db_printf(")\n");
439
440         db_print_indent(indent);
441         db_printf("so_qstate: 0x%x (", so->so_qstate);
442         db_print_soqstate(so->so_qstate);
443         db_printf(")   ");
444         db_printf("so_pcb: %p   ", so->so_pcb);
445         db_printf("so_proto: %p\n", so->so_proto);
446
447         if (so->so_proto != NULL)
448                 db_print_protosw(so->so_proto, "so_proto", indent);
449
450         db_print_indent(indent);
451         db_printf("so_head: %p   ", so->so_head);
452         db_printf("so_incomp first: %p   ", TAILQ_FIRST(&so->so_incomp));
453         db_printf("so_comp first: %p\n", TAILQ_FIRST(&so->so_comp));
454
455         db_print_indent(indent);
456         /* so_list skipped */
457         db_printf("so_qlen: %d   ", so->so_qlen);
458         db_printf("so_incqlen: %d   ", so->so_incqlen);
459         db_printf("so_qlimit: %d   ", so->so_qlimit);
460         db_printf("so_timeo: %d   ", so->so_timeo);
461         db_printf("so_error: %d\n", so->so_error);
462
463         db_print_indent(indent);
464         db_printf("so_sigio: %p   ", so->so_sigio);
465         db_printf("so_oobmark: %lu   ", so->so_oobmark);
466         db_printf("so_aiojobq first: %p\n", TAILQ_FIRST(&so->so_aiojobq));
467
468         db_print_sockbuf(&so->so_rcv, "so_rcv", indent);
469         db_print_sockbuf(&so->so_snd, "so_snd", indent);
470 }
471
472 DB_SHOW_COMMAND(socket, db_show_socket)
473 {
474         struct socket *so;
475
476         if (!have_addr) {
477                 db_printf("usage: show socket <addr>\n");
478                 return;
479         }
480         so = (struct socket *)addr;
481
482         db_print_socket(so, "socket", 0);
483 }
484
485 DB_SHOW_COMMAND(sockbuf, db_show_sockbuf)
486 {
487         struct sockbuf *sb;
488
489         if (!have_addr) {
490                 db_printf("usage: show sockbuf <addr>\n");
491                 return;
492         }
493         sb = (struct sockbuf *)addr;
494
495         db_print_sockbuf(sb, "sockbuf", 0);
496 }
497
498 DB_SHOW_COMMAND(protosw, db_show_protosw)
499 {
500         struct protosw *pr;
501
502         if (!have_addr) {
503                 db_printf("usage: show protosw <addr>\n");
504                 return;
505         }
506         pr = (struct protosw *)addr;
507
508         db_print_protosw(pr, "protosw", 0);
509 }
510
511 DB_SHOW_COMMAND(domain, db_show_domain)
512 {
513         struct domain *d;
514
515         if (!have_addr) {
516                 db_printf("usage: show protosw <addr>\n");
517                 return;
518         }
519         d = (struct domain *)addr;
520
521         db_print_domain(d, "domain", 0);
522 }
523 #endif