
Connect to the target or serial port using the target command, then continue execution on the remote target to perform a backtrace and debug the kernel.
Disable kernel address space layout randomization to reveal function addresses during debugging. Use the no casula flag on the target machine, observe backtrace and breakpoint behavior.
learn how to enable kgdb at runtime by configuring the serial port baud rate and sending the magic sequence to switch the target into debugging mode, enabling remote kernel debugging.
Learn to set breakpoints on a specific line with the syntax break <target>, line number, then run and continue to verify execution at that line; delete breakpoints as needed.
Learn to print and inspect kernel variables during debugging, using breakpoints and global symbols to verify values on the target machine, while noting that local variables cannot be printed.
Copy the target build, load module symbols with the text segment address, and use breakpoints in the in-tree module to trace packet transmission during kernel module debugging.
Set a breakpoint at the interrupt handler and observe the function execution on the target. Single-step through the interrupt handler and inspect AC to learn debugging interrupts with breakpoints.
Debug the init and exit sections by setting breakpoints in kernel/module.c, loading the module on the target, and stepping through module load and delete module cleanup.
Build an image for the Raspberry Pi 3 with the required kernel configuration, update the kernel config, enable the serial port, and deploy the image.
Build and install the sdk by generating a toolchain that includes gdb and the dcc compiler, then install the sdk tailored for the rba image.
Flash a downloaded image onto an SD card for the Raspberry Pi 3 via a VM, then connect the serial port to complete the setup.
Connect the serial port to the Raspberry Pi, set the baud rate to 1150 with minicom or screen, and verify the flashed image and module presence.
Set up an agent proxy to share a single serial port among the console and devices, using localhost and designated ports on the Raspberry Pi 3.
Configure gdb for Linux kernel debugging by setting substitute-path to the kernel source and pointing it to the Raspberry Pi 3 source folder, then use list to inspect lines.
User space processes can be debugged using gdb. With gdb you can
single-step,
stop,
resume,
put break-points,
inspect memory and variables,
look through call stack information
What if we can use gdb on running Linux Kernel.
Problem:
How can a gdb debug running kernel as it is just a user space process.
Solution:
Client/Server Architecture
User space programs can be debugged remotely using the combination of gdbserver on the target machine and gdb on the host machine/development machine.
The Linux kernel has a GDB Server implementation called KGDB. It communicates with a GDB client over network or serial port connection
In this course we will learn:
How to setup KGDB
Various ways of getting the target into development machine
Setting Breakpoints
Printing and Setting Variables
Using a single serial port for both kgdb and console messages
Getting the kernel messages in gdb window
Debugging Linux Kernel Modules (In-Tree, out of tree)
Use of GDB Scripts present in the Linux Kernel