Drop obsoleted patch.
[linux-flexiantxendom0-3.2.10.git] / kdb / modules / kdbm_vm.c
1 /*
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  *
6  * Copyright (c) 1999-2004 Silicon Graphics, Inc.  All Rights Reserved.
7  */
8
9 #include <linux/blkdev.h>
10 #include <linux/types.h>
11 #include <linux/kdb.h>
12 #include <linux/kdbprivate.h>
13 #include <linux/module.h>
14 #include <linux/init.h>
15 #include <linux/mm.h>
16 #include <linux/swap.h>
17 #include <linux/swapops.h>
18
19 #include <scsi.h>
20 #include <scsi/scsi_host.h>
21
22 MODULE_AUTHOR("SGI");
23 MODULE_DESCRIPTION("Debug VM information");
24 MODULE_LICENSE("GPL");
25
26 struct __vmflags {
27         unsigned long mask;
28         char *name;
29 };
30
31 static struct __vmflags vmflags[] = {
32         { VM_READ, "READ" },
33         { VM_WRITE, "WRITE" },
34         { VM_EXEC, "EXEC" },
35         { VM_SHARED, "SHARED" },
36         { VM_MAYREAD, "MAYREAD" },
37         { VM_MAYWRITE, "MAYWRITE" },
38         { VM_MAYEXEC, "MAYEXEC" },
39         { VM_MAYSHARE, "MAYSHARE" },
40         { VM_GROWSDOWN, "GROWSDOWN" },
41         { VM_GROWSUP, "GROWSUP" },
42         { VM_SHM, "SHM" },
43         { VM_DENYWRITE, "DENYWRITE" },
44         { VM_EXECUTABLE, "EXECUTABLE" },
45         { VM_LOCKED, "LOCKED" },
46         { VM_IO , "IO " },
47         { 0, "" }
48 };
49
50 static int
51 kdbm_print_vm(struct vm_area_struct *vp, unsigned long addr, int verbose_flg)
52 {
53         struct __vmflags *tp;
54
55         kdb_printf("struct vm_area_struct at 0x%lx for %d bytes\n",
56                    addr, (int) sizeof (struct vm_area_struct));
57
58         kdb_printf("vm_start = 0x%p   vm_end = 0x%p\n", (void *) vp->vm_start,
59                    (void *) vp->vm_end);
60         kdb_printf("vm_page_prot = 0x%lx\n", pgprot_val(vp->vm_page_prot));
61
62         kdb_printf("vm_flags: ");
63         for (tp = vmflags; tp->mask; tp++) {
64                 if (vp->vm_flags & tp->mask) {
65                         kdb_printf(" %s", tp->name);
66                 }
67         }
68         kdb_printf("\n");
69
70         if (!verbose_flg)
71                 return 0;
72
73         kdb_printf("vm_mm = 0x%p\n", (void *) vp->vm_mm);
74         kdb_printf("vm_next = 0x%p\n", (void *) vp->vm_next);
75         kdb_printf("shared.vm_set.list.next = 0x%p\n", (void *) vp->shared.vm_set.list.next);
76         kdb_printf("shared.vm_set.list.prev = 0x%p\n", (void *) vp->shared.vm_set.list.prev);
77         kdb_printf("shared.vm_set.parent = 0x%p\n", (void *) vp->shared.vm_set.parent);
78         kdb_printf("shared.vm_set.head = 0x%p\n", (void *) vp->shared.vm_set.head);
79         kdb_printf("anon_vma_node.next = 0x%p\n", (void *) vp->anon_vma_node.next);
80         kdb_printf("anon_vma_node.prev = 0x%p\n", (void *) vp->anon_vma_node.prev);
81         kdb_printf("vm_ops = 0x%p\n", (void *) vp->vm_ops);
82         if (vp->vm_ops != NULL) {
83                 kdb_printf("vm_ops->open = 0x%p\n", vp->vm_ops->open);
84                 kdb_printf("vm_ops->close = 0x%p\n", vp->vm_ops->close);
85                 kdb_printf("vm_ops->nopage = 0x%p\n", vp->vm_ops->nopage);
86 #ifdef HAVE_VMOP_MPROTECT
87                 kdb_printf("vm_ops->mprotect = 0x%p\n", vp->vm_ops->mprotect);
88 #endif
89         }
90         kdb_printf("vm_pgoff = 0x%lx\n", vp->vm_pgoff);
91         kdb_printf("vm_file = 0x%p\n", (void *) vp->vm_file);
92         kdb_printf("vm_private_data = 0x%p\n", vp->vm_private_data);
93
94         return 0;
95 }
96
97 static int
98 kdbm_print_vmp(struct vm_area_struct *vp, int verbose_flg)
99 {
100         struct __vmflags *tp;
101
102         if (verbose_flg) {
103                 kdb_printf("0x%lx:  ", (unsigned long) vp);
104         }
105
106         kdb_printf("0x%p  0x%p ", (void *) vp->vm_start, (void *) vp->vm_end);
107
108         for (tp = vmflags; tp->mask; tp++) {
109                 if (vp->vm_flags & tp->mask) {
110                         kdb_printf(" %s", tp->name);
111                 }
112         }
113         kdb_printf("\n");
114
115         return 0;
116 }
117
118 /*
119  * kdbm_vm
120  *
121  *     This function implements the 'vm' command.  Print a vm_area_struct.
122  *
123  *     vm [-v] <address>        Print vm_area_struct at <address>
124  *     vmp [-v] <pid>           Print all vm_area_structs for <pid>
125  */
126
127 static int
128 kdbm_vm(int argc, const char **argv, const char **envp, struct pt_regs *regs)
129 {
130         unsigned long addr;
131         long offset = 0;
132         int nextarg;
133         int diag;
134         int verbose_flg = 0;
135
136         if (argc == 2) {
137                 if (strcmp(argv[1], "-v") != 0) {
138                         return KDB_ARGCOUNT;
139                 }
140                 verbose_flg = 1;
141         } else if (argc != 1) {
142                 return KDB_ARGCOUNT;
143         }
144
145         if (strcmp(argv[0], "vmp") == 0) {
146                 struct task_struct *g, *tp;
147                 struct vm_area_struct *vp;
148                 pid_t pid;
149
150                 if ((diag = kdbgetularg(argv[argc], (unsigned long *) &pid)))
151                         return diag;
152
153                 kdb_do_each_thread(g, tp) {
154                         if (tp->pid == pid) {
155                                 if (tp->mm != NULL) {
156                                         if (verbose_flg)
157                                                 kdb_printf
158                                                     ("vm_area_struct       ");
159                                         kdb_printf
160                                             ("vm_start            vm_end              vm_flags\n");
161                                         vp = tp->mm->mmap;
162                                         while (vp != NULL) {
163                                                 kdbm_print_vmp(vp, verbose_flg);
164                                                 vp = vp->vm_next;
165                                         }
166                                 }
167                                 return 0;
168                         }
169                 } kdb_while_each_thread(g, tp);
170
171                 kdb_printf("No process with pid == %d found\n", pid);
172
173         } else {
174                 struct vm_area_struct v;
175
176                 nextarg = argc;
177                 if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset,
178                                           NULL, regs))
179                     || (diag = kdb_getarea(v, addr)))
180                         return (diag);
181
182                 kdbm_print_vm(&v, addr, verbose_flg);
183         }
184
185         return 0;
186 }
187
188 static int
189 kdbm_print_pte(pte_t * pte)
190 {
191         kdb_printf("0x%lx (", (unsigned long) pte_val(*pte));
192
193         if (pte_present(*pte)) {
194                 if (pte_exec(*pte))
195                         kdb_printf("X");
196                 if (pte_write(*pte))
197                         kdb_printf("W");
198                 if (pte_read(*pte))
199                         kdb_printf("R");
200                 if (pte_young(*pte))
201                         kdb_printf("A");
202                 if (pte_dirty(*pte))
203                         kdb_printf("D");
204
205         } else {
206                 kdb_printf("OFFSET=0x%lx ", swp_offset(pte_to_swp_entry(*pte)));
207                 kdb_printf("TYPE=0x%ulx", swp_type(pte_to_swp_entry(*pte)));
208         }
209
210         kdb_printf(")");
211
212         /* final newline is output by caller of kdbm_print_pte() */
213
214         return 0;
215 }
216
217 /*
218  * kdbm_pte
219  *
220  *     This function implements the 'pte' command.  Print all pte_t structures
221  *     that map to the given virtual address range (<address> through <address>
222  *     plus <nbytes>) for the given process. The default value for nbytes is
223  *     one.
224  *
225  *     pte -m <mm> <address> [<nbytes>]    Print all pte_t structures for
226  *                                         virtual <address> in address space
227  *                                         of <mm> which is a pointer to a
228  *                                         mm_struct
229  *     pte -p <pid> <address> [<nbytes>]   Print all pte_t structures for
230  *                                         virtual <address> in address space
231  *                                         of <pid>
232  */
233
234 static int
235 kdbm_pte(int argc, const char **argv, const char **envp, struct pt_regs *regs)
236 {
237         unsigned long addr;
238         long offset = 0;
239         int nextarg;
240         unsigned long nbytes = 1;
241         long npgs;
242         int diag;
243         int found;
244         pid_t pid;
245         struct task_struct *tp;
246         struct mm_struct *mm;
247         pgd_t *pgd;
248         pmd_t *pmd;
249         pte_t *pte;
250
251         if (argc < 3 || argc > 4) {
252                 return KDB_ARGCOUNT;
253         }
254
255          if (strcmp(argv[1], "-p") == 0) {
256                 if ((diag = kdbgetularg(argv[2], (unsigned long *) &pid))) {
257                         return diag;
258                 }
259
260                 found = 0;
261                 for_each_process(tp) {
262                         if (tp->pid == pid) {
263                                 if (tp->mm != NULL) {
264                                         found = 1;
265                                         break;
266                                 }
267                                 kdb_printf("task structure's mm field is NULL\n");
268                                 return 0;
269                         }
270                 }
271
272                 if (!found) {
273                         kdb_printf("No process with pid == %d found\n", pid);
274                         return 0;
275                 }
276                 mm = tp->mm;
277         } else if (strcmp(argv[1], "-m") == 0) {
278                 struct mm_struct copy_of_mm;
279
280
281                 nextarg = 2;
282                 if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset,
283                                           NULL, regs))
284                     || (diag = kdb_getarea(copy_of_mm, addr)))
285                         return (diag);
286                 mm = &copy_of_mm;
287         } else {
288                 return KDB_ARGCOUNT;
289         }
290
291         if ((diag = kdbgetularg(argv[3], &addr))) {
292                 return diag;
293         }
294
295         if (argc == 4) {
296                 if ((diag = kdbgetularg(argv[4], &nbytes))) {
297                         return diag;
298                 }
299         }
300
301         kdb_printf("vaddr              pte\n");
302
303         npgs = ((((addr & ~PAGE_MASK) + nbytes) + ~PAGE_MASK) >> PAGE_SHIFT);
304         while (npgs-- > 0) {
305
306                 kdb_printf("0x%p ", (void *) (addr & PAGE_MASK));
307
308                 pgd = pgd_offset(mm, addr);
309                 if (pgd_present(*pgd)) {
310                         pmd = pmd_offset(pgd, addr);
311                         if (pmd_present(*pmd)) {
312                                 pte = pte_offset_map(pmd, addr);
313                                 if (pte_present(*pte)) {
314                                         kdbm_print_pte(pte);
315                                 }
316                         }
317                 }
318
319                 kdb_printf("\n");
320                 addr += PAGE_SIZE;
321         }
322
323         return 0;
324 }
325
326 static int
327 kdbm_fp(int argc, const char **argv, const char **envp, struct pt_regs *regs)
328 {
329         struct file   f;
330         struct inode *i = NULL;
331         struct dentry d;
332         int nextarg;
333         unsigned long addr;
334         long offset;
335         int diag;
336
337         if (argc != 1)
338                 return KDB_ARGCOUNT;
339
340         nextarg = 1;
341         if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL, regs)) ||
342             (diag = kdb_getarea(f, addr)) ||
343             (diag = kdb_getarea(d, (unsigned long)f.f_dentry)))
344                 goto out;
345         if (!(i = kmalloc(sizeof(*i), GFP_ATOMIC))) {
346                 kdb_printf("kdbm_fp: cannot kmalloc inode\n");
347                 goto out;
348         }
349         if ((diag = kdb_getarea(*i, (unsigned long)d.d_inode)))
350                 goto out;
351
352         kdb_printf("name.name 0x%p  name.len  %d\n",
353                     d.d_name.name, d.d_name.len);
354
355         kdb_printf("File Pointer at 0x%lx\n", addr);
356
357         kdb_printf(" f_list.nxt = 0x%p f_list.prv = 0x%p\n",
358                                         f.f_list.next, f.f_list.prev);
359
360         kdb_printf(" f_dentry = 0x%p f_op = 0x%p\n",
361                                         f.f_dentry, f.f_op);
362
363         kdb_printf(" f_count = %d f_flags = 0x%x f_mode = 0x%x\n",
364                                         f.f_count.counter, f.f_flags, f.f_mode);
365
366         kdb_printf(" f_pos = %Ld\n",
367                                         f.f_pos);
368
369         kdb_printf("\nDirectory Entry at 0x%p\n", f.f_dentry);
370         kdb_printf(" d_name.len = %d d_name.name = 0x%p>\n",
371                                         d.d_name.len, d.d_name.name);
372
373         kdb_printf(" d_count = %d d_flags = 0x%x d_inode = 0x%p\n",
374                                         atomic_read(&d.d_count), d.d_flags, d.d_inode);
375
376         kdb_printf(" d_hash.nxt = 0x%p d_hash.prv = 0x%p\n",
377                                         d.d_hash.next, d.d_hash.pprev);
378
379         kdb_printf(" d_lru.nxt = 0x%p d_lru.prv = 0x%p\n",
380                                         d.d_lru.next, d.d_lru.prev);
381
382         kdb_printf(" d_child.nxt = 0x%p d_child.prv = 0x%p\n",
383                                         d.d_child.next, d.d_child.prev);
384
385         kdb_printf(" d_subdirs.nxt = 0x%p d_subdirs.prv = 0x%p\n",
386                                         d.d_subdirs.next, d.d_subdirs.prev);
387
388         kdb_printf(" d_alias.nxt = 0x%p d_alias.prv = 0x%p\n",
389                                         d.d_alias.next, d.d_alias.prev);
390
391         kdb_printf(" d_op = 0x%p d_sb = 0x%p\n\n",
392                                         d.d_op, d.d_sb);
393
394
395         kdb_printf("\nInode Entry at 0x%p\n", d.d_inode);
396
397         kdb_printf(" i_mode = 0%o  i_nlink = %d  i_rdev = 0x%x\n",
398                                         i->i_mode, i->i_nlink, i->i_rdev);
399
400         kdb_printf(" i_ino = %ld i_count = %d\n",
401                                         i->i_ino, atomic_read(&i->i_count));
402
403         kdb_printf(" i_hash.nxt = 0x%p i_hash.prv = 0x%p\n",
404                                         i->i_hash.next, i->i_hash.pprev);
405
406         kdb_printf(" i_list.nxt = 0x%p i_list.prv = 0x%p\n",
407                                         i->i_list.next, i->i_list.prev);
408
409         kdb_printf(" i_dentry.nxt = 0x%p i_dentry.prv = 0x%p\n",
410                                         i->i_dentry.next, i->i_dentry.prev);
411
412 out:
413         if (i)
414                 kfree(i);
415         return diag;
416 }
417
418 static int
419 kdbm_fl(int argc, const char **argv, const char **envp, struct pt_regs *regs)
420 {
421         struct file_lock fl;
422         int nextarg;
423         unsigned long addr;
424         long offset;
425         int diag;
426
427
428         if (argc != 1)
429                 return KDB_ARGCOUNT;
430
431         nextarg = 1;
432         if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL, regs)) ||
433                 (diag = kdb_getarea(fl, addr)))
434                         return diag;
435
436         kdb_printf("File_lock at 0x%lx\n", addr);
437
438         kdb_printf(" fl_next = 0x%p fl_link.nxt = 0x%p fl_link.prv = 0x%p\n",
439                         fl.fl_next, fl.fl_link.next, fl.fl_link.prev);
440         kdb_printf(" fl_block.nxt = 0x%p fl_block.prv = 0x%p\n",
441                         fl.fl_block.next, fl.fl_block.prev);
442         kdb_printf(" fl_owner = 0x%p fl_pid = %d fl_wait = 0x%p\n",
443                         fl.fl_owner, fl.fl_pid, &fl.fl_wait);
444         kdb_printf(" fl_file = 0x%p fl_flags = 0x%x\n",
445                         fl.fl_file, fl.fl_flags);
446         kdb_printf(" fl_type = %d fl_start = 0x%llx fl_end = 0x%llx\n",
447                         fl.fl_type, fl.fl_start, fl.fl_end);
448
449         kdb_printf(" file_lock_operations\n");
450         kdb_printf("   fl_insert = 0x%p fl_remove = 0x%p fl_copy_lock = 0x%p fl_release_private = 0x%p\n",
451                         fl.fl_ops->fl_insert, fl.fl_ops->fl_remove,
452                         fl.fl_ops->fl_copy_lock, fl.fl_ops->fl_release_private);
453
454         kdb_printf(" lock_manager_operations\n");
455         kdb_printf("   fl_compare_owner = 0x%p fl_notify = 0x%p\n",
456                         fl.fl_lmops->fl_compare_owner, fl.fl_lmops->fl_notify);
457
458         kdb_printf(" fl_fasync = 0x%p fl_break 0x%lx\n",
459                         fl.fl_fasync, fl.fl_break_time);
460
461         return 0;
462 }
463
464
465 static int
466 kdbm_dentry(int argc, const char **argv, const char **envp, struct pt_regs *regs)
467 {
468         struct dentry d;
469         int nextarg;
470         unsigned long addr;
471         long offset;
472         int diag;
473         char buf[256];
474
475         if (argc != 1)
476                 return KDB_ARGCOUNT;
477
478         nextarg = 1;
479         if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL, regs)) ||
480             (diag = kdb_getarea(d, addr)))
481                 return diag;
482
483
484         kdb_printf("Dentry at 0x%lx\n", addr);
485
486         if ((d.d_name.len > sizeof(buf)) || (diag = kdb_getarea_size(buf, (unsigned long)(d.d_name.name), d.d_name.len)))
487                 kdb_printf(" d_name.len = %d d_name.name = 0x%p\n",
488                                         d.d_name.len, d.d_name.name);
489         else
490                 kdb_printf(" d_name.len = %d d_name.name = 0x%p <%.*s>\n",
491                                         d.d_name.len, d.d_name.name,
492                                         (int)(d.d_name.len), d.d_name.name);
493
494         kdb_printf(" d_count = %d d_flags = 0x%x d_inode = 0x%p\n",
495                                         atomic_read(&d.d_count), d.d_flags, d.d_inode);
496
497         kdb_printf(" d_parent = 0x%p\n", d.d_parent);
498
499         kdb_printf(" d_hash.nxt = 0x%p d_hash.prv = 0x%p\n",
500                                         d.d_hash.next, d.d_hash.pprev);
501
502         kdb_printf(" d_lru.nxt = 0x%p d_lru.prv = 0x%p\n",
503                                         d.d_lru.next, d.d_lru.prev);
504
505         kdb_printf(" d_child.nxt = 0x%p d_child.prv = 0x%p\n",
506                                         d.d_child.next, d.d_child.prev);
507
508         kdb_printf(" d_subdirs.nxt = 0x%p d_subdirs.prv = 0x%p\n",
509                                         d.d_subdirs.next, d.d_subdirs.prev);
510
511         kdb_printf(" d_alias.nxt = 0x%p d_alias.prv = 0x%p\n",
512                                         d.d_alias.next, d.d_alias.prev);
513
514         kdb_printf(" d_op = 0x%p d_sb = 0x%p\n\n",
515                                         d.d_op, d.d_sb);
516
517         return 0;
518 }
519
520 static int
521 kdbm_kobject(int argc, const char **argv, const char **envp, struct pt_regs *regs)
522 {
523         struct kobject k;
524         int nextarg;
525         unsigned long addr;
526         long offset;
527         int diag;
528
529         if (argc != 1)
530                 return KDB_ARGCOUNT;
531
532         nextarg = 1;
533         if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL, regs)) ||
534             (diag = kdb_getarea(k, addr)))
535                 return diag;
536
537
538         kdb_printf("kobject at 0x%lx\n", addr);
539
540         if (k.k_name) {
541                 char c;
542                 kdb_printf(" k_name 0x%p", k.k_name);
543                 if (kdb_getarea(c, (unsigned long)k.k_name) == 0)
544                         kdb_printf(" '%s'", k.k_name);
545                 kdb_printf("\n");
546         }
547
548         if (k.k_name != ((struct kobject *)addr)->name)
549                 kdb_printf(" name '%." __stringify(KOBJ_NAME_LEN) "s'\n", k.k_name);
550
551         kdb_printf(" kref.refcount %d'\n", atomic_read(&k.kref.refcount));
552
553         kdb_printf(" entry.next = 0x%p entry.prev = 0x%p\n",
554                                         k.entry.next, k.entry.prev);
555
556         kdb_printf(" parent = 0x%p kset = 0x%p ktype = 0x%p dentry = 0x%p\n",
557                                         k.parent, k.kset, k.ktype, k.dentry);
558
559         return 0;
560 }
561
562 static int
563 kdbm_sh(int argc, const char **argv, const char **envp, struct pt_regs *regs)
564 {
565         int diag;
566         int nextarg;
567         unsigned long addr;
568         long offset = 0L;
569         struct Scsi_Host sh;
570
571         if (argc != 1)
572                 return KDB_ARGCOUNT;
573
574         nextarg = 1;
575         if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL, regs)) ||
576             (diag = kdb_getarea(sh, addr)))
577                 return diag;
578
579         kdb_printf("Scsi_Host at 0x%lx\n", addr);
580         kdb_printf("host_queue = 0x%p\n", sh.__devices.next);
581         kdb_printf("ehandler = 0x%p eh_wait = 0x%p  en_notify = 0x%p eh_action = 0x%p\n",
582                    sh.ehandler, sh.eh_wait, sh.eh_notify, sh.eh_action);
583         kdb_printf("eh_active = 0x%d host_wait = 0x%p hostt = 0x%p\n",
584                    sh.eh_active, &sh.host_wait, sh.hostt);
585         kdb_printf("host_failed = %d  host_no = %d resetting = %d\n",
586                    sh.host_failed, sh.host_no, sh.resetting);
587         kdb_printf("max id/lun/channel = [%d/%d/%d]  this_id = %d\n",
588                    sh.max_id, sh.max_lun, sh.max_channel, sh.this_id);
589         kdb_printf("can_queue = %d cmd_per_lun = %d  sg_tablesize = %d u_isa_dma = %d\n",
590                    sh.can_queue, sh.cmd_per_lun, sh.sg_tablesize, sh.unchecked_isa_dma);
591         kdb_printf("host_blocked = %d  reverse_ordering = %d \n",
592                    sh.host_blocked, sh.reverse_ordering);
593
594         return 0;
595 }
596
597 static int
598 kdbm_sd(int argc, const char **argv, const char **envp, struct pt_regs *regs)
599 {
600         int diag;
601         int nextarg;
602         unsigned long addr;
603         long offset = 0L;
604         struct scsi_device *sd = NULL;
605
606         if (argc != 1)
607                 return KDB_ARGCOUNT;
608
609         nextarg = 1;
610         if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL, regs)))
611                 goto out;
612         if (!(sd = kmalloc(sizeof(*sd), GFP_ATOMIC))) {
613                 kdb_printf("kdbm_sd: cannot kmalloc sd\n");
614                 goto out;
615         }
616         if ((diag = kdb_getarea(*sd, addr)))
617                 goto out;
618
619         kdb_printf("scsi_device at 0x%lx\n", addr);
620         kdb_printf("next = 0x%p   prev = 0x%p  host = 0x%p\n",
621                    sd->siblings.next, sd->siblings.prev, sd->host);
622         kdb_printf("device_busy = %d   current_cmnd 0x%p\n",
623                    sd->device_busy, sd->current_cmnd);
624         kdb_printf("id/lun/chan = [%d/%d/%d]  single_lun = %d  device_blocked = %d\n",
625                    sd->id, sd->lun, sd->channel, sd->single_lun, sd->device_blocked);
626         kdb_printf("queue_depth = %d current_tag = %d  scsi_level = %d\n",
627                    sd->queue_depth, sd->current_tag, sd->scsi_level);
628         kdb_printf("%8.8s %16.16s %4.4s\n", sd->vendor, sd->model, sd->rev);
629 out:
630         if (sd)
631                 kfree(sd);
632         return diag;
633 }
634
635 static int
636 kdbm_sc(int argc, const char **argv, const char **envp, struct pt_regs *regs)
637 {
638         int diag;
639         int nextarg;
640         unsigned long addr;
641         long offset = 0L;
642         struct scsi_cmnd *sc = NULL;
643
644         if (argc != 1)
645                 return KDB_ARGCOUNT;
646
647         nextarg = 1;
648         if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL, regs)))
649                 goto out;
650         if (!(sc = kmalloc(sizeof(*sc), GFP_ATOMIC))) {
651                 kdb_printf("kdbm_sc: cannot kmalloc sc\n");
652                 goto out;
653         }
654         if ((diag = kdb_getarea(*sc, addr)))
655                 goto out;
656
657         kdb_printf("scsi_cmnd at 0x%lx\n", addr);
658         kdb_printf("state = %d  owner = %d  device = 0x%p\nb",
659                     sc->state, sc->owner, sc->device);
660         kdb_printf("next = 0x%p  eh_state = %d done = 0x%p\n",
661                    sc->list.next, sc->eh_state, sc->done);
662         kdb_printf("serial_number = %ld  serial_num_at_to = %ld retries = %d timeout = %d\n",
663                    sc->serial_number, sc->serial_number_at_timeout, sc->retries, sc->timeout);
664         kdb_printf("cmd_len = %d  old_cmd_len = %d\n",
665                    sc->cmd_len, sc->old_cmd_len);
666         kdb_printf("cmnd = [%2.2x/%2.2x/%2.2x/%2.2x/%2.2x/%2.2x/%2.2x/%2.2x/%2.2x/%2.2x/%2.2x/%2.2x]\n",
667                    sc->cmnd[0], sc->cmnd[1], sc->cmnd[2], sc->cmnd[3], sc->cmnd[4],
668                    sc->cmnd[5], sc->cmnd[6], sc->cmnd[7], sc->cmnd[8], sc->cmnd[9],
669                    sc->cmnd[10], sc->cmnd[11]);
670         kdb_printf("data_cmnd = [%2.2x/%2.2x/%2.2x/%2.2x/%2.2x/%2.2x/%2.2x/%2.2x/%2.2x/%2.2x/%2.2x/%2.2x]\n",
671                    sc->data_cmnd[0], sc->data_cmnd[1], sc->data_cmnd[2], sc->data_cmnd[3], sc->data_cmnd[4],
672                    sc->data_cmnd[5], sc->data_cmnd[6], sc->data_cmnd[7], sc->data_cmnd[8], sc->data_cmnd[9],
673                    sc->data_cmnd[10], sc->data_cmnd[11]);
674         kdb_printf("request_buffer = 0x%p  request_bufflen = %d\n",
675                    sc->request_buffer, sc->request_bufflen);
676         kdb_printf("use_sg = %d  old_use_sg = %d sglist_len = %d abore_reason = %d\n",
677                    sc->use_sg, sc->old_use_sg, sc->sglist_len, sc->abort_reason);
678         kdb_printf("bufflen = %d  buffer = 0x%p  underflow = %d transfersize = %d\n",
679                    sc->bufflen, sc->buffer, sc->underflow, sc->transfersize);
680         kdb_printf("tag = %d pid = %ld\n",
681                    sc->tag, sc->pid);
682
683 out:
684         if (sc)
685                 kfree(sc);
686         return diag;
687 }
688
689 static int __init kdbm_vm_init(void)
690 {
691         kdb_register("vm", kdbm_vm, "[-v] <vaddr>", "Display vm_area_struct", 0);
692         kdb_register("vmp", kdbm_vm, "[-v] <pid>", "Display all vm_area_struct for <pid>", 0);
693         kdb_register("pte", kdbm_pte, "( -m <mm> | -p <pid> ) <vaddr> [<nbytes>]", "Display pte_t for mm_struct or pid", 0);
694         kdb_register("dentry", kdbm_dentry, "<dentry>", "Display interesting dentry stuff", 0);
695         kdb_register("kobject", kdbm_kobject, "<kobject>", "Display interesting kobject stuff", 0);
696         kdb_register("filp", kdbm_fp, "<filp>", "Display interesting filp stuff", 0);
697         kdb_register("fl", kdbm_fl, "<fl>", "Display interesting file_lock stuff", 0);
698         kdb_register("sh", kdbm_sh, "<vaddr>", "Show scsi_host", 0);
699         kdb_register("sd", kdbm_sd, "<vaddr>", "Show scsi_device", 0);
700         kdb_register("sc", kdbm_sc, "<vaddr>", "Show scsi_cmnd", 0);
701
702         return 0;
703 }
704
705 static void __exit kdbm_vm_exit(void)
706 {
707         kdb_unregister("vm");
708         kdb_unregister("vmp");
709         kdb_unregister("pte");
710         kdb_unregister("dentry");
711         kdb_unregister("kobject");
712         kdb_unregister("filp");
713         kdb_unregister("fl");
714         kdb_unregister("sh");
715         kdb_unregister("sd");
716         kdb_unregister("sc");
717 }
718
719 module_init(kdbm_vm_init)
720 module_exit(kdbm_vm_exit)