/// <summary> /// 处理中断 /// </summary> private void HandleInterrupt() { NeedDebug?.Invoke(); // 挂起调试器进程等待用户操作 Thread.CurrentThread.Suspend(); // 根据用户输入决定调试模式 switch (mode) { case -1: vm.Stop(); break; case 0: // Step into模式 // 根据当前行号获取保存的中间代码 int line0 = vm.GetLastCodeInformation().Line; IntermediateCodeInformation information0 = intermediateCodeInformations[line0]; int address0 = information0.Address; IntermediateCode saved = savedInstructions[address0]; // 查询当前行是否为函数调用 if (information0.IsFunctionCall) { // 对函数入口表中的每一个函数入口指令进行保存并替换int指令 foreach (int functionEntry in information0.FuncionEntryList) { if (!savedInstructions.ContainsKey(functionEntry)) { IntermediateCode function = vm.ReplaceWithInt(functionEntry); savedInstructions.Add(functionEntry, function); } } } // 单条执行中间代码 vm.InterpretSingleInstruction(saved); // 对下一行源代码对应的中间代码进行保存并替换int ReplaceNextLine(line0); break; case 1: // Step over模式 // 根据当前行号获取保存的中间代码 int line1 = vm.GetLastCodeInformation().Line; IntermediateCodeInformation information1 = intermediateCodeInformations[line1]; int address1 = information1.Address; IntermediateCode saved1 = savedInstructions[address1]; // 单条执行中间代码 vm.InterpretSingleInstruction(saved1); // 对下一行源代码对应的中间代码进行保存并替换int ReplaceNextLine(line1); break; case 2: // Continue模式 // 根据当前行号获取保存的中间代码 int line2 = vm.GetLastCodeInformation().Line; IntermediateCodeInformation information2 = intermediateCodeInformations[line2]; int address2 = information2.Address; IntermediateCode saved2 = savedInstructions[address2]; // 单条执行中间代码 vm.InterpretSingleInstruction(saved2); break; default: // 其他模式 break; } }
/// <summary> /// 中断指令 /// </summary> void i() { // 调用调试器处理 NeedDebug?.Invoke(); }