Microsoft.Scripting.Debugging.CompilerServices.DebugContext.DispatchDebugEvent C# (CSharp) Method

DispatchDebugEvent() private method

private DispatchDebugEvent ( DebugThread thread, int debugMarker, TraceEventKind eventKind, object payload ) : void
thread DebugThread
debugMarker int
eventKind TraceEventKind
payload object
return void
        internal void DispatchDebugEvent(DebugThread thread, int debugMarker, TraceEventKind eventKind, object payload) {
            DebugFrame leafFrame = null;
            bool hasFrameObject = false;

            FunctionInfo functionInfo;
            int stackDepth;
            if (eventKind != TraceEventKind.ThreadExit) {
                functionInfo = thread.GetLeafFrameFunctionInfo(out stackDepth);
            } else {
                stackDepth = Int32.MaxValue;
                functionInfo = null;
            }

            if (eventKind == TraceEventKind.Exception || eventKind == TraceEventKind.ExceptionUnwind) {
                thread.ThrownException = (Exception)payload;
            }
            thread.IsInTraceback = true;

            try {
                // Fire the event
                IDebugCallback traceHook = _traceHook;
                if (traceHook != null) {
                    traceHook.OnDebugEvent(eventKind, thread, functionInfo, debugMarker, stackDepth, payload);
                }

                // Check if the frame object is created after the traceback.  If it's created - then we need
                // to check if we need to remap
                hasFrameObject = thread.TryGetLeafFrame(ref leafFrame);
                if (hasFrameObject) {
                    Debug.Assert(!leafFrame.InGeneratorLoop || (leafFrame.InGeneratorLoop && !leafFrame.ForceSwitchToGeneratorLoop));

                    if (leafFrame.ForceSwitchToGeneratorLoop && !leafFrame.InGeneratorLoop) {
                        throw new ForceToGeneratorLoopException();
                    }
                }
            } finally {
                if (hasFrameObject) {
                    leafFrame.IsInTraceback = false;
                }

                thread.IsInTraceback = false;
                thread.ThrownException = null;
            }
        }