如何使用 systemtap $$param$$ 和 $$return$$ 显示 double/float 值

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

我正在使用 systemtap 获取带有参数和 return 值的调用图,但 float 和 double 变量显示为 ?字符。有没有办法显示正确的值?

我的 systemtap 脚本是这样的:

#! /usr/bin/env stap

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

还有一个简单的C程序代码来测试:

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

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

脚本的输出 运行 上面的代码(注意 c 和 e 值,以及测试 return):

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

Systemtap 目前本身不支持浮点值(主要是因为在内核上下文中不允许进行浮点运算)。另见 https://sourceware.org/bugzilla/show_bug.cgi?id=13838 and https://sourceware.org/bugzilla/show_bug.cgi?id=13832 .

笨拙的解决方法可能类似于

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

或类似地,使用 user_int(& $e) 来访问浮点值,就好像它是整数一样。以十进制形式呈现它是一个单独的问题,但即使只是通过脚本语言函数将 mantissa/exponents 分开也可能是一回事。