TrapManager.scala 1.17 KB
Newer Older
1 2 3
package uvm.refimpl.itpr

import uvm.refimpl._
4
import scala.collection.mutable.HashSet
5

6
class TrapManager(implicit microVM: MicroVM) {
7 8
  var trapHandler: TrapHandler = DefaultTrapHandler

9 10 11 12 13 14 15 16
  private val enabledWatchPoints = new HashSet[Int]()

  def isWatchPointEnabled(wpID: Int): Boolean = enabledWatchPoints.contains(wpID)

  def enableWatchPoint(wpID: Int): Unit = enabledWatchPoints.add(wpID)

  def disableWatchPoint(wpID: Int): Unit = enabledWatchPoints.remove(wpID)

17
  object DefaultTrapHandler extends TrapHandler {
Kunshan Wang's avatar
Kunshan Wang committed
18 19
    def handleTrap(ctx: MuCtx, thread: MuThreadRefValue, stack: MuStackRefValue, watchPointID: Int): TrapHandlerResult = {
      val thrID = thread.vb.asInstanceOf[BoxThread].thread.get.id
Kunshan Wang's avatar
Kunshan Wang committed
20 21 22 23 24 25 26 27
      val staID = stack.vb.asInstanceOf[BoxStack].stack.get.id
      val cursor = ctx.newCursor(stack)
      val curFuncID = ctx.curFunc(cursor)
      val curFuncVerID = ctx.curFuncVer(cursor)
      val curInstID = ctx.curInst(cursor)
      ctx.closeCursor(cursor)
      throw new UvmRuntimeException("Unhandled trap. thread %d, stack: %d, func: %d, funcver: %d, inst %d, watch point ID %d".format(
        thrID, staID, curFuncID, curFuncVerID, curInstID, watchPointID))
28 29 30 31
    }
  }

}