From 619766be16b4c41a65431dfa97da6079eab502f9 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Thu, 27 Jun 2024 11:14:44 +0200 Subject: [PATCH 01/25] feat: add "Debugging Gno Programs" post --- posts/2024-06-28-gno-debugger/README.md | 218 ++++++++++++++++++++++++ 1 file changed, 218 insertions(+) create mode 100644 posts/2024-06-28-gno-debugger/README.md diff --git a/posts/2024-06-28-gno-debugger/README.md b/posts/2024-06-28-gno-debugger/README.md new file mode 100644 index 0000000..16dbca6 --- /dev/null +++ b/posts/2024-06-28-gno-debugger/README.md @@ -0,0 +1,218 @@ +--- +title: "Debugging Gno Programs" +publication_date: 2024-06-28T13:37:00Z +slug: gno-debugger-blog-post +tags: [blog, post, tutorial, gno, debugger] +authors: [@mvertes] +--- +# Debugging Gno Programs + +In this article, we introduce the new Gno debugger feature and show how it can be used to better understand gno programs and help fixing bugs. + +## Motivation for a Gno debugger + +> Debugging is twice as hard as writing code. +> Brian Kerninghan, "The Elements of Programming Style" + +> On average, you spend about eight to ten times debugging as you do writing code. +> Anonymous + +Having a good debugger is important. But the Gno language is almost Go, and gnoland itself is entirely written in Go. Could I just use the existing Go tools, i.e. the [delve] debugger, to take control and debug my gno programs? + +You cannot debug your *gno* program this way because doing so would entail debugging the Gno virtual machine rather than your own program. The relevant state information would be opaque and would need to be reversed and reconstructed from internal Gno virtual machine data structures. + +The Gno debugger addresses this issue by displaying the state of the Gno program memory symbolically. It allows for control of program execution at the source code level, regardless of the virtual machine implementation. + +## Setting up + +The Gno debugger is fully integrated in the [gno] single binary, which is the tool required to build, test and run gno programs locally. + +There is no need to install a specific tool. You just have to install gno itself by: + +```shell= +git clone https://github.com/gnolang/gno +cd gno +go install ./gnovm/cmd/gno +``` + +We are now ready to play with gno programs. Let's consider a simple classical example as a target program, the computation of [Fibonacci numbers]: + +```go= +// fib.gno +package main + +// fib returns the nth number in the Fibonacci sequence. +func fib(n int) int { + if n < 2 { + return n + } + return fib(n-2) + fib(n-1) +} + +func main() { + println(fib(4)) +} + +``` +To execute this program, we run the command `gno run ./fib.gno`. To activate the debugger, we just pass the `-debug` flag: `gno run -debug ./fib.gno`. Use `gno run -help` to get more options if needed. + +## Quick tour of the debugger + +When you start a program under debug, you are greeted by a prompt allowing you to interact through the terminal: +```shell= +$ gno run -debug ./fib.gno +Welcome to the GnoVM debugger. type 'help' for list of commands. +dbg> +``` + +Entering `help` gives you the list of available commands and their short usage: + +```shell +dbg> help +The following commands are available: + +break|b [locspec] Set a breakpoint. +breakpoints|bp Print out info for active breakpoints. +clear [id] Delete breakpoint (all if no id). +continue|c Run until breakpoint or program termination. +detach Close debugger and resume program. +down [n] Move the current frame down by n (default 1). +exit|quit|q Exit the debugger and program. +help|h [command] Print the help message. +list|l [locspec] Show source code. +print|p Print a variable or expression. +stack|bt Print stack trace. +step|s Single step through program. +stepi|si Single step a single VM instruction. +up [n] Move the current frame up by n (default 1). + +Type help followed by a command for full documentation. +dbg> +``` + +If you have already used a debugger before, like [gdb] of [lldb] for C/C++ programs, or [delve] for Go programs, the Gno debugger should look familiar: the commands are similar in their syntax and their use. + +Those commands can be classified in the following categories: +- managing breakpoints: `break`, `breakpoints`, `clear`, +- controlling execution: `step`, `stepi`, `continue`, +- browse code, data and stack: `list`, `print`, `stack`, +- navigate the stack: `up`, `down`, +- quit the debugger: `detach`, `exit`. + +## Controlling and exploring the program state + +Let's go back to our Fibonacci program, still paused. We `step` a first time, which instructs the GnoVM to execute a single statement and give back control to the user: + +```shell +dbg> s +> main.main() main/./fib.gno:11:1 + 7: return n + 8: } + 9: return fib(n-2) + fib(n-1) + 10: } + 11: +=> 12: func main() { + 13: println(fib(4)) + 14: } +``` + +The first output line `> main.main() main/./fib.gno:11:1` indicates the precise current location in source code, followed by a short source listing around this location. The current line is indicated by the cursor `=>`. + +From there, we could repeat `step` commands to progress, but that would be too tedious. Instead, we set a breakpoint at an interesting line in the `fib` function, and `continue` to it directly: + +```shell +dbg> b 7 +Breakpoint 0 at main main/./fib.gno:7:1 +dbg> c +> main.fib() main/./fib.gno:7:10 + 2: package main + 3: + 4: // fib returns the nth number in the Fibonacci sequence. + 5: func fib(n int) int { + 6: if n < 2 { +=> 7: return n + 8: } + 9: return fib(n-2) + fib(n-1) + 10: } + 11: +dbg> +``` + +Note that we have used the short alias of commands: `b` for `break` and `c` for `continue`. We could also just provide the target line number instead of the full location including the file name, because the stay in the same source file. + +We can now examine the caller stack which indicates the successive nested function calls up to the current location: + +```shell +dbg> stack +0 in main.fib + at main/./fib.gno:7:10 +1 in main.fib + at main/./fib.gno:9:20 +2 in main.fib + at main/./fib.gno:9:20 +3 in main.main + at main/./fib.gno:13:2 +dbg> +``` +We see a call stack of depth 4, with call frames (local function contexts) numbered from 0 to 3, 0 being the current call level (the deepest). This information is crucial especially when debugging recursive functions like `fib`. We know that the caller and its caller were both `fib`. + +We want now to examine the value of the local parameter `n`, for each call level: +```shell! +dbg> print n +(0 int) +dbg> up +> main.fib() main/./fib.gno:7:10 +Frame 1: main/./fib.gno:9:20 + 4: // fib returns the nth number in the Fibonacci sequence. + 5: func fib(n int) int { + 6: if n < 2 { + 7: return n + 8: } +=> 9: return fib(n-2) + fib(n-1) + 10: } + 11: + 12: func main() { + 13: println(fib(4)) +dbg> print n +(2 int) +dbg> up +> main.fib() main/./fib.gno:7:10 +Frame 2: main/./fib.gno:9:20 + 4: // fib returns the nth number in the Fibonacci sequence. + 5: func fib(n int) int { + 6: if n < 2 { + 7: return n + 8: } +=> 9: return fib(n-2) + fib(n-1) + 10: } + 11: + 12: func main() { + 13: println(fib(4)) +dbg> print n +(4 int) +dbg> +``` +We see that the local value `n` is 0 at current frame 0, 2 at frame 1 and 4 at frame 2, which corresponds to the nested calls of `fib` expressed at line 9. + +With the stack navigation commands `up` and `down` the debugger is able to display the value of local function variables and parameters for the whole call chain. + +In this example, the `n` variable is simply an integer, but the `print` command is also able to handle more complex expressions to uncover the content of arbitrary maps, struct, arrays, etc using the same syntax as Go, for example as in `print a.b[n]` with a being a value of type: +```go= +var a struct { + b []string +} +``` +For security reasons, `print` command will only evaluate expressions with no side effects on the virtual machine state. For example it is not possible to perform an arithmetic operation like `print a + 2`, or to call a function like `printf f(6)`. + +## Conclusion + +We have introduced the new Gno debugger and presented its main capabilities. + +This is just the start of a new project, with a lot of room for improvement. The whole Gno project being open source, you are welcome not only to provide feedbacks and suggestions, but also to contribute at https://github.com/gnolang/gno. + + +[delve]: https://github.com/go-delve/delve +[gno]: https://github.com/gnolang/gno/tree/master/gnovm/cmd/gno +[Fibonacci numbers]: https://simple.wikipedia.org/wiki/Fibonacci_number +[gdb]: https://sourceware.org/gdb/ +[lldb]: https://lldb.llvm.org From a519e7a7ea63b465ab48653acc1ecaf42e069cea Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Mon, 1 Jul 2024 16:06:49 +0200 Subject: [PATCH 02/25] Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: Leon Hudak <33522493+leohhhn@users.noreply.github.com> --- posts/2024-06-28-gno-debugger/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/posts/2024-06-28-gno-debugger/README.md b/posts/2024-06-28-gno-debugger/README.md index 16dbca6..ddd1fb3 100644 --- a/posts/2024-06-28-gno-debugger/README.md +++ b/posts/2024-06-28-gno-debugger/README.md @@ -3,7 +3,7 @@ title: "Debugging Gno Programs" publication_date: 2024-06-28T13:37:00Z slug: gno-debugger-blog-post tags: [blog, post, tutorial, gno, debugger] -authors: [@mvertes] +authors: [mvertes] --- # Debugging Gno Programs From 20f3e7bd30238ada605dec2d086df7578d129348 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Mon, 1 Jul 2024 16:07:08 +0200 Subject: [PATCH 03/25] Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: Leon Hudak <33522493+leohhhn@users.noreply.github.com> --- posts/2024-06-28-gno-debugger/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/posts/2024-06-28-gno-debugger/README.md b/posts/2024-06-28-gno-debugger/README.md index ddd1fb3..6bdd3a8 100644 --- a/posts/2024-06-28-gno-debugger/README.md +++ b/posts/2024-06-28-gno-debugger/README.md @@ -17,7 +17,7 @@ In this article, we introduce the new Gno debugger feature and show how it can b > On average, you spend about eight to ten times debugging as you do writing code. > Anonymous -Having a good debugger is important. But the Gno language is almost Go, and gnoland itself is entirely written in Go. Could I just use the existing Go tools, i.e. the [delve] debugger, to take control and debug my gno programs? +Having a good debugger is important. But the Gno language is almost Go, and gno.land itself is entirely written in Go. Could I just use the existing Go tools, i.e. the [delve] debugger, to take control and debug my Gno programs? You cannot debug your *gno* program this way because doing so would entail debugging the Gno virtual machine rather than your own program. The relevant state information would be opaque and would need to be reversed and reconstructed from internal Gno virtual machine data structures. From 35a2dd92c0e5fbdba2752fdd2b0c18861d499ad1 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Mon, 1 Jul 2024 16:07:19 +0200 Subject: [PATCH 04/25] Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: Leon Hudak <33522493+leohhhn@users.noreply.github.com> --- posts/2024-06-28-gno-debugger/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/posts/2024-06-28-gno-debugger/README.md b/posts/2024-06-28-gno-debugger/README.md index 6bdd3a8..72f9dbc 100644 --- a/posts/2024-06-28-gno-debugger/README.md +++ b/posts/2024-06-28-gno-debugger/README.md @@ -19,7 +19,7 @@ In this article, we introduce the new Gno debugger feature and show how it can b Having a good debugger is important. But the Gno language is almost Go, and gno.land itself is entirely written in Go. Could I just use the existing Go tools, i.e. the [delve] debugger, to take control and debug my Gno programs? -You cannot debug your *gno* program this way because doing so would entail debugging the Gno virtual machine rather than your own program. The relevant state information would be opaque and would need to be reversed and reconstructed from internal Gno virtual machine data structures. +You cannot debug your *Gno* program this way because doing so would entail debugging the Gno virtual machine rather than your own program. The relevant state information would be opaque and would need to be reversed and reconstructed from internal Gno virtual machine data structures. The Gno debugger addresses this issue by displaying the state of the Gno program memory symbolically. It allows for control of program execution at the source code level, regardless of the virtual machine implementation. From c47fcb027ce2dc2b5bd0dc14baf4499947c7d4ae Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Mon, 1 Jul 2024 16:07:48 +0200 Subject: [PATCH 05/25] Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: Leon Hudak <33522493+leohhhn@users.noreply.github.com> --- posts/2024-06-28-gno-debugger/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/posts/2024-06-28-gno-debugger/README.md b/posts/2024-06-28-gno-debugger/README.md index 72f9dbc..490a334 100644 --- a/posts/2024-06-28-gno-debugger/README.md +++ b/posts/2024-06-28-gno-debugger/README.md @@ -25,7 +25,7 @@ The Gno debugger addresses this issue by displaying the state of the Gno program ## Setting up -The Gno debugger is fully integrated in the [gno] single binary, which is the tool required to build, test and run gno programs locally. +The Gno debugger is fully integrated in the [gno](https://docs.gno.land/gno-tooling/cli/gno-tooling-gno) single binary, which is the tool required to build, test and run gno programs locally. There is no need to install a specific tool. You just have to install gno itself by: From e4bf413cb9f729807c809ce22341d2cbd2f51d6f Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Mon, 1 Jul 2024 16:08:03 +0200 Subject: [PATCH 06/25] Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: Leon Hudak <33522493+leohhhn@users.noreply.github.com> --- posts/2024-06-28-gno-debugger/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/posts/2024-06-28-gno-debugger/README.md b/posts/2024-06-28-gno-debugger/README.md index 490a334..054af0c 100644 --- a/posts/2024-06-28-gno-debugger/README.md +++ b/posts/2024-06-28-gno-debugger/README.md @@ -27,7 +27,7 @@ The Gno debugger addresses this issue by displaying the state of the Gno program The Gno debugger is fully integrated in the [gno](https://docs.gno.land/gno-tooling/cli/gno-tooling-gno) single binary, which is the tool required to build, test and run gno programs locally. -There is no need to install a specific tool. You just have to install gno itself by: +There is no need to install a specific tool. You just have to install the `gno` tool itself with: ```shell= git clone https://github.com/gnolang/gno From a577adc895a6103bc2e3fd2dd0b89818ee872530 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Mon, 1 Jul 2024 16:08:21 +0200 Subject: [PATCH 07/25] Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: Leon Hudak <33522493+leohhhn@users.noreply.github.com> --- posts/2024-06-28-gno-debugger/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/posts/2024-06-28-gno-debugger/README.md b/posts/2024-06-28-gno-debugger/README.md index 054af0c..57dfad2 100644 --- a/posts/2024-06-28-gno-debugger/README.md +++ b/posts/2024-06-28-gno-debugger/README.md @@ -35,7 +35,7 @@ cd gno go install ./gnovm/cmd/gno ``` -We are now ready to play with gno programs. Let's consider a simple classical example as a target program, the computation of [Fibonacci numbers]: +We are now ready to play with Gno programs. Let's consider a simple classic example as a target program, the computation of [Fibonacci numbers]: ```go= // fib.gno From 0bd1d4fa56c1f95ac0c1918498bc0eb1725b038d Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Mon, 1 Jul 2024 16:08:45 +0200 Subject: [PATCH 08/25] Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: Leon Hudak <33522493+leohhhn@users.noreply.github.com> --- posts/2024-06-28-gno-debugger/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/posts/2024-06-28-gno-debugger/README.md b/posts/2024-06-28-gno-debugger/README.md index 57dfad2..a0805a9 100644 --- a/posts/2024-06-28-gno-debugger/README.md +++ b/posts/2024-06-28-gno-debugger/README.md @@ -1,7 +1,7 @@ --- title: "Debugging Gno Programs" publication_date: 2024-06-28T13:37:00Z -slug: gno-debugger-blog-post +slug: gno-debugger tags: [blog, post, tutorial, gno, debugger] authors: [mvertes] --- From e4b831d8ed47a116e985d25d6949abca03c06e00 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Mon, 1 Jul 2024 16:08:57 +0200 Subject: [PATCH 09/25] Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: Leon Hudak <33522493+leohhhn@users.noreply.github.com> --- posts/2024-06-28-gno-debugger/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/posts/2024-06-28-gno-debugger/README.md b/posts/2024-06-28-gno-debugger/README.md index a0805a9..16916a0 100644 --- a/posts/2024-06-28-gno-debugger/README.md +++ b/posts/2024-06-28-gno-debugger/README.md @@ -7,7 +7,7 @@ authors: [mvertes] --- # Debugging Gno Programs -In this article, we introduce the new Gno debugger feature and show how it can be used to better understand gno programs and help fixing bugs. +In this article, we introduce the new Gno debugger feature and show how it can be used to better understand Gno programs and help fixing bugs. ## Motivation for a Gno debugger From cad39f37d7d49878b030687a834c726394670744 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Sun, 21 Jul 2024 11:05:07 +0200 Subject: [PATCH 10/25] Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: deelawn --- posts/2024-06-28-gno-debugger/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/posts/2024-06-28-gno-debugger/README.md b/posts/2024-06-28-gno-debugger/README.md index 16916a0..c3befcb 100644 --- a/posts/2024-06-28-gno-debugger/README.md +++ b/posts/2024-06-28-gno-debugger/README.md @@ -7,7 +7,7 @@ authors: [mvertes] --- # Debugging Gno Programs -In this article, we introduce the new Gno debugger feature and show how it can be used to better understand Gno programs and help fixing bugs. +In this article, we introduce the new Gno debugger feature and show how it can be used to better understand Gno programs and help to fix bugs. ## Motivation for a Gno debugger From b9c7fb03d0d424421ce615c2a091b8feb8a94e57 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Sun, 21 Jul 2024 11:05:25 +0200 Subject: [PATCH 11/25] Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: deelawn --- posts/2024-06-28-gno-debugger/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/posts/2024-06-28-gno-debugger/README.md b/posts/2024-06-28-gno-debugger/README.md index c3befcb..834d288 100644 --- a/posts/2024-06-28-gno-debugger/README.md +++ b/posts/2024-06-28-gno-debugger/README.md @@ -25,7 +25,7 @@ The Gno debugger addresses this issue by displaying the state of the Gno program ## Setting up -The Gno debugger is fully integrated in the [gno](https://docs.gno.land/gno-tooling/cli/gno-tooling-gno) single binary, which is the tool required to build, test and run gno programs locally. +The Gno debugger is fully integrated in the [gno](https://docs.gno.land/gno-tooling/cli/gno-tooling-gno) binary, which is the tool required to build, test, and run Gno programs locally. There is no need to install a specific tool. You just have to install the `gno` tool itself with: From df35cff432becef87f7b66cc263d9053e60a7f02 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Sun, 21 Jul 2024 11:05:34 +0200 Subject: [PATCH 12/25] Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: deelawn --- posts/2024-06-28-gno-debugger/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/posts/2024-06-28-gno-debugger/README.md b/posts/2024-06-28-gno-debugger/README.md index 834d288..e688185 100644 --- a/posts/2024-06-28-gno-debugger/README.md +++ b/posts/2024-06-28-gno-debugger/README.md @@ -58,7 +58,7 @@ To execute this program, we run the command `gno run ./fib.gno`. To activate the ## Quick tour of the debugger -When you start a program under debug, you are greeted by a prompt allowing you to interact through the terminal: +When you start a program in debug mode, you are greeted by a prompt allowing you to interact with it via the terminal: ```shell= $ gno run -debug ./fib.gno Welcome to the GnoVM debugger. type 'help' for list of commands. From 5604a2f2adbd6a1c9a4b04694ab9f13bd5062fda Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Sun, 21 Jul 2024 11:06:01 +0200 Subject: [PATCH 13/25] Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: deelawn --- posts/2024-06-28-gno-debugger/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/posts/2024-06-28-gno-debugger/README.md b/posts/2024-06-28-gno-debugger/README.md index e688185..87d0d7b 100644 --- a/posts/2024-06-28-gno-debugger/README.md +++ b/posts/2024-06-28-gno-debugger/README.md @@ -90,7 +90,7 @@ Type help followed by a command for full documentation. dbg> ``` -If you have already used a debugger before, like [gdb] of [lldb] for C/C++ programs, or [delve] for Go programs, the Gno debugger should look familiar: the commands are similar in their syntax and their use. +If you have already used a debugger before, like [gdb] or [lldb] for C/C++ programs, or [delve] for Go programs, the Gno debugger should look familiar; the commands are similar in their syntax and usage. Those commands can be classified in the following categories: - managing breakpoints: `break`, `breakpoints`, `clear`, From 6e3336d443a9da51aaefbf8cc08ef1c21f1c7016 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Sun, 21 Jul 2024 11:06:15 +0200 Subject: [PATCH 14/25] Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: deelawn --- posts/2024-06-28-gno-debugger/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/posts/2024-06-28-gno-debugger/README.md b/posts/2024-06-28-gno-debugger/README.md index 87d0d7b..23dcc8b 100644 --- a/posts/2024-06-28-gno-debugger/README.md +++ b/posts/2024-06-28-gno-debugger/README.md @@ -92,7 +92,7 @@ dbg> If you have already used a debugger before, like [gdb] or [lldb] for C/C++ programs, or [delve] for Go programs, the Gno debugger should look familiar; the commands are similar in their syntax and usage. -Those commands can be classified in the following categories: +The commands can be classified in the following categories: - managing breakpoints: `break`, `breakpoints`, `clear`, - controlling execution: `step`, `stepi`, `continue`, - browse code, data and stack: `list`, `print`, `stack`, From cf75851228eed469fcb8247458eabce98ab947dd Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Sun, 21 Jul 2024 11:06:41 +0200 Subject: [PATCH 15/25] Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: deelawn --- posts/2024-06-28-gno-debugger/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/posts/2024-06-28-gno-debugger/README.md b/posts/2024-06-28-gno-debugger/README.md index 23dcc8b..8447d11 100644 --- a/posts/2024-06-28-gno-debugger/README.md +++ b/posts/2024-06-28-gno-debugger/README.md @@ -196,7 +196,7 @@ We see that the local value `n` is 0 at current frame 0, 2 at frame 1 and 4 at f With the stack navigation commands `up` and `down` the debugger is able to display the value of local function variables and parameters for the whole call chain. -In this example, the `n` variable is simply an integer, but the `print` command is also able to handle more complex expressions to uncover the content of arbitrary maps, struct, arrays, etc using the same syntax as Go, for example as in `print a.b[n]` with a being a value of type: +In this example, the `n` variable is simply an integer, but the `print` command is also able to handle more complex expressions to uncover the content of arbitrary maps, struct, arrays, etc using the same syntax as Go. For example, `print a.b[n]` will print as expected, with `a` being a value of type: ```go= var a struct { b []string From 83d99110594f26499ac30bb8faf026cf5e48b36e Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Sun, 21 Jul 2024 11:09:31 +0200 Subject: [PATCH 16/25] Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: deelawn --- posts/2024-06-28-gno-debugger/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/posts/2024-06-28-gno-debugger/README.md b/posts/2024-06-28-gno-debugger/README.md index 8447d11..7837698 100644 --- a/posts/2024-06-28-gno-debugger/README.md +++ b/posts/2024-06-28-gno-debugger/README.md @@ -202,7 +202,7 @@ var a struct { b []string } ``` -For security reasons, `print` command will only evaluate expressions with no side effects on the virtual machine state. For example it is not possible to perform an arithmetic operation like `print a + 2`, or to call a function like `printf f(6)`. +For security reasons, the `print` command will only evaluate expressions with no side effects on the virtual machine state. For example, it is not possible to perform an arithmetic operation like `print a + 2`, or to call a function like `printf f(6)`. ## Conclusion From 0d3e044a70e69c91de84a758c5186197d6d1f645 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Sun, 21 Jul 2024 11:16:56 +0200 Subject: [PATCH 17/25] Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: deelawn --- posts/2024-06-28-gno-debugger/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/posts/2024-06-28-gno-debugger/README.md b/posts/2024-06-28-gno-debugger/README.md index 7837698..c442c3d 100644 --- a/posts/2024-06-28-gno-debugger/README.md +++ b/posts/2024-06-28-gno-debugger/README.md @@ -15,7 +15,8 @@ In this article, we introduce the new Gno debugger feature and show how it can b > Brian Kerninghan, "The Elements of Programming Style" > On average, you spend about eight to ten times debugging as you do writing code. -> Anonymous +> +> -- Anonymous Having a good debugger is important. But the Gno language is almost Go, and gno.land itself is entirely written in Go. Could I just use the existing Go tools, i.e. the [delve] debugger, to take control and debug my Gno programs? From 169344e089a532c63fa167b64031d062ae7d1ba3 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Sun, 21 Jul 2024 11:17:08 +0200 Subject: [PATCH 18/25] Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: deelawn --- posts/2024-06-28-gno-debugger/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/posts/2024-06-28-gno-debugger/README.md b/posts/2024-06-28-gno-debugger/README.md index c442c3d..e865abe 100644 --- a/posts/2024-06-28-gno-debugger/README.md +++ b/posts/2024-06-28-gno-debugger/README.md @@ -12,7 +12,8 @@ In this article, we introduce the new Gno debugger feature and show how it can b ## Motivation for a Gno debugger > Debugging is twice as hard as writing code. -> Brian Kerninghan, "The Elements of Programming Style" +> +> -- Brian Kerninghan, "The Elements of Programming Style" > On average, you spend about eight to ten times debugging as you do writing code. > From 0502d8b9354a3b7c3f1586afdf5b52cee25e2a8d Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Sun, 21 Jul 2024 11:42:00 +0200 Subject: [PATCH 19/25] fix code section delimiters --- posts/2024-06-28-gno-debugger/README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/posts/2024-06-28-gno-debugger/README.md b/posts/2024-06-28-gno-debugger/README.md index e865abe..59d5112 100644 --- a/posts/2024-06-28-gno-debugger/README.md +++ b/posts/2024-06-28-gno-debugger/README.md @@ -31,7 +31,7 @@ The Gno debugger is fully integrated in the [gno](https://docs.gno.land/gno-tool There is no need to install a specific tool. You just have to install the `gno` tool itself with: -```shell= +```shell git clone https://github.com/gnolang/gno cd gno go install ./gnovm/cmd/gno @@ -39,7 +39,7 @@ go install ./gnovm/cmd/gno We are now ready to play with Gno programs. Let's consider a simple classic example as a target program, the computation of [Fibonacci numbers]: -```go= +```go // fib.gno package main @@ -61,7 +61,7 @@ To execute this program, we run the command `gno run ./fib.gno`. To activate the ## Quick tour of the debugger When you start a program in debug mode, you are greeted by a prompt allowing you to interact with it via the terminal: -```shell= +```shell $ gno run -debug ./fib.gno Welcome to the GnoVM debugger. type 'help' for list of commands. dbg> @@ -159,7 +159,7 @@ dbg> We see a call stack of depth 4, with call frames (local function contexts) numbered from 0 to 3, 0 being the current call level (the deepest). This information is crucial especially when debugging recursive functions like `fib`. We know that the caller and its caller were both `fib`. We want now to examine the value of the local parameter `n`, for each call level: -```shell! +```shell dbg> print n (0 int) dbg> up @@ -199,7 +199,7 @@ We see that the local value `n` is 0 at current frame 0, 2 at frame 1 and 4 at f With the stack navigation commands `up` and `down` the debugger is able to display the value of local function variables and parameters for the whole call chain. In this example, the `n` variable is simply an integer, but the `print` command is also able to handle more complex expressions to uncover the content of arbitrary maps, struct, arrays, etc using the same syntax as Go. For example, `print a.b[n]` will print as expected, with `a` being a value of type: -```go= +```go var a struct { b []string } From a000923d72f0d08ee6fe7d0f178d583f7344fd21 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Mon, 22 Jul 2024 13:43:50 +0200 Subject: [PATCH 20/25] Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: deelawn --- posts/2024-06-28-gno-debugger/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/posts/2024-06-28-gno-debugger/README.md b/posts/2024-06-28-gno-debugger/README.md index 59d5112..8fbe897 100644 --- a/posts/2024-06-28-gno-debugger/README.md +++ b/posts/2024-06-28-gno-debugger/README.md @@ -140,7 +140,7 @@ dbg> c dbg> ``` -Note that we have used the short alias of commands: `b` for `break` and `c` for `continue`. We could also just provide the target line number instead of the full location including the file name, because the stay in the same source file. +Note that we have used the short alias of commands: `b` for `break` and `c` for `continue`. We only need to specify the line number when setting the break point here, due to it being in the same file. Setting break points in other files requires specifying the full file path and line number. We can now examine the caller stack which indicates the successive nested function calls up to the current location: From 8af81c29be16039df163cfaa255815fac5ac4971 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Mon, 22 Jul 2024 13:44:12 +0200 Subject: [PATCH 21/25] Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: deelawn --- posts/2024-06-28-gno-debugger/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/posts/2024-06-28-gno-debugger/README.md b/posts/2024-06-28-gno-debugger/README.md index 8fbe897..d6db71f 100644 --- a/posts/2024-06-28-gno-debugger/README.md +++ b/posts/2024-06-28-gno-debugger/README.md @@ -142,7 +142,7 @@ dbg> Note that we have used the short alias of commands: `b` for `break` and `c` for `continue`. We only need to specify the line number when setting the break point here, due to it being in the same file. Setting break points in other files requires specifying the full file path and line number. -We can now examine the caller stack which indicates the successive nested function calls up to the current location: +We can now examine the call stack which indicates the successive nested function calls up to the current location: ```shell dbg> stack From ec50647f641513ad1ee8401ef5d765099c8cf5b7 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Mon, 22 Jul 2024 13:44:44 +0200 Subject: [PATCH 22/25] Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: deelawn --- posts/2024-06-28-gno-debugger/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/posts/2024-06-28-gno-debugger/README.md b/posts/2024-06-28-gno-debugger/README.md index d6db71f..04a0aa4 100644 --- a/posts/2024-06-28-gno-debugger/README.md +++ b/posts/2024-06-28-gno-debugger/README.md @@ -156,7 +156,7 @@ dbg> stack at main/./fib.gno:13:2 dbg> ``` -We see a call stack of depth 4, with call frames (local function contexts) numbered from 0 to 3, 0 being the current call level (the deepest). This information is crucial especially when debugging recursive functions like `fib`. We know that the caller and its caller were both `fib`. +We see a call stack of depth 4, with call frames (local function contexts) numbered from 0 to 3, 0 being the current call level (the deepest). This information is crucial, especially when debugging recursive functions like `fib`. We know that the caller and its caller were both `fib`. We want now to examine the value of the local parameter `n`, for each call level: ```shell From fb6a7b00ac425580755f6a44e3a62413be465e7a Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Mon, 22 Jul 2024 13:45:07 +0200 Subject: [PATCH 23/25] Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: deelawn --- posts/2024-06-28-gno-debugger/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/posts/2024-06-28-gno-debugger/README.md b/posts/2024-06-28-gno-debugger/README.md index 04a0aa4..764ae30 100644 --- a/posts/2024-06-28-gno-debugger/README.md +++ b/posts/2024-06-28-gno-debugger/README.md @@ -158,7 +158,7 @@ dbg> ``` We see a call stack of depth 4, with call frames (local function contexts) numbered from 0 to 3, 0 being the current call level (the deepest). This information is crucial, especially when debugging recursive functions like `fib`. We know that the caller and its caller were both `fib`. -We want now to examine the value of the local parameter `n`, for each call level: +Now we want to examine the value of the local parameter `n`, for each call level: ```shell dbg> print n (0 int) From 1c992c2ff4d815d8fd98a84a386b1480e882b623 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Mon, 22 Jul 2024 13:45:25 +0200 Subject: [PATCH 24/25] Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: deelawn --- posts/2024-06-28-gno-debugger/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/posts/2024-06-28-gno-debugger/README.md b/posts/2024-06-28-gno-debugger/README.md index 764ae30..20c9af6 100644 --- a/posts/2024-06-28-gno-debugger/README.md +++ b/posts/2024-06-28-gno-debugger/README.md @@ -196,7 +196,7 @@ dbg> ``` We see that the local value `n` is 0 at current frame 0, 2 at frame 1 and 4 at frame 2, which corresponds to the nested calls of `fib` expressed at line 9. -With the stack navigation commands `up` and `down` the debugger is able to display the value of local function variables and parameters for the whole call chain. +The `up` and `down` stack navigation commands enable the debugger to display the value of local function variables and parameters for the whole call chain. In this example, the `n` variable is simply an integer, but the `print` command is also able to handle more complex expressions to uncover the content of arbitrary maps, struct, arrays, etc using the same syntax as Go. For example, `print a.b[n]` will print as expected, with `a` being a value of type: ```go From 08070d5c4cbc7b1f2ccb495526b1af987e8bec73 Mon Sep 17 00:00:00 2001 From: Leon Hudak <33522493+leohhhn@users.noreply.github.com> Date: Mon, 5 Aug 2024 17:25:48 +0200 Subject: [PATCH 25/25] Apply suggestions from code review --- posts/2024-06-28-gno-debugger/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/posts/2024-06-28-gno-debugger/README.md b/posts/2024-06-28-gno-debugger/README.md index 20c9af6..06f28bf 100644 --- a/posts/2024-06-28-gno-debugger/README.md +++ b/posts/2024-06-28-gno-debugger/README.md @@ -97,9 +97,9 @@ If you have already used a debugger before, like [gdb] or [lldb] for C/C++ progr The commands can be classified in the following categories: - managing breakpoints: `break`, `breakpoints`, `clear`, - controlling execution: `step`, `stepi`, `continue`, -- browse code, data and stack: `list`, `print`, `stack`, -- navigate the stack: `up`, `down`, -- quit the debugger: `detach`, `exit`. +- browsing code, data and stack: `list`, `print`, `stack`, +- navigating the stack: `up`, `down`, +- quitting the debugger: `detach`, `exit`. ## Controlling and exploring the program state