[PATCH] add page lookup to page command

linas at austin.ibm.com linas at austin.ibm.com
Thu Mar 4 12:12:07 EST 2004


Hi,

The attached patch adds support for automatic struct page * lookup
for the 'page' command.  By typing 'page -s <vaddr>', it will find
the mem_map[] entry that corresponds to vaddr, and display that.
(To do this manually is a bit tedious; besides chasing non-exported
symbols in System.map, one has to do some hex multiplication by
sizeof(struct page); so this patch automates that.)

It also enables the memmap command for PPC64. I think the comments
about it being arch-dependent are bogus; I think all arches use
the same code.  But I took the conservative approach and just added
CONFIG_PPC64 instead.

--linas

-------------- next part --------------
--- kdb/modules/kdbm_pg.c.orig	2004-03-03 17:03:39.000000000 -0600
+++ kdb/modules/kdbm_pg.c	2004-03-03 17:49:21.000000000 -0600
@@ -151,18 +151,32 @@ kdbm_page(int argc, const char **argv, c
 	long	offset=0;
 	int nextarg;
 	int diag;
+	int lookup_page = 0;

-	if (argc != 1)
+	if (argc == 2) {
+		if (strcmp(argv[1], "-s") != 0) {
+			return KDB_ARGCOUNT;
+		}
+		lookup_page = 1;
+	} else if (argc != 1) {
 		return KDB_ARGCOUNT;
+	}

-	nextarg = 1;
+	nextarg = argc;
 	diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL, regs);
 	if (diag)
 		return diag;

+	/* Assume argument is a page number, not address */
 	if (addr < PAGE_OFFSET)
 		addr = (unsigned long) &mem_map[addr];

+	/* Get the struct page * that corresponds to this addr */
+	if (lookup_page)
+	{
+		addr = (unsigned long) virt_to_page(addr);
+	}
+
 	if ((diag = kdb_getarea(page, addr)))
 		return(diag);

@@ -476,9 +490,10 @@ out:



-#ifdef	CONFIG_X86
-/* According to Steve Lord, this code is ix86 specific.  Patches to extend it to
- * other architectures will be greatefully accepted.
+#if	defined(CONFIG_X86) | defined(CONFIG_PPC64)
+/* According to Steve Lord, this code is ix86 specific.
+ * Patches to extend it to other architectures will be
+ * greatefully accepted.
  */
 static int
 kdbm_memmap(int argc, const char **argv, const char **envp,
@@ -541,12 +556,12 @@ kdbm_memmap(int argc, const char **argv,
 	kdb_printf("  high page count:  %6d\n", page_counts[8]);
 	return 0;
 }
-#endif	/* CONFIG_X86 */
+#endif	/* CONFIG_X86 | CONFIG_PPC64 */

 static int __init kdbm_pg_init(void)
 {
 #ifndef CONFIG_DISCONTIGMEM
-	kdb_register("page", kdbm_page, "<vaddr>", "Display page", 0);
+	kdb_register("page", kdbm_page, "[-s] <vaddr>", "Display page [or page of addr]", 0);
 #endif
 	kdb_register("inode", kdbm_inode, "<vaddr>", "Display inode", 0);
 	kdb_register("sb", kdbm_sb, "<vaddr>", "Display super_block", 0);
@@ -554,7 +569,7 @@ static int __init kdbm_pg_init(void)
 	kdb_register("inode_pages", kdbm_inode_pages, "<inode *>", "Display pages in an inode", 0);
 	kdb_register("req", kdbm_request, "<vaddr>", "dump request struct", 0);
 	kdb_register("rqueue", kdbm_rqueue, "<vaddr>", "dump request queue", 0);
-#ifdef	CONFIG_X86
+#if	defined(CONFIG_X86) | defined(CONFIG_PPC64)
 	kdb_register("memmap", kdbm_memmap, "", "page table summary", 0);
 #endif

@@ -573,7 +588,7 @@ static void __exit kdbm_pg_exit(void)
 	kdb_unregister("inode_pages");
 	kdb_unregister("req");
 	kdb_unregister("rqueue");
-#ifdef	CONFIG_X86
+#if	defined(CONFIG_X86) | defined(CONFIG_PPC64)
 	kdb_unregister("memmap");
 #endif
 }


More information about the Linuxppc64-dev mailing list