gno icon indicating copy to clipboard operation
gno copied to clipboard

feat: add an interactive debugger to GnoVM

Open mvertes opened this issue 1 year ago • 2 comments

gno-debug

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

Contributors' checklist...
  • [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, if any. More info here.

mvertes avatar Jan 19 '24 14:01 mvertes

I have found some issues when computing the stack from a non func block (like if or for body).

I also found some issues when printing a global var.

I would like also to set a test suite for the various debugger commands and in the various possible contexts such as the ones mentioned above. That requires a bit more work, maybe in a new PR (still pondering).

mvertes avatar Feb 02 '24 11:02 mvertes

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 48.43%. Comparing base (977a3f4) to head (50c3edf).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1563      +/-   ##
==========================================
- Coverage   55.01%   48.43%   -6.58%     
==========================================
  Files         481      409      -72     
  Lines       67432    61940    -5492     
==========================================
- Hits        37097    30001    -7096     
- Misses      27318    29442    +2124     
+ Partials     3017     2497     -520     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Apr 04 '24 10:04 codecov[bot]

Yes @thehowl, I will now look at unifying common parts as you suggest. Thanks for your thorough review and useful suggestions.

mvertes avatar May 14 '24 20:05 mvertes