Hello, Mike.

Can you help me one more time, please.

I wrote a simple C program, which just print string and its address. Here it is:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MSG "Hello, World!"

int main(int argc, char* argv[])
{
    int length = strlen(MSG);
    char* message = malloc(length + 1);
    memcpy(message, MSG, length);
    message[length + 1] = 0;

    unsigned int address = (unsigned int) message;

    printf("Message is: %s\n", message);
    printf("Address is: %x\n", address);

    getchar();

    free(message);

    return EXIT_SUCCESS;
}

bash-3.00# cc -g -o test test.c
bash-3.00# ./test
Message is: Hello, World!
Address is: 8060e90

I want to translate the virtual address 8060e90 to the physical
address with mdb.
It is ok, when I just run mdb and print string by virtual address:

bash-3.00# mdb -p `ps -a | pgrep test`
Loading modules: [ ld.so.1 libc.so.1 ]
> 8060e90/s
0x8060e90:      Hello, World!

But neither "::vtop", nor "\" works for me.

> 8060e90::vtop
mdb: failed to get physical mapping: operation not supported by target
> 8060e90\s
mdb: failed to read data from target: operation not supported by target
0x8060e90:

I guess that I need to do something more then just call ::vtop. May be
I need to load some mdb-module or to provide some additional data.
Well, I actually have no any idea.


2009/8/20, Mike Shapiro <m...@sun.com>:
> On Thu, Aug 20, 2009 at 03:57:28AM -0700, Dmitry Afanasyev wrote:
>> Hello!
>>
>> I need to get physical memory address from virtual and read some data by
>> it from /dev/mem. Does kvm_physaddr from libkvm can help me?
>>
>> For example, I have a pointer of type int and it points to 5. If I
>> translate that pointer address to physical address by kvm_physaddr and
>> read from /dev/mem with physical address as shift in /dev/mem do I get 5?
>
> Yes.  This is essentially what mdb does for its physical memory
> debugging APIs, so you can demonstrate the above using ::vtop
> and "\" (format from physical instead of virtual) to see this.
>
> I'll pick the symbol "rootfs" which is a struct but begins
> with a well-known string:
>
> # mdb -k
> ...
>> rootfs/s
> rootfs:
> rootfs:         zfs
>> rootfs::vtop
> virtual fffffffffbc00f48 mapped to physical a400f48
>> a400f48\s
> 0xa400f48:      zfs
>
> -Mike
>
> --
> Mike Shapiro, Sun Microsystems Open Storage / Fishworks. blogs.sun.com/mws/
>


-- 
Sincerely yours,
Dmitry Afanasyev.

Using Ubuntu GNU/Linux 8.10 "Intrepid Ibex".
_______________________________________________
opensolaris-code mailing list
opensolaris-code@opensolaris.org
http://mail.opensolaris.org/mailman/listinfo/opensolaris-code

Reply via email to