How can I debug or analyze qemu code while running linux on the qemu virtual machine?

331 Views Asked by At

I can run ubuntu 20.04 on a virtual machine (here ab21q) like this. The disk drive0 already has ubuntu installed on it(ab21q-ubuntu-20.04-image.img).

qemu-system-aarch64 -nographic -machine ab21q,gic-version=max -m 512M -cpu max -smp 4 -netdev user,id=vnet,hostfwd=:127.0.0.1:0-:22 -device virtio-net-pci,netdev=vnet -drive file=ab21q-ubuntu-20.04-image.img,if=none,id=drive0,cache=writeback -device virtio-blk,drive=drive0,bootindex=0 -drive file=ubuntu-20.04-mini.iso,if=none,id=drive1,cache=writeback -device virtio-blk,drive=drive1,bootindex=1 -drive file=flash0.img,format=raw,if=pflash -drive file=flash1.img,format=raw,if=pflash

I have to debug an application and driver on ubuntu and for this I want to see qemu code, by setting breakpoint in qemu code to examine the passed data. If I were to debug an 'application' on the virtual machine, I used to run the qemu with '-s -S' option and run gdb for the elf file using the debugger for the virtual machine. But this time I want to debug qemu. I tried running

ddd -command=gdb_script_qemu --args qemu-system-aarch64 -nographic -machine ab21q,gic-version=max -m 512M -cpu max -smp 4 -netdev user,id=vnet,hostfwd=:127.0.0.1:0-:22 -device virtio-net-pci,netdev=vnet -drive file=ab21q-ubuntu-20.04-image.img,if=none,id=drive0,cache=writeback -device virtio-blk,drive=drive0,bootindex=0 -drive file=ubuntu-20.04-mini.iso,if=none,id=drive1,cache=writeback -device virtio-blk,drive=drive1,bootindex=1 -drive file=flash0.img,format=raw,if=pflash -drive file=flash1.img,format=raw,if=pflash

But the debugger window shows the linux boot message and prompted me to enter user name and password. It took so long after I entered my login id so I quit the process. (and even if I enter the ubuntu, will I be able to use the linux shell also as gdb shell?) What I want to do is run the program as I do and later attach the debugger with qemu-system-aarch64 executable image to the running process. I tried ddd qemu-system-aarch64 pid but this asked me to start the qemu-system-aarch64 from start not attaching to the process with pid. How can I do it?

1

There are 1 best solutions below

0
Chan Kim On

Oh, this was a long forgotten question. I later found that by turning 'Execution Window' in the 'View' menu of the ddd, I can see the linux shell in a separate execution window and still use ddd commands in the ddd command window. Hope this helps!