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

Type Breakpoint contains empty source #66

Closed
corneliusweig opened this issue Nov 18, 2022 · 6 comments · Fixed by #67
Closed

Type Breakpoint contains empty source #66

corneliusweig opened this issue Nov 18, 2022 · 6 comments · Fixed by #67

Comments

@corneliusweig
Copy link
Collaborator

corneliusweig commented Nov 18, 2022

The Breakpoint is defined as

type Breakpoint struct {
	Id                   int    `json:"id,omitempty"`
	Verified             bool   `json:"verified"`
	Message              string `json:"message,omitempty"`
	Source               Source `json:"source,omitempty"`
	Line                 int    `json:"line,omitempty"`
	Column               int    `json:"column,omitempty"`
	EndLine              int    `json:"endLine,omitempty"`
	EndColumn            int    `json:"endColumn,omitempty"`
	InstructionReference string `json:"instructionReference,omitempty"`
	Offset               int    `json:"offset,omitempty"`
}

It says "source,omitempty", but an empty object is serialised as:

data, _ := json.Marshal(dap.Breakpoint{})
fmt.Println(string(data))

// {"verified":false,"source":{}}
//                     ^^^^^^^^

This means that BreakpointEvent types with missing source are serialised with an empty source object, which clears the breakpoint location in the UI.

Can the Source field be changed to a pointer field instead?

@corneliusweig
Copy link
Collaborator Author

I haven't checked other types in this repository, but I can look up if this is also an issue elsewhere.

@hyangah
Copy link
Collaborator

hyangah commented Nov 23, 2022

Thanks for the bug report.
Can you help us find the part in the spec that explains the editor's behavior you were observing? More specifically, I want to understand why the editor is clearing the breakpoint location when seeing completely empty Source object.

@corneliusweig
Copy link
Collaborator Author

The spec is a bit vague, but I think it's there:

  1. The documentation for BreakpointEvent (https://microsoft.github.io/debug-adapter-protocol/specification#Events_Breakpoint) says:

        /**
         * The `id` attribute is used to find the target breakpoint, the other
         * attributes are used as the new values.
         */
        breakpoint: Breakpoint;

    I think the phrase the other attributes are used as the new values means that whatever is specified in the breakpoint updates existing values.

  2. The Breakpoint type has an optional source field (https://microsoft.github.io/debug-adapter-protocol/specification#Types_Breakpoint):

      /**
       * The source where the breakpoint is located.
       */
      source?: Source;

Taken together, I think it makes sense to read it as "when present, the source field updates existing values".

Note: All fields in the Source type are optional. However, if they would always be merged into the existing values, it would be impossible to clear fields. Therefore, I think it does not make sense to assume that an empty Source gets merged into an existing one.

@hyangah
Copy link
Collaborator

hyangah commented Nov 28, 2022

Thanks @corneliusweig for helping with interpreting the spec (cc @weinand to confirm the interpretation of the breakpoint source field)

I guess the proposed change will affect only the shape of the messages produced by debug adapter (e.g. Delve), and clients (e.g. VS Code) will continue to work with old/new versions of Delve. So, the impact on the Delve and editors that use Delve DAP is not concerning once delve is updated to work with the newer version of go-dap after the change.

There are a couple of debug adapters using go-dap outside Delve https://pkg.go.dev/github.com/google/go-dap?tab=importedby From my quick search, I believe they can quickly resolve the incompatibility when they upgrade the dependencies.

IMO the change to fix the bug is acceptable, but I want to hear opinion from @polinasok @suzmue @aarzilli @derekparker
(And go-dap is still in v0 😄 ).

@suzmue
Copy link
Collaborator

suzmue commented Nov 28, 2022

I agree that fixing this bug makes sense.

Some initial investigation in the vscode source VS Code seems that it handles undefined differently than zero (https://github.com/microsoft/vscode/blob/9dba5385c7aefebe3756ed413da7fedf1868a71c/src/vs/workbench/contrib/debug/common/debugModel.ts#L966).

Delve does not yet use BreakpointEvents to update breakpoints. Delve sends all information about breakpoints through the response to the setBreakpoints requests.

@corneliusweig
Copy link
Collaborator Author

Thank you! I tentatively created a PR for this trivial change.

If this is fixed for Breakpoint.Source, there are a few other places that should possibly be updated too. I found a few fields that are marked as omitempty, but are struct types, so they would be serialised as empty objects as described above. Additional fields I could imagine are problematic are:

  • DisassembledInstruction.Location
  • Scope.Source
  • SetExpressionResponseBody.PresentationHint
  • EvaluateResponseBody.PresentationHint

suzmue added a commit to suzmue/go-dap that referenced this issue Dec 1, 2022
The DAP client may distinguish between a nil source and an empty
source, clearing the source information if it is present and
empty. Make the Source field on the breakpoint a pointer since it
is optional.

Fixes google#66
suzmue added a commit to corneliusweig/go-dap that referenced this issue Dec 6, 2022
This updates the gentypes to make the Source field of Breakpoint
a pointer in the generated Go types.

For google#66
@suzmue suzmue closed this as completed in #67 Dec 6, 2022
suzmue added a commit that referenced this issue Dec 6, 2022
* Make `Source` field in `Breakpoint` events optional

Fixes #66

* cmd/gentypes: update code generator to make Source a pointer

This updates the gentypes to make the Source field of Breakpoint
a pointer in the generated Go types.

For #66

Co-authored-by: Suzy Mueller <suzmue@golang.org>
hyangah added a commit to hyangah/delve that referenced this issue Jan 2, 2023
derekparker pushed a commit to go-delve/delve that referenced this issue Jan 3, 2023
* go.mod: update github.com/google/go-dap to v0.7.0

Updates google/go-dap#66

* Run go mod tidy
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 a pull request may close this issue.

3 participants