Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add an interactive debugger to GnoVM (#1563)
![gno-debug](https://github.com/gnolang/gno/assets/5792239/96c50686-df6c-4dd8-a1d1-63f787a9328d) We provide here an embedded interactive debugger to let the user control and inspect its program at symbolic level, with the same features and commands as classical debuggers: gdb, lldb or delve. The debugger is enabled by setting the `-debug` flag in `gno run` command, which loads the target program and immediately shows a debugger prompt on the console: $ gno run -debug /tmp/my-program.gno Welcome to the Gnovm debugger. Type 'help' for list of commands. dbg> Providing `-debug-addr` flag allows to start a remote debugging session, and not interfer with the program stdin and stdout. For example, in a first terminal: $ gno run -debug-addr :4000 /tmp/my-program.gno Waiting for debugger client to connect at :4000 And in a second terminal, using a netcat like nc(1): $ nc localhost 4000 Welcome to the Gnovm debugger. Type 'help' for list of commands. dbg> The debugger works by intercepting each execution step at virtual machine level (each iteration within `Machine.Run` loop) to a callback, which in turns can provide a debugger command REPL or check if the execution can proceed to the next step, etc. The general logic and structure is there. It is possible to `continue`, `stepi`, `detach`, `print`, `stack`, etc and get a general feedback of the user experience and the impact on the code. Efforts are made to make this feature minimally intrusive in the actual VM, and not interfering when the debugger is not used. It is planned shortly after this PR is integrated to add the capacity to attach to an already running program, and to taylor the data format for existing debugging environments such as VScode, etc, as demand arises. Resolves gnolang/hackerspace#54 <!-- please provide a detailed description of the changes made in this pull request. --> <details><summary>Contributors' checklist...</summary> - [x] Added new tests, or not needed, or not feasible - [x] Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory - [x] Updated the official documentation or not needed - [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message was included in the description - [x] Added references to related issues and PRs - [x] Provided any useful hints for running manual tests - [ ] Added new benchmarks to [generated graphs](https://gnoland.github.io/benchmarks), if any. More info [here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md). </details> --------- Co-authored-by: Morgan <morgan@morganbaz.com>
- Loading branch information