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. 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,
};
/*
* 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;
}
* 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!
Enjoy a try and hope it helps!
5695

被折叠的 条评论
为什么被折叠?



