Create a project with source code and debug armlinux kernel panic

Suppose there is a project folder /home/srcdbg/project/module_prj in the WSL ubuntu18 whose host name is localhost. PC is at hello_init+0x24/0x38 [test] when the linux kernel crashes. Here are steps to create a new project to locate the crash position of the source code.

1. Crash log
~ # insmod /data/test/test.ko
[ 1800.770522] test: module license 'unspecified' taints kernel.
[ 1800.775576] Disabling lock debugging due to kernel taint
[ 1800.781344] Hello, world
[ 1800.783066] CRASH_TEST defined
[ 1800.794416] Befor crash
[ 1800.795867] Unable to handle kernel NULL pointer dereference at virtual address 00000000
[ 1800.803923] pgd = dab54000
[ 1800.817604] [00000000] *pgd=00000000
[ 1800.820169] Internal error: Oops: 805 [#1] PREEMPT ARM
[ 1800.825280] Modules linked in: test(PO+) embms_kernel(O) NTN_HSIC(O)
[ 1800.831623] CPU: 0 PID: 1355 Comm: insmod Tainted: P W O 3.18.48 #1
[ 1800.838738] task: da517600 ti: dab44000 task.ti: dab44000
[ 1800.844123] PC is at hello_init+0x24/0x38 [test]
[ 1800.848720] LR is at hello_init+0x1c/0x38 [test]
[ 1800.853317] pc : [<bf019024>] lr : [<bf01901c>] psr: 600b0113
[ 1800.853317] sp : dab45e00 ip : 00000000 fp : bf0170a0
[ 1800.864772] r10: c0c2ac60 r9 : c0c2ac60 r8 : 00000000
[ 1800.869983] r7 : c0c22008 r6 : dab44008 r5 : bf019000 r4 : da792200
[ 1800.876495] r3 : 00000001 r2 : 00000001 r1 : c0a30fe3 r0 : 00000000
[ 1800.883002] Flags: nZCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment none
[ 1800.890122] Control: 10c53c7d Table: 9ab54059 DAC: 00000051
[ 1800.895845] Process insmod (pid: 1355, stack limit = 0xdab44208)
[ 1800.901835] Stack: (0xdab45e00 to 0xdab46000)
[ 1800.906188] 5e00: 00000000 c0008b0c 00000051 00000004 bf000000 dab45e5c 00000004 00000000
[ 1800.914340] 5e20: 0000000c c00a6054 da792180 00000040 00000001 dec01f00 dab44008 000000d0
[ 1800.922502] 5e40: 00023330 c00e0ed8 bf0170a0 c00e1f34 00000008 c0c22c4c df6f0ed0 507ede2b
[ 1800.930664] 5e60: bf0170a0 dab45f54 da792180 bf017094 da792880 bf0170dc 00000001 da7928a4
[ 1800.938826] 5e80: bf0170a0 c0073358 bf0170a0 00007fff 00000000 c0071074 dab44028 dab44008
[ 1800.946987] 5ea0: 00000000 c0070abc bf0171ec 0000002f e0be66f4 e0be8490 7f66e685 da792180
[ 1800.955139] 5ec0: 000000d2 000074e0 00000000 00000000 00000000 00000000 00000000 00000000
[ 1800.963299] 5ee0: 6e72656b 00006c65 00000000 00000000 00000000 00000000 00000000 00000000
[ 1800.971461] 5f00: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 507ede2b
[ 1800.979622] 5f20: 00000000 7f68f080 00000051 7f66e685 00000080 c000ea84 dab44000 00000000
[ 1800.987784] 5f40: 001169b4 c0073a2c da7350c8 c00fde78 da7350c0 e0be1000 000074e0 e0be7f18
[ 1800.995945] 5f60: e0be6572 e0be69e4 000001fc 000002ac 00000000 00000000 00000000 000003dc
[ 1801.004097] 5f80: 00000023 00000024 00000010 00000000 0000000e 00000000 b6f29f10 00000000
[ 1801.012258] 5fa0: 00000069 c000e8c0 b6f29f10 00000000 7f68f080 000074e0 7f66e685 00000001
[ 1801.020420] 5fc0: b6f29f10 00000000 00000069 00000080 be985e50 7fffffff 000f69bd 001169b4
[ 1801.028582] 5fe0: 7f68bce4 be985a90 7f577cc8 b6e0c890 60000010 7f68f080 00000000 00000000
[ 1801.036771] [<bf019024>] (hello_init [test]) from [<c0008b0c>] (do_one_initcall+0x19c/0x1dc)
[ 1801.045175] [<c0008b0c>] (do_one_initcall) from [<c0073358>] (load_module+0x17bc/0x1d80)
[ 1801.053237] [<c0073358>] (load_module) from [<c0073a2c>] (SyS_init_module+0x110/0x120)
[ 1801.061139] [<c0073a2c>] (SyS_init_module) from [<c000e8c0>] (ret_fast_syscall+0x0/0x44)
[ 1801.069207] Code: e59f0018 eb5f5bc1 e3a00000 e3a03001 (e5c03000)
[ 1801.078203] ---[ end trace 416124111e139cbc ]---
Segmentation fault

2. Select File > New > Solution... > Wizard... and then click the OK button.

3. Enter the name of the project and click Next button.

4. Enter the correct Remote host, Port, Username, Password, Initial path and click Next button.

5. Click Next button.

6. Click Next button.

7. Click Finish button.

8. Enter the solution File name and click Save button.

9. Enter the project File name and click Save button.

10. Right click the srcdbg_test project and select Add > Add Existing Remote File to add the project files.

11. Select the needed folders and files and click Open button.

12. Select Build > Synchronize Files... to synchronize files and build the project symbols.

13. Right click the linux_module_test project and select Properties.
Change Attach to program as "-i=mi ./test.ko".
Configure Entry function as "hello_init".

14. Select Debug > Start Debugging to debug the project.

15. Input "hello_init+0x24" in the find box and press Ctrl+J to jump to the source code.

16. It will automatically navigate to the corresponding location of the crash in the source code as below.

17. If you want to use relocation addresses for offline code analysis, you can execute the following command on the arm board:
# cat /sys/module/test/sections/.init.text
0xbf019000
# cat /sys/module/test/sections/.exit.text
0xbf017000

Then right click the linux_module_test project and select Properties:
Configure Attach to program as "-i=mi".
Configure Entry function as "hello_init".
Configure Postdebug command as "add-symbol-file /home/srcdbg/project/module_prj/test.ko -s .init.text 0xbf019000 -s .exit.text 0xbf017000".
Then you can use the relocation address (e.g. 0xbf019024) for offline code debugging in a similar way as above.