Solved There is any way to see the list of vmspace and their corresponding vm_map, vm_map_entries?

Hi,
I currently reading The Design and Implementation of The FreeBSD Operating System Chapter 6, I wonder if there is any way to see the list of vmspace and their corresponding vm_map(), vm_map_entries, and vm_objects through a shell command or using Dtrace?
 
I personally used only the built in debugger, i.e. I always triggered the jump to debugger via console.
I wrote this dtrace script to check if I can answer your question:
Code:
#!/usr/sbin/dtrace -s

#pragma D option quiet

BEGIN { entries = 0; matched = 0;  }

sched:::wakeup
/pid == $1 && entries == 0/
{
        matched = 1;
        proc = curthread->td_proc;
        vmapspc = proc->p_vmspace;

        printf("\n\ncurthread:\t%p\n  proc:\t%p\n  vmap space:\t%p\n", curthread, proc, vmapspc);

        vmap = &vmapspc->vm_map;

        entries = vmap->nentries;
        cur_ent = &vmap->header;

        printf("maps: %d\n", entries);

}

:::tick-5000 / entries != 0 / {
        printf("\t0x%.16x - 0x%.16x, %x\n", cur_ent->start, cur_ent->end, cur_ent->protection);
        cur_ent = cur_ent->right;
        entries--;
}

:::tick-5000 / entries == 0 && matched == 1/ { exit(0) }
I'm not that good in dtrace though. I had troubles walking the structure as there's no flow control. I've helped myself with the predicates to walk the map. It works but the map could change if process is doing mmap()s while we walk the map. Requires pid as argument:
Code:
$ ./test.d 1028


curthread:    fffffe00c50a7560
  proc:    fffffe00c5eaaac0
  vmap space:    fffffe00c5f0fa00
maps: 50
    0x0000800000000000 - 0x0000000000001000, 0
    0x0000000000200000 - 0x0000000000251000, 1
    0x0000000000251000 - 0x00000000002e5000, 5
    0x00000000002e5000 - 0x00000000002e6000, 3
    0x00000000002e6000 - 0x00000000002e9000, 3
    0x00000000002e9000 - 0x00000000002f6000, 3
    0x0000000800a22000 - 0x0000000820a02000, 0
    0x0000000820a02000 - 0x0000000820a22000, 3
    0x000000082132b000 - 0x000000082132c000, 5
    0x000000082153f000 - 0x0000000821557000, 3
    0x0000000821d11000 - 0x0000000821d18000, 3
    0x00000008269f6000 - 0x00000008269fc000, 3
    0x00000008269fc000 - 0x0000000826c2b000, 3
    0x0000000827c00000 - 0x0000000827e00000, 3
    0x0000000828cf9000 - 0x0000000828ef9000, 3
    0x00003167cd2e9000 - 0x00003167cd2eb000, 3
    0x00007ffffffff000 - 0x0000800000000000, 0
    0x0000800000000000 - 0x0000000000001000, 0
    0x0000000000200000 - 0x0000000000251000, 1
    0x0000000000251000 - 0x00000000002e5000, 5
    0x00000000002e5000 - 0x00000000002e6000, 3
    0x00000000002e6000 - 0x00000000002e9000, 3
    0x00000000002e9000 - 0x00000000002f6000, 3
    0x0000000800a22000 - 0x0000000820a02000, 0
    0x0000000820a02000 - 0x0000000820a22000, 3
    0x000000082132b000 - 0x000000082132c000, 5
    0x000000082153f000 - 0x0000000821557000, 3
    0x0000000821d11000 - 0x0000000821d18000, 3
    0x00000008269f6000 - 0x00000008269fc000, 3
    0x00000008269fc000 - 0x0000000826c2b000, 3
    0x0000000827c00000 - 0x0000000827e00000, 3
    0x0000000828cf9000 - 0x0000000828ef9000, 3
    0x00003167cd2e9000 - 0x00003167cd2eb000, 3
    0x00007ffffffff000 - 0x0000800000000000, 0
    0x0000800000000000 - 0x0000000000001000, 0
    0x0000000000200000 - 0x0000000000251000, 1
    0x0000000000251000 - 0x00000000002e5000, 5
    0x00000000002e5000 - 0x00000000002e6000, 3
    0x00000000002e6000 - 0x00000000002e9000, 3
    0x00000000002e9000 - 0x00000000002f6000, 3
    0x0000000800a22000 - 0x0000000820a02000, 0
    0x0000000820a02000 - 0x0000000820a22000, 3
    0x000000082132b000 - 0x000000082132c000, 5
    0x000000082153f000 - 0x0000000821557000, 3
    0x0000000821d11000 - 0x0000000821d18000, 3
    0x00000008269f6000 - 0x00000008269fc000, 3
    0x00000008269fc000 - 0x0000000826c2b000, 3
    0x0000000827c00000 - 0x0000000827e00000, 3
    0x0000000828cf9000 - 0x0000000828ef9000, 3
    0x00003167cd2e9000 - 0x00003167cd2eb000, 3
 
Back
Top