方法:使用 virsh qemu-monitor-command 命名,它的基本用法是:
$ virsh qemu-monitor-command --help
NAME
qemu-monitor-command - QEMU 监控程序命令
SYNOPSIS
qemu-monitor-command <domain> [--hmp] [--pretty] {[--cmd] <string>}...
DESCRIPTION
QEMU 监控程序命令
OPTIONS
[--domain] <string> domain name, id or uuid
--hmp 采用认同监控协议的命令
--pretty 以美化格式输出任意 qemu 监视器协议输出结果
[--cmd] <string> 命令
这里需要了解一下 qemu monitor 所支持的命令,详见参考资料,dump 虚拟机中的一段内存需要使用 x/fmt 命令,它的基本格式是:
x/fmt addr
Virtual memory dump starting at addr.
fmt is a format which tells the command how to format the data.
Its syntax is: /{count}{format}{size}
count
is the number of items to be dumped.
format
can be x (hex), d (signed decimal), u (unsigned decimal),
o (octal),c (char) or i (asm instruction).
size
can be b (8 bits), h (16 bits), w (32 bits) or g (64 bits).
On x86,h or w can be specified with the i format
to respectively select 16 or 32 bit code instruction size.
下面是使用示例,dump 虚拟机 generic 从虚拟地址 0xffffffff8020b2c0 开始的 256 条指令到 memory.dump 文件:
$ virsh qemu-monitor-command generic --hmp x/256i 0xffffffff8020b2c0 > memory.dump
$ head memory.dump
0xffffffff8020b2c0: move v0,a0
0xffffffff8020b2c4: sltiu t2,a2,40
0xffffffff8020b2c8: andi t0,a0,0xf
0xffffffff8020b2cc: bnez t2,0xffffffff8020b620
0xffffffff8020b2d0: andi t1,a1,0xf
0xffffffff8020b2d4: beqz t0,0xffffffff8020b308
0xffffffff8020b2d8: bnec t0,t8,0xffffffff8020b29c
0xffffffff8020b2dc: ldr t3,0(a1)
0xffffffff8020b2e0: sltiu t4,t0,8
0xffffffff8020b2e4: ldl t3,7(a1)
参考资料:
1. https://qemu.readthedocs.io/en/latest/system/monitor.html