[PATCH] add -s option to vm to display one vma at a time

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Dave,

When I am using "vm -p" command, I feel it is chaotic when too much data is printed. I think it is clear to display one vma each time.

In the patch, I compare all vmas with the argument of -s option. If an equal vma is found, it will be printed like below.

crash> vm -ps ffff88028ff7d3a0
      VMA           START       END     FLAGS FILE
ffff88028ff7d3a0 7fff29b71000 7fff29b87000 100173
VIRTUAL     PHYSICAL
7fff29b71000  (not mapped)
7fff29b72000  (not mapped)
7fff29b73000  (not mapped)
7fff29b74000  (not mapped)
7fff29b75000  (not mapped)
7fff29b76000  (not mapped)
7fff29b77000  27faad000
7fff29b78000  2807aa000
7fff29b79000  280781000
7fff29b7a000  280787000
7fff29b7b000  280776000
7fff29b7c000  280786000
7fff29b7d000  27f2df000
7fff29b7e000  27f2e0000
7fff29b7f000  27f2e1000
7fff29b80000  27f2d7000
7fff29b81000  28b1ac000
7fff29b82000  28ecc1000
7fff29b83000  28c5c2000
7fff29b84000  28aaf4000
7fff29b85000  28aaf9000
7fff29b86000  289566000
crash>

--
--
Regards
Qiao Nuohan


diff --git a/defs.h b/defs.h
index a942dbb..f3ca47b 100755
--- a/defs.h
+++ b/defs.h
@@ -2241,6 +2241,7 @@ struct load_module {
 #define PRINT_INODES      (0x10)   /* KVADDR, UVADDR, and PHYSADDR */
 #define PRINT_MM_STRUCT   (0x20)
 #define PRINT_VMA_STRUCTS (0x40)
+#define PRINT_SINGLE_VMA  (0x80)
 
 #define MIN_PAGE_SIZE  (4096)
 
diff --git a/memory.c b/memory.c
index 55a184b..d3ac2dc 100755
--- a/memory.c
+++ b/memory.c
@@ -3045,7 +3045,7 @@ cmd_vm(void)
 	ref = NULL;
 	BZERO(&reference, sizeof(struct reference));
 
-        while ((c = getopt(argcnt, args, "f:pmvR:")) != EOF) {
+        while ((c = getopt(argcnt, args, "f:pmvR:s:")) != EOF) {
                 switch(c)
 		{
 		case 'f':
@@ -3059,13 +3059,13 @@ cmd_vm(void)
 			break;
 
 		case 'p': 
-			if (flag)
+			if (flag & ~PRINT_SINGLE_VMA)
 				argerrs++;
 			else
 				flag |= PHYSADDR;
 			break;
 		case 'm':
-			if (flag)
+			if (flag & ~PRINT_SINGLE_VMA)
 				argerrs++;
 			else
 				flag |= PRINT_MM_STRUCT;
@@ -3090,6 +3090,17 @@ cmd_vm(void)
 			}
 			break;
 
+		case 's':
+			if ((flag & PRINT_MM_STRUCT) || ref) {
+				error(INFO, "-s option is only valid with -p/-v");
+				argerrs++;
+			} else {
+				flag |= PRINT_SINGLE_VMA;
+				ref = &reference;
+				ref->hexval = htol(optarg, FAULT_ON_ERROR, NULL);
+			}
+			break;
+
 		default:
 			argerrs++;
 			break;
@@ -3388,6 +3399,8 @@ vm_area_dump(ulong task, ulong flag, ulong vaddr, struct reference *ref)
 	ulonglong vm_flags;
 	ulong vm_file, inode;
 	ulong dentry, vfsmnt;
+	ulong single_vma;
+	int single_vma_header;
 	int found;
 	struct task_mem_usage task_mem_usage, *tm;
 	char buf1[BUFSIZE];
@@ -3401,6 +3414,12 @@ vm_area_dump(ulong task, ulong flag, ulong vaddr, struct reference *ref)
 	tm = &task_mem_usage;
 	get_task_mem_usage(task, tm);
 
+	single_vma_header = 0;
+	if (flag & PRINT_SINGLE_VMA) {
+		single_vma = ref->hexval;
+		ref = NULL;
+	}
+
 	if (ref) {
 		ref->cmdflags = VM_REF_SEARCH;
 		if (IS_A_NUMBER(ref->str)) {
@@ -3420,7 +3439,7 @@ vm_area_dump(ulong task, ulong flag, ulong vaddr, struct reference *ref)
                 return (ulong)NULL;
         }
 
-        if (!(flag & (UVADDR|PRINT_MM_STRUCT|PRINT_VMA_STRUCTS)) &&
+        if (!(flag & (UVADDR|PRINT_MM_STRUCT|PRINT_VMA_STRUCTS|PRINT_SINGLE_VMA)) &&
 	    !DO_REF_SEARCH(ref)) 
 		PRINT_VM_DATA();
 
@@ -3449,7 +3468,7 @@ vm_area_dump(ulong task, ulong flag, ulong vaddr, struct reference *ref)
 
 	for (found = FALSE; vma; vma = vm_next) {
 
-		if ((flag & PHYSADDR) && !DO_REF_SEARCH(ref))
+		if ((flag & PHYSADDR) && !DO_REF_SEARCH(ref) && !single_vma_header)
 			fprintf(fp, "%s", vma_header);
 
 		inode = 0;
@@ -3462,6 +3481,12 @@ vm_area_dump(ulong task, ulong flag, ulong vaddr, struct reference *ref)
 		vm_start = ULONG(vma_buf + OFFSET(vm_area_struct_vm_start));
 		vm_flags = get_vm_flags(vma_buf);
 		vm_file = ULONG(vma_buf + OFFSET(vm_area_struct_vm_file));
+		
+		if (flag & PRINT_SINGLE_VMA) {
+			single_vma_header++;
+			if (vma != single_vma)
+				continue;
+		}
 
 		if (flag & PRINT_VMA_STRUCTS) {
 			dump_struct("vm_area_struct", vma, 0);
--
Crash-utility mailing list
Crash-utility@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/crash-utility

[Index of Archives]     [Fedora Development]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [KDE Users]     [Fedora Tools]

 

Powered by Linux