Qemu Trace功能
Qemu 的 trace 系统允许你在不修改代码或重新编译的情况下,动态跟踪 Qemu内部的各种事件和函数调用。
Trace事件定义
Trace 事件定义在 Qemu 源码的 trace-events 文件中,按模块组织:
在这里以hs0703.c(I2c总线的)的hs0703_read函数为例
在hw/i2c/trace-events文件中添加hs0703_read函数
# hs0703.c
# Trace 事件语法:<subsystem>_<event_name>(<parameters>) "<format string>"
# 在这里可以随意定义任何名字,如hs0703_read或者xxx,然后trace会自动拼接trace_ + 在这里定义的函数名称,然后括号是传入的参数,后面的字符串是输出的格式
# 也就是最后调用trace_hs0703_read这个函数,然后日志就会输出I2C controller read offset: offeset值
hs0703_read(uint8_t offset) "I2C controller read offset: 0x%02x"
在代码中使用 Trace
在hs0703.c代码中添加
#include "trace.h"
...
static uint64_t hs0703_read(void *opaque, hwaddr offset, unsigned size)
{
...
// 在想跟踪的函数中调用trace函数(命名来源见上面的trace-events的解析)
trace_hs0703_read(offset);
DPRINTF("[i2c read reg]:0x%lx [offset:0x%x data:0x%x]\n", (uint64_t)opaque, (uint32_t)offset, (uint32_t)ret);
return ret;
}
重新编译qemu二进制
python3 build.py
将编译后的二进制文件迁移到manifest的temp/qemu_temp/qemu_start_temp/qemu-system-aarch64-release,将生成的qemu-system-aarch64改名为qemu-system-aarch64-release。
修改启动脚本
在build/works/packet/qemu_shells/vemake_1711.py中修改run_wsl这函数,添加’-trace’, “hs0703_*”,类似这种形式
解析说明:使用’-trace’, “hs0703_*”这个会跟踪所有qemu二进制中所有trace_hs0703_xxx的跟踪函数,例如trace_hs0703_111, trace_hs0703_222等
然后在manifest的终端运行python3 build/works/packet/qemu_shells/vemake_1711.py >qemu_stdout.log 2>qemu_stderr.log,然后输出的内容在qemu_stderr.log日志



