public void OnTraceEvent(TraceEventKind kind, string name, string sourceFileName, Microsoft.Scripting.SourceSpan sourceSpan, Microsoft.Scripting.Utils.Func <Microsoft.Scripting.IAttributesCollection> scopeCallback, object payload, object customPayload)
        {
            switch (kind)
            {
            case TraceEventKind.TracePoint:
            case TraceEventKind.FrameEnter:
            case TraceEventKind.FrameExit:
                Trace.TraceInformation("{4} at {0} Line {1} column {2}-{3}", sourceFileName, sourceSpan.Start.Line, sourceSpan.Start.Column, sourceSpan.End.Column, kind);
                if (scopeCallback != null)
                {
                    IAttributesCollection attr = scopeCallback();
                    if (attr != null)
                    {
                        Trace.TraceInformation("Attrs {0}", attr);
                    }
                }
                break;

            case TraceEventKind.Exception:
            case TraceEventKind.ExceptionUnwind:
                //Don't know what to do
                break;

            case TraceEventKind.ThreadExit:
                Trace.TraceInformation("Page completed successfully.");
                break;

            default:
                //Do nothing
                break;
            }
        }
        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;
            }
        }
        void IDebugCallback.OnDebugEvent(TraceEventKind kind, DebugThread thread, FunctionInfo functionInfo, int sequencePointIndex, int stackDepth, object payload)
        {
            ITraceCallback traceCallback = _traceCallback;

            if (traceCallback != null)
            {
                // $TODO: what if the callback throws an exception? should we swallow it?
                var curThread = _traceFrame.Value;
                try {
                    if (kind == TraceEventKind.FrameExit || kind == TraceEventKind.ThreadExit)
                    {
                        traceCallback.OnTraceEvent(
                            kind,
                            kind == TraceEventKind.FrameExit ? functionInfo.Name : null,
                            null,
                            SourceSpan.None,
                            null,
                            payload,
                            functionInfo != null ? functionInfo.CustomPayload : null
                            );
                    }
                    else
                    {
                        DebugFrame leafFrame = thread.GetLeafFrame();
                        _traceFrame.Value = leafFrame;
                        Debug.Assert(sequencePointIndex >= 0 && sequencePointIndex < functionInfo.SequencePoints.Length);
                        DebugSourceSpan sourceSpan = functionInfo.SequencePoints[sequencePointIndex];
                        traceCallback.OnTraceEvent(
                            kind,
                            functionInfo.Name,
                            sourceSpan.SourceFile.Name,
                            sourceSpan.ToDlrSpan(),
                            () => { return(leafFrame.GetLocalsScope()); },
                            payload,
                            functionInfo.CustomPayload
                            );
                    }
                } finally {
                    _traceFrame.Value = curThread;
                }
            }
        }
Example #4
0
            }             // ctor

            public void OnTraceEvent(TraceEventKind kind, string name, string sourceFileName, SourceSpan sourceSpan, Func <IDictionary <object, object> > scopeCallback, object payload, object customPayload)
            {
                switch (kind)
                {
                case TraceEventKind.ExceptionUnwind:
                    traceLineDebugger.OnExceptionUnwind(new LuaTraceLineExceptionEventArgs(name, sourceFileName, sourceSpan.Start.Line, scopeCallback, (Exception)payload));
                    break;

                case TraceEventKind.FrameEnter:
                    traceLineDebugger.OnFrameEnter(new LuaTraceLineEventArgs(name, sourceFileName, sourceSpan.Start.Line, scopeCallback));
                    break;

                case TraceEventKind.FrameExit:
                    traceLineDebugger.OnFrameExit();
                    break;

                case TraceEventKind.TracePoint:
                    traceLineDebugger.OnTracePoint(new LuaTraceLineEventArgs(name, sourceFileName, sourceSpan.Start.Line, scopeCallback));
                    break;
                }
            }     // proc OnTraceEvent
Example #5
0
        void IDebugCallback.OnDebugEvent(TraceEventKind kind, DebugThread thread, FunctionInfo functionInfo, int sequencePointIndex, int stackDepth, object payload) {
            ITraceCallback traceCallback = _traceCallback;

            if (traceCallback != null) {
                // $TODO: what if the callback throws an exception? should we swallow it?
                var curThread = _traceFrame.Value;
                try {
                    if (kind == TraceEventKind.FrameExit || kind == TraceEventKind.ThreadExit) {
                        traceCallback.OnTraceEvent(
                            kind,
                            kind == TraceEventKind.FrameExit ? functionInfo.Name : null,
                            null, 
                            SourceSpan.None, 
                            null,
                            payload,
                            functionInfo != null ? functionInfo.CustomPayload : null
                        );
                    } else  {
                        DebugFrame leafFrame = thread.GetLeafFrame();
                        _traceFrame.Value = leafFrame;
                        Debug.Assert(sequencePointIndex >= 0 && sequencePointIndex < functionInfo.SequencePoints.Length);
                        DebugSourceSpan sourceSpan = functionInfo.SequencePoints[sequencePointIndex];
                        traceCallback.OnTraceEvent(
                            kind,
                            functionInfo.Name,
                            sourceSpan.SourceFile.Name,
                            sourceSpan.ToDlrSpan(),
                            () => { return leafFrame.GetLocalsScope(); },
                            payload,
                            functionInfo.CustomPayload
                        );
                    }
                } finally {
                    _traceFrame.Value = curThread;
                }
            }
        }
Example #6
0
        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;
            }
        }
        public void OnTraceEvent(TraceEventKind kind, string name, string sourceFileName, SourceSpan sourceSpan, Func<IDictionary<object, object>> scopeCallback, object payload, object customPayload)
        {
            if (kind == TraceEventKind.ThreadExit || // we don't care about thread-exit events
                kind == TraceEventKind.ExceptionUnwind) // and we always have a try/catch so we don't care about methods unwinding.
            {
                return;
            }

            TracebackDelegate traceDispatch = null;
            object traceDispatchObject = null;
            var thread = TotemOps.GetFunctionStack();
            TraceBackFrame toFrame;

            if (InTraceBack)
                return;

            try
            {
                if (kind == TraceEventKind.FrameEnter)
                {
                    traceDispatch = _globalTraceDispatch;
                    traceDispatchObject = _globalTraceObject;

                    var properties = (FunctionCode.TotemDebuggingPayload)customPayload;

                    // push the new frame
                    toFrame = new TraceBackFrame(
                        this,
                        properties.Code,
                        thread.Count == 0 ? null : thread[thread.Count - 1].Frame,
                        properties,
                        scopeCallback
                    );

                    thread.Add(new FunctionStack(toFrame));

                    if (traceDispatchObject == null)
                        return;

                    toFrame.Trace = traceDispatchObject;
                }
                else
                {
                    if (thread.Count == 0)
                        return;

                    toFrame = thread[thread.Count - 1].Frame;
                    if (toFrame == null)
                    {
                        // force creation of Totem frame
                        throw new NotImplementedException();
                        //toFrame = SysModule.GetFrameImpl(thread[thread.Count - 1], 0);
                    }

                    traceDispatch = toFrame.TraceDelegate;
                    traceDispatchObject = toFrame.Trace;
                }

                // Update the current line
                if (kind != TraceEventKind.FrameExit)
                {
                    toFrame._lineNo = sourceSpan.Start.Line;
                }

                if (traceDispatchObject != null && !_exceptionThrown)
                {
                    DispatchTrace(thread, kind, payload, traceDispatch, traceDispatchObject, toFrame);
                }
            }
            finally
            {
                if (kind == TraceEventKind.FrameExit && thread.Count > 0)
                {
                    // don't pop frames we didn't push
                    if (thread[thread.Count - 1].Code == ((FunctionCode.TotemDebuggingPayload)customPayload).Code)
                    {
                        thread.RemoveAt(thread.Count - 1);
                    }
                }
            }
        }
        private void DispatchTrace(List<FunctionStack> thread, TraceEventKind kind, object payload, TracebackDelegate traceDispatch, object traceDispatchObject, TraceBackFrame toFrame)
        {
            object args = null;

            // Prepare the event
            string traceEvent = String.Empty;
            switch (kind)
            {
                case TraceEventKind.FrameEnter: traceEvent = "call"; break;
                case TraceEventKind.TracePoint: traceEvent = "line"; break;
                case TraceEventKind.Exception: traceEvent = "exception";
                    throw new NotImplementedException();
                case TraceEventKind.FrameExit: traceEvent = "return";
                    args = payload;
                    break;
            }

            bool traceDispatchThrew = true;
            InTraceBack = true;
            try
            {
                TracebackDelegate dlg = traceDispatch(toFrame, traceEvent, args);
                traceDispatchThrew = false;
                toFrame.Trace = dlg;
            }
            finally
            {
                InTraceBack = false;
                if (traceDispatchThrew)
                {
                    // We're matching CPython's behavior here.  If the trace dispatch throws any exceptions
                    // we don't re-enable tracebacks.  We need to leave the trace callback in place though
                    // so that we can pop our frames.
                    _globalTraceObject = _globalTraceDispatch = null;
                    _exceptionThrown = true;
                }
            }
        }