dump_stack使用方法
对于大型驱动,想要知道某个回调函数由谁调用,非常困难。到底有没有办法知道呢?回答是肯定的,通过内核提供的接口dump_stack()可以满足要求。其实能够想到使用dump_stack()来跟踪,是根据当内核发生panic时候,也会主动调用该接口,所以我们可以在调试过程中主动调用该接口来进行测试。
TP双击唤醒部分驱动代码段:
---------------------------------------------------注册notifier到内核start-----------------------------------------------------------
#if defined(CONFIG_FB)
data->fb_notif.notifier_call = fb_notifier_callback;//回调函数在啥时候调用呢?
err = fb_register_client(&data->fb_notif);
if (err)
dev_err(&client->dev, "Unable to register fb_notifier: %d\n",
err);
#endif
---------------------------------------------------注册notifier到内核end------------------------------------------------------------
--------------------------------------------fb_notifier_callback实现方法start----------------------------------------------------
#if defined(CONFIG_FB)
static int fb_notifier_callback(struct notifier_block *self,
unsigned long event, void *data)
{
struct fb_event *evdata = data;
int *blank;
struct ft5x06_ts_data *ft5x06_data =
container_of(self, struct ft5x06_ts_data, fb_notif);
printk(KERN_ALERT"--------------[fyl] dump_stack start----------------");
dump_stack();
printk(KERN_ALERT"--------------[fyl] dump_stack end----------------");
if (evdata && evdata->data && event == FB_EVENT_BLANK &&
ft5x06_data && ft5x06_data->client) {
blank = evdata->data;
if (*blank == FB_BLANK_UNBLANK)
ft5x06_ts_resume(&ft5x06_data->client->dev);
else if (*blank == FB_BLANK_POWERDOWN)
ft5x06_ts_suspend(&ft5x06_data->client->dev);
}
return 0;
}
#endif
--------------------------------------------fb_notifier_callback实现方法end------------------------------------------------------
测试抓取log:
<1>[ 950.351269] --------------[fyl] dump_stack start----------------
<6>[ 950.351270] CPU: 2 PID: 295 Comm: surfaceflinger Tainted: G W O 3.10.49-gc92b51d-dirty #4
<6>[ 950.351288] [<c010be4c>] (unwind_backtrace+0x0/0x11c) from [<c0109a08>] (show_stack+0x10/0x14)
<6>[ 950.351300] [<c0109a08>] (show_stack+0x10/0x14) from [<c05ca74c>] (fb_notifier_callback+0x20/0x9c)//定位到该函数
<6>[ 950.351310] [<c05ca74c>] (fb_notifier_callback+0x20/0x9c) from [<c0a7b098>] (notifier_call_chain+0x40/0x68) //nofier_call_chain调用了fb_notifier_callback
<6>[ 950.351321] [<c0a7b098>] (notifier_call_chain+0x40/0x68) from [<c01459e8>] (__blocking_notifier_call_chain+0x40/0x58)
<6>[ 950.351333] [<c01459e8>] (__blocking_notifier_call_chain+0x40/0x58) from [<c0145a14>] (blocking_notifier_call_chain+0x14/0x1c)
<6>[ 950.351344] [<c0145a14>] (blocking_notifier_call_chain+0x14/0x1c) from [<c0374ba0>] (fb_blank+0x34/0x88)
<6>[ 950.351353] [<c0374ba0>] (fb_blank+0x34/0x88) from [<c03755cc>] (do_fb_ioctl+0x51c/0x598)
<6>[ 950.351363] [<c03755cc>] (do_fb_ioctl+0x51c/0x598) from [<c021039c>] (vfs_ioctl+0x28/0x3c)
<6>[ 950.351372] [<c021039c>] (vfs_ioctl+0x28/0x3c) from [<c0210e44>] (do_vfs_ioctl+0x4d8/0x588)
<6>[ 950.351380] [<c0210e44>] (do_vfs_ioctl+0x4d8/0x588) from [<c0210f40>] (SyS_ioctl+0x4c/0x78)
<6>[ 950.351389] [<c0210f40>] (SyS_ioctl+0x4c/0x78) from [<c0105f60>] (ret_fast_syscall+0x0/0x30)
<1>[ 950.642678] --------------[fyl] dump_stack end----------------
黄色标注中从下往上表示调用顺序。
总结:内核中的某些方法可以借鉴,大胆尝试,细心验证。