Printing arguments to a kernel function in dtrace

997 views Asked by At

I need to debug my Solaris kernel module particularly extract the data in a structure passed by reference to my kernel function.

msg_recv(sk_buff *skbp, uint_t link, uchar_t* src)
{
    pkt_hdr_t *pkt;
    pkt = (pkt_hdr_t *)skbp->data;
    port = pkt->port;    
}

I have written a systemtap script in linux to access the argument and extract data.

How can I do this using DTRACE for solaris modules.

I tried looking into the system and trying few commands, but thats all i know about dtrace:

[root@vcssx247-ldm7 ~]#dtrace -l | grep msg_recv
 7090        fbt               mymod                     msg_recv1 entry
 7091        fbt               mymod                     msg_recv1 return
 7548        fbt               mymod                     msg_recv entry
 7549        fbt               mymod                     msg_recv return
1

There are 1 answers

0
myaut On

DTrace is similar conceptually to SystemTap (actually, vice versa as SystemTap came later):

  1. Like SystemTap, it can attach probes to function, but it requires different syntax:

    kernel.function("xxx")                 ->    fbt:genunix:xxx:return
    module("mod").function("xxx")          ->    fbt:mod:xxx:entry
    module("mod").function("xxx").return   ->    fbt:mod:xxx:return
    
  2. Accessing arguments is quite different as DTrace doesn't support DWARF for argument names (it has arg0 .. arg9 variables which contains uintptr_t values of arguments):

    @cast($skpb, "struct sk_buff", "mod")  ->    ((struct sk_buff*) arg0) 
    
  3. Accessing in-kernel data, is similar, but printing functions are different:

    print($skpb->sk_field)                 ->    trace(args[0]->sk_field)
    print("%32m", $src)                    ->    tracemem(arg2, 32)
    

I've added links to my open book about DTrace/SystemTap where you can find more info