We can use 9p fs to do this, qemu cmdline like below:
1 | qemu-system-aarch64 -machine virt -cpu cortex-a57 \ |
Here path=p9root is the directory which we can see in host and guest.
We can use path=/home/your_account/p9root for example also, but it should be a
full path.
Then we can start qemu, and in qemu do:
1 | mount -t 9p p9 /mnt |
Then you can see the files in host p9root directory in guest /mnt.
Then we can also debug the kernel running in qemu by gdb. We should add
“-gdb tcp::1234” to start a gdb server in qemu and wait on local port 1234 of tcp.
Whole qemu cmdline is like:
1 | qemu-system-aarch64 -machine virt -cpu cortex-a57 \ |
After kernel in qemu boots up, you can start a gdb cline in host and connect to
the gdb server in qemu.
1 | aarch64-linux-gnu-gdb |
Here we use a arm64 based gdb as an example. After “target remote:1234”, we
can use gdb to debug kernel in qemu. You can just set break points, print value
of variables…
Or you can -s -S in qemu command line, then in another window, run gdb;
target remote:1234 to connect gdb server in qemu. Then you can set breakpoint,
run and so on. If you have done like above steps, but fail to set a breakpoint,
please disable kaslr, and retry it. For disable kaslr, adding nokaslr in kernel
command line, you can do this in qemu -append, like, -append “xxxx nokaslr”
For debug qemu itself, you can run qemu and get the pid of qemu, then run gdb;
attach