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

feat: add an interactive debugger to GnoVM #1563

Merged
merged 42 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
21832ab
feat: and an interactive debugger to GnoVM
mvertes Jan 19, 2024
6d55061
Determine location in source from VM current state. Improve comments.
mvertes Jan 25, 2024
103ae9a
add list command to print current source code.
mvertes Jan 25, 2024
0cd9c23
Implement step command, to single step through program.
mvertes Jan 30, 2024
80b17c4
Implement breakpoint setting, listing and clearing.
mvertes Jan 30, 2024
8169086
Fix breakpoint setting with empty file.
mvertes Jan 30, 2024
f74fd61
Implement 'stack' command to print the call stack.
mvertes Jan 31, 2024
55d89de
Improve stack trace
mvertes Feb 1, 2024
f5e13d7
Implement 'up' and 'down' command to navigate the call stack.
mvertes Feb 1, 2024
071b4be
Implement 'print' command to print a symbol value.
mvertes Feb 1, 2024
2a64081
Remove dependency on log package.
mvertes Feb 1, 2024
a7c3876
Improve comment and function naming to address feedback from @go7066
mvertes Feb 2, 2024
c302790
Add unit tests for debugger
mvertes Feb 6, 2024
66ace69
Fix scope issues when for stack and print commands.
mvertes Feb 9, 2024
3976c57
Implement a go expression parser for the 'print' command.
mvertes Feb 16, 2024
0ac45cb
Harden line scanning. Ignore lines starting by '#' (comments).
mvertes Feb 18, 2024
7455761
simplify debug command names sorting
mvertes Mar 28, 2024
49149cc
Revert "simplify debug command names sorting"
mvertes Mar 28, 2024
11f51de
Address review feedback. No semantic change.
mvertes Apr 4, 2024
9fd850c
Merge branch 'master' into debugger
mvertes Apr 4, 2024
d4cda36
fix typo
mvertes Apr 4, 2024
c7e14a6
fix thelper lint
mvertes Apr 4, 2024
860d8bc
simplify after bump to go1.21
mvertes Apr 4, 2024
7fe0fec
move debugger_test.go in pkg/gnolang to improve test coverage
mvertes Apr 5, 2024
a8edb0a
improve test coverage
mvertes Apr 5, 2024
79096ba
fix test
mvertes Apr 6, 2024
e4ebcc7
fix: add boundary check for list
mvertes Apr 11, 2024
445c565
fix printing literal string and rune. Allow space in debug args.
mvertes Apr 24, 2024
26dd6a3
typos
mvertes Apr 24, 2024
a69a496
revert alternate debugPrint
mvertes Apr 24, 2024
3b19e1a
fix list and break commands when source file is not set
mvertes Apr 25, 2024
e573bb4
fix previous
mvertes Apr 25, 2024
dfb202e
Merge branch 'master' into debugger
mvertes Apr 29, 2024
98d9b1f
fix: don not panic in case of error of remote debugger connection
mvertes May 6, 2024
3fad6b9
fix: lookup values in if body. Do not panic if debug expr error.
mvertes May 10, 2024
a6700bf
fix test
mvertes May 10, 2024
1d4bc06
fix printing values in a external package
mvertes May 13, 2024
a7a2602
fix: no need to embed the Debugger in Machine. Explicit is ok.
mvertes May 13, 2024
50c3edf
Merge branch 'master' into debugger
mvertes May 13, 2024
9557a26
Merge branch 'master' into debugger
thehowl May 14, 2024
dc77bed
Merge branch 'master' into debugger
thehowl May 14, 2024
1c52ee6
fix invalid test
thehowl May 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions gnovm/cmd/gno/debug_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package main

import (
"bytes"
"context"
"strings"
"testing"

"github.com/gnolang/gno/tm2/pkg/commands"
)

type dtest struct{ in, out string }

const debugTarget = "../../tests/integ/debugger/sample.gno"

func runDebugTest(t *testing.T, tests []dtest) {
args := []string{"run", "-debug", debugTarget}

for _, test := range tests {
test := test
t.Run("", func(t *testing.T) {
out := bytes.NewBufferString("")
err := bytes.NewBufferString("")
io := commands.NewTestIO()
io.SetIn(bytes.NewBufferString(test.in))
io.SetOut(commands.WriteNopCloser(out))
io.SetErr(commands.WriteNopCloser(err))
if err := newGnocliCmd(io).ParseAndRun(context.Background(), args); err != nil {
t.Fatal(err)
}
t.Log("in:", test.in, "out:", out)
if !strings.Contains(out.String(), test.out) {
t.Errorf("result does not contain \"%s\", got \"%s\"", test.out, out.String())
}
})
}
}

func TestDebug(t *testing.T) {
brk := "break " + debugTarget + ":7\n"
cont := brk + "continue\n"

runDebugTest(t, []dtest{
{in: "", out: "Welcome to the Gnovm debugger. Type 'help' for list of commands."},
{in: "help\n", out: "The following commands are available"},
{in: "h\n", out: "The following commands are available"},
{in: "help h\n", out: "Print the help message."},
{in: "list " + debugTarget + ":1\n", out: "1: // This is a sample target"},
{in: brk, out: "Breakpoint 0 at main "},
{in: cont, out: "=> 7: println(name, i)"},
{in: cont + "stack\n", out: "2 in main.main"},
{in: cont + "up\n", out: "=> 11: f(s, n)"},
{in: cont + "print name\n", out: `("hello" string)`},
{in: cont + "p i\n", out: `(3 int)`},
mvertes marked this conversation as resolved.
Show resolved Hide resolved
})
}
32 changes: 26 additions & 6 deletions gnovm/cmd/gno/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ import (
)

type runCfg struct {
verbose bool
rootDir string
expr string
verbose bool
rootDir string
expr string
debug bool
debugAddr string
}

func newRunCmd(io commands.IO) *commands.Command {
Expand Down Expand Up @@ -58,6 +60,20 @@ func (c *runCfg) RegisterFlags(fs *flag.FlagSet) {
"main()",
"value of expression to evaluate. Defaults to executing function main() with no args",
)

fs.BoolVar(
&c.debug,
"debug",
false,
"enable interactive debugger using stdin and stdout",
)

fs.StringVar(
&c.debugAddr,
"debug-addr",
mvertes marked this conversation as resolved.
Show resolved Hide resolved
"",
"enable interactive debugger using tcp address in the form [host]:port",
)
}

func execRun(cfg *runCfg, args []string, io commands.IO) error {
Expand Down Expand Up @@ -96,10 +112,14 @@ func execRun(cfg *runCfg, args []string, io commands.IO) error {
}

m := gno.NewMachineWithOptions(gno.MachineOptions{
PkgPath: string(files[0].PkgName),
Output: stdout,
Store: testStore,
PkgPath: string(files[0].PkgName),
Output: stdout,
Store: testStore,
Debug: cfg.debug || cfg.debugAddr != "",
DebugAddr: cfg.debugAddr,
})
m.DebugIn = stdin
m.DebugOut = stdout

defer m.Release()

Expand Down
Loading
Loading