我正在嘗試調試內核模塊。我懷疑有一些內存泄漏。爲了檢查它,我準備了內核和模塊啓用內存泄漏調試的構建。而我得到了一些來自警告:內核模塊addr2line
[11839.429168] slab error in verify_redzone_free(): cache `size-64': memory outside object was overwritten
[11839.438659] [<c005575c>] (unwind_backtrace+0x0/0x164) from [<c0116ca0>] (kfree+0x278/0x4d8)
[11839.447357] [<c0116ca0>] (kfree+0x278/0x4d8) from [<bf083f48>] (some_function+0x18/0x1c [my_module])
[11839.457214] [<bf083f48>] (some_function+0x18/0x1c [my_module]) from [<bf08762c>] (some_function+0x174/0x718 [my_module])
[11839.470184] [<bf08762c>] (some_function+0x174/0x718 [my_module]) from [<bf0a56b8>] (some_function+0x12c/0x16c [my_module])
[11839.483917] [<bf0a56b8>] (some_function+0x12c/0x16c [my_module]) from [<bf085790>] (some_function+0x8/0x10 [my_module])
[11839.496368] [<bf085790>] (some_function+0x8/0x10 [my_module]) from [<bf07b74c>] (some_function+0x358/0x6d4 [my_module])
[11839.507476] [<bf07b74c>] (some_function+0x358/0x6d4 [my_module]) from [<c00a60f8>] (worker_thread+0x1e8/0x284)
[11839.517211] [<c00a60f8>] (worker_thread+0x1e8/0x284) from [<c00a9edc>] (kthread+0x78/0x80)
[11839.525543] [<c00a9edc>] (kthread+0x78/0x80) from [<c004f8fc>] (kernel_thread_exit+0x0/0x8)
有翻譯指向內核地址沒有問題:
$ addr2line -f -e vmlinux.kmeml c0116ca0
verify_redzone_free
/[...]/kernel/mm/slab.c:2922
但我不能這樣做,如果地址是從my_module:
$ addr2line -f -e vmlinux.kmeml bf0a56b8
??
??:0
我也與模塊文件嘗試:
$ addr2line -f -e my_module.ko bf0a56b8
??
??:0
如何將這些地址轉換爲文件和行號?
附註。如果您正在使用x86並且您的Linux內核是2.6.31或更新的版本,您可能會發現更輕量級的KEDR系統(http://kedr.berlios.de/),可用於檢查模塊是否存在內存泄漏。與像Kmemleak這樣的內核設施不同,KEDR不需要重建內核。它應該很容易設置和使用。 – Eugene 2011-05-27 14:01:27