カーネルモジュールのデバッグ

カーネルモジュールのデバッグ

Raspberry PiはRaspbian(カーネルバージョン4.9.24)用のネットワークドライバを開発していますが、モジュールをロードするたびにクラッシュします。

ログを使用すると、/var/log/messagesどのような方法が失敗したのかがわかりましたが、まだ失敗した理由はわかりません。

May  7 17:15:29 raspberrypi kernel: [  228.384164] CPU: 0 PID: 1163 Comm: insmod Tainted: P           O    4.9.24+ #993
May  7 17:15:29 raspberrypi kernel: [  228.388503] Hardware name: BCM2835
May  7 17:15:29 raspberrypi kernel: [  228.390701] task: d888ed00 task.stack: da696000
May  7 17:15:29 raspberrypi kernel: [  228.392901] PC is at register_netdevice+0x20/0x4cc
May  7 17:15:29 raspberrypi kernel: [  228.395064] LR is at register_netdev+0x24/0x34
May  7 17:15:29 raspberrypi kernel: [  228.397106] pc : [<c04eea38>]    lr : [<c04eef08>]    psr: 60000013
May  7 17:15:29 raspberrypi kernel: [  228.397106] sp : da697d48  ip : da697d90  fp : da697d8c
May  7 17:15:29 raspberrypi kernel: [  228.401178] r10: 00000000  r9 : 00000001  r8 : da69bac0
May  7 17:15:29 raspberrypi kernel: [  228.403177] r7 : bf38b4c0  r6 : da6b22c0  r5 : 00000000  r4 : 00000000
May  7 17:15:29 raspberrypi kernel: [  228.405203] r3 : c090bd50  r2 : 00000000  r1 : c08b262c  r0 : 00000000
May  7 17:15:29 raspberrypi kernel: [  228.407187] Flags: nZCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment user
May  7 17:15:29 raspberrypi kernel: [  228.409194] Control: 00c5387d  Table: 188a8008  DAC: 00000055
May  7 17:15:29 raspberrypi kernel: [  228.527223] [<c04eea38>] (register_netdevice) from [<c04eef08>] (register_netdev+0x24/0x34)
May  7 17:15:29 raspberrypi kernel: [  228.532724] [<c04eef08>] (register_netdev) from [<bf38b15c>] (init_module+0x64/0xa4 [lum])
May  7 17:15:29 raspberrypi kernel: [  228.538298] [<bf38b15c>] (init_module [lum]) from [<c0009a1c>] (do_one_initcall+0x4c/0x188)
May  7 17:15:29 raspberrypi kernel: [  228.543850] [<c0009a1c>] (do_one_initcall) from [<c00e3ffc>] (do_init_module+0x6c/0x1dc)
May  7 17:15:29 raspberrypi kernel: [  228.549346] [<c00e3ffc>] (do_init_module) from [<c00837d0>] (load_module+0x1a64/0x1fb8)
May  7 17:15:29 raspberrypi kernel: [  228.554907] [<c00837d0>] (load_module) from [<c0083efc>] (SyS_finit_module+0x9c/0xac)
May  7 17:15:29 raspberrypi kernel: [  228.560463] [<c0083efc>] (SyS_finit_module) from [<c000fe40>] (ret_fast_syscall+0x0/0x1c)
May  7 17:15:29 raspberrypi kernel: [  228.568861] ---[ end trace 279ccc9024b7e026 ]---

だからregister_netdevice方法は失敗しますが、どこかはわかりません。また、スタックを呼び出すと、insmod端末に次のものが印刷されます。

$ sudo insmod lum.ko
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.375707] Internal error: Oops: 5 [#1] ARM
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.411149] Process insmod (pid: 1163, stack limit = 0xda696188)
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.413044] Stack: (0xda697d48 to 0xda698000)
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.414943] 7d40:                   bf38b4c0 da69bac0 00000001 c05d16bc da697d7c da697d68
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.418939] 7d60: c05d16bc c05d023c 00000000 bf38b0f8 da6b22c0 bf38b4c0 da69bac0 00000001
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.423013] 7d80: da697da4 da697d90 c04eef08 c04eea24 bf38b6a0 bf38b4c0 da697dbc da697da8
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.427108] 7da0: bf38b15c c04eeef0 00000001 00000001 da697e3c da697dc0 c0009a1c bf38b104
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.431275] 7dc0: da69bac8 024000c0 c00e3fc0 dac01e60 0000000c 2596455c da697dfc da697de8
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.435731] 7de0: c05d0220 c05cfa70 da696000 024000c0 da697e0c da697e00 c05d0278 c05d020c
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.440472] 7e00: da697e3c da697e10 c01334a0 c05d023c 00000001 bf38b4c0 da69bac8 da6b22c0
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.445382] 7e20: bf38b4c0 da69bac0 00000001 2596455c da697e64 da697e40 c00e3ffc c00099dc
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.450472] 7e40: 00000001 bf38b4c0 da697e64 da697f3c da69bac8 00000001 da697f14 da697e68
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.455746] 7e60: c00837d0 c00e3f9c bf38b4cc 00007fff bf38b4c0 c0080f4c da697ea4 00000000
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.461149] 7e80: bf38b4cc bf38b4cc bf38b6a4 bf38b684 bf38b5b4 bf38b508 da697ee4 da697ea8
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.466589] 7ea0: c014b170 c014aaf4 dd4b2000 00000000 00000000 00000000 00000000 00000000
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.472117] 7ec0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.477650] 7ee0: 00000000 00000000 7fffffff 00000000 00000003 7f5d73b0 0000017b 7fffffff
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.483112] 7f00: 00000000 00000000 da697fa4 da697f18 c0083efc c0081d78 7fffffff 00000000
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.488641] 7f20: 00000003 c0106b70 da697f74 dd4b2000 0000158c 00000000 00000002 dd4b2000
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.494167] 7f40: 0000158c dd4b31cc dd4b29ac dd4b2e70 000006a4 000008a4 00000000 00000000
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.499628] 7f60: 00000000 0000054c 00000016 00000017 0000000f 0000000d 0000000c 00000000
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.505155] 7f80: bee37758 a5d60900 7f5e9000 bee37758 c000ffc4 da696000 00000000 da697fa8
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.510672] 7fa0: c000fe40 c0083e6c a5d60900 7f5e9000 00000003 7f5d73b0 00000000 00000002
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.516137] 7fc0: a5d60900 7f5e9000 bee37758 0000017b 7f5d73b0 00000002 7f5d320c 00000000
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.521670] 7fe0: bee37590 bee37580 7f5cc0ac b6e4cc40 60000010 00000003 00000000 00000000
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.565948] Code: e52de004 e8bd4000 e59f3460 e1a05000 (e59062e0)

何が起こっているのかを正しく理解するためにカーネルモジュールを使用したことがないので、正しくデバッグする方法が疑問に思います。

編集する:

IP私の考えでは、ファイルのシンボルを解析することはうまくいくようですが、/var/log/messages実際に何をすべきかわかりません。

ベストアンサー1

最も簡単な方法は、コードにprintkの呼び出しを追加し、モジュールを再コンパイルすることです。より多くのデバッグオプションを見るには、第4章、デバッグのヒント存在するLinuxデバイスドライバ、第3版。この本は少し古いですが、まだ関連性があります。

おすすめ記事