A little kernel debug tip

I want to share with you one piece of kernel debug tip, and also remind myself in the future.

As you know linux kernel organizesits components into various subsystems. And in order to support various  devices, each subsystem provides common interface structures to let  devices describe themselves at initialization. 

So you'll be seeing this kind of staff alot:

const struct address_space_operations jfs_metapage_aops = {
    .readpage    = metapage_readpage,
    .writepage    = metapage_writepage,
    .sync_page    = block_sync_page,
    .releasepage    = metapage_releasepage,
    .invalidatepage    = metapage_invalidatepage,
    .set_page_dirty    = __set_page_dirty_nobuffers,
};


Then within the subsystem, you'll only see readpage, writepage called but unknowing which device actually implemented them.

Take this one as an example, in page-writeback.c:

/*
 * Function used by generic_writepages to call the real writepage
 * function and set the mapping flags on error
 */
static int __writepage(struct page *page, struct writeback_control *wbc,
               void *data)
{
    struct address_space *mapping = data;
    int ret = mapping->a_ops->writepage(page, wbc);
    mapping_set_error(mapping, ret);
    return ret;
}


I don't know which real writepage function is called actually, so:

1. Print the function address of mapping->a_ops->writepage, use %p. It's 0xc11fb260 in my test.
2. Check the kernel symbol table using `readelf -s <your kernel image>`
3.  Now you can see the address range of the kernel image. In my cases it's  0x80xxxxxx, clearly not matching the function address. So it's highly  possible the function is defined within a kernel module, e.g. ko.
4. Log on the STB, `cat /proc/module` find the kernel module  which has a mapping address close to the function address. In this case  its jfs.ko, it live between 0xc11e1000 and 0xc1197000.
5. Get the in module address offset by 0xc11fb260 - 0xc11e10000, the result is 0x1a260.
6. Find the jfs.ko, and `addr2line -f -e jfs.ko 0x1a260`,  then you can see the actuall function is metapage_writepage, and it's  defined in jfs_metapage.c

It's a small piece of tip, so I think I just mail it instead of a knowledge share. Ignore it if it's too simple for you :P 

Enjoy a try and hope it helps!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值