private void ProcessData(byte data) { if (_state == DebuggerState.NotConnected) { DettectDebugRequest(data); if (_state != DebuggerState.NotConnected) { Trace.WriteLine( $"Debugger Attached Version = {DebugVersion}, Signature = 0x{DeviceSignature:X8}, Caps = {Caps}"); InDebug = true; Task.Run(() => { DebuggerAttached?.Invoke(); }); } } else { if (_currentCommand != null) { _currentCommandBuffer[_currentCommandReceiveIdx++] = data; if (_currentCommandReceiveIdx != _currentCommand.Command.ResponseSize) { return; } Trace.WriteLine("Debugger Server - DONE Command " + _currentCommand.Command); _currentCommand.TCS.SetResult(_currentCommandBuffer); _currentCommand = null; } else { //Trace.WriteLine($"Debugger Server - Unknown Data 0x{data:X2} - `{Convert.ToChar(data)}`"); UnknownData?.Invoke(data); } } }
private void _commandsWorker_DoWork(object sender, DoWorkEventArgs e) { while (!_commandsWorker.CancellationPending) { DebugCommandWrapper tempCommand = null; if (_currentCommand == null && _commands.TryDequeue(out tempCommand)) { // Carefully when changing this, // We have the receive task that is running async if (tempCommand.Command.ResponseSize == 0) { Trace.WriteLine("Debugger Server - Send Command " + tempCommand.Command); _transport.Write(tempCommand.Command.CommandBuffer); tempCommand.TCS.SetResult(_emptyCommandResponse); continue; // Try the next command, do not wait } _currentCommandBuffer = new byte[tempCommand.Command.ResponseSize]; _currentCommandReceiveIdx = 0; _currentCommand = tempCommand; Trace.WriteLine("Debugger Server - Send Command " + tempCommand.Command); _transport.Write(_currentCommand.Command.CommandBuffer); } // Delay a bit so we don't block the CPU Thread.Sleep(10); } }
public Task <byte[]> AddCommand(IDebugCommand cmd) { if (_state == DebuggerState.NotConnected || _state == DebuggerState.Stopping) { return(Task.FromResult <byte[]>(null)); } var wrapper = new DebugCommandWrapper(cmd); _commands.Enqueue(wrapper); return(wrapper.TCS.Task); }
private void ExecuteCommandWithClearState(IDebugCommand command) { InDebug = false; _state = DebuggerState.NotConnected; // Notify anyone interested DebuggerDetached?.Invoke(); Trace.WriteLine("Debugger Server - Execute Command with Clear " + command); // Clear the commands buffer DebugCommandWrapper cmd; while (_commands.TryDequeue(out cmd)) { cmd.TCS.SetResult(_emptyCommandResponse); } // Clear the current command _currentCommand = null; _currentCommandBuffer = null; _currentCommandReceiveIdx = 0; _transport.Write(command.CommandBuffer); }