public static Server.ResponseType Stacktrace(this DebugServer self, NameValueCollection query, StringBuilder sb) { using var writer = new JsonWriter(sb); using var root = writer.Array; if (self.vm == null) { return(Server.ResponseType.Json); } var cache = new StringBuilder(); for (var i = self.vm.callFrameStack.count - 1; i >= 0; i--) { var callframe = self.vm.callFrameStack.buffer[i]; switch (callframe.type) { case CallFrame.Type.EntryPoint: break; case CallFrame.Type.Function: using (var st = root.Object) { var codeIndex = System.Math.Max(callframe.codeIndex - 1, 0); var sourceContentIndex = self.vm.chunk.sourceSlices.buffer[codeIndex].index; var source = self.sources.buffer[self.vm.chunk.FindSourceIndex(codeIndex)]; var pos = FormattingHelper.GetLineAndColumn( source.content, sourceContentIndex ); cache.Clear(); self.vm.chunk.FormatFunction(callframe.functionIndex, cache); st.String("name", cache.ToString()); st.Number("line", pos.lineIndex + 1); st.Number("column", pos.columnIndex + 1); st.String("sourceUri", source.uri.value); } break; case CallFrame.Type.NativeFunction: using (var st = root.Object) { cache.Clear(); cache.Append("native "); self.vm.chunk.FormatNativeFunction(callframe.functionIndex, cache); st.String("name", cache.ToString()); } break; } } return(Server.ResponseType.Json); }
void IDebugger.OnDebugHook() { var codeIndex = vm.callFrameStack.buffer[vm.callFrameStack.count - 1].codeIndex; if (codeIndex < 0) { return; } var sourceIndex = vm.chunk.FindSourceIndex(codeIndex); if (sourceIndex < 0) { return; } var source = sources.buffer[sourceIndex]; var sourceSlice = vm.chunk.sourceSlices.buffer[codeIndex]; var line = (ushort)(FormattingHelper.GetLineAndColumn(source.content, sourceSlice.index).lineIndex + 1); var position = new SourcePosition(source.uri, line); Execution ex; lock (this) { ex = execution; } switch (ex) { case Execution.Continuing: lock (this) { for (var i = 0; i < breakpoints.count; i++) { var breakpoint = breakpoints.buffer[i]; var wasOnBreakpoint = //lastPosition.uri.value == position.uri.value && lastPosition.line == breakpoint.line; if (!wasOnBreakpoint && position.line == breakpoint.line) { execution = Execution.BreakpointPaused; break; } } } break; case Execution.Stepping: if (lastPosition.uri.value != position.uri.value || lastPosition.line != position.line) { lock (this) { execution = Execution.StepPaused; } break; } break; } while (true) { lock (this) { if (!IsPaused) { break; } } Thread.Sleep(1000); } lastPosition = position; }