【问题标题】:Can we single step QEMU using libvert我们可以使用 libvirt 单步 QEMU
【发布时间】:2019-06-14 05:40:56
【问题描述】:

我正在开发一个外围硬件,想用QEMU来测试。

计划是在 QEMU 中运行设备驱动程序并使用 libvert(或其他?)将 VM 与基于 python 的外围设备仿真模型连接。 我知道 QEMU 可以通过 GDB 单步执行,但我正在寻找一种 python 方法来执行以下操作。

  1. 等待写入特定内存位置。
  2. 暂停 QEMU
  3. 在主机中运行一些后台任务。
  4. 为 N 个周期运行 QEMU。
  5. 写入内存位置
  6. 继续

这可以通过 libvert 或任何其他工具包实现吗?

【问题讨论】:

    标签: virtual-machine virtualization qemu


    【解决方案1】:

    我需要做类似的事情,并遇到了两种方法:

    1. 在 GDB 中运行 Python,使用命令的 Python 脚本
    2. 对 GDB 使用 Python API,例如 pygdbmi

    后者最终变得更加灵活,因此我将在此处解释这些步骤。 使用调试信息配置 qemu:

    ./configure --enable-debug
    

    构建 qemu 并使用调试钩子暂停调用它:

    make
    sudo make install
    qemu-system-x86_64 -S -s
    

    现在,使用 Python 脚本通过 pygdbmi(instructions here) 附加到 qemu 并与之交互:

    from pygdbmi.gdbcontroller import GdbController
    from pprint import pprint
    
    # Start gdb process
    gdbmi = GdbController()
    print(gdbmi.get_subprocess_cmd())  # print actual command run as subprocess
    
    gdbmi.write('target remote localhost:1234');  # attach to QEMU GDB socket
    pprint(response)
    response = gdbmi.write('-break-insert main')  # machine interface (MI) commands start with a '-'
    response = gdbmi.write('break main')  # normal gdb commands work too, but the return value is slightly different
    response = gdbmi.write('-exec-run')
    response = gdbmi.write('run')
    response = gdbmi.write('-exec-next', timeout_sec=0.1)  # the wait time can be modified from the default of 1 second
    response = gdbmi.write('next')
    response = gdbmi.write('next', raise_error_on_timeout=False)
    response = gdbmi.write('next', raise_error_on_timeout=True, timeout_sec=0.01)
    response = gdbmi.write('-exec-continue')
    response = gdbmi.send_signal_to_gdb('SIGKILL')  # name of signal is okay
    response = gdbmi.send_signal_to_gdb(2)  # value of signal is okay too
    response = gdbmi.interrupt_gdb()  # sends SIGINT to gdb
    response = gdbmi.write('si 20') # step 20 instructions
    response = gdbmi.write('continue')
    response = gdbmi.exit()
    
    

    如果您在使用内核符号时遇到问题,您可能还需要发出命令“file myKernel”来从该文件加载符号表,假设它是使用调试信息编译的。

    作为参考,'-s' 命令在 localhost:1234 添加 GDB 挂钩。所以你发出的第一个命令必须让 gdb 去那里看:

    gdbmi.write('target remote localhost:1234');
    

    【讨论】:

      猜你喜欢
      • 2011-10-21
      • 2022-06-11
      • 2012-02-04
      • 2016-12-19
      • 1970-01-01
      • 2013-09-27
      • 1970-01-01
      • 1970-01-01
      • 2013-11-15
      相关资源
      最近更新 更多