This article introduces the compilation process of QEMU and GDB debugging methods, covering in detail the compilation steps for the aarch64 architecture, debugging option configuration, automatic generation of the compile_commands.json file, and related settings for code debugging via the .gdbinit script.
Environment
os
Compilation
Compile aarch64 Optional: Enable O0, -g3 debugging information
sudo apt-get install python3.9 python3-pip ninja-build python3.9 -m pip install --user tomli sphinx sphinx_rtd_theme # Set environment variables in ~/.bashrc or ~/.zshrc export PATH="$HOME/.local/bin:$PATH" # The version installed via apt is too old, while qemu-10.2.0 requires 2.66.0 or higher sudo apt-get install libglib2.0-dev pkg-config
# Confirm after compilation, it should output: RUNPATH /home/zhaohang/tools/glib-2.72.4/_install/lib objdump -p _install/bin/qemu-system-aarch64 | grep RUNPATH
# Recommended to set environment variables in ~/.bashrc or ~/.zshrc export PATH="$HOME/tools/qemu-10.2.0/bin:$PATH"
compile_commands.json
Compilation will automatically generate compile_commands.json
1
cp build/compile_commands.json .
GDB debugging
There is a .gdbinit in the qemu directory. Executing gdb in this directory will automatically run the scripts/qemu-gdb.py script. For specific debugging methods, refer to: