Skip to content
Permalink
Browse files
Makefile: add kernel debugging flags for qemu
  • Loading branch information
stapelberg committed Feb 19, 2020
1 parent e2f8fb8 commit fd798e188a673884d50b8f96e17a7204b8ae2c3d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
@@ -30,6 +30,28 @@ QEMU=qemu-system-x86_64 \
-device virtio-scsi-pci,id=scsi \
-device scsi-hd,drive=hd

# To use gdb to debug the Linux kernel, use e.g.:
#
# make qemu-serial \
# kgdb=1 \
# kernel=/home/michael/fuse-debug/linux/arch/x86/boot/bzImage \
# cmdline="panic_on_oops=1"
#
# gdb vmlinux
# (gdb) target remote localhost:1234
# (gdb) continue
ifdef kgdb
cmdline+= nokaslr
cmdline+= kgdbwait
cmdline+= kgdboc=ttyS0,115200
QEMU+= -serial tcp::1234,server,nowait
endif

ifdef kernel
QEMU+= -kernel "${kernel}"
QEMU+= -append "root=/dev/sda4 ro ${cmdline} $(shell tr -d '\n' < ${DISKIMG}.cmdline)"
endif

PACKFLAGS=

# for when you want to see non-kernel console output (e.g. systemd), useful with qemu
@@ -861,7 +861,11 @@ name=root`)
if p.bootDebug {
params = append(params, "systemd.log_level=debug systemd.log_target=console")
}
mkconfigCmd := "GRUB_CMDLINE_LINUX=\"console=ttyS0,115200 " + strings.Join(params, " ") + " init=/init systemd.setenv=PATH=/bin rw\" GRUB_TERMINAL=serial grub-mkconfig -o /boot/grub/grub.cfg"
cmdline := "console=ttyS0,115200 " + strings.Join(params, " ") + " init=/init systemd.setenv=PATH=/bin rw"
if err := ioutil.WriteFile(p.diskImg+".cmdline", []byte(cmdline+"\n"), 0644); err != nil {
return err
}
mkconfigCmd := fmt.Sprintf(`GRUB_CMDLINE_LINUX=%q GRUB_TERMINAL=serial grub-mkconfig -o /boot/grub/grub.cfg`, cmdline)
mkconfig := exec.Command("sudo", "chroot", "/mnt", "sh", "-c", mkconfigCmd)
mkconfig.Stderr = os.Stderr
mkconfig.Stdout = os.Stdout

0 comments on commit fd798e1

Please sign in to comment.