On Wed, Sep 20, 2017 at 09:57:00AM +0530, Nayan Gadre wrote:
> Hi,
> 
> I have managed to do few things. @Jim and @Mathew inputs were helpful. Thanks
> 
> So i have
> [root@vcssx247-ldm7 ~]#dtrace -lvn fbt:my_mod:msg_recv1:entry
>    ID   PROVIDER            MODULE                          FUNCTION NAME
>  7090        fbt               mymod                     msg_recv1 entry
> 
>         Probe Description Attributes
>                 Identifier Names: Private
>                 Data Semantics:   Private
>                 Dependency Class: Unknown
> 
>         Argument Attributes
>                 Identifier Names: Private
>                 Data Semantics:   Private
>                 Dependency Class: ISA
> 
>         Argument Types
>                 args[0]: mblk_t *
>                 args[1]: uint_t
>                 args[2]: uchar_t *
>                 args[3]: ulong_t
> 
> And my probe then becomes:
> dtrace -n 'msg_recv1:entry { printf("msg_recv1: %x, %x\n",
> *(uchar_t*)args[0]->b_rptr, *((uchar_t*)args[0]->b_rptr + 1)); }'
> 
> Now, the args[0]->b_rptr points to my custom structure pkt_hdr_t { }.
> 
> Is is possible to typecast this args[0]->b_rptr to struct pkt_hdr_t *
> in the dtrace script for better readable access of the private
> structure variables instead of using offsets to b_rptr:
> 
> Something like this:
> struct pkt_hdr_t* ppkt = (struct pkt_hdr_t*)args[0]->b_rptr;
> 
> Then printf("%d\n", ppkt->member1);

In general, local variables to a probe are created and accessed using
this->varname.  So you can easily store b_rptr in ppkt:

        this->ppkt = args[0]->b_rptr;

But this will just use the type of b_rptr, so you'll still
need to cast stuff; you can put a cast before it, and then
the variable will be of that type.

In general, once you reach a certain complexity, a dtrace script is
easier to deal with.  Your above code would look like:

% cat > myscript.d <<\EOF
#!/usr/sbin/dtrace -s

msg_recv1:entry {
        this->ppkt = (uchar_t *)args[0]->b_rptr;
        printf("msg_recv1: %x, %x\n", *this->ppkt, *(this->ppkt + 1));
}
EOF
% chmod +x myscript.d

If your module has CTF data (which would require you to change your build
process, and is not well documented), you could do:

% cat > myscript.d <<\EOF
#!/usr/sbin/dtrace -s

msg_recv1:entry {
        this->ppkt = (struct pkt_hdr_t *)args[0]->b_rptr;
        printf("msg_recv1: %x, %x\n", this->ppkt->foo, this->ppkt->bar);
}
EOF
% chmod +x myscript.d

You can also just define the structure in your script, or #include your
headers, using the -C arg to invoke the preprocessor:

(note the "struct C`struct_name" syntax; it makes sure you get the definitions
from the headers)

% cat > myscript.d <<\EOF
#!/usr/sbin/dtrace -Cs

#include "my_header.h"

msg_recv1:entry {
        this->ppkt = (struct C`pkt_hdr_t *)args[0]->b_rptr;
        printf("msg_recv1: %x, %x\n", this->ppkt->foo, this->ppkt->bar);
}
EOF
% chmod +x myscript.d

Cheers,
- jonathan

> Regards
> 
> On Wed, Sep 20, 2017 at 12:13 AM, jim mauro <jim.ma...@gmail.com> wrote:
> > It's been a while (2+ years), but...
> >
> > The fbt provider makes function args available at entry probes via
> > args[0] ... args[n]. This are typed.
> >
> > So you should be able to dereference structure members of sk_buff
> > doing 'args[0]->structure_member', etc, when fbt:mymod:msg_recv:entry
> > fires....
> >
> > args[1] will be the link value
> > args[2] will be the src pointer.
> >
> > (jeez...I hope I'm remember this correctly. There was a book....).
> >
> > Thanks
> > Jim
> >
> >
> > On Tue, Sep 19, 2017 at 6:00 AM, Nayan Gadre <beejoy.na...@gmail.com> wrote:
> >> 
> >> Hi,
> >> 
> >> I am new to solaris dtrace debugging tool, but I have prior experience
> >> with Linux SystemTap.
> >> 
> >> I need to debug my Solaris kernel module particularly extract the data
> >> in a structure passed by reference to my kernel function.
> >> 
> >> msg_recv(struct 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
> >> 
> >> Any pointers to correct, to the point documentation would be appreciated.
> >> 
> >> Thanks
> >> Nayan
> >> 
> >
> >
> 
> 


-------------------------------------------
dtrace-discuss
Archives: https://www.listbox.com/member/archive/184261/=now
RSS Feed: https://www.listbox.com/member/archive/rss/184261/25769126-e243886f
Modify Your Subscription: 
https://www.listbox.com/member/?member_id=25769126&id_secret=25769126-8d47a7b2
Powered by Listbox: http://www.listbox.com

Reply via email to