From a1fdc45fcb9e43a7b06722fc4f622d8905dbc2e6 Mon Sep 17 00:00:00 2001 From: jaipaljadeja Date: Sat, 20 Apr 2024 03:39:36 +0530 Subject: [PATCH 1/5] feat: single step debugging mode for sierra statements --- components/Editor/index.tsx | 9 +- components/Tracer/ExecutionStatus.tsx | 48 +++++- components/Tracer/index.tsx | 226 +++++++++++++++----------- context/cairoVMApiContext.tsx | 96 ++++++++++- 4 files changed, 274 insertions(+), 105 deletions(-) diff --git a/components/Editor/index.tsx b/components/Editor/index.tsx index 6c806a8..f5f67e0 100644 --- a/components/Editor/index.tsx +++ b/components/Editor/index.tsx @@ -18,6 +18,7 @@ import { useTheme } from 'next-themes' import { CairoVMApiContext, ProgramCompilationState, + ProgramDebugMode, ProgramExecutionState, } from 'context/cairoVMApiContext' import { Setting, SettingsContext } from 'context/settingsContext' @@ -63,6 +64,8 @@ const Editor = ({ readOnly = false }: Props) => { currentSierraVariables, sierraStatementsToCairoInfo, logs: apiLogs, + sierraSubStepNumber, + debugMode, } = useContext(CairoVMApiContext) const { addToConsoleLog, isThreeColumnLayout } = useContext(AppUiContext) @@ -406,7 +409,11 @@ const Editor = ({ readOnly = false }: Props) => { instructions={sierraStatements} codeType={codeType} activeIndexes={ - casmToSierraProgramMap[activeCasmInstructionIndex] ?? [] + debugMode === ProgramDebugMode.Sierra + ? sierraSubStepNumber !== undefined + ? [sierraSubStepNumber] + : [] + : casmToSierraProgramMap[activeCasmInstructionIndex] ?? [] } errorIndexes={ casmToSierraProgramMap[errorCasmInstructionIndex] ?? [] diff --git a/components/Tracer/ExecutionStatus.tsx b/components/Tracer/ExecutionStatus.tsx index 7d9f98f..c473777 100644 --- a/components/Tracer/ExecutionStatus.tsx +++ b/components/Tracer/ExecutionStatus.tsx @@ -1,14 +1,31 @@ +import { useContext, useId, useMemo } from 'react' + import { RiArrowGoForwardLine, RiArrowGoBackLine, RiPlayCircleLine, } from '@remixicon/react' import { Priority, useRegisterActions } from 'kbar' +import Select from 'react-select' + +import { CairoVMApiContext, ProgramDebugMode } from 'context/cairoVMApiContext' import { Button } from 'components/ui' import { TraceEntry } from '.' +type DebugModeOption = { + value: ProgramDebugMode + label: ProgramDebugMode +} + +const debugModeOptions: DebugModeOption[] = ( + Object.keys(ProgramDebugMode) as Array +).map((mode) => ({ + value: ProgramDebugMode[mode], + label: ProgramDebugMode[mode], +})) + const ExecutionStatus = ({ onStepIn, onStepOut, @@ -22,6 +39,16 @@ const ExecutionStatus = ({ trace: TraceEntry[] | undefined executionTraceStepNumber: number }) => { + const { debugMode, setDebugMode } = useContext(CairoVMApiContext) + + const debugModeValue: DebugModeOption = useMemo( + () => ({ + value: debugMode, + label: debugMode, + }), + [debugMode], + ) + const actions = [ { id: 'stepnext', @@ -61,14 +88,27 @@ const ExecutionStatus = ({ }, ] + const onChangeDebugMode = (option: DebugModeOption | null) => { + if (option) { + setDebugMode(option.value) + } + } + useRegisterActions(actions, [onStepIn, onStepOut, onContinueExecution]) return (
-
- - Execution Trace - +
+