I searched all over the internet but couldn't find proper steps to debug linux module remotely using gdb. I am tring qemu but facing many issues there. Is there any other tool that I can use or if not then can you provide me proper steps to debug linux module remotely?

1 Answer 1


Shouldn't be that hard. From the official kernel documentation (don't search "all over the internet". Search the official documentation and you'll find less bad information):

  1. Have a kernel that has KGBD enabled, and also make sure that during building the config option CONFIG_GDB_SCRIPTS is on. (Refer to documentation for CentOS on how to build a kernel package; that's the easiest way)
    • run make scripts_gdb
  2. Copy that kernel (vmlinux) into your host system, so that it's easy to know the kernel symbols locally
  3. Run the Linux distro of your choice in QEMU
    • with QEMU's GDB stub enabled, and listening on some port, i.e., run qemu with -gdb tcp::$SOMEPORT, where $SOMEPORT is the port number you want to use (should be > 1024, < 2¹⁶). Alternatively, run with -s, which is identical to -gdb tcp::1234.
    • Make sure that QEMU doesn't boot the machine instantly by supplying the -S option
  4. on the host, run gdb /path/to/the/kernel/vmlinux
  5. in gdb, attach to your QEMU stub: target remote :$SOMEPORT.
  6. you can now run continue to boot the VM
  • Hii Marcus, to be clear I am looking for a way to debug linux driver remotely. For ex. Module is running on VM A and I want to debug that module from VM B through GDB? Do you know any way to do it? Apr 11, 2023 at 13:11
  • exactly the method I described above. The module is part of the kernel space, so if you want to debug it, this is exactly what you need to do. Apr 11, 2023 at 13:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .