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

Suspend breakpoint if file is not found #3900

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/proc/bininfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,10 @@ func (err *ErrCouldNotFindLine) Error() string {
return fmt.Sprintf("could not find file %s", err.filename)
}

func (err *ErrCouldNotFindLine) IsFileFound() bool {
return err.fileFound
}

// AllPCsForFileLines returns a map providing all PC addresses for filename and each line in linenos
func (bi *BinaryInfo) AllPCsForFileLines(filename string, linenos []int) map[int][]uint64 {
r := make(map[int][]uint64)
Expand Down
4 changes: 4 additions & 0 deletions service/dap/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1510,6 +1510,10 @@ func (s *Session) setBreakpoints(prefix string, totalBps int, metadataFunc func(
if err == nil {
// Create new breakpoints.
got, err = s.debugger.CreateBreakpoint(bp, "", nil, false)
if createBpError, isCouldNotFindLine := err.(*proc.ErrCouldNotFindLine); isCouldNotFindLine && !createBpError.IsFileFound() {
Copy link
Member

Choose a reason for hiding this comment

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

I think it's fine to just call CreateBreakpoint with suspended == true here, but you still have to say that the breakpoint is unverified if it does indeed end up being suspended: the user needs some kind of feedback for breakpoints that can't be enabled, it could be that they are enabled by a plugin later, but it could also be that they are just being set on a line that isn't in the executable.

Copy link
Member

Choose a reason for hiding this comment

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

Also, what does the protocol say we should be doing when a previously unverified breakpoint becomes verified?

Copy link
Author

Choose a reason for hiding this comment

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

I think it's fine to just call CreateBreakpoint with suspended == true here,

this part would fail without the additional check: https://github.com/LittleChimera/delve/blob/suspend-non-verified-breakpoints/service/dap/server_test.go#L2896-L2898

but you still have to say that the breakpoint is unverified if it does indeed end up being suspended:

i was thinking to just take the latest error for example, or combine them with errors.Join

however, as you asked, we'd need to find some way to update them to verified once the plugin is reloaded. although, we could consider implementing this in another PR since it doesn't seem to affect the functionality in VSCode for example (the only difference is error message on hover).

from the DAP docs:

If a debug adapter is unable to apply a breakpoint at the time when it’s first sent, it should mark the breakpoint as unverified using verified: false in the SetBreakpointsResponse. If the breakpoint changes its state at a later point in time, the debug adapter should use the breakpoint event to notify the client.

The verified property of a Breakpoint object signals whether the exception breakpoint or filter could be successfully created and whether the condition is valid. In case of an error the message property explains the problem. The id property can be used to introduce a unique ID for the exception breakpoint or filter so that it can be updated subsequently by sending breakpoint events.

Copy link
Member

Choose a reason for hiding this comment

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

this part would fail without the additional check: https://github.com/LittleChimera/delve/blob/suspend-non-verified-breakpoints/service/dap/server_test.go#L2896-L2898

True. We probably want to keep the error, something like this then:

got, err = s.debugger.CreateBreakpoint(bp, "", nil, false)
if err != nil {
	// try to create a suspended breakpoint instead
	got, _ = s.debugger.CreateBreakpoint(bp, "", nil, true)
}

// try to create a suspended breakpoint instead
got, _ = s.debugger.CreateBreakpoint(bp, "", nil, true)
}
}
}
}
Expand Down