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 all 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
4 changes: 2 additions & 2 deletions gnovm/cmd/gno/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func testMainCaseRun(t *testing.T, tc []testMainCase) {
if r := recover(); r != nil {
output := fmt.Sprintf("%v", r)
t.Log("recover", output)
require.False(t, recoverShouldBeEmpty, "should panic")
require.False(t, recoverShouldBeEmpty, "should not panic")
require.True(t, errShouldBeEmpty, "should not return an error")
if test.recoverShouldContain != "" {
require.Regexpf(t, test.recoverShouldContain, output, "recover should contain")
Expand All @@ -100,7 +100,7 @@ func testMainCaseRun(t *testing.T, tc []testMainCase) {
}
checkOutputs(t)
} else {
require.True(t, recoverShouldBeEmpty, "should not panic")
require.True(t, recoverShouldBeEmpty, "should panic")
}
}()

Expand Down
31 changes: 28 additions & 3 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 @@ -97,12 +113,21 @@ func execRun(cfg *runCfg, args []string, io commands.IO) error {

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

defer m.Release()

// If the debug address is set, the debugger waits for a remote client to connect to it.
if cfg.debugAddr != "" {
if err := m.Debugger.Serve(cfg.debugAddr); err != nil {
return err
}
}

// run files
m.RunFiles(files...)
runExpr(m, cfg.expr)
Expand Down
8 changes: 8 additions & 0 deletions gnovm/cmd/gno/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ func TestRunApp(t *testing.T) {
args: []string{"run", "../../tests/integ/undefined_variable_test/undefined_variables_test.gno"},
recoverShouldContain: "--- preprocess stack ---", // should contain preprocess debug stack trace
},
{
args: []string{"run", "-debug", "../../tests/integ/debugger/sample.gno"},
stdoutShouldContain: "Welcome to the Gnovm debugger",
},
{
args: []string{"run", "-debug-addr", "invalidhost:17538", "../../tests/integ/debugger/sample.gno"},
errShouldContain: "listen tcp: lookup invalidhost",
},
// TODO: a test file
// TODO: args
// TODO: nativeLibs VS stdlibs
Expand Down
Loading
Loading