在上一篇文章中,我们下载并编译了qemu的源码。详见关于qemu的二三事(4)————qemu源码的下载与编译,以及fdt
目前,这个qemu的版本号是:
[root@localhost x86_64-softmmu]# ./qemu-system-x86_64 --version
QEMU emulator version 2.9.50 (v2.9.0-941-g0748b35-dirty)
Copyright (c) 2003-2017 Fabrice Bellard and the QEMU Project developers
源码的commit号是:0748b3526e8cb78b9cd64208426bfc3d54a72b04
这篇文章我会尝试用gdb单步调试的方式,来简要分析一下qemu源码的执行流程。
上篇文章提到,我们专门建立了一个目录 /bin/debug/native作为本地调试的目录。现在打开这个路径,你会发现里面多了许多文件和目录。其中有个x86_64-softmmu的文件夹下面就有文明要用的的qemu主程序qemu-system-x86_64。好了,现在准备gdb搞起来~
作为C语言编写的程序,qemu的main函数是在vl.c这个文件里面的,打开vl.c我们能看到的它包含一些头文件,然后就是定义了一堆变量、数组和结构体,还有一些函数,摘录一点简单例子:
int singlestep = 0;
int smp_cpus = 1;
int max_cpus = 1;
int smp_cores = 1;
int smp_threads = 1;
int acpi_enabled = 1;
int no_hpet = 0;
int fd_bootchk = 1;
static int no_reboot;
int no_shutdown = 0;
int cursor_hide = 1;
int graphic_rotate = 0;
const char *watchdog;
QEMUOptionRom option_rom[MAX_OPTION_ROMS];
int nb_option_roms;
... ...
还有这些: