Skip to content

feat: add debugger support#739

Merged
sbarzowski merged 1 commit intogoogle:masterfrom
grafana:feat/debugger-support
Jun 9, 2024
Merged

feat: add debugger support#739
sbarzowski merged 1 commit intogoogle:masterfrom
grafana:feat/debugger-support

Conversation

@theSuess
Copy link
Copy Markdown
Contributor

@theSuess theSuess commented Dec 28, 2023

This PR adds an extension point for future debugger implementations.

We first investigated having the entire debugger codebase only use go-jsonnet as a dependency, but many of the fields and types needed to implement this are not exposed to external packages.

To solve this, we added a new Debugger type, which allows debugging frontends to control the evaluation of a specific file.

The API type is heavily inspired by the Debug Adapter Protocol and can be used to implement basic debugging functionality like:

  • Stepping through evaluation
  • Setting Breakpoints
  • Automatically breaking on exceptions
  • Viewing a rudimentary stack trace
  • Inspecting variables at runtime

Example implementations of clients using this interface can be found in the example-clients branch of our fork.

The following recording shows the basic capabilities in action by using the DAP example client with VSCode:

dap.mp4

@theSuess theSuess marked this pull request as ready for review December 28, 2023 08:26
@theSuess
Copy link
Copy Markdown
Contributor Author

We have released an implementation of the example client as a standalone package at grafana/jsonnet-debugger.

It is also integrated into the latest version of our vscode-jsonnet extension.

The debugger uses the grafana/go-jsonnet-debugger fork to implement the functionality until the PR is merged

Comment thread interpreter.go
}

func (i *interpreter) evaluate(a ast.Node, tc tailCallStatus) (value, error) {
i.evalHook.pre(i, a)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably make evalHook a pointer and avoid a virtual call here if it's null (so that the performance overhead when not debugging is smaller). Not sure how significant that is, given other overhead.

Comment thread debugger.go
@@ -0,0 +1,401 @@
package jsonnet
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's quite a bit of complexity here - some tests would be nice.

@sbarzowski sbarzowski merged commit 6838b0a into google:master Jun 9, 2024
@sbarzowski
Copy link
Copy Markdown
Contributor

Really cool stuff.

Added some comments for potential follow-up, but merging as it is.

theSuess added a commit to theSuess/go-jsonnet that referenced this pull request Jun 11, 2024
The `valueToString` operation introduced by google#742 is incompatible with the way
the implementation from google#739 as it tries to manifest an object from stack while
the implementation needed by the debugger returns the value as-is without
further evaluation.
sbarzowski pushed a commit that referenced this pull request Jun 11, 2024
The `valueToString` operation introduced by #742 is incompatible with the way
the implementation from #739 as it tries to manifest an object from stack while
the implementation needed by the debugger returns the value as-is without
further evaluation.
vhata pushed a commit to discord/go-jsonnet that referenced this pull request Aug 30, 2024
vhata pushed a commit to discord/go-jsonnet that referenced this pull request Aug 30, 2024
The `valueToString` operation introduced by google#742 is incompatible with the way
the implementation from google#739 as it tries to manifest an object from stack while
the implementation needed by the debugger returns the value as-is without
further evaluation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants