summerofcode2023projects:lldbkernelmoduleimprovement

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
summerofcode2023projects:lldbkernelmoduleimprovement [2023/06/28 10:54] – Use MailTo macro LiWenHsusummerofcode2023projects:lldbkernelmoduleimprovement [2023/08/30 14:17] (current) – feat: change commit branch to simplify change ShengYiHong
Line 21: Line 21:
  
 In LLDB’s userspace implementation, it read the kinfovmentry to get the In LLDB’s userspace implementation, it read the kinfovmentry to get the
-loaded module information, and thus modules can be found in the [[/GetLoadedModuleFileSpce|GetLoadedModuleFileSpce]] method.+loaded module information, and thus modules can be found in the %%GetLoadedModuleFileSpce%% method.
 What we have to do is to combine LLDB userspace and kgdb in LLDB What we have to do is to combine LLDB userspace and kgdb in LLDB
 kernel space. kernel space.
Line 33: Line 33:
 1. LKM parse and LLDB %%FreeBSD%% Kernel Module implementation 1. LKM parse and LLDB %%FreeBSD%% Kernel Module implementation
  
-===== Milestones =====+===== Report =====
  
-(5-10 milestones, with dates, indicating when you hope or expect to be able to complete features. This section is mandatory. Please negotiate these with your mentor to make sure you're not under or over-estimating the amount of work to be done. Please also make sure the following four dates are included within your milestones)+  * May 29th - June 12th
  
-  * May 14th: Start of coding +Busy on my school final exam. 
-    * You'll be doing this in the first week +The development environment have been set up in these weeks. 
-  * May 21st: Week 2 + 
-    * You plan to do this in the second week +  * June 12th - June 26th 
-  * June 11th - June 15th: Mid-term Evaluations #1 + 
-  * July 9th - July 13th: Mid-term Evaluations #2 +In this week, I implement LLDB interface sketch for %%DynamicLoader%% %%FreeBSD%% Kernel (%%DynamicLoaderFreeBSDKernel%%) that contains parsing kernel loader address and designinbg kld memory Image structure that contain enough information to create lldb Module. 
-  * August 6th: End of coding (soft) +Also, the lldb Module information for Kernel is also parsed so that can provide lldb recognize the Kernel. 
-    * You may wish to use this time to complete documentation etc + 
-  * August 14th: End of coding (hard)+  * June 26th - July 10th 
 + 
 +Parse kld info and Finish all implementation about %%DynamicLoaderFreeBSDKernel%%. The kld info is in a linked list structure defined at linked_files symbol that is a TAILQ structure. The necessary member's offset in the structure is provided by the kernel to provide the compatibility in different implementation. 
 +Merge the source code from llvm-project to %%FreeBSD%% codebase 
 + 
 +  * June 14th - July 2th 
 + 
 +Found the unloaded debug caused by merging LLDB plugin from llvm codebase to freebsd codebase. Finally the plugin successfully loaded and can load plugin kernel address in the binary. However the kernel module part still needs debug more. 
 + 
 +  * July 3th - July 17th 
 + 
 +Finish all implementation and finally the module can shown and debug symbol can be loaded
  
 ===== Test Plan ===== ===== Test Plan =====
Line 58: Line 69:
 ===== The Code ===== ===== The Code =====
  
-(Link to your code, for example https://svnweb.freebsd.org/socsvn/soc2018/username/ or a Github URL etc)+https://github.com/aokblast/freebsd-src/tree/lldb_dynamicloader_freebsd_kernel_review 
 + 
 +===== Final Production ===== 
 + 
 +As I have finished implementing %%DynamicLoaderFreeBSDKernel%% class, we have the following feature enabled on LLDB when debugging %%FreeBSDKernel%% Image: 
 + 
 +1. Display all kernel module and it's load address 
 + 
 +<code> 
 +(lldb) image list 
 +[  0] 013C9080-98CC-F2F1-237C-AFAA727809F7-8144DCF4 0xffffffff80200000 /boot/kernel/kernel 
 +      /usr/lib/debug/boot/kernel/kernel.debug 
 +[  1] F67FE954-8379-A3D1-848C-946C8C239092-6EAD3444 0xffffffff81f50000 /boot/kernel/zfs.ko 
 +      /usr/lib/debug/boot/kernel/zfs.ko.debug 
 +[  2] C580C510-DF33-FB7D-81AC-7989646C889C-26A50D5F 0xffffffff82644000 /boot/kernel/cryptodev.ko 
 +      /usr/lib/debug/boot/kernel/cryptodev.ko.debug 
 +[  3] 34D8ADD5-836D-7AB7-F62E-0C35987F19D0-9659DE07 0xffffffff82b18000 /boot/kernel/intpm.ko 
 +      /usr/lib/debug/boot/kernel/intpm.ko.debug 
 +[  4] B90304EB-A9FE-5495-9B77-E92790CF6EAF-FC35AA21 0xffffffff82b1c000 /boot/kernel/smbus.ko 
 +      /usr/lib/debug/boot/kernel/smbus.ko.debug 
 +[  5] 1AC7F0BF-CE67-8AD0-1A14-2E4444489F0E-7742EFF9 0xffffffff82b1f000 /boot/kernel/uhid.ko 
 +      /usr/lib/debug/boot/kernel/uhid.ko.debug 
 +[  6] CF312DEA-1D10-5C8B-D139-153111326704-24679FD8 0xffffffff82b23000 /boot/kernel/usbhid.ko 
 +      /usr/lib/debug/boot/kernel/usbhid.ko.debug 
 +[  7] B2A238B6-767A-D503-ADAC-8C828C613FF4-0D1D1D86 0xffffffff82b27000 /boot/kernel/hidbus.ko 
 +      /usr/lib/debug/boot/kernel/hidbus.ko.debug 
 +[  8] 9AF49EC4-8C0D-D9CE-5372-749EFF8A2F50-394D4184 0xffffffff82b2b000 /boot/kernel/wmt.ko 
 +      /usr/lib/debug/boot/kernel/wmt.ko.debug 
 +</code> 
 + 
 +2. Display content of a Symbol 
 + 
 +<code> 
 +(lldb) p cryptodev_mod 
 +(moduledata_t) $0 = { 
 +  name = 0xffffffff8264718f "cryptodev" 
 +  evhand = 0xffffffff82644000 (cryptodev.ko`cryptodev_modevent at cryptodev.c:1281) 
 +  priv = 0x0000000000000000 
 +</code> 
 + 
 +Of course it's address: 
 + 
 +<code> 
 +(lldb) p &cryptodev_mod 
 +(moduledata_t *) $3 = 0xffffffff826482b0 
 +</code> 
 + 
 +3. Some information dump from module dump 
 + 
 +<code> 
 +(lldb) image dump symtab cryptodev.ko 
 +Symtab, file = /boot/kernel/cryptodev.ko, num_symbols = 120: 
 +               Debug symbol 
 +               |Synthetic symbol 
 +               ||Externally Visible 
 +               ||| 
 +Index   UserID DSX Type            File Address/Value Load Address       Size               Flags      Name 
 +------- ------ --- --------------- ------------------ ------------------ ------------------ ---------- ---------------------------------- 
 +[    0]      1     SourceFile      0x0000000000000000                    0x0000000000000000 0x00000004 cryptodev.c 
 +[    1]      2     Code            0x0000000000000000 0xffffffff82644000 0x000000000000006e 0x00000002 cryptodev_modevent 
 +[    2]      3     Data            0x00000000000042c8 0xffffffff826482c8 0x00000000000000b8 0x00000001 crypto_cdevsw 
 +[    3]      4     Data            0x0000000000004400 0xffffffff82648400 0x0000000000000008 0x00000001 crypto_dev 
 +[    4]      5     Code            0x0000000000000070 0xffffffff82644070 0x000000000000008d 0x00000002 crypto_open 
 +[    5]      6     Data            0x0000000000004230 0xffffffff82648230 0x0000000000000070 0x00000001 M_CRYPTODEV 
 +[    6]      7     Code            0x0000000000002240 0xffffffff82646240 0x00000000000000de 0x00000002 fcrypt_dtor 
 +[    7]      8     Code            0x0000000000000100 0xffffffff82644100 0x0000000000002132 0x00000002 crypto_ioctl 
 +[    8]      9     Data            0x00000000000043f8 0xffffffff826483f8 0x0000000000000001 0x00000001 use_outputbuffers 
 +[    9]     10     Data            0x00000000000043f9 0xffffffff826483f9 0x0000000000000001 0x00000001 use_separate_aad 
 +[   10]     11     Code            0x00000000000023b0 0xffffffff826463b0 0x00000000000000d2 0x00000002 cod_alloc 
 +[   11]     12     Code            0x0000000000002320 0xffffffff82646320 0x0000000000000089 0x00000002 cse_free 
 +[   12]     13     Code            0x0000000000002490 0xffffffff82646490 0x0000000000000056 0x00000002 cryptodev_cb 
 +</code>
  
  • summerofcode2023projects/lldbkernelmoduleimprovement.1687949688.txt.gz
  • Last modified: 2023/06/28 10:54
  • by LiWenHsu