[Crash-utility] ptov command

Dave Anderson anderson at redhat.com
Fri Jul 6 15:39:52 UTC 2012



----- Original Message -----
> Below you find my version of the ptov function. I have just added a
> few lines and placed them under "#if defined(ARM)". The test is
> reasonable for ARM so I would appreciate if you include it. For
> other platforms please do whatever you like.
> 
> Jan
> 
> 
> void
> cmd_ptov(void)
> {
> 	int c;
> 	ulong vaddr;
> 	physaddr_t paddr;
> #if defined(ARM)
> 	physaddr_t paddr_tst;
> #endif
> 	char buf1[BUFSIZE];
> 	char buf2[BUFSIZE];
> 	int others;
> 
> 	while ((c = getopt(argcnt, args, "")) != EOF) {
> 		switch(c)
> 		{
> 		default:
> 			argerrs++;
> 			break;
> 		}
> 	}
> 
> 	if (argerrs || !args[optind])
> 		cmd_usage(pc->curcmd, SYNOPSIS);
> 
> 	others = 0;
> 	while (args[optind]) {
> 		paddr = htoll(args[optind], FAULT_ON_ERROR, NULL);
> 		vaddr = PTOV(paddr);
> 
> #if defined(ARM)
> 		if (kvtop(0, vaddr, &paddr_tst, 0) && paddr_tst==paddr) {
> #endif
> 		fprintf(fp, "%s%s  %s\n", others++ ? "\n" : "",
> 		    mkstring(buf1, VADDR_PRLEN, LJUST, "VIRTUAL"),
> 		    mkstring(buf2, VADDR_PRLEN, LJUST, "PHYSICAL"));
> 		fprintf(fp, "%s  %s\n",
> 		    mkstring(buf1, VADDR_PRLEN, LJUST|LONG_HEX, MKSTR(vaddr)),
>                     mkstring(buf2, VADDR_PRLEN, LJUST|LONGLONG_HEX,
> 			MKSTR(&paddr)));
> #if defined(ARM)
> 		} else {
> 			fprintf(fp, "Unknown virtual address for physical address
> 			0x%08llx\n", paddr);
> 		}
> #endif
> 
> 		optind++;
> 	}
> }

I hate the "#ifdef ARM" sections and the error message doesn't fit
into multiple-argument usage.  How's this work for you?

--- crash-6.0.8/memory.c.orig   2012-07-06 11:28:13.000000000 -0400
+++ crash-6.0.8/memory.c        2012-07-06 11:32:02.000000000 -0400
@@ -2975,9 +2975,9 @@
 void
 cmd_ptov(void)
 {
-       int c;
+       int c, unknown;
        ulong vaddr;
-       physaddr_t paddr;
+       physaddr_t paddr, paddr_test;
        char buf1[BUFSIZE];
        char buf2[BUFSIZE];
        int others;
@@ -2999,10 +2999,14 @@
                paddr = htoll(args[optind], FAULT_ON_ERROR, NULL);
                vaddr = PTOV(paddr);

+               unknown = BITS32() && (!kvtop(0, vaddr, &paddr_test, 0) ||
+                   (paddr_test != paddr));
+
                fprintf(fp, "%s%s  %s\n", others++ ? "\n" : "",
                    mkstring(buf1, VADDR_PRLEN, LJUST, "VIRTUAL"),
                    mkstring(buf2, VADDR_PRLEN, LJUST, "PHYSICAL"));
-               fprintf(fp, "%s  %s\n",
+               fprintf(fp, "%s  %s\n", unknown ?
+                   mkstring(buf1, VADDR_PRLEN, LJUST, "unknown") :
                    mkstring(buf1, VADDR_PRLEN, LJUST|LONG_HEX, MKSTR(vaddr)),
                     mkstring(buf2, VADDR_PRLEN, LJUST|LONGLONG_HEX,


With one my sample ARM dumps, it looks like this:

  crash> kmem -p
    PAGE    PHYSICAL   MAPPING    INDEX CNT FLAGS
  c0b47000  80000000         0         0  0 0
  c0b47020  80001000         0         0  0 0
  c0b47040  80002000         0         0  0 0
  ... [ cut ] ...
  c0d46fa0  8fffd000         0         0  1 400
  c0d46fc0  8fffe000         0         0  1 400
  c0d46fe0  8ffff000         0         0  1 400
  crash> 

  crash> ptov 7ffff000 80000000 8ffff000 9000000
  VIRTUAL   PHYSICAL
  unknown   7ffff000

  VIRTUAL   PHYSICAL
  c0000000  80000000

  VIRTUAL   PHYSICAL
  cffff000  8ffff000

  VIRTUAL   PHYSICAL
  unknown   9000000 
  crash>

Dave


-------------- next part --------------
A non-text attachment was scrubbed...
Name: ptov.patch
Type: text/x-patch
Size: 965 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/crash-utility/attachments/20120706/ce7d2dff/attachment.bin>


More information about the Crash-utility mailing list