如何在 x86 模拟器中测试 CPU 异常? [英] How to test CPU exceptions in an x86 emulator?

查看:40
本文介绍了如何在 x86 模拟器中测试 CPU 异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在编写一个专门的模拟器来模拟 x86 程序,我们通过将其效果与真实事物进行比较来对指令进行单元测试.它是通过在调试器中设置断点来完成的,然后检查寄存器、标志和各种内存地址是否在给定点设置为与模拟器中相同的值.

We are writing a specialized emulator to emulate x86 programs, and we unit test the instructions by comparing its effects with the real thing. It's accomplished by setting a breakpoint in the debugger, then examining the registers, flags and various memory addresses whether they set to the same value as in the emulator at the given point.

它非常适合测试正常操作.

It works very well for testing normal operation.

但是我们如何对可能出现的 CPU 异常进行单元测试?例如.段错误,零除法等等?普通的用户态调试器能不能得到异常中断号之类的东西?

But how can we unittest CPU exceptions that can arise? Eg. segfaults, zero divison and such? Is it possible to obtain the exception interrupt number or something like that with an ordinary user mode debugger?

推荐答案

如果我正确地假设您正在构建用户模式模拟器,那么您将必须自己实现异常处理.根据手册,当处理器响应中断或异常时,它会停止当前任务的执行,并切换到为 IDT 中的异常条件安装的处理程序(有一些异常,如 SMI).应用程序可以访问这些处理程序,但我不确定这对您是否有用.此外,请记住,某些中断/异常可能会保存相关状态(请参阅说明参考手册).

If I'm assuming correctly that you're building a user-mode emulator, you will have to implement exception handling yourself. Per the manuals, when the processor responds to an interrupt or exception, it halts execution of the current task, and switches to a handler installed for that exception condition in the IDT (with some exceptions, like SMI). Application programs can access those handlers, but I'm not sure if that would be useful to you. Additionally, keep in mind that some interrupts/exceptions may save related state (consult the instruction reference manuals).

无论如何,您都可以安装处理程序(在您的模拟 CPU 中)来跟踪异常和发生时的状态,以便您可以对它们进行单元测试.

At any rate, you can install handlers (in your emulated CPU) to keep track of exceptions and state when occurred so you can unit-test them.

这篇关于如何在 x86 模拟器中测试 CPU 异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆