From 01d47d75eb632b87e5988d542a457252722c388f Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Tue, 6 Aug 2024 12:31:59 +0200 Subject: [PATCH 1/5] feat: add "Debugging Gno Programs" post (#100) * feat: add "Debugging Gno Programs" post * Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: Leon Hudak <33522493+leohhhn@users.noreply.github.com> * Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: Leon Hudak <33522493+leohhhn@users.noreply.github.com> * Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: Leon Hudak <33522493+leohhhn@users.noreply.github.com> * Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: Leon Hudak <33522493+leohhhn@users.noreply.github.com> * Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: Leon Hudak <33522493+leohhhn@users.noreply.github.com> * Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: Leon Hudak <33522493+leohhhn@users.noreply.github.com> * Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: Leon Hudak <33522493+leohhhn@users.noreply.github.com> * Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: Leon Hudak <33522493+leohhhn@users.noreply.github.com> * Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: deelawn * Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: deelawn * Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: deelawn * Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: deelawn * Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: deelawn * Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: deelawn * Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: deelawn * Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: deelawn * Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: deelawn * fix code section delimiters * Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: deelawn * Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: deelawn * Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: deelawn * Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: deelawn * Update posts/2024-06-28-gno-debugger/README.md Co-authored-by: deelawn * Apply suggestions from code review --------- Co-authored-by: Leon Hudak <33522493+leohhhn@users.noreply.github.com> Co-authored-by: deelawn --- posts/2024-06-28-gno-debugger/README.md | 220 ++++++++++++++++++++++++ 1 file changed, 220 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..06f28bf --- /dev/null +++ b/posts/2024-06-28-gno-debugger/README.md @@ -0,0 +1,220 @@ +--- +title: "Debugging Gno Programs" +publication_date: 2024-06-28T13:37:00Z +slug: gno-debugger +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 to fix 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 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. + +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](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: + +```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 classic 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 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. +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] 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. + +The commands can be classified in the following categories: +- managing breakpoints: `break`, `breakpoints`, `clear`, +- controlling execution: `step`, `stepi`, `continue`, +- browsing code, data and stack: `list`, `print`, `stack`, +- navigating the stack: `up`, `down`, +- quitting 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 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 call 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`. + +Now we want 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. + +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 +var a struct { + b []string +} +``` +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 + +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 eb0a435d7cfdaaf7711c352e3b13ab3bbd33ee65 Mon Sep 17 00:00:00 2001 From: Leon Hudak <33522493+leohhhn@users.noreply.github.com> Date: Tue, 6 Aug 2024 12:26:42 +0100 Subject: [PATCH 2/5] chore: update debugger pub date (#107) * update date * rm title frontmatter --- posts/2024-06-28-gno-debugger/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/posts/2024-06-28-gno-debugger/README.md b/posts/2024-06-28-gno-debugger/README.md index 06f28bf..05c456a 100644 --- a/posts/2024-06-28-gno-debugger/README.md +++ b/posts/2024-06-28-gno-debugger/README.md @@ -1,10 +1,10 @@ --- -title: "Debugging Gno Programs" -publication_date: 2024-06-28T13:37:00Z +publication_date: 2024-08-06T13:37:00Z slug: gno-debugger 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 to fix bugs. From a4de80883e10ba9fa1988f54ff7f1317d529239a Mon Sep 17 00:00:00 2001 From: Michelle <117160070+michelleellen@users.noreply.github.com> Date: Tue, 6 Aug 2024 13:39:52 +0200 Subject: [PATCH 3/5] Update CONTRIBUTING.md (#108) --- CONTRIBUTING.md | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0f2371f..52503e9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,9 +1,9 @@ # Contributing to the Gno Blog -Thank you for considering a contribution to the Gno Blog. We appreciate all and every open-source contribution to the Gno.land project, as everything we do revolves around open-source. -Below, you will find guidelines on how to submit a blog post to the Gno Blog. +Thank you for considering a contribution to the gno.land blog. We appreciate all and every open-source contribution to the gno.land project, as everything we do revolves around open-source. +Below, you will find guidelines on how to submit a blog post to the gno.land blog. -If you are unsure about something, please don’t hesitate to reach out for help by opening an issue here, on Discord, or directly to the Gno.land DevRel team. +If you are unsure about something, please don’t hesitate to reach out for help by opening an issue here, on Discord, or directly to the gno.land DevRel team. Likewise, if you have an idea on how to improve this guide, go for it as well. ### What we are looking for @@ -12,23 +12,21 @@ We’re seeking contributions that will bring value to our growing community of Below are topics of particular interest to us, but we’re open to all suggestions, so if you have an idea that’s not on the list, but you believe will make great reading, feel free to submit your story. - Web3 news and developments and how they impact our community (e.g. legislation, industry trends, technical advances) -- Gno ecosystem news (e.g. interesting new realms/apps, newly-added core functionality, etc.) - Technical deep dives (e.g. language comparisons, pros and cons, examining the core stack) -- Tutorials and how-to guides -- Useful intros about basic concepts in Gno.land (e.g. package/realm distinction) +- Useful intros about basic concepts in gno.land (e.g. package/realm distinction) - General content that helps explain reasoning or thought processes (e.g. writing the entire stack in Go vs implementing components in Rust) - Op-ed pieces and alternative views (e.g. building effective governance, decentralizing social media, the importance of censorship-resistant tools) ### Contribution process -If you've considered the previous section and would like to contribute to the Gno Blog, here are the steps to follow: +If you've considered the previous section and would like to contribute to the gno.land blog, here are the steps to follow: - Write a blog post you'd like to see included to the Gno Blog, while strictly following the [Style Guide](#gno-blog-style-guide). - Submit a PR using [this template](https://github.com/gnolang/blog/pull/35), while following the structure of the folders & naming, as shown in the example blog post. -- Ping the Gno.land DevRel team, [@waymobetta](https://github.com/waymobetta) and [@leohhhn](https://github.com/leohhhn) for a review. +- Ping the gno.land DevRel team, [@leohhhn](https://github.com/leohhhn) and [@michelleellen](https://github.com/michelleellen) for a review. After your blog post passes the review process, it will be merged into the `main` branch and shortly after deployed on-chain. -## Gno Blog Style Guide +## Gno.land Blog Style Guide This style guide offers rules and preferences for contributing to the Gno Blog. Below are some rules to follow when writing a blog post. @@ -50,4 +48,4 @@ Below are some rules to follow when writing a blog post. #### Tags Tags, or [hashtags](https://en.wikipedia.org/wiki/Hashtag), should be lowercase and without spaces; eg, #foobar NOT #FooBar. -If you're unsure of how to style or format something, take a look at the [example blog post PR](https://github.com/gnolang/blog/pull/35) or review the other [blog posts in this repo](posts) for inspiration; as a last resort, message [@waymobetta](https://github.com/waymobetta) or [@leohhhn](https://github.com/leohhhn) for help within your PR or issue thread. +If you're unsure of how to style or format something, take a look at the [example blog post PR](https://github.com/gnolang/blog/pull/35) or review the other [blog posts in this repo](posts) for inspiration; as a last resort, message [@leohhhn](https://github.com/leohhhn) or [@michelleellen](https://github.com/michelleellen) for help within your PR or issue thread. From 370469fa035a10270a92b3a922ac2632d41cdbde Mon Sep 17 00:00:00 2001 From: Leon Hudak <33522493+leohhhn@users.noreply.github.com> Date: Tue, 6 Aug 2024 13:41:05 +0200 Subject: [PATCH 4/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3be0d77..fb1771d 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ _Disclaimer: This repo is highly experimental and subject to breaking changes._ Tools and content to manage blogposts on the [`r/gnoland/blog` realm](https://github.com/gnolang/gno/tree/master/examples/gno.land/r/gnoland/blog), powered by the [`p/demo/blog` library](https://github.com/gnolang/gno/tree/master/examples/gno.land/p/demo/blog). -(Current) live version: https://test3.gno.land/r/gnoland/blog. +(Current) live version: [https://gno.land/r/gnoland/blog](https://gno.land/r/gnoland/blog). ## Posts ([`./posts`](./posts)) From b7b945bd6adf2c833faa042fc0cb1a8d7c031ec1 Mon Sep 17 00:00:00 2001 From: Leon Hudak <33522493+leohhhn@users.noreply.github.com> Date: Fri, 16 Aug 2024 16:30:57 +0200 Subject: [PATCH 5/5] feat: Add "gno.land at GopherCon US 2024" (#109) * add gcus24 blog post, fix folder name * add links * add link, styling * rm old tags * newline, fix extra space * rm the * rm dylan blog post * G>g * Update README.md * update link, add tags * update link * update capitalization --------- Co-authored-by: Valeh <151614088+VT-Cosmos@users.noreply.github.com> --- .../README.md | 0 posts/2024-08-12_gc-us24/README.md | 100 ++++++++++++++++++ 2 files changed, 100 insertions(+) rename posts/{2024-06-28-gno-debugger => 2024-06-28_gno-debugger}/README.md (100%) create mode 100644 posts/2024-08-12_gc-us24/README.md diff --git a/posts/2024-06-28-gno-debugger/README.md b/posts/2024-06-28_gno-debugger/README.md similarity index 100% rename from posts/2024-06-28-gno-debugger/README.md rename to posts/2024-06-28_gno-debugger/README.md diff --git a/posts/2024-08-12_gc-us24/README.md b/posts/2024-08-12_gc-us24/README.md new file mode 100644 index 0000000..a2c9c5d --- /dev/null +++ b/posts/2024-08-12_gc-us24/README.md @@ -0,0 +1,100 @@ +--- +publication_date: 2024-08-12T00:00:00Z +slug: gc-us24 +tags: [techconference, events, outreach, GoDevelopers, GoToGno, gophers] +authors: [VT-Cosmos] +--- + +# gno.land at GopherCon US 2024 + +GopherCon US is one of the largest events for the Go programming community. +This year, in the vibrant city of Chicago, we had the honor of being the Diamond +Sponsor at GopherCon US 2024. From July 7th to July 10th, we were surrounded by +top Go talent; it was an incredible opportunity for us to connect with developers, +showcase our innovations, and share our expertise. + +GopherCon US 2024 was held at the stunning McCormick Place, bringing together +nearly one thousand Go enthusiasts from around the world. Our team was thrilled +to be part of this gathering, contributing to the vibrant ecosystem of Go +developers. + +## Highlights of Our Collaboration + +### Jae’s Talk + +Jae Kwon, the founder of gno.land, gave a talk on “**Gno: Lessons in Building a +Go Interpreter in Go.**” + +Jae’s talk provided an in-depth overview of why this technology is gaining +traction in the development community. The discussion began with the key reasons +to use Gno, and its seamless interoperability which allows for effortless +integration. Detailed comparisons were made between Gno and other prominent +programming languages such as Solidity and Rust which are running other smart +contract platforms, showcasing Gno’s distinct advantages. The strengths of the +GnoVM were a focal point, particularly its stack based AST architecture, its +auto persistence, as well as its determinism and other features. The presentation +also shared valuable lessons learned from GnoVM's development and implementation, +offering insights into best practices and challenges overcome in the future work. +Be sure to make some time to watch [the recording](https://www.youtube.com/watch?v=betUkghf_jo)! + +### Gno Workshop + +Participants had the opportunity to dive deep into the development process, +guided by our expert engineer **[Dylan Boltz](https://github.com/deelawn)** who hosted a workshop on Community +Day: **Building a decentralized app on gno.land**. The workshop provided practical +insights and step-by-step guidance, empowering attendees to start building their +own applications. If you missed our workshop or want to revisit the session, you +can find a recorded version of the workshop [here](https://www.youtube.com/watch?v=lwL2VyjaV-A). + +### The gno.land Booth +One of the most rewarding feelings about attending these kinds of conferences +is watching our booth quickly become a hub of activity, drawing a steady stream +of visitors intrigued by our project. We engaged with developers from various +backgrounds, answering a myriad of questions about Gno, gno.land, our company, +and the company’s [open employment opportunities](https://jobs.lever.co/allinbits). +Having all of this direct human interaction was not only informative but also +deeply insightful, providing us with valuable feedback and ideas. For more +information, check out our [Official Documentation](https://docs.gno.land/). + +### The Gno Raffle + +One of the major attractions at our booth, amongst the “gnome” beanie hat as +well as the T-shirts, was the raffle for a high-end mechanical keyboard. The +raffle participants had a direct opportunity to interact with gno.land by +following the raffle instructions, leading them to use [Gno Playground](https://play.gno.land/) to import +and deploy a smart contract raffle realm from their own laptop. The excitement +was palpable as attendees eagerly gathered for the drawing. The raffle not only +drew crowds, but also sparked numerous engaging conversations that led to Go +engineers giving Gno a try. + +### The Challenge Series + +This year we had the privilege to participate in a collaborative partnership +with the CodePro team to build the [challenge series](https://gophercon.challengeseries.org/). This collaboration was an +opportunity for participants to learn how to interact with blockchain and +discover how realms (smart contracts) can be utilized for stateful applications +without relying on explicitly managing a file system or database. This was an +opportunity to showcase gno.land’s features, like using a deployed contract as +both an API and as an import for other contracts. + +## Conclusion + +Overall, the enthusiasm of the attendees at GopherCon was infectious, and we +were delighted to see such a high level of engagement and curiosity. Whether +it was at our booth, during the raffle, or in the workshop, the interactions +were meaningful and enriching. Sponsoring and collaborating at GopherCon US +2024 was an unforgettable experience. We are grateful for the opportunity to +connect with the Go community, share our knowledge, and learn from fellow +developers. We extend our heartfelt thanks to everyone who visited our booth, +participated in the raffle, attended Jae Kwon's presentation on Gno, and joined +our workshop. + +We invite you to stay connected with us on our [Discord](https://discord.gg/43HC5NZzHe), +and our [blog](https://gno.land/r/gnoland/blog) where we +will be sharing more insights and updates on +[Test4](https://gno.land/r/gnoland/blog:p/test4-live), our current testnet, as +well as the progress towards our launch. + +Thank you, [GopherCon US 2024](https://x.com/gophercon), for an incredible experience. +We can't wait to see what the next event holds! +