I’m trying to debug Haiku x86_64 in QEMU,
I start QEMU with -s -S and connect using gdb.
I built using jam -q @nightly-raw(i forgot to enable debug option while building)
GDB connects, but i’m not sure
Which bootKernelArgs are recommended for kernel debugging?
Is there anything special needed for early boot debugging?
I need your suggestions and provide resources.
why i’m doing this because i’m curious and i want to know what hardware devices enable/disable at specific states because i want to build kexec feature to Haiku, so i need to know when to stop/start and where to stop/start hardware and etc.
@waddlesplash mentioned about Linux kexec supports EFI. This may be the easiest way to implement kexec anyway, and then the standard EFI loader can be used to start a new kernel.
You will want to enable debug information on a per-directory basis, most likely, rather than the whole tree (which will result in a much slower system, and also tons more debug prints making the syslog basically unusable.) See UserBuildConfig for how this is done.
You will need to build the bootloader with debugging information, and compute some offsets to figure out what its load address is in order to tell GDB. I have some notes on that which I should likely find a way to add to the developer documentation…
For x86_64, debugging the kernel is easy, and drivers are pretty easy too. Basically, you need to build the kernel with DEBUG enabled, and then just connect to QEMU with the kernel_x86_64 specified as the load image. The kernel on x86_64 is loaded at a fixed address, so we don’t need to do anything fancy here.
For drivers and other modules with non-fixed load addresses, you need to get their load address from the running kernel to add them in GDB. Either use the image KDL command and find the text.start address of the relevant image, or get the address in the first column from the relevant row in the output of listimage 1 run in a Terminal. Then, in the GDB console, run the command add-symbol-file PATH-TO-DRIVER -o ADDRESS to load the symbols.
I use Qt Creator as a GUI for GDB, and it works very well. You can enable the “Debugger Log” pane to inject commands to GDB to load symbols for other modules.
I enabled debug information for whole Haiku source tree without reducing optimization level or adding extra checks or tracing: build: enable debug information · X547/haiku@6228cd4 · GitHub. It should not affect efficiency, only increase image file size.