MDB Example: Writing your own dmods

In my previous post i showed how to display process environment variables using series of mdb commands. Here is the example of debugger module that does the same thing.

Grab the source from http://www.curthread.org/download/mdbprintenv/mdbprintenv-1.0.tar.gz and compile it:


# gcc -fPIC -D_KERNEL -shared -R/usr/sfw/lib/sparcv9 \\
    -m64 -mcpu=v9 printenv.c -o printenv.so

and install:


# install -s -f /usr/lib/mdb/kvm/sparcv9 -m 555 -u root \\
    -g sys printenv.so

Run mdb in kernel mode and load new dmod:


# mdb -k
> ::load printenv
> ::dmods -l
...
printenv
----------------------------------------------
  dcmd printenv    - print process environment
...

And now:


> 0t12161::pid2proc | ::printenv
debugger context set to proc 6000ae9f7f8
PATH=/usr/sbin:/usr/bin
SMF_FMRI=svc:/system/sysevent:default
SMF_METHOD=/lib/svc/method/svc-syseventd start
SMF_RESTARTER=svc:/system/svc/restarter:default
TZ=Europe/Moscow
debugger context set to kernel

Tags: , ,

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>