Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Epic: Implement Noir debugger #3094

Open
13 tasks done
dmvict opened this issue Oct 11, 2023 · 5 comments
Open
13 tasks done

Epic: Implement Noir debugger #3094

dmvict opened this issue Oct 11, 2023 · 5 comments
Labels
enhancement New feature or request

Comments

@dmvict
Copy link
Contributor

dmvict commented Oct 11, 2023

Problem

This is a tracking issue for the implementation of a alternative debugger for Noir. As the base implementation I get debugger from #3015.

Codebase

The codebase of the debugger is placed in my fork. Visit branch debugger to check it.

I opened no PR for now. You can get diffs using link. I'll open a PR after discussion and approve.

Features

The debugger have next features:

  • it is oriented on debugger adapter protocol (DAP) and it uses crate dap to provide compatible interface
  • it compiles and debugs brillig bytecode using brillig_vm as the executor
  • it has dap and repl implementations. The differences between them in implementation of dap server. For repl implementation I wrote custom (mock) server that communicates with stdin and maps commands into dap requests.

The repo has no proper way to compile brillig bytecode. I modified two crates to get brillig bytecode for noir programs. The changes are quite unstable. I checked compiled bytecode for a few simple noir programs and it seems to be correct.

State of work

General

  • basic compilation of brillig bytecode
  • advanced compilation. Program compiles into brillig bytecode but it has non handled opcode in the end of each program. I need to solve it. Also I'm going to handle inputs like acvm realization
  • basic dap implementation
  • basic repl implementation
  • improved dap and repl implementations
  • documentation
  • tests

Dap realization

  • Advanced handling of noir modules (like debugger from issue)
  • Advanced handling of commands
  • TS plugin for VSCode

Repl realization

  • Advanced handling of noir modules (like debugger from issue)
  • Advanced handling of commands
  • Improved output

Any ideas and wants are welcome and can be considered, just comment here!

Happy Case

I think happy case for the debuggers is to combine them into single app. The app will provide single interface for both targets.

We cannot combine apps with no additional work. I guess it would be better to use the scheme:

Of course, the scheme can be reverted and @mverzilli can get my version and combine it into single debugger app.

How I see the CLI interface:

  • additional option to choose the bytecode target like --vm brillig. Default is acvm.

How I see the IDE interface:

  • additional option in plugin setup. The VSCode has json file for plugin setup, it will have field "vm": "acvm". And I think, we should provide some kind of switch button to choose the target but first implementation would use only config file.

Alternatives Considered

No response

Additional Context

No response

Would you like to submit a PR for this Issue?

No

Support Needs

No response

@dmvict dmvict added the enhancement New feature or request label Oct 11, 2023
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Oct 11, 2023
@TomAFrench TomAFrench changed the title feat: Implement Noir debugger Epic: Implement Noir debugger Oct 11, 2023
@dmvict
Copy link
Contributor Author

dmvict commented Nov 2, 2023

Hello everyone.

I got ready repl version and not tested but written dap version of debugger.

I'm going to open a PR and I'll mention the issue in the PR description. The PR is a good point to improve the codebase and UX. I'm going to work with dap version of debugger after opening the PR.

The main features (can be duplicated with the previous message):

  • debugs noir binary modules
  • compiles and debugs brillig bytecode
  • support inputs from prover file
  • support repl and dap version of program (the feature dap is used)
  • designed to be extended by acvm version of debugger

The main points to discuss:

  • name of crate can be changed
  • as I said before, I modified two compiler crates to get compiled brillig bytecode. I checked no new code, but it can contains the desired features, If you know such changes, notify me please. Here is diff. The last commit I'll delete later.
  • the file compile.rs has some duplicated code to provide required functionality with no changes in codebase
  • I implemented only integration tests. If you find non covered critical code I'm ready to add unit/integration tests for it.
  • improve repl by help messages, breackpoints, etc.
  • integration of repl into nargo binary
    Any additional reviews/question will be helpful.

How to try repl version

You can try the repl version of debugger.
The steps:

  • clone repo https://github.com/dmvict/noir
    git clone https://github.com/dmvict/noir.git
  • switch to a_debugger branch
    git switch -c a_debugger origing/a_debugger
  • build app in release mode
    cargo build -p noirc_dbg --release
  • navigate to noir binary app directory, for example
    cd tooling/nargo_dbg/tests/simple/
  • run app
    ../../../../target/release/noirc_dbg
  • load program
    type l and Enter
    You can skip the asked path or type '.' and press Enter
    In the future the app will ask about vm type.

To debug program use
s - step
c - run to the end
r - registers
m - memory
d - opcodes (compiled program)
q - quit

@dmvict
Copy link
Contributor Author

dmvict commented Nov 22, 2023

Hello everyone

I added support of dap and marked pr #3404 as ready for review.
I need feedback about implementation.
Here is a gif with demonstration of work.
Peek 2023-11-22 11-00

Since the dap is a binary the ts adapter code is very small. But I spent a lot of time to get it working.

If you want to try the debugger in your editor follow next steps please:

  • clone repo https://github.com/dmvict/noir
    git clone https://github.com/dmvict/noir.git
  • switch to a_debugger branch
    git switch -c a_debugger origing/a_debugger
  • build app in release mode
    cargo build -p noirc_dbg --features dap --release
  • navigate to plugin directory and build adapter
    cd tooling/noirc_dbg/vs_plugin && npm run esbuild-base
  • copy binary to plugin directory from root of repository
    mkdir tooling/noirc_dbg/vs_plugin/out/ && cp target/release/noirc_dbg tooling/noirc_dbg/vs_plugin/out/
  • open editor and install the plugin from developer panel
  • try debugger in editor

@mverzilli
Copy link
Contributor

Hi @dmvict! We're working on extending the official Noir VS Code plugin with debugger capabilities here: noir-lang/vscode-noir@master...manastech:vscode-noir:dap-support

Embedding a DAP server in Nargo here: master...manastech:noir:dap

In parallel, we're working heavily on instrumenting the compiler to make source level variable inspection possible, see here: #3523

There's also work going on https://github.com/manastech/noir/tree/feature/wasm-debugger to expose the same debugger capabilities to JS runtimes via WASM. This is so eventually not only binaries but also contracts are debuggable.

Our respective approaches have diverged substantially and at the moment I'm not sure how we can converge into a single solution.

We're now starting to integrate the work on variable inspection with the DAP server. Hopefully once we have that down there will be some more clarity, but I wanted to raise this to your attention 🙏

@dmvict
Copy link
Contributor Author

dmvict commented Nov 24, 2023

Hello @mverzilli

Good work. I'll look at the changes later.

I believe we will be able to integrate the changes. It's my happy case.

github-merge-queue bot pushed a commit that referenced this issue Dec 19, 2023
# Description

Implements the DAP protocol to allow a tool such as VS.Code to drive the
debugger in a Noir binary project. A separate PR for the [VS.Code Noir
extension](https://github.com/noir-lang/vscode-noir) will be submitted
later.

## Problem

Part of #3015 

The beginning of this implementation was heavily inspired by @dmvict
[implementation](#3094) of an
alternative debugger for Noir programs.

## Summary

This PR implements a new `nargo` subcommand `dap`. This starts a DAP
server in single session mode through stdin/stdout and waits for a
launch request. Using the arguments in the launch request
(`projectFolder`, and optionally `package` and `proverName`) it compiles
the Noir binary package and starts it in debug mode. Through DAP
requests, a tool can then step through the program, set breakpoints and
list the generated opcodes using a disassemble request.

## Additional Context



## Documentation

Check one:
- [ ] No documentation needed.
- [ ] Documentation included in this PR.
- [X] **[Exceptional Case]** Documentation to be submitted in a separate
PR.

# PR Checklist\*

- [X] I have tested the changes locally.
- [X] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.

---------

Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
@mverzilli
Copy link
Contributor

Hi @dmvict! The debugger is now shipping with Nargo, as well as the VS Code official extension, you can check the preview docs here: https://noir-lang.org/docs/dev/tooling/debugger

I think it would make sense to close this PR, and open new ones building upon the work on master if you want to add new features to the debugger 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: 📋 Backlog
Development

No branches or pull requests

2 participants