Skip to content

Instantly share code, notes, and snippets.

@mpictor
Created Apr 27, 2020
Embed
What would you like to do?
gdb / qemu kernel debug notes
# notes from when I had trouble with kexec some time back. possibly useful to others.
# disable kaslr or boot with nokaslr, or no symbols will match and no breakpoints will be hit
#
# hbreak used to be necessary? not any more
qemu-system-x86_64 --version
#QEMU emulator version 4.0.0
gdb --version
#GNU gdb (Gentoo 8.3 vanilla) 8.3
#update these
kernel=$GOPATH/src/github.com/u-root/u-root/work/i/arch/x86/boot/bzImage
uinteg=/tmp/uroot-integration646325419
#in one console window
qemu-system-x86_64 -machine accel=tcg -nographic \
-kernel $kernel \
-append 'nokaslr console=ttyS0 earlyprintk=ttyS0' \
-initrd $uinteg/initramfs.cpio \
-drive file=fat:rw:$uinteg,if=none,id=tmpdir \
-device ich9-ahci,id=ahci -device ide-drive,drive=tmpdir,bus=ahci.0 \
-device virtio-rng-pci \
-s -S
#in another console window
gdb vmlinux -ex 'target remote localhost:1234' \
-ex 'b __x64_sys_kexec_load' \
-ex 'b __x64_sys_kexec_file_load' \
-ex 'b __x64_sys_execve' \
-ex 'b __x64_sys_execveat' \
-ex 'b do_syscall_64' \
-ex 'b do_execve_file' \
-ex 'b open_exec'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment