How to debug the Linux kernel with GDB and QEMU?
I'd try:
(gdb) target remote localhost:1234
(gdb) continue
Using the '-s' option makes qemu listen on port tcp::1234, which you can connect to as localhost:1234 if you are on the same machine. Qemu's '-S' option makes Qemu stop execution until you give the continue command.
Best thing would probably be to have a look at a decent GDB tutorial to get along with what you are doing. This one looks quite nice.
debugging kernel with qemu and gdb, breakpoint not working?
This was solve not long after my posting the question and I forgot to put an answer.
It was because of the KASLR (kernel address space location randomization). You should disable it in the kernel configuration, or give option in the boot parameter. (without it, the kernel image is located in random location, causing mismach between debug symbol location and actual code location). This KASLR is turned on by default for aarch64.
In my case I did it with :
${QEMU_DIR}/qemu-system-aarch64 -M ${QMACHINE} -cpu cortex-a72 -kernel ${LINUX_DIR}/arch/arm64/boot/Image -initrd ${BUSYBOX_DIR}/initramfs.cpio.gz --append "root=/dev/ram init=/init nokaslr" -m 2048M -nographic
And I had to use 'hb'(or hbreak (hardware break)) instead of 'b'(or break).
How to debug Linux kernel modules with QEMU?
The easiest way in my opinion is to use buildroot
http://buildroot.uclibc.org/
clone it, configure it to use your custom kernel (default userspace is fine for a start, you might want to change it later).
it will build your kernel and root filesystem. the entire process takes about half an hour, twenty minutes of which is compiling the monster
my run line looks something:
qemu-system-i386
-hda rootfs.ext2
-kernel bzImage
-m 512M
-append "root=/dev/sda console=ttyS0"
-localtime
-serial stdio
and some more options regarding a tap device
Can't get gdb to stop at breakpoint in Linux kernel running under Qemu
The solution to the problem was to add nokaslr
option and use hbreak
. That means replace
-append "root=/dev/sda1"
with
`-append "root=/dev/sda1 nokaslr"
and
break start_kernel
with
hbreak start_kernel
then gdb
properly catches kernel breakpoints.
Related Topics
How to Reload Google Chrome Tab from Terminal
How to Grep For Contents After Pattern
How to Quickly Sum All Numbers in a File
Use of Floating Point in the Linux Kernel
Spring Boot Application as a Service
Apache Virtualhost 403 Forbidden
How to Run a Script At a Certain Time on Linux
How to Simulate Just One Enter in Command Line After Executing a Jar File
Can You Run Gui Applications in a Linux Docker Container
Get Exit Code of a Background Process
How to Automatically Redirect Http to Https on Apache Servers
Adding a New Entry to the Path Variable in Zsh
How to Permanently Export a Variable in Linux