aboutsummaryrefslogblamecommitdiffhomepage
path: root/content/2019-10-27-kernel-debugging-qemu/run.sh
blob: b9548adceb47c8813cf3d0dc358094a82cacc986 (plain) (tree)
1
2
3

           
         



















                                                                      

                                                                               
#!/bin/bash

VER=6.6.2

# Launch the emulator with our kernel.
qemu-system-x86_64                                                   \
  -kernel ./linux-$VER/arch/x86/boot/bzImage                         \
  -nographic                                                         \
  -append "earlyprintk=ttyS0 console=ttyS0 nokaslr init=/init debug" \
  -initrd ./initramfs.cpio.gz                                        \
  -serial telnet:localhost:12345,server,nowait                       \
  -monitor none                                                      \
  -gdb tcp::1234                                                     \
  -S &

# Kill qemu when we exit.
QEMU_PID=$!
trap "kill $QEMU_PID" EXIT

# Give qemu some time to come up.
sleep 0.5

# Attach debugger to qemu and load the kernel symbols.
which cgdb >& /dev/null && GDB=cgdb || GDB=gdb
$GDB -ex 'target remote :1234' -ex 'set style enabled off' ./linux-$VER/vmlinux