No empty .Rs/.Re
[netbsd-mini2440.git] / usr.bin / pmap / pmap.c
blob4c65383adba472ecbf4b6c0bfaa4c8140abb4681
1 /* $NetBSD$ */
3 /*
4 * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Brown.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 #ifndef lint
34 __RCSID("$NetBSD$");
35 #endif
37 #include <string.h>
39 #include "pmap.h"
40 #include "main.h"
42 static void dump_vm_anon(kvm_t *, struct vm_anon **, int);
43 static char *findname(kvm_t *, struct kbit *, struct kbit *, struct kbit *,
44 struct kbit *, struct kbit *);
45 static int search_cache(kvm_t *, struct kbit *, char **, char *, size_t);
47 /* when recursing, output is indented */
48 #define indent(n) ((n) * (recurse > 1 ? recurse - 1 : 0))
49 #define rwx (VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE)
51 int heapfound;
53 void
54 process_map(kvm_t *kd, struct kinfo_proc2 *proc,
55 struct kbit *vmspace, const char *thing)
57 struct kbit kbit, *vm_map = &kbit;
59 if (proc) {
60 heapfound = 0;
61 A(vmspace) = (u_long)proc->p_vmspace;
62 S(vmspace) = sizeof(struct vmspace);
63 thing = "proc->p_vmspace.vm_map";
64 } else if (S(vmspace) == (size_t)-1) {
65 heapfound = 0;
66 /* A(vmspace) set by caller */
67 S(vmspace) = sizeof(struct vmspace);
68 /* object identified by caller */
69 } else {
70 heapfound = 1; /* but really, do kernels have a heap? */
71 A(vmspace) = 0;
72 S(vmspace) = 0;
73 thing = "kernel_map";
76 S(vm_map) = sizeof(struct vm_map);
78 if (S(vmspace) != 0) {
79 KDEREF(kd, vmspace);
80 A(vm_map) = A(vmspace) + offsetof(struct vmspace, vm_map);
81 memcpy(D(vm_map, vm_map), &D(vmspace, vmspace)->vm_map,
82 S(vm_map));
83 } else {
84 memset(vmspace, 0, sizeof(*vmspace));
85 A(vm_map) = kernel_map_addr;
86 KDEREF(kd, vm_map);
89 dump_vm_map(kd, proc, vmspace, vm_map, thing);
92 void
93 dump_vm_map(kvm_t *kd, struct kinfo_proc2 *proc,
94 struct kbit *vmspace, struct kbit *vm_map, const char *mname)
96 struct kbit kbit[2], *header, *vm_map_entry;
97 struct vm_map_entry *last, *next;
98 size_t total;
99 u_long addr, end;
101 if (S(vm_map) == (size_t)-1) {
102 heapfound = 1;
103 S(vm_map) = sizeof(struct vm_map);
104 KDEREF(kd, vm_map);
107 header = &kbit[0];
108 vm_map_entry = &kbit[1];
109 A(header) = 0;
110 A(vm_map_entry) = 0;
112 A(header) = A(vm_map) + offsetof(struct vm_map, header);
113 S(header) = sizeof(struct vm_map_entry);
114 memcpy(D(header, vm_map_entry), &D(vm_map, vm_map)->header, S(header));
116 if (S(vmspace) != 0 && (debug & PRINT_VMSPACE)) {
117 printf("proc->p_vmspace %p = {", P(vmspace));
118 printf(" vm_refcnt = %d,", D(vmspace, vmspace)->vm_refcnt);
119 printf(" vm_shm = %p,\n", D(vmspace, vmspace)->vm_shm);
120 printf(" vm_rssize = %d,", D(vmspace, vmspace)->vm_rssize);
121 printf(" vm_swrss = %d,", D(vmspace, vmspace)->vm_swrss);
122 printf(" vm_tsize = %d,", D(vmspace, vmspace)->vm_tsize);
123 printf(" vm_dsize = %d,\n", D(vmspace, vmspace)->vm_dsize);
124 printf(" vm_ssize = %d,", D(vmspace, vmspace)->vm_ssize);
125 printf(" vm_taddr = %p,", D(vmspace, vmspace)->vm_taddr);
126 printf(" vm_daddr = %p,\n", D(vmspace, vmspace)->vm_daddr);
127 printf(" vm_maxsaddr = %p,",
128 D(vmspace, vmspace)->vm_maxsaddr);
129 printf(" vm_minsaddr = %p }\n",
130 D(vmspace, vmspace)->vm_minsaddr);
133 if (debug & PRINT_VM_MAP) {
134 printf("%*s%s %p = {", indent(2), "", mname, P(vm_map));
135 printf(" pmap = %p,\n", D(vm_map, vm_map)->pmap);
136 printf("%*s lock = <struct lock>,", indent(2), "");
137 printf(" header = <struct vm_map_entry>,");
138 printf(" nentries = %d,\n", D(vm_map, vm_map)->nentries);
139 printf("%*s size = %#"PRIxVSIZE",", indent(2), "",
140 D(vm_map, vm_map)->size);
141 printf(" ref_count = %d,", D(vm_map, vm_map)->ref_count);
142 printf("%*s hint = %p,", indent(2), "",
143 D(vm_map, vm_map)->hint);
144 printf("%*s first_free = %p,", indent(2), "",
145 D(vm_map, vm_map)->first_free);
146 printf(" flags = %x <%s%s%s%s%s >,\n", D(vm_map, vm_map)->flags,
147 D(vm_map, vm_map)->flags & VM_MAP_PAGEABLE ? " PAGEABLE" : "",
148 D(vm_map, vm_map)->flags & VM_MAP_INTRSAFE ? " INTRSAFE" : "",
149 D(vm_map, vm_map)->flags & VM_MAP_WIREFUTURE ? " WIREFUTURE" : "",
150 #ifdef VM_MAP_DYING
151 D(vm_map, vm_map)->flags & VM_MAP_DYING ? " DYING" :
152 #endif
154 #ifdef VM_MAP_TOPDOWN
155 D(vm_map, vm_map)->flags & VM_MAP_TOPDOWN ? " TOPDOWN" :
156 #endif
157 "");
158 printf("%*s timestamp = %u }\n", indent(2), "",
159 D(vm_map, vm_map)->timestamp);
161 if (print_ddb) {
162 const char *name = mapname(P(vm_map));
164 printf("%*s%s %p: [0x%#"PRIxVADDR"->0x%#"PRIxVADDR"]\n", indent(2), "",
165 recurse < 2 ? "MAP" : "SUBMAP", P(vm_map),
166 vm_map_min(D(vm_map, vm_map)),
167 vm_map_max(D(vm_map, vm_map)));
168 printf("\t%*s#ent=%d, sz=%"PRIxVSIZE", ref=%d, version=%d, flags=0x%x\n",
169 indent(2), "", D(vm_map, vm_map)->nentries,
170 D(vm_map, vm_map)->size, D(vm_map, vm_map)->ref_count,
171 D(vm_map, vm_map)->timestamp, D(vm_map, vm_map)->flags);
172 printf("\t%*spmap=%p(resident=<unknown>)\n", indent(2), "",
173 D(vm_map, vm_map)->pmap);
174 if (verbose && name != NULL)
175 printf("\t%*s([ %s ])\n", indent(2), "", name);
178 dump_vm_map_entry(kd, proc, vmspace, header, 1);
181 * we're not recursing into a submap, so print headers
183 if (recurse < 2) {
184 /* headers */
185 #ifdef DISABLED_HEADERS
186 if (print_map)
187 printf("%-*s %-*s rwx RWX CPY NCP I W A\n",
188 (int)sizeof(long) * 2 + 2, "Start",
189 (int)sizeof(long) * 2 + 2, "End");
190 if (print_maps)
191 printf("%-*s %-*s rwxp %-*s Dev Inode File\n",
192 (int)sizeof(long) * 2 + 0, "Start",
193 (int)sizeof(long) * 2 + 0, "End",
194 (int)sizeof(long) * 2 + 0, "Offset");
195 if (print_solaris)
196 printf("%-*s %*s Protection File\n",
197 (int)sizeof(long) * 2 + 0, "Start",
198 (int)sizeof(int) * 2 - 1, "Size ");
199 #endif
200 if (print_all)
201 printf("%-*s %-*s %*s %-*s rwxpc RWX I/W/A Dev %*s"
202 " - File\n",
203 (int)sizeof(long) * 2, "Start",
204 (int)sizeof(long) * 2, "End",
205 (int)sizeof(int) * 2, "Size ",
206 (int)sizeof(long) * 2, "Offset",
207 (int)sizeof(int) * 2, "Inode");
210 /* these are the "sub entries" */
211 total = 0;
212 next = D(header, vm_map_entry)->next;
213 last = P(header);
214 end = 0;
216 while (next != 0 && next != last) {
217 addr = (u_long)next;
218 A(vm_map_entry) = addr;
219 S(vm_map_entry) = sizeof(struct vm_map_entry);
220 KDEREF(kd, vm_map_entry);
221 next = D(vm_map_entry, vm_map_entry)->next;
223 if (end == 0)
224 end = D(vm_map_entry, vm_map_entry)->start;
225 else if (verbose > 1 &&
226 end != D(vm_map_entry, vm_map_entry)->start)
227 printf("%*s[%lu pages / %luK]\n", indent(2), "",
228 (D(vm_map_entry, vm_map_entry)->start - end) /
229 page_size,
230 (D(vm_map_entry, vm_map_entry)->start - end) /
231 1024);
232 total += dump_vm_map_entry(kd, proc, vmspace, vm_map_entry, 0);
234 end = D(vm_map_entry, vm_map_entry)->end;
238 * we're not recursing into a submap, so print totals
240 if (recurse < 2) {
241 if (print_solaris)
242 printf("%-*s %8luK\n",
243 (int)sizeof(void *) * 2 - 2, " total",
244 (unsigned long)total);
245 if (print_all)
246 printf("%-*s %9luk\n",
247 (int)sizeof(void *) * 4 - 1, " total",
248 (unsigned long)total);
252 size_t
253 dump_vm_map_entry(kvm_t *kd, struct kinfo_proc2 *proc, struct kbit *vmspace,
254 struct kbit *vm_map_entry, int ishead)
256 struct kbit kbit[3];
257 struct kbit *uvm_obj, *vp, *vfs;
258 struct vm_map_entry *vme;
259 size_t sz;
260 char *name;
261 dev_t dev;
262 ino_t inode;
264 if (S(vm_map_entry) == (size_t)-1) {
265 heapfound = 1;
266 S(vm_map_entry) = sizeof(struct vm_map_entry);
267 KDEREF(kd, vm_map_entry);
270 uvm_obj = &kbit[0];
271 vp = &kbit[1];
272 vfs = &kbit[2];
274 A(uvm_obj) = 0;
275 A(vp) = 0;
276 A(vfs) = 0;
278 vme = D(vm_map_entry, vm_map_entry);
280 if ((ishead && (debug & PRINT_VM_MAP_HEADER)) ||
281 (!ishead && (debug & PRINT_VM_MAP_ENTRY))) {
282 printf("%*s%s %p = {", indent(2), "",
283 ishead ? "vm_map.header" : "vm_map_entry",
284 P(vm_map_entry));
285 printf(" prev = %p,", vme->prev);
286 printf(" next = %p,\n", vme->next);
287 printf("%*s start = %#"PRIxVADDR",", indent(2), "", vme->start);
288 printf(" end = %#"PRIxVADDR",", vme->end);
289 printf(" object.uvm_obj/sub_map = %p,\n", vme->object.uvm_obj);
290 printf("%*s offset = %" PRIx64 ",", indent(2), "",
291 vme->offset);
292 printf(" etype = %x <%s%s%s%s >,", vme->etype,
293 UVM_ET_ISOBJ(vme) ? " OBJ" : "",
294 UVM_ET_ISSUBMAP(vme) ? " SUBMAP" : "",
295 UVM_ET_ISCOPYONWRITE(vme) ? " COW" : "",
296 UVM_ET_ISNEEDSCOPY(vme) ? " NEEDSCOPY" : "");
297 printf(" protection = %x,\n", vme->protection);
298 printf("%*s max_protection = %x,", indent(2), "",
299 vme->max_protection);
300 printf(" inheritance = %d,", vme->inheritance);
301 printf(" wired_count = %d,\n", vme->wired_count);
302 printf("%*s aref = { ar_pageoff = %x, ar_amap = %p },",
303 indent(2), "", vme->aref.ar_pageoff, vme->aref.ar_amap);
304 printf(" advice = %d,\n", vme->advice);
305 printf("%*s flags = %x <%s%s%s%s%s > }\n", indent(2), "",
306 vme->flags,
307 vme->flags & UVM_MAP_KERNEL ? " KERNEL" : "",
308 vme->flags & UVM_MAP_KMAPENT ? " KMAPENT" : "",
309 vme->flags & UVM_MAP_FIRST ? " FIRST" : "",
310 vme->flags & UVM_MAP_QUANTUM ? " QUANTUM" : "",
311 vme->flags & UVM_MAP_NOMERGE ? " NOMERGE" : "");
314 if ((debug & PRINT_VM_AMAP) && (vme->aref.ar_amap != NULL)) {
315 struct kbit akbit, *amap;
317 amap = &akbit;
318 P(amap) = vme->aref.ar_amap;
319 S(amap) = sizeof(struct vm_amap);
320 KDEREF(kd, amap);
321 dump_amap(kd, amap);
324 if (ishead)
325 return (0);
327 A(vp) = 0;
328 A(uvm_obj) = 0;
330 if (vme->object.uvm_obj != NULL) {
331 P(uvm_obj) = vme->object.uvm_obj;
332 S(uvm_obj) = sizeof(struct uvm_object);
333 KDEREF(kd, uvm_obj);
334 if (UVM_ET_ISOBJ(vme) &&
335 UVM_OBJ_IS_VNODE(D(uvm_obj, uvm_object))) {
336 P(vp) = P(uvm_obj);
337 S(vp) = sizeof(struct vnode);
338 KDEREF(kd, vp);
342 A(vfs) = 0;
344 if (P(vp) != NULL && D(vp, vnode)->v_mount != NULL) {
345 P(vfs) = D(vp, vnode)->v_mount;
346 S(vfs) = sizeof(struct mount);
347 KDEREF(kd, vfs);
348 D(vp, vnode)->v_mount = D(vfs, mount);
352 * dig out the device number and inode number from certain
353 * file system types.
355 #define V_DATA_IS(vp, type, d, i) do { \
356 struct kbit data; \
357 P(&data) = D(vp, vnode)->v_data; \
358 S(&data) = sizeof(*D(&data, type)); \
359 KDEREF(kd, &data); \
360 dev = D(&data, type)->d; \
361 inode = D(&data, type)->i; \
362 } while (0/*CONSTCOND*/)
364 dev = 0;
365 inode = 0;
367 if (A(vp) &&
368 D(vp, vnode)->v_type == VREG &&
369 D(vp, vnode)->v_data != NULL) {
370 switch (D(vp, vnode)->v_tag) {
371 case VT_UFS:
372 case VT_LFS:
373 case VT_EXT2FS:
374 V_DATA_IS(vp, inode, i_dev, i_number);
375 break;
376 case VT_ISOFS:
377 V_DATA_IS(vp, iso_node, i_dev, i_number);
378 break;
379 default:
380 break;
384 name = findname(kd, vmspace, vm_map_entry, vp, vfs, uvm_obj);
386 if (print_map) {
387 printf("%*s0x%#"PRIxVADDR" 0x%#"PRIxVADDR" %c%c%c %c%c%c %s %s %d %d %d",
388 indent(2), "",
389 vme->start, vme->end,
390 (vme->protection & VM_PROT_READ) ? 'r' : '-',
391 (vme->protection & VM_PROT_WRITE) ? 'w' : '-',
392 (vme->protection & VM_PROT_EXECUTE) ? 'x' : '-',
393 (vme->max_protection & VM_PROT_READ) ? 'r' : '-',
394 (vme->max_protection & VM_PROT_WRITE) ? 'w' : '-',
395 (vme->max_protection & VM_PROT_EXECUTE) ? 'x' : '-',
396 UVM_ET_ISCOPYONWRITE(vme) ? "COW" : "NCOW",
397 UVM_ET_ISNEEDSCOPY(vme) ? "NC" : "NNC",
398 vme->inheritance, vme->wired_count,
399 vme->advice);
400 if (verbose) {
401 if (inode)
402 printf(" %llu,%llu %llu",
403 (unsigned long long)major(dev),
404 (unsigned long long)minor(dev),
405 (unsigned long long)inode);
406 if (name[0])
407 printf(" %s", name);
409 printf("\n");
412 if (print_maps) {
413 printf("%*s%0*"PRIxVADDR"-%0*"PRIxVADDR" %c%c%c%c %0*" PRIx64 " %02llx:%02llx %llu %s\n",
414 indent(2), "",
415 (int)sizeof(void *) * 2, vme->start,
416 (int)sizeof(void *) * 2, vme->end,
417 (vme->protection & VM_PROT_READ) ? 'r' : '-',
418 (vme->protection & VM_PROT_WRITE) ? 'w' : '-',
419 (vme->protection & VM_PROT_EXECUTE) ? 'x' : '-',
420 UVM_ET_ISCOPYONWRITE(vme) ? 'p' : 's',
421 (int)sizeof(void *) * 2,
422 vme->offset,
423 (unsigned long long)major(dev),
424 (unsigned long long)minor(dev),
425 (unsigned long long)inode,
426 (name[0] != ' ') || verbose ? name : "");
429 if (print_ddb) {
430 printf("%*s - %p: 0x%"PRIxVADDR"->0x%"PRIxVADDR": obj=%p/0x%" PRIx64 ", amap=%p/%d\n",
431 indent(2), "",
432 P(vm_map_entry), vme->start, vme->end,
433 vme->object.uvm_obj, vme->offset,
434 vme->aref.ar_amap, vme->aref.ar_pageoff);
435 printf("\t%*ssubmap=%c, cow=%c, nc=%c, prot(max)=%d/%d, inh=%d, "
436 "wc=%d, adv=%d\n",
437 indent(2), "",
438 UVM_ET_ISSUBMAP(vme) ? 'T' : 'F',
439 UVM_ET_ISCOPYONWRITE(vme) ? 'T' : 'F',
440 UVM_ET_ISNEEDSCOPY(vme) ? 'T' : 'F',
441 vme->protection, vme->max_protection,
442 vme->inheritance, vme->wired_count, vme->advice);
443 if (verbose) {
444 printf("\t%*s", indent(2), "");
445 if (inode)
446 printf("(dev=%llu,%llu ino=%llu [%s] [%p])\n",
447 (unsigned long long)major(dev),
448 (unsigned long long)minor(dev),
449 (unsigned long long)inode, name, P(vp));
450 else if (name[0] == ' ')
451 printf("(%s)\n", &name[2]);
452 else
453 printf("(%s)\n", name);
457 sz = 0;
458 if (print_solaris) {
459 char prot[30];
461 prot[0] = '\0';
462 prot[1] = '\0';
463 if (vme->protection & VM_PROT_READ)
464 strlcat(prot, "/read", sizeof(prot));
465 if (vme->protection & VM_PROT_WRITE)
466 strlcat(prot, "/write", sizeof(prot));
467 if (vme->protection & VM_PROT_EXECUTE)
468 strlcat(prot, "/exec", sizeof(prot));
470 sz = (size_t)((vme->end - vme->start) / 1024);
471 printf("%*s%0*lX %6luK %-15s %s\n",
472 indent(2), "",
473 (int)sizeof(void *) * 2,
474 (unsigned long)vme->start,
475 (unsigned long)sz,
476 &prot[1],
477 name);
480 if (print_all) {
481 sz = (size_t)((vme->end - vme->start) / 1024);
482 printf(A(vp) ?
483 "%*s%0*"PRIxVADDR"-%0*"PRIxVADDR" %7luk %0*" PRIx64 " %c%c%c%c%c (%c%c%c) %d/%d/%d %02llu:%02llu %7llu - %s [%p]\n" :
484 "%*s%0*"PRIxVADDR"-%0*"PRIxVADDR" %7luk %0*" PRIx64 " %c%c%c%c%c (%c%c%c) %d/%d/%d %02llu:%02llu %7llu - %s\n",
485 indent(2), "",
486 (int)sizeof(void *) * 2,
487 vme->start,
488 (int)sizeof(void *) * 2,
489 vme->end - (vme->start != vme->end ? 1 : 0),
490 (unsigned long)sz,
491 (int)sizeof(void *) * 2,
492 vme->offset,
493 (vme->protection & VM_PROT_READ) ? 'r' : '-',
494 (vme->protection & VM_PROT_WRITE) ? 'w' : '-',
495 (vme->protection & VM_PROT_EXECUTE) ? 'x' : '-',
496 UVM_ET_ISCOPYONWRITE(vme) ? 'p' : 's',
497 UVM_ET_ISNEEDSCOPY(vme) ? '+' : '-',
498 (vme->max_protection & VM_PROT_READ) ? 'r' : '-',
499 (vme->max_protection & VM_PROT_WRITE) ? 'w' : '-',
500 (vme->max_protection & VM_PROT_EXECUTE) ? 'x' : '-',
501 vme->inheritance,
502 vme->wired_count,
503 vme->advice,
504 (unsigned long long)major(dev),
505 (unsigned long long)minor(dev),
506 (unsigned long long)inode,
507 name, P(vp));
510 /* no access allowed, don't count space */
511 if ((vme->protection & rwx) == 0)
512 sz = 0;
514 if (recurse && UVM_ET_ISSUBMAP(vme)) {
515 struct kbit mkbit, *submap;
517 recurse++;
518 submap = &mkbit;
519 P(submap) = vme->object.sub_map;
520 S(submap) = sizeof(*vme->object.sub_map);
521 KDEREF(kd, submap);
522 dump_vm_map(kd, proc, vmspace, submap, "submap");
523 recurse--;
526 return (sz);
529 void
530 dump_amap(kvm_t *kd, struct kbit *amap)
532 struct vm_anon **am_anon;
533 int *am_slots;
534 int *am_bckptr;
535 int *am_ppref;
536 size_t l;
537 int i, r, e;
539 if (S(amap) == (size_t)-1) {
540 heapfound = 1;
541 S(amap) = sizeof(struct vm_amap);
542 KDEREF(kd, amap);
545 printf("%*s amap %p = { am_ref = %d, "
546 "am_flags = %x,\n"
547 "%*s am_maxslot = %d, am_nslot = %d, am_nused = %d, "
548 "am_slots = %p,\n"
549 "%*s am_bckptr = %p, am_anon = %p, am_ppref = %p }\n",
550 indent(2), "",
551 P(amap),
552 D(amap, amap)->am_ref,
553 D(amap, amap)->am_flags,
554 indent(2), "",
555 D(amap, amap)->am_maxslot,
556 D(amap, amap)->am_nslot,
557 D(amap, amap)->am_nused,
558 D(amap, amap)->am_slots,
559 indent(2), "",
560 D(amap, amap)->am_bckptr,
561 D(amap, amap)->am_anon,
562 D(amap, amap)->am_ppref);
564 if (!(debug & DUMP_VM_AMAP_DATA))
565 return;
568 * Assume that sizeof(struct vm_anon *) >= sizeof(size_t) and
569 * allocate that amount of space.
571 l = sizeof(struct vm_anon *) * D(amap, amap)->am_maxslot;
572 am_anon = malloc(l);
573 _KDEREF(kd, (u_long)D(amap, amap)->am_anon, am_anon, l);
575 l = sizeof(int) * D(amap, amap)->am_maxslot;
576 am_bckptr = malloc(l);
577 _KDEREF(kd, (u_long)D(amap, amap)->am_bckptr, am_bckptr, l);
579 l = sizeof(int) * D(amap, amap)->am_maxslot;
580 am_slots = malloc(l);
581 _KDEREF(kd, (u_long)D(amap, amap)->am_slots, am_slots, l);
583 if (D(amap, amap)->am_ppref != NULL &&
584 D(amap, amap)->am_ppref != PPREF_NONE) {
585 l = sizeof(int) * D(amap, amap)->am_maxslot;
586 am_ppref = malloc(l);
587 _KDEREF(kd, (u_long)D(amap, amap)->am_ppref, am_ppref, l);
588 } else {
589 am_ppref = NULL;
592 printf(" page# %9s %8s", "am_bckptr", "am_slots");
593 if (am_ppref)
594 printf(" %8s ", "am_ppref");
595 printf(" %10s\n", "am_anon");
597 l = r = 0;
598 e = verbose > 1 ? D(amap, amap)->am_maxslot : D(amap, amap)->am_nslot;
599 for (i = 0; i < e; i++) {
600 printf(" %4lx", (unsigned long)i);
602 if (am_anon[i] || verbose > 1)
603 printf(" %8x", am_bckptr[i]);
604 else
605 printf(" %8s", "-");
607 if (i < D(amap, amap)->am_nused || verbose > 1)
608 printf(" %8x", am_slots[i]);
609 else
610 printf(" %8s", "-");
612 if (am_ppref) {
613 if (l == 0 || r || verbose > 1)
614 printf(" %8d", am_ppref[i]);
615 else
616 printf(" %8s", "-");
617 r = 0;
618 if (l == 0) {
619 if (am_ppref[i] > 0) {
620 r = am_ppref[i] - 1;
621 l = 1;
622 } else {
623 r = -am_ppref[i] - 1;
624 l = am_ppref[i + 1];
626 printf(" (%4ld @ %4ld)", (long)l, (long)r);
627 r = (l > 1) ? 1 : 0;
629 else
630 printf(" ");
631 l--;
634 dump_vm_anon(kd, am_anon, i);
637 free(am_anon);
638 free(am_bckptr);
639 free(am_slots);
640 if (am_ppref)
641 free(am_ppref);
644 static void
645 dump_vm_anon(kvm_t *kd, struct vm_anon **alist, int i)
648 printf(" %10p", alist[i]);
650 if (debug & PRINT_VM_ANON) {
651 struct kbit kbit, *anon = &kbit;
653 A(anon) = (u_long)alist[i];
654 S(anon) = sizeof(struct vm_anon);
655 if (A(anon) == 0) {
656 printf(" = { }\n");
657 return;
659 else
660 KDEREF(kd, anon);
662 printf(" = { an_ref = %d, an_page = %p, an_swslot = %d }",
663 D(anon, anon)->an_ref, D(anon, anon)->an_page,
664 D(anon, anon)->an_swslot);
667 printf("\n");
670 static char*
671 findname(kvm_t *kd, struct kbit *vmspace,
672 struct kbit *vm_map_entry, struct kbit *vp,
673 struct kbit *vfs, struct kbit *uvm_obj)
675 static char buf[1024], *name;
676 struct vm_map_entry *vme;
677 size_t l;
679 vme = D(vm_map_entry, vm_map_entry);
681 if (UVM_ET_ISOBJ(vme)) {
682 if (A(vfs)) {
683 l = (unsigned)strlen(D(vfs, mount)->mnt_stat.f_mntonname);
684 switch (search_cache(kd, vp, &name, buf, sizeof(buf))) {
685 case 0: /* found something */
686 name--;
687 *name = '/';
688 /*FALLTHROUGH*/
689 case 2: /* found nothing */
690 name -= 5;
691 memcpy(name, " -?- ", (size_t)5);
692 name -= l;
693 memcpy(name,
694 D(vfs, mount)->mnt_stat.f_mntonname, l);
695 break;
696 case 1: /* all is well */
697 name--;
698 *name = '/';
699 if (l != 1) {
700 name -= l;
701 memcpy(name,
702 D(vfs, mount)->mnt_stat.f_mntonname, l);
704 break;
707 else if (UVM_OBJ_IS_DEVICE(D(uvm_obj, uvm_object))) {
708 struct kbit kdev;
709 dev_t dev;
711 P(&kdev) = P(uvm_obj);
712 S(&kdev) = sizeof(struct uvm_device);
713 KDEREF(kd, &kdev);
714 dev = D(&kdev, uvm_device)->u_device;
715 name = devname(dev, S_IFCHR);
716 if (name != NULL)
717 snprintf(buf, sizeof(buf), "/dev/%s", name);
718 else
719 snprintf(buf, sizeof(buf), " [ device %llu,%llu ]",
720 (unsigned long long)major(dev),
721 (unsigned long long)minor(dev));
722 name = buf;
724 else if (UVM_OBJ_IS_AOBJ(D(uvm_obj, uvm_object))) {
725 snprintf(buf, sizeof(buf), " [ uvm_aobj ]");
726 name = buf;
728 else if (UVM_OBJ_IS_UBCPAGER(D(uvm_obj, uvm_object))) {
729 snprintf(buf, sizeof(buf), " [ ubc_pager ]");
730 name = buf;
732 else if (UVM_OBJ_IS_VNODE(D(uvm_obj, uvm_object))) {
733 snprintf(buf, sizeof(buf), " [ ?VNODE? ]");
734 name = buf;
736 else {
737 snprintf(buf, sizeof(buf), " [ ?? %p ?? ]",
738 D(uvm_obj, uvm_object)->pgops);
739 name = buf;
743 else if ((char *)D(vmspace, vmspace)->vm_maxsaddr <=
744 (char *)vme->start &&
745 ((char *)D(vmspace, vmspace)->vm_maxsaddr + (size_t)maxssiz) >=
746 (char *)vme->end) {
747 snprintf(buf, sizeof(buf), " [ stack ]");
748 name = buf;
751 else if (!heapfound &&
752 (vme->protection & rwx) == rwx &&
753 vme->start >= (u_long)D(vmspace, vmspace)->vm_daddr) {
754 heapfound = 1;
755 snprintf(buf, sizeof(buf), " [ heap ]");
756 name = buf;
759 else if (UVM_ET_ISSUBMAP(vme)) {
760 const char *sub = mapname(vme->object.sub_map);
761 snprintf(buf, sizeof(buf), " [ %s ]", sub ? sub : "(submap)");
762 name = buf;
765 else {
766 snprintf(buf, sizeof(buf), " [ anon ]");
767 name = buf;
770 return (name);
773 static int
774 search_cache(kvm_t *kd, struct kbit *vp, char **name, char *buf, size_t blen)
776 char *o, *e;
777 struct cache_entry *ce;
778 struct kbit svp;
780 if (nchashtbl == NULL)
781 load_name_cache(kd);
783 P(&svp) = P(vp);
784 S(&svp) = sizeof(struct vnode);
786 e = &buf[blen - 1];
787 o = e;
788 do {
789 LIST_FOREACH(ce, &lcache, ce_next)
790 if (ce->ce_vp == P(&svp))
791 break;
792 if (ce && ce->ce_vp == P(&svp)) {
793 if (o != e)
794 *(--o) = '/';
795 o -= ce->ce_nlen;
796 memcpy(o, ce->ce_name, (unsigned)ce->ce_nlen);
797 P(&svp) = ce->ce_pvp;
799 else
800 break;
801 } while (1/*CONSTCOND*/);
802 *e = '\0';
803 *name = o;
805 if (e == o)
806 return (2);
808 KDEREF(kd, &svp);
809 return (D(&svp, vnode)->v_vflag & VV_ROOT);