2016-01-21 96 views
0

我有一个愚蠢的问题, 我想通过系统tap来了解源代码流,因为我试图使用内核访问本地变量。语句探测函数,它会显示除指针之外的所有其他变量。systemtap:能够访问本地变量,但不能访问本地指针

probe module("Module_Path/proc_rw.ko").statement("[email protected] Src Path/proc_rw.c+9") 
{ 
    printf("local = %s\n", $$locals) 
} 


Module Code : 
static ssize_t my_write(struct file *f, const char __user *buf, size_t len, loff_t *off) 
{ 
     pid_t pid; 
     int ret; 
     struct task_struct *task_local; 
     int *i;  
     ret=copy_from_user(c, buf, len); 
     i=&ret; 
     pid=simple_strtol(buf, NULL, 10); 
     task_local=pid_task(find_vpid(pid), PIDTYPE_PID); 
     return len; 
} 

在i执行上述STAP代码,就返回,

本地= PID = 0xf98 RET =为0x0 task_local =?我=?

任何有助于理解为什么task_local和i值不打印的将有所帮助。

Regards, Yash。

回答

1

你在这里看到的是编译器优化的一个假象。不再使用的变量可能会释放其资源(寄存器或堆栈帧插槽重用),因此即使它们在理论上处于范围之内,也没有任何价值可供读取。

如果您在类似程序上运行gdb并跨步到一个很远的路线,然后尝试打印这些变量,您会看到同样的情况。或者试试:

stap -L 'module("Module_Path/proc_rw.ko").statement("[email protected]*:*")' 

看到可在每个&变量的语句的转储。

另请参阅https://lkml.org/lkml/2015/4/23/605了解内核补丁,旨在消除最近(2014-10)不希望的调试信息质量下降。 (它没有被合并。)但是你可以通过定制你自己的Makefile来修复它自己的模块。