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 debugger support #739

Merged
merged 1 commit into from
Jun 9, 2024

Conversation

theSuess
Copy link
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

Verified

This commit was signed with the committer’s verified signature.
theSuess Dominik Süß
@theSuess theSuess marked this pull request as ready for review December 28, 2023 08:26
@theSuess
Copy link
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

@@ -287,6 +308,13 @@ func (i *interpreter) newCall(env environment, trimmable bool) error {
}

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

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.

@@ -0,0 +1,401 @@
package jsonnet
Copy link
Collaborator

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
Collaborator

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

Verified

This commit was signed with the committer’s verified signature.
theSuess Dominik Süß
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

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
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.

None yet

2 participants