Kernel debugging problems

Hello.

I am a computer science student and picked modifying the netgraph module from the FreeBSD kernel as my thesis.

I have quite some trouble setting up my kernel debugging procedure.

I have a virtual machine running with quemu, and I am trying to debug using gdb from linux.

I run the machine using this command for serial connection
Code:
qemu-system-x86_64 -s -S -enable-kvm -m 4096 -drive file=FreeBSD-14.1-RELEASE-amd64-ufs.qcow2,format=qcow2 -netdev bridge,id=net0,br=virbr0 -device e1000,netdev=net0,mac=52:54:00:ec:fc:d3,bus=pci.0,addr=0x3
I made a new configuration file and added the gdb and netgraph options, you can find my configuration file attached.
I built and installed the kernel, and then copied the /usr/lib/debug/boot/kernel/ folder to my linux machine.

I am using endeavour os and gdb 15.2, but when I run
Code:
❯ gdb kernel.debug
GNU gdb (GDB) 15.2
Copyright (C) 2024 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <[URL]http://gnu.org/licenses/gpl.html[/URL]>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<[URL]https://www.gnu.org/software/gdb/bugs/[/URL]>.
Find the GDB manual and other documentation resources online at:
    <[URL]http://www.gnu.org/software/gdb/documentation/[/URL]>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from kernel.debug...
(gdb) target remote localhost:1234
Remote debugging using localhost:1234
warning: remote target does not support file transfer, attempting to access files from local filesystem.
warning: Unable to find dynamic linker breakpoint function.
GDB will be unable to debug shared library initializers
and track explicitly loaded dynamic code.
0x000000000000fff0 in ?? ()
(gdb) c
Continuing.
Warning:
Cannot insert breakpoint -2.
Cannot access memory at address 0xffffffff80b6a380
Command aborted.
(gdb)
This is the result.
I tried building gdb, but I get the same warnings and errors. I even tried it on Ubuntu and got the same problem.

I would really appreciate to tell me what am I doing wrong and how can I improve my setup for debugging.

I have been trying a lot of different methods for the past month and nothing worked, please help if you can :)
 

Attachments

I would really appreciate to tell me what am i doing wrong and how can i improve my setup for debugging.

I have been trying a lot of different methods for the past month and nothing worked, please help if you can :)
Use FreeBSD on both sides — the VM which you are debugging and the VM on which you run the debugger.
 
Documentation for debugging a kernel: https://docs.freebsd.org/en/books/developers-handbook/kerneldebug/#kerneldebug-online-gdb
Towards the end of the chapter you will find useful options which you can add to your kernel configuration file.

LLDB can be used as an alternative to gdb for FreeBSD kernel debugging at least in some scenarios. Here are some relevant links:
 
Back
Top