Xiao-Hai Ivan Shi
2006-Apr-19 05:12 UTC
[dtrace-discuss] How to get the var/args in kernel function
Hi, I am very new in dtrace, I just want to get some values in kernel function, can anyone help me? In kernel, there are two functions like the following: int func1 (void) { int arg1; int arg2; char *arg3; int ret; arg1=100; arg3="test"; ret=func2(arg1, &arg2, arg3); ... return 0; } int func2 (int arg1, int *arg2, char *arg3) { char *var; *arg2 = arg1; var=arg3; ... return (0); } I want to get the following values for func2: 1) on entry, the value of arg1, arg2, arg3. 2) on return, the value of arg2 which is set in func2, and func2''s returned value. How can I compose a D-script to get these values? Can I get the value of local variable "var" in func2? Thanks you very much. Thanks, Ivan
Roch Bourbonnais - Performance Engineering
2006-Apr-19 07:07 UTC
[dtrace-discuss] How to get the var/args in kernel function
Xiao-Hai Ivan Shi writes: > Hi, > > I am very new in dtrace, I just want to get some values in kernel > function, can anyone help me? > > In kernel, there are two functions like the following: > > int func1 (void) > { > int arg1; > int arg2; > char *arg3; > int ret; > > arg1=100; > arg3="test"; > ret=func2(arg1, &arg2, arg3); > ... > return 0; > } > > int func2 (int arg1, int *arg2, char *arg3) > { > char *var; > > *arg2 = arg1; > var=arg3; > ... > return (0); > } > > I want to get the following values for func2: > 1) on entry, the value of arg1, arg2, arg3. If the module is postprocessed with CTF: fbt::func2:entry{trace(args[0]); trace(args[1]); trace(args[2]);} otherwise you have to supply the types: fbt::func2:entry{trace((int)arg0); trace((int*)arg1); trace((char*)arg2);} > 2) on return, the value of arg2 which is set in func2, > and func2''s returned value. You''ll need 2 probes (one that saves the pointer argument and one that reads it later when data has been stored into it); The fbt:::return probes contains the return value of function is arg1 (second argument to the return probe); arg0 is the address within the function that called ret and the likes. In some cases when func2 would end in a tail-call; then arg1 may not be meaningfull. fbt::func2:entry{self->arg2 = (int*)arg1} fbt::func2:return{trace(*(self->arg2)); trace(arg1); self->arg2 = NULL} > > > How can I compose a D-script to get these values? Can I get the value of > local variable "var" in func2? You can''t easily get var since the compiler may or may not have used it. You need so custom stuff here including looking as dissembly and then asking ''someone else'' ;-) -r > > Thanks you very much. > > Thanks, > Ivan > _______________________________________________ > dtrace-discuss mailing list > dtrace-discuss at opensolaris.org