Esempio n. 1
0
        protected override StackTraceResponse HandleStackTraceRequest(StackTraceArguments arguments)
        {
            if (!this.stopped)
            {
                throw new ProtocolException("Not in break mode!");
            }

            return(this.ThreadManager.HandleStackTraceRequest(arguments));
        }
        internal StackTraceResponse HandleStackTraceRequest(StackTraceArguments args)
        {
            SampleThread thread = this.GetThread(args.ThreadId);

            if (thread == null)
            {
                throw new ProtocolException(Invariant($"Invalid thread id '{args.ThreadId}'!"));
            }

            return(thread.HandleStackTraceRequest(args));
        }
Esempio n. 3
0
        protected override StackTraceResponse HandleStackTraceRequest(StackTraceArguments arguments)
        {
            List <StackFrame> result = new List <StackFrame>();

            if (debugged.Threads.TryGetValue(arguments.ThreadId, out IThread t))
            {
                var thread = t as VSCodeThread;
                foreach (var i in thread.VSCodeStackFrames)
                {
                    result.Add(i.Frame);
                }
            }

            return(new StackTraceResponse(result));
        }
        public Task <StackTraceResponse> Handle(StackTraceArguments request, CancellationToken cancellationToken)
        {
            StackFrameDetails[] stackFrameDetails =
                _debugService.GetStackFrames();

            // Handle a rare race condition where the adapter requests stack frames before they've
            // begun building.
            if (stackFrameDetails == null)
            {
                return(Task.FromResult(new StackTraceResponse
                {
                    StackFrames = Array.Empty <StackFrame>(),
                    TotalFrames = 0
                }));
            }

            List <StackFrame> newStackFrames = new List <StackFrame>();

            long startFrameIndex = request.StartFrame ?? 0;
            long maxFrameCount   = stackFrameDetails.Length;

            // If the number of requested levels == 0 (or null), that means get all stack frames
            // after the specified startFrame index. Otherwise get all the stack frames.
            long requestedFrameCount = (request.Levels ?? 0);

            if (requestedFrameCount > 0)
            {
                maxFrameCount = Math.Min(maxFrameCount, startFrameIndex + requestedFrameCount);
            }

            for (long i = startFrameIndex; i < maxFrameCount; i++)
            {
                // Create the new StackFrame object with an ID that can
                // be referenced back to the current list of stack frames
                //newStackFrames.Add(
                //    StackFrame.Create(
                //        stackFrameDetails[i],
                //        i));
                newStackFrames.Add(
                    LspDebugUtils.CreateStackFrame(stackFrameDetails[i], id: i));
            }

            return(Task.FromResult(new StackTraceResponse
            {
                StackFrames = newStackFrames,
                TotalFrames = newStackFrames.Count
            }));
        }
Esempio n. 5
0
        protected override StackTraceResponse HandleStackTraceRequest(StackTraceArguments arguments)
        {
            IEnumerable <StackFrame> enumFrames = _frames;

            if (arguments.StartFrame.HasValue)
            {
                enumFrames = enumFrames.Skip(arguments.StartFrame.Value);
            }
            if (arguments.Levels.HasValue)
            {
                enumFrames = enumFrames.Take(arguments.Levels.Value);
            }
            return(new StackTraceResponse
            {
                StackFrames = enumFrames.ToList(),
                TotalFrames = _frames.Count
            });
        }
Esempio n. 6
0
        protected override StackTraceResponse HandleStackTraceRequest(StackTraceArguments arguments)
        {
            try
            {
                if (session == null)
                {
                    throw new InvalidOperationException();
                }

                var frames = session.GetStackFrames(arguments).ToList();
                return(new StackTraceResponse(frames));
            }
            catch (Exception ex)
            {
                Log(ex.Message, LogCategory.DebugAdapterOutput);
                throw new ProtocolException(ex.Message, ex);
            }
        }
Esempio n. 7
0
        protected override StackTraceResponse HandleStackTraceRequest(StackTraceArguments arguments)
        {
            var stackFrames = new List <StackFrame>();

            var frames = Controller.CallStack.ToArray();

            if (frames.Length > 0)
            {
                PushStackFrame(Controller.PC, frames[0].SubroutineAddress);
            }
            for (int i = 1; i < frames.Length; i++)
            {
                PushStackFrame(frames[i - 1].ReturnAddress, frames[i].SubroutineAddress);
            }

            return(new StackTraceResponse()
            {
                StackFrames = stackFrames,
                TotalFrames = stackFrames.Count
            });

            void PushStackFrame(uint address, uint subroutine)
            {
                var frame   = new StackFrame();
                var mapping = DebugMap?.GetMapping(address);

                if (mapping.HasValue)
                {
                    frame.Line   = mapping.Value.Line;
                    frame.Name   = DebugMap.FindNearestLabel(subroutine) ?? "???";
                    frame.Source = new Source()
                    {
                        Path = mapping.Value.Path
                    };
                }
                else
                {
                    frame.Name = "???";
                }
                stackFrames.Add(frame);
            }
        }
Esempio n. 8
0
        internal StackTraceResponse HandleStackTraceRequest(StackTraceArguments arguments)
        {
            IEnumerable <SampleStackFrame> enumFrames = this.frames;

            if (arguments.StartFrame.HasValue)
            {
                enumFrames = enumFrames.Skip(arguments.StartFrame.Value);
            }

            if (arguments.Levels.HasValue)
            {
                enumFrames = enumFrames.Take(arguments.Levels.Value);
            }

            List <StackFrame> stackFrames = enumFrames.Select(f => f.GetProtocolObject(arguments.Format)).ToList();

            return(new StackTraceResponse(
                       stackFrames: stackFrames,
                       totalFrames: this.frames.Count));
        }
Esempio n. 9
0
        public IEnumerable <StackFrame> GetStackFrames(StackTraceArguments args)
        {
            System.Diagnostics.Debug.Assert(args.ThreadId == 1);

            if ((engine.State & HALT_OR_FAULT) == 0)
            {
                var start = args.StartFrame ?? 0;
                var count = args.Levels ?? int.MaxValue;
                var end   = Math.Min(engine.InvocationStack.Count, start + count);

                for (var i = start; i < end; i++)
                {
                    var context = engine.InvocationStack.Peek(i);
                    var method  = Contract.GetMethod(context);

                    var frame = new StackFrame()
                    {
                        Id       = i,
                        Name     = method?.DisplayName ?? "<unknown>",
                        ModuleId = context.ScriptHash,
                    };

                    var sequencePoint = method?.GetCurrentSequencePoint(context);

                    if (sequencePoint != null)
                    {
                        frame.Source = new Source()
                        {
                            Name = Path.GetFileName(sequencePoint.Document),
                            Path = sequencePoint.Document
                        };
                        frame.Line      = sequencePoint.StartLine;
                        frame.Column    = sequencePoint.StartColumn;
                        frame.EndLine   = sequencePoint.EndLine;
                        frame.EndColumn = sequencePoint.EndColumn;
                    }

                    yield return(frame);
                }
            }
        }