Introduce globals: KvaStart, KvaEnd, and KvaSize. Used by the kernel
[dfdiff.git] / test / debug / ttyinfo.c
blob68e5827b0aff506058e463f0f6c39f4fe698272f
1 /*
2 * TTYINFO.C
4 * cc -I/usr/src/sys ttyinfo.c -o /usr/local/bin/ttyinfo -lkvm
6 * ttyinfo
9 * Copyright (c) 2004 The DragonFly Project. All rights reserved.
11 * This code is derived from software contributed to The DragonFly Project
12 * by Matthew Dillon <dillon@backplane.com>
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in
22 * the documentation and/or other materials provided with the
23 * distribution.
24 * 3. Neither the name of The DragonFly Project nor the names of its
25 * contributors may be used to endorse or promote products derived
26 * from this software without specific, prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
31 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
32 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
33 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
34 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
35 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
36 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
37 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
38 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 * SUCH DAMAGE.
41 * $DragonFly: src/test/debug/ttyinfo.c,v 1.2 2004/10/08 18:32:58 dillon Exp $
44 #define _KERNEL_STRUCTURES_
45 #include <sys/param.h>
46 #include <sys/user.h>
47 #include <sys/malloc.h>
48 #include <sys/signalvar.h>
49 #include <sys/vnode.h>
50 #include <sys/namecache.h>
51 #include <sys/tty.h>
52 #include <sys/clist.h>
54 #include <vm/vm.h>
55 #include <vm/vm_page.h>
56 #include <vm/vm_kern.h>
57 #include <vm/swap_pager.h>
58 #include <vm/vnode_pager.h>
60 #include <stdio.h>
61 #include <stdlib.h>
62 #include <string.h>
63 #include <fcntl.h>
64 #include <kvm.h>
65 #include <nlist.h>
66 #include <getopt.h>
68 struct nlist Nl[] = {
69 { "_cfreelist" },
70 { "_cfreecount" },
71 { "_cslushcount" },
72 { "_ctotcount" },
73 { NULL }
76 static void kkread(kvm_t *kd, u_long addr, void *buf, size_t nbytes);
77 static int scanfree(kvm_t *kd, struct cblock *cfree);
79 main(int ac, char **av)
81 struct cblock *cfree;
82 int cbytes;
83 int count;
84 int slush;
85 int totalcnt;
86 int ch;
87 kvm_t *kd;
88 const char *corefile = NULL;
89 const char *sysfile = NULL;
91 while ((ch = getopt(ac, av, "M:N:")) != -1) {
92 switch(ch) {
93 case 'M':
94 corefile = optarg;
95 break;
96 case 'N':
97 sysfile = optarg;
98 break;
99 default:
100 fprintf(stderr, "%s [-M core] [-N system]\n", av[0]);
101 exit(1);
105 if ((kd = kvm_open(sysfile, corefile, NULL, O_RDONLY, "kvm:")) == NULL) {
106 perror("kvm_open");
107 exit(1);
109 if (kvm_nlist(kd, Nl) != 0) {
110 perror("kvm_nlist");
111 exit(1);
113 kkread(kd, Nl[0].n_value, &cfree, sizeof(cfree));
114 kkread(kd, Nl[1].n_value, &cbytes, sizeof(cbytes));
115 kkread(kd, Nl[2].n_value, &slush, sizeof(slush));
116 kkread(kd, Nl[3].n_value, &totalcnt, sizeof(totalcnt));
117 count = scanfree(kd, cfree);
118 printf("blksize %d, freespc %d bytes, %d blks (%d total), %d slush",
119 CBSIZE, cbytes, cbytes / CBSIZE, totalcnt, slush);
120 if (cbytes % CBSIZE)
121 printf(" [unaligned]\n");
122 else
123 printf(" [aligned]\n");
124 printf("freelist found to have %d blocks\n", count);
125 return(0);
128 static int
129 scanfree(kvm_t *kd, struct cblock *cfree)
131 int count = 0;
132 struct cblock cb;
134 while (cfree) {
135 kkread(kd, (u_long)cfree, &cb, sizeof(cb));
136 cfree = cb.c_head.ch_next;
137 ++count;
139 return(count);
142 static void
143 kkread(kvm_t *kd, u_long addr, void *buf, size_t nbytes)
145 if (kvm_read(kd, addr, buf, nbytes) != nbytes) {
146 perror("kvm_read");
147 exit(1);