private unsafe static void HighLevelDebugFuncEvalHelper() { uint parameterBufferSize = RuntimeAugments.RhpGetFuncEvalParameterBufferSize(); IntPtr debuggerFuncEvalParameterBufferReadyResponsePointer; IntPtr parameterBufferPointer; byte *parameterBuffer = stackalloc byte[(int)parameterBufferSize]; parameterBufferPointer = new IntPtr(parameterBuffer); DebuggerFuncEvalParameterBufferReadyResponse debuggerFuncEvalParameterBufferReadyResponse = new DebuggerFuncEvalParameterBufferReadyResponse { kind = DebuggerResponseKind.FuncEvalParameterBufferReady, bufferAddress = parameterBufferPointer.ToInt64() }; debuggerFuncEvalParameterBufferReadyResponsePointer = new IntPtr(&debuggerFuncEvalParameterBufferReadyResponse); RuntimeAugments.RhpSendCustomEventToDebugger(debuggerFuncEvalParameterBufferReadyResponsePointer, Unsafe.SizeOf <DebuggerFuncEvalParameterBufferReadyResponse>()); // .. debugger magic ... the parameterBuffer will be filled with parameter data FuncEvalMode mode = (FuncEvalMode)RuntimeAugments.RhpGetFuncEvalMode(); switch (mode) { case FuncEvalMode.CallParameterizedFunction: CallParameterizedFunction(parameterBuffer, parameterBufferSize); break; case FuncEvalMode.NewStringWithLength: NewStringWithLength(parameterBuffer, parameterBufferSize); break; case FuncEvalMode.NewParameterizedArray: NewParameterizedArray(parameterBuffer, parameterBufferSize); break; case FuncEvalMode.NewParameterizedObjectNoConstructor: NewParameterizedObjectNoConstructor(parameterBuffer, parameterBufferSize); break; case FuncEvalMode.NewParameterizedObject: NewParameterizedObject(parameterBuffer, parameterBufferSize); break; default: Debug.Assert(false, "Debugger provided an unexpected func eval mode."); break; } }
private unsafe static void HighLevelDebugFuncEvalHelper() { uint parameterBufferSize = RuntimeAugments.RhpGetFuncEvalParameterBufferSize(); IntPtr writeParameterCommandPointer; IntPtr parameterBufferPointer; byte *parameterBuffer = stackalloc byte[(int)parameterBufferSize]; parameterBufferPointer = new IntPtr(parameterBuffer); WriteParameterCommand writeParameterCommand = new WriteParameterCommand { commandCode = 1, bufferAddress = parameterBufferPointer.ToInt64() }; writeParameterCommandPointer = new IntPtr(&writeParameterCommand); RuntimeAugments.RhpSendCustomEventToDebugger(writeParameterCommandPointer, Unsafe.SizeOf <WriteParameterCommand>()); // .. debugger magic ... the debuggerBuffer will be filled with parameter data FuncEvalMode mode = (FuncEvalMode)RuntimeAugments.RhpGetFuncEvalMode(); switch (mode) { case FuncEvalMode.RegularFuncEval: RegularFuncEval(parameterBuffer, parameterBufferSize); break; case FuncEvalMode.NewStringWithLength: NewStringWithLength(parameterBuffer, parameterBufferSize); break; default: Debug.Assert(false, "Debugger provided an unexpected func eval mode."); break; } }
private unsafe static void HighLevelDebugFuncEvalHelper() { long lastFuncEvalId = s_funcEvalId; long myFuncEvalId = 0; FuncEvalResult funcEvalResult = new FuncEvalResult(); s_funcEvalThread = RuntimeAugments.RhpGetCurrentThread(); Exception ex = null; try { uint parameterBufferSize = RuntimeAugments.RhpGetFuncEvalParameterBufferSize(); IntPtr debuggerFuncEvalParameterBufferReadyResponsePointer; IntPtr parameterBufferPointer; byte *parameterBuffer = stackalloc byte[(int)parameterBufferSize]; parameterBufferPointer = new IntPtr(parameterBuffer); DebuggerFuncEvalParameterBufferReadyResponse *debuggerFuncEvalParameterBufferReadyResponse = stackalloc DebuggerFuncEvalParameterBufferReadyResponse[1]; debuggerFuncEvalParameterBufferReadyResponse->kind = DebuggerResponseKind.FuncEvalParameterBufferReady; debuggerFuncEvalParameterBufferReadyResponse->bufferAddress = parameterBufferPointer.ToInt64(); debuggerFuncEvalParameterBufferReadyResponsePointer = new IntPtr(debuggerFuncEvalParameterBufferReadyResponse); RuntimeAugments.RhpSendCustomEventToDebugger(debuggerFuncEvalParameterBufferReadyResponsePointer, Unsafe.SizeOf <DebuggerFuncEvalParameterBufferReadyResponse>()); // .. debugger magic ... the parameterBuffer will be filled with parameter data FuncEvalMode mode = (FuncEvalMode)RuntimeAugments.RhpGetFuncEvalMode(); switch (mode) { case FuncEvalMode.CallParameterizedFunction: funcEvalResult = CallParameterizedFunction(ref myFuncEvalId, parameterBuffer, parameterBufferSize); break; case FuncEvalMode.NewStringWithLength: funcEvalResult = NewStringWithLength(ref myFuncEvalId, parameterBuffer, parameterBufferSize); break; case FuncEvalMode.NewParameterizedArray: funcEvalResult = NewParameterizedArray(ref myFuncEvalId, parameterBuffer, parameterBufferSize); break; case FuncEvalMode.NewParameterizedObjectNoConstructor: funcEvalResult = NewParameterizedObjectNoConstructor(ref myFuncEvalId, parameterBuffer, parameterBufferSize); break; case FuncEvalMode.NewParameterizedObject: funcEvalResult = NewParameterizedObject(ref myFuncEvalId, parameterBuffer, parameterBufferSize); break; default: Debug.Assert(false, "Debugger provided an unexpected func eval mode."); break; } if (Interlocked.CompareExchange(ref s_funcEvalId, lastFuncEvalId, myFuncEvalId) == myFuncEvalId) { ReturnToDebuggerWithReturn(funcEvalResult); // ... debugger magic ... the process will go back to wherever it was before the func eval } else { // Wait for the abort to complete while (true) { RuntimeAugments.RhYield(); } } } catch (Exception e) { RuntimeAugments.RhpCancelThreadAbort(s_funcEvalThread); ex = e; // It is important that we let the try block complete to clean up runtime data structures, // therefore, while the result is already available, we still need to let the runtime exit the catch block // cleanly before we return to the debugger. } s_funcEvalId = lastFuncEvalId; ReturnToDebuggerWithReturn(new FuncEvalResult(ex, true)); // ... debugger magic ... the process will go back to wherever it was before the func eval }