private bool HandleExceptions(MeadowDebugAdapterThreadState threadState)
        {
            // Try to obtain an exception at this point
            if (threadState.CurrentStepIndex.HasValue)
            {
                // Obtain an exception at the current point.
                ExecutionTraceException traceException = threadState.ExecutionTraceAnalysis.GetException(threadState.CurrentStepIndex.Value);

                // If we have an exception, throw it and return the appropriate status.
                if (traceException != null)
                {
                    // Send our exception event.
                    var stoppedEvent = new StoppedEvent(StoppedEvent.ReasonValue.Exception)
                    {
                        Text     = traceException.Message,
                        ThreadId = threadState.ThreadId
                    };
                    Protocol.SendEvent(stoppedEvent);
                    return(true);
                }
            }

            // We did not find an exception here, return false
            return(false);
        }
Example #2
0
        private bool HandleExceptions(MeadowDebugAdapterThreadState threadState)
        {
            bool ShouldProcessException()
            {
                lock (_exceptionBreakpointFilters)
                {
                    if (_exceptionBreakpointFilters.Contains(EXCEPTION_BREAKPOINT_FILTER_ALL))
                    {
                        return(true);
                    }

                    if (!threadState.ExpectingException && _exceptionBreakpointFilters.Contains(EXCEPTION_BREAKPOINT_FILTER_UNHANDLED))
                    {
                        return(true);
                    }

                    return(false);
                }
            }

            // Try to obtain an exception at this point
            if (ShouldProcessException() && threadState.CurrentStepIndex.HasValue)
            {
                // Obtain an exception at the current point.
                ExecutionTraceException traceException = threadState.ExecutionTraceAnalysis.GetException(threadState.CurrentStepIndex.Value);

                // If we have an exception, throw it and return the appropriate status.
                if (traceException != null)
                {
                    // Send our exception event.
                    var stoppedEvent = new StoppedEvent(StoppedEvent.ReasonValue.Exception)
                    {
                        Text     = traceException.Message,
                        ThreadId = threadState.ThreadId
                    };
                    Protocol.SendEvent(stoppedEvent);
                    return(true);
                }
            }

            // We did not find an exception here, return false
            return(false);
        }
Example #3
0
        internal static ExecutionTrace CoreExecutionTraceJsonExecutionTrace(Meadow.EVM.Debugging.Tracing.ExecutionTrace coreExecutionTrace)
        {
            // If the execution trace is null, we return null
            if (coreExecutionTrace == null)
            {
                return(null);
            }

            // Create our array of trace points
            ExecutionTracePoint[] tracepoints = new ExecutionTracePoint[coreExecutionTrace.Tracepoints.Count];

            // Populate all tracepoint items.
            for (int i = 0; i < tracepoints.Length; i++)
            {
                // Obtain our trace point.
                var executionTracePoint = coreExecutionTrace.Tracepoints[i];

                // Define our memory and stack
                Data[] executionMemory = null;
                Data[] executionStack  = executionTracePoint.Stack.Select(s => new Data(s)).ToArray();

                if (executionTracePoint.Memory != null)
                {
                    int         wordCount  = (int)EVMDefinitions.GetWordCount(executionTracePoint.Memory.Length);
                    Span <byte> memorySpan = executionTracePoint.Memory;
                    executionMemory = new Data[wordCount];
                    for (int x = 0; x < executionMemory.Length; x++)
                    {
                        executionMemory[x] = new Data(memorySpan.Slice(x * EVMDefinitions.WORD_SIZE, EVMDefinitions.WORD_SIZE));
                    }
                }

                // Obtain our memory
                tracepoints[i] = new ExecutionTracePoint()
                {
                    CallData         = executionTracePoint.CallData,
                    Code             = executionTracePoint.Code,
                    ContractAddress  = executionTracePoint.ContractAddress == null ? (Address?)null : new Address(executionTracePoint.ContractAddress.ToByteArray()),
                    ContractDeployed = executionTracePoint.ContractDeployed,
                    Opcode           = executionTracePoint.Opcode,
                    GasRemaining     = (UInt256)executionTracePoint.GasRemaining,
                    GasCost          = (UInt256)executionTracePoint.GasCost,
                    PC      = executionTracePoint.PC,
                    Depth   = executionTracePoint.Depth,
                    Stack   = executionStack,
                    Memory  = executionMemory,
                    Storage = executionTracePoint.Storage
                };
            }

            // Create our array of exceptions
            ExecutionTraceException[] exceptions = new ExecutionTraceException[coreExecutionTrace.Exceptions.Count];

            // Populate all exception items
            for (int i = 0; i < exceptions.Length; i++)
            {
                // Set our item.
                exceptions[i] = new ExecutionTraceException()
                {
                    TraceIndex = coreExecutionTrace.Exceptions[i].TraceIndex,
                    Message    = coreExecutionTrace.Exceptions[i].Exception.Message
                };
            }

            // Obtain our execution trace analysis.
            ExecutionTrace executionTrace = new ExecutionTrace()
            {
                Tracepoints = tracepoints,
                Exceptions  = exceptions
            };

            // Return our execution trace.
            return(executionTrace);
        }