Questions tagged [kgdb]

KGDB is a source level debugger for the linux kernel. It is used along with gdb to debug linux kernels. It requires two machines that are connected via a serial connection.

Kernel developers can debug a kernel similar to application programs with use of KGDB. It makes it possible to place breakpoints in kernel code, step through the code and observe variables.

Two machines are required for using KGDB. One of these machines is a development machine and the other is a test machine. The machines are connected through a serial line, a null-modem cable which connects their serial ports. The kernel to be debugged runs on the test machine. gdb runs on the development machine. The serial line is used by gdb to communicate with the kernel being debugged.

KGDB is available for i386, x86_64, ppc and s390 architectures.

KGDB is a kernel patch. It has to be applied to a linux kernel to enable kernel debugging. KGDB adds the following components to a kernel.

  • gdb stub - The gdb stub is the heart of the debugger. It is the part that handles requests coming from gdb on the development machine. It has control of all processors in the target machine when the kernel running on it is inside the debugger.
  • modifications to fault handlers - Kernel gives control to debugger when an unexpected fault occurs. A kernel which does not contain gdb panics on unexpected faults. Modifications to fault handles allow kernel developers to analyze unexpected faults.
  • serial communication - This component uses a serial driver in the kernel and offers an interface to gdb stub in the kernel. It is responsible for sending and receiving data from a serial line. This component is also responsible for handling control break requests sent by gdb.

Project site

66 questions
1
vote
0 answers

KGDB for nexus 5

I'm debugging a kernel for Nexus 5. It's so buggy that the phone will never start normally, as there are many bugs. I'd like to debug it with KGDB via the audio jack (as it's a serial port). I've already learned how to compile the kernel to enable…
1
vote
1 answer

connect gdb client through terminal server with authentication

I am trying to do remote debugging. My GDB server runs as expected (in my case it is KGDB in kernel side). KGDB hangs up well so that GDB client can connect. I need to connect GDB client using terminal server and port number because my device is…
Jegan
  • 188
  • 3
  • 15
1
vote
1 answer

GDB - redirect serial output (from dmesg) to file, but not gdb output / TUI?

I'm using kgdb to debug something via a serial cable, so I "set remote /dev/ttyS1" in gdb, which gives me output from the remote machine through gdb. Is there any way to redirect this output to a file WITHOUT redirecting the rest of gdb's output? It…
Jordan
  • 9,014
  • 8
  • 37
  • 47
1
vote
1 answer

Not able to view source code while debugging kernel with gdb

I have kgdb setup using serial port between two VMs(Target is clone of host.) and I am able to set breakpoints in it. But when breakpoint is hit, I try to view source using list command in gdb, but it shows source of kgdb.c instead of my file in…
pratik
  • 434
  • 2
  • 8
1
vote
0 answers

Can't debug syscalls

I'm trying to debug kernel with KVM and gdb, it works fine. But the breakpoints on syscalls doesn't seem to work. In gdb I set a breakpoint: (gdb) b sys_uname Breakpoint 1 at 0xffffffff8106f3b0: file kernel/sys.c, line 1341. Then I type c to…
daisy
  • 22,498
  • 29
  • 129
  • 265
1
vote
2 answers

kgdb cannot find the source code when debugging kernel module

I want to debug a kernel module with kgdb,do as the following: gdb: add-symbol-file /home/gaoqiang/kernel-32/fs/ext4/ext4.ko 0xffffffffa0122000 -s .bss 0xffffffffa016b380 -s .data 0xffffffffa0168400 gdb: break ext4_getattr gdb: c I successfully get…
0
votes
0 answers

How to remotely debug linux module using GDB?

I want to debug linux module remotely. So, linux module is loaded on VM-A and I want to debug that module on VM-B using GDB. I have gone through QEMU way but I don't want that because the target VM-A is unrelated and doesn't related to same host.…
0
votes
0 answers

With Linux kgdb, breakpoints not being hit on Ubuntu/UTM/Apple M1 Silicon

I'm having trouble with getting breakpoints to work (including hardware breakpoints). I got my kernel compiled file and can debug remotely but I can't set breakpoints. Whether they're supported by UTM or not, I'm not sure (breakpoints in gdb for…
0
votes
1 answer

GDB Scripts commands(lx commands) not working

I have Beagle bone running Linux.On the Host system I am using cross gdb (arm gdb) to debug kernel and kernel modules. In my kernel build directory,there is no symlink(vmlinux-gdb.py) pointing to /build_directory/scripts/gdb/vmlinux-gdb.py. But the…
akumar
  • 39
  • 7
0
votes
0 answers

vmlinux or vmlinuz not containg device driver function name and address but same driver is working correctly

there is a function rtl8169_poll in linux kernel linux-5.12.6 inside realtek Ethernet device driver. inside the location lib/modules/5.12.6/kernel/drivers/net/ethernet/realtek/ there is r8169.ko which shows the function exists and gives offset…
user786
  • 3,902
  • 4
  • 40
  • 72
0
votes
1 answer

How does addr2line work with virtual addresses for kernel space debugging?

I was trying my hands on addr2line to convert a "pc" register value from a kernel oops (example) to a line in the kernel code. I believe that the value of the program counter represents a virtual address. Now this post on Stack Overflow says that we…
Naveen
  • 7,944
  • 12
  • 78
  • 165
0
votes
1 answer

How can I prevent interrupts stepping out from my code while debugging?

I'm currently debugging the linux kernel and it's properly set up with kgdb. I set a breakpoint to a function I am trying to debug, and the break occurs once I run my program which needs this kernel function to do something, this is wanted. But…
Blingu
  • 41
  • 1
0
votes
1 answer

How to debug Linux Kernel on a remote machine?

How to debug a custom Linux Kernel on a remote machine? I have a remote machine with a custom-built Linux Kernel originally from 5.6.8. The system under the kernel is running into problems which I want to fix. The kgdb-related options…
Some Name
  • 8,555
  • 5
  • 27
  • 77
0
votes
0 answers

function names not displayed in gdb backtrace kgdb setup

I have set up a debugging environment of KGDB between two VMWare virtual machines using the following link: https://embeddedguruji.blogspot.com/2018/12/debugging-linux-kernel-using-kgdb-part-1.html When I run backtrace, I am not getting the function…
md.jamal
  • 4,067
  • 8
  • 45
  • 108
0
votes
0 answers

Next step error when debugging Android kernel

I am researching Linux kernel source code on Android. So I built a debugging environment on Android emulator (the emulator based on qemu). But, when I debug the kernel using gdb, the next command always jump to error code. Here is the example: (gdb)…