Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| summerofcode2023projects:lldbkernelmoduleimprovement [2023/06/01 16:05] – Add template for LLDB Kernel Module wiki page EdMaste | summerofcode2023projects:lldbkernelmoduleimprovement [2023/08/30 14:17] (current) – feat: change commit branch to simplify change ShengYiHong | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Project name ====== | ====== Project name ====== | ||
| - | * Student: [[/StudentName|StudentName]] (student@email.address) | + | * Student: [[/ShengYiHong|ShengYiHong]] (< |
| - | * Mentor: | + | * Mentor: |
| ===== Project description ===== | ===== Project description ===== | ||
| - | (Two or three paragraphs about your project, | + | %%FreeBSD%% has replaced |
| + | long time. In the LLVM toolchain, there is a bundle debugger called lldb, | ||
| + | which is also bundled in %%FreeBSD%%. The lldb debug facilities in userland have | ||
| + | been well implemented for a long time. However, there are some works still | ||
| + | need to be done in the kernel space. What I want to do is to finish the parse | ||
| + | mechanism about kernel module information for the kernel debugger | ||
| ===== Approach to solving the problem ===== | ===== Approach to solving the problem ===== | ||
| - | (Details as to how you intend | + | In kgdb’s scheme, it does the following things: |
| + | |||
| + | - Setup the related structure offset in ./ | ||
| + | - Search the LKM from the raw and absolute path to find the corresponding kernel module and get the table offset from bfd | ||
| + | - Relocating sections in ko files found in step 2 with LKM base address found in step 1 | ||
| + | - Load symbol from symbol file and thus finish | ||
| + | |||
| + | In LLDB’s userspace implementation, | ||
| + | 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 | ||
| + | kernel space. | ||
| + | Except for the LKM, I also want to support static kernel module which is | ||
| + | also a possible module type in the %%FreeBSD%% kernel. But things are different | ||
| + | in that the static kernel module will not appear in kldstat. In other words, | ||
| + | it will not appear in linkerfiles, | ||
| ===== Deliverables ===== | ===== Deliverables ===== | ||
| - | (List of features you plan to implement) | + | 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 | + | * 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' | ||
| + | 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 | ||
| + | |||
| + | * July 3th - July 17th | ||
| + | |||
| + | Finish all implementation and finally the module can shown and debug symbol can be loaded | ||
| ===== Test Plan ===== | ===== Test Plan ===== | ||
| - | (List of steps you plan to use to test your work, as discussed with your mentor) | + | Because performance is not that important for a debugger, I will focus the |
| + | test on functionality. In the first stage of the test, I will try to write some | ||
| + | small kernel modules with some function symbols contained for debug pur- | ||
| + | poses. In the second stage of the test, I will try to use the large kernel module | ||
| + | like wifi to test the functionality. In the second stage of the test, I will post | ||
| + | my work on reviews.freebsd.org to let other module developers test it. | ||
| ===== The Code ===== | ===== The Code ===== | ||
| - | (Link to your code, for example | + | https://github.com/ |
| + | |||
| + | ===== 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 | ||
| + | |||
| + | < | ||
| + | (lldb) image list | ||
| + | [ 0] 013C9080-98CC-F2F1-237C-AFAA727809F7-8144DCF4 0xffffffff80200000 | ||
| + | | ||
| + | [ 1] F67FE954-8379-A3D1-848C-946C8C239092-6EAD3444 0xffffffff81f50000 / | ||
| + | / | ||
| + | [ 2] C580C510-DF33-FB7D-81AC-7989646C889C-26A50D5F 0xffffffff82644000 / | ||
| + | / | ||
| + | [ 3] 34D8ADD5-836D-7AB7-F62E-0C35987F19D0-9659DE07 0xffffffff82b18000 / | ||
| + | / | ||
| + | [ 4] B90304EB-A9FE-5495-9B77-E92790CF6EAF-FC35AA21 0xffffffff82b1c000 / | ||
| + | / | ||
| + | [ 5] 1AC7F0BF-CE67-8AD0-1A14-2E4444489F0E-7742EFF9 0xffffffff82b1f000 / | ||
| + | / | ||
| + | [ 6] CF312DEA-1D10-5C8B-D139-153111326704-24679FD8 0xffffffff82b23000 / | ||
| + | / | ||
| + | [ 7] B2A238B6-767A-D503-ADAC-8C828C613FF4-0D1D1D86 0xffffffff82b27000 / | ||
| + | / | ||
| + | [ 8] 9AF49EC4-8C0D-D9CE-5372-749EFF8A2F50-394D4184 0xffffffff82b2b000 / | ||
| + | / | ||
| + | </ | ||
| + | |||
| + | 2. Display content of a Symbol | ||
| + | |||
| + | < | ||
| + | (lldb) p cryptodev_mod | ||
| + | (moduledata_t) $0 = { | ||
| + | name = 0xffffffff8264718f " | ||
| + | evhand = 0xffffffff82644000 (cryptodev.ko`cryptodev_modevent at cryptodev.c: | ||
| + | priv = 0x0000000000000000 | ||
| + | </ | ||
| - | ===== Notes ===== | + | Of course it's address: |
| - | (A place to make notes that will be useful to others looking at your code. You probably don't need to put anything here on day one) | + | <code> |
| + | (lldb) p & | ||
| + | (moduledata_t *) $3 = 0xffffffff826482b0 | ||
| + | </ | ||
| - | ===== Useful links ===== | + | 3. Some information dump from module dump |
| - | (Links to any external resources, work, research etc which may be useful to you or to anybody wanting to understand your work) | + | < |
| + | (lldb) image dump symtab cryptodev.ko | ||
| + | Symtab, file = / | ||
| + | Debug symbol | ||
| + | | ||
| + | | ||
| + | ||| | ||
| + | Index | ||
| + | ------- ------ --- --------------- ------------------ ------------------ ------------------ ---------- ---------------------------------- | ||
| + | [ 0] 1 | ||
| + | [ 1] 2 | ||
| + | [ 2] 3 | ||
| + | [ 3] 4 | ||
| + | [ 4] 5 | ||
| + | [ 5] 6 | ||
| + | [ 6] 7 | ||
| + | [ 7] 8 | ||
| + | [ 8] 9 | ||
| + | [ 9] | ||
| + | [ | ||
| + | [ | ||
| + | [ | ||
| + | </ | ||