Debug kernel module / kernel driver - #532
Open
QuangNguyenMinh123 wants to merge 11 commits into
Open
Conversation
QuangNguyenMinh123
marked this pull request as draft
August 23, 2026 11:56
QuangNguyenMinh123
force-pushed
the
feature/Debug_kernel_module
branch
from
August 23, 2026 16:25
79e8231 to
21b9275
Compare
Contributor
Author
|
A particular example Rpi4 openWRT image:
|
Contributor
Author
QuangNguyenMinh123
marked this pull request as ready for review
September 5, 2026 12:16
Contributor
Author
|
Demo video: https://youtu.be/jpcxMeApOQU |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

A kernel module is a piece of code that extends system capabilities — such as adding device drivers or file system support.
It can do many things: toggle an LED, drive a motor, or handle a monitor, a camera, and so on.
Kernel modules account for up to 70% of the source code in the upstream Linux kernel.
There are two types of kernel module: loadable and built-in.
Built-in kernel modules are "baked into" or "embedded in" the kernel at build time. They are essentially part of the kernel itself, so their load addresses are predetermined.
Loadable kernel modules are built into .ko files. A .ko file is essentially an ELF file in position-independent executable (PIE) format, which means it can be loaded and run at any arbitrary address.
As mentioned above, the load addresses of built-in kernel modules and of the Linux kernel itself are predetermined, which makes debugging them easy with JTAG.
The load address of a loadable kernel module, however, is unknown and only determined at runtime, which makes debugging more challenging.
Solution:
There is a Linux kernel function that can help us:
load_module().It is responsible for parsing a kernel module, checking its compatibility, and loading it into the kernel's memory layout. It decides where each segment of the module — .text, .data, .rodata, and so on — will be placed.
By reading the relevant kernel variables, we can tell GDB which part of the module's memory is mapped to which part of the kernel's memory layout, and thus debug kernel modules through a GUI.