Skip to content

Feature: Implement a Step-by-Step Debugger with Breakpoint Support #16

@Sansi-28

Description

@Sansi-28

To be a truly powerful educational tool, KidCode needs a debugger. This would allow users to pause execution, inspect the state of variables, and step through their code line by line to understand how it works.

Building this feature requires significant changes to the execution loop and state management.

Proposed Plan:

  1. Introduce an ExecutionContext:

    • Create a class that holds the state of an execution: PAUSED, RUNNING, STEPPING, TERMINATED.
    • The KidCodeEngine and Evaluator must be aware of this context. The stop signal Supplier<Boolean> should be enhanced or replaced by this context object.
  2. Modify the Evaluator for Pausing:

    • The Evaluator must check the ExecutionContext state before executing each Statement.
    • If the state is PAUSED (e.g., at a breakpoint), the execution thread must wait(). It will be resumed by an external signal (notify()).
    • If the state is STEPPING, it should execute one statement and then immediately re-enter the PAUSED state.
  3. Breakpoint Management:

    • The UI (web and desktop) needs a way for users to set breakpoints on specific line numbers.
    • This information (Set<Integer> breakpoints) must be passed to the KidCodeEngine at the start of execution.
    • Before executing a statement, the Evaluator must check if the current statement's line number is in the set of breakpoints. If so, it transitions the ExecutionContext to PAUSED.
  4. Variable Inspection:

    • When paused, the UI needs a way to request the current state of all variables.
    • This requires adding a method to the Environment to dump all key-value pairs in the current scope. An API endpoint or WebSocket message would be needed to fetch this data from a paused execution context.
  5. UI Controls:

    • The desktop and web UIs need new buttons: "Debug", "Continue", "Step Over", "Stop".
    • These buttons will interact with the ExecutionContext to change its state (e.g., "Continue" sets the state to RUNNING and notifies the waiting thread).

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions