Skip to content

Conversation

@anaPerezGhiglia
Copy link
Contributor

@anaPerezGhiglia anaPerezGhiglia commented Mar 28, 2025

Description

Expand debugger funcionality to support debugging test functions and configure an external oracle-resolver url.
This will allow to debug contract tests using the TXE as oracle resolver

Problem*

Resolves #5208

Summary*

  • Add the possibility to compile and debug a test function
  • Add a new config parameter to configure an external oracle resolver when debugging
  • REPL: execute the debugger in a separate thread than the repl cli
  • Add new Debug test codelens request. Related vscode-noir PR (feat(codelens): add debug test codelens manastech/vscode-noir#3))

Additional Context

Debugger changes

  • add test-name and oracle-resolver arg options to debugger (both repl and dap interfaces)
  • modify DebugForeignCallExecutor to support setting a resolver_url
  • modify the debugger to know how to compile a specific function that's not the main function
  • create a new DebugExecutionResult enum that represents the possible outcomes of debugging a program
  • modify the debugger to expose the execution result once the debug session ends
  • add the responsibility of analyzing the execution result once the debugger finishes with the execution to analyze whether the execution matches the test expectations (some test may be marked to should_fail)
  • convert ReplDebugger into AsyncReplDebugger
    • this involved spawining a new thread and communicating with the debugger through a mpsc channel
      • this implied moving some responsibility from the _cmd to the debugger mod, and from the repl to the context- like creating the Bn254BlackBoxSolver or restarting the debugging context
    • the async debugger entry points are defined by the DebugCommandAPI enum

Modifications in nargo module

  • extract logic of mapping a OpcodeResolutionError to an ExecutionError from nargo::ops::execute into a new function nargo::errors::execution_error_from. Use this new function in debugger::context and nargo::ops::execute
  • create a new nargo::ops::debug module. Extract reused debug functions into it.
    The moved functions are mostly about knowing how to compile or prepare the package for compiling for debugging. This also avoids generating inter-dependencies between debug_cmd and dap_cmd
  • extract check_crate_and_report_errors from check_cmd to nargo::ops since it was being used in different commands
  • make some test functions and structs public to be able to use them from debugger cli commands
    • make some nargo::ops::test functions public
    • create TestResult::new function to be able to construct one from dap
  • modify RPCForeignCallExecutor to apply workaround for RPCForeignCallExecutor fails on long delays between requests #7463

Modifications in noirc_frontend::debug module

  • Modify the DebugInstrumenter to instrument contract functions in addition to top-level functions

Observations

Documentation*

Check one:

  • No documentation needed.
  • Documentation included in this PR.
  • [For Experimental Features] Documentation to be submitted in a separate PR.

Evidence

REPL: Debug simple noir test function

image

REPL: Debug aztec contract test function

image

  • DAP + VsCode extension: Debug aztec contract test function*
dapDebuggerContractTest.mov

PR Checklist*

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt on default settings.

anaPerezGhiglia and others added 3 commits March 25, 2025 11:33
 - Add the possibility to compile and debug a test function
 - Add a new config parameter to configure an external oracle resolver when debugging
 - REPL: execute the debugger in a separate thread than the repl cli
 - Add new `Debug test` codelens request. Related vscode-noir PR (noir-lang/vscode-noir#100)

---------

Co-authored-by: Martin Verzilli <[email protected]>
@github-actions
Copy link
Contributor

Thank you for your contribution to the Noir language.

Please do not force push to this branch after the Noir team have started review of this PR. Doing so will only delay us merging your PR as we will need to start the review process from scratch.

Thanks for your understanding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Debugger should work with tests

1 participant