Exemple #1
0
 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);
         }
     }
 }
Exemple #2
0
        private void DettectDebugRequest(byte data)
        {
            if (_state != DebuggerState.NotConnected)
            {
                return;
            }

            _debugPreambleBuffer[_debugPreambleIdx] = data;

            if (_debugPreambleData[_debugPreambleIdx].Action == DebugDetectAction.Skip)
            {
                _debugPreambleIdx++;
                return;
            }
            if (_debugPreambleData[_debugPreambleIdx].Value != data)
            {
                // If we have data and we could not match the preamble
                //  Dump the data (basically notify anyone else interested in the data)
                for (var i = 0; i <= _debugPreambleIdx; ++i)
                {
                    UnknownData?.Invoke(_debugPreambleBuffer[i]);
                }
                _debugPreambleIdx = 0;
                return;
            }

            _debugPreambleIdx++;
            if (_debugPreambleIdx != _debugPreambleData.Count)
            {
                return;
            }

            _state          = DebuggerState.Connected;
            DebugVersion    = _debugPreambleBuffer[5];
            DeviceSignature = (uint)(
                (_debugPreambleBuffer[6] << 16) +
                (_debugPreambleBuffer[7] << 8) +
                _debugPreambleBuffer[8]
                );
            Caps = (DebuggerCapabilities)(
                (_debugPreambleBuffer[10] << 8) +
                _debugPreambleBuffer[9]
                );
            _debugPreambleIdx = 0;
        }