Sunday 1 August 2010

Where in the world is args[] setup ? !

This is driving me nuts. I am trying to debug a translator - a simple
one for SDT probes. Heres the translator:
 
translator fileinfo_t  <buf_t *B> {
fi_offset = B->fi_offset;
};


In Dtrace, when a probe fires, we get the arguments to the probe
via arg0, arg1, .... In addition, DTrace arranges args[0..n] to be a
'translated' version of a kernel binary structure. The "translator" maps
from kernel format to publically visible format.


(See http://wikis.sun.com/display/DTrace/Translators for more details).


What is frustrating is that by suitable type casting, arg2 has my
pointer in for io:::start, but args[2] - when going through the translator,
doesnt access the same pointer ("B" in the case above).


I know this wont make sense to most of the world, but I cannot even
find the code which sets up the args[] array.


The key here is that when probes fire, the memory we need to print things
out has to be copied from kernel space to user space. DTrace does this
by assuming everything is some form of struct/union, and the whole
translator business allows DTrace to marshall the data structures
in a safe and coherent way. Without them, D code would be fugly with
lots of pointer/typecasts. In a sense, a translator is like a method,
but its a funny method which deals with user-level typecasting, rather
than executing procedural code. If done properly, most users wont
ever know how/what happens - they will just do stuff.


Why do I even care? Because I am trying to get /usr/lib/dtrace/io.d to
be correct and allow use of 3rd party scripts which utilise the IO provider
to intercept when apps do I/O and sleep.


Oh well, more on another day.


Post created by CRiSP v10.0.2a-b5881

No comments:

Post a Comment