Search code examples
systemtap

How can I show double/float values using systemtap $$param$$ and $$return$$


I'm using systemtap to get a callgraph with parameters and return values, but float and double variables are shown as ? char. Is there a way to show the correct value?

My systemtap script is this:

#! /usr/bin/env stap

probe $1.call   { trace(1, $$parms$$) }
probe $1.return { trace(-1, $$return$$) }   

And a simple C program code to test:

double test(int a, char b, double c, float e){
    return c;
}

int main(void){
    test(1,'1',1.0,1.0f);
    return 0;
}

The output of the script running the code above (note the c and e values, and the test return):

test a=1 b='1' c=? e=?
test return=?
main 
main return=0

Solution

  • Systemtap does not currently support floating point values natively (mainly because floating point operations are not permitted in kernel context). See also https://sourceware.org/bugzilla/show_bug.cgi?id=13838 and https://sourceware.org/bugzilla/show_bug.cgi?id=13832 .

    A clumsy workaround could be something like

    probe process("a.out").function("test") {
        hexdump = sprintf("%.*M", 4, & $e)
    }
    

    or similarly, using user_int(& $e) to get access to the floating-point value as if it were an integer. Rendering it in decimal form is a separate issue, but even just getting the mantissa/exponents separated via script language functions could be something.