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

service/dap: update go-dap to latest #3414

Merged
merged 3 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/creack/pty v1.1.9
github.com/derekparker/trie v0.0.0-20221213183930-4c74548207f4
github.com/go-delve/liner v1.2.3-0.20220127212407-d32d89dd2a5d
github.com/google/go-dap v0.7.0
github.com/google/go-dap v0.9.1
github.com/hashicorp/golang-lru v0.5.4
github.com/mattn/go-colorable v0.0.9
github.com/mattn/go-isatty v0.0.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-dap v0.7.0 h1:088PdKBUkxAxrXrnY8FREUJXpS6Y6jhAyZIuJv3OGOM=
github.com/google/go-dap v0.7.0/go.mod h1:5q8aYQFnHOAZEMP+6vmq25HKYAEwE+LF5yh7JKrrhSQ=
github.com/google/go-dap v0.9.1 h1:d8dETjgHMR9/xs+Xza+NrZmB7jxIS5OtM2uRsyJVA/c=
github.com/google/go-dap v0.9.1/go.mod h1:HAeyoSd2WIfTfg+0GRXcFrb+RnojAtGNh+k+XTIxJDE=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
Expand Down
12 changes: 9 additions & 3 deletions service/dap/daptest/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (c *Client) ExpectMessage(t *testing.T) dap.Message {
func (c *Client) ExpectInvisibleErrorResponse(t *testing.T) *dap.ErrorResponse {
t.Helper()
er := c.ExpectErrorResponse(t)
if er.Body.Error.ShowUser {
if er.Body.Error != nil && er.Body.Error.ShowUser {
t.Errorf("\ngot %#v\nwant ShowUser=false", er)
}
return er
Expand All @@ -82,7 +82,7 @@ func (c *Client) ExpectInvisibleErrorResponse(t *testing.T) *dap.ErrorResponse {
func (c *Client) ExpectVisibleErrorResponse(t *testing.T) *dap.ErrorResponse {
t.Helper()
er := c.ExpectErrorResponse(t)
if !er.Body.Error.ShowUser {
if er.Body.Error == nil || !er.Body.Error.ShowUser {
t.Errorf("\ngot %#v\nwant ShowUser=true", er)
}
return er
Expand All @@ -91,6 +91,10 @@ func (c *Client) ExpectVisibleErrorResponse(t *testing.T) *dap.ErrorResponse {
func (c *Client) ExpectErrorResponseWith(t *testing.T, id int, message string, showUser bool) *dap.ErrorResponse {
t.Helper()
er := c.ExpectErrorResponse(t)
if er.Body.Error == nil {
t.Errorf("got nil, want Id=%d Format=%q ShowUser=%v", id, message, showUser)
return er
}
if matched, _ := regexp.MatchString(message, er.Body.Error.Format); !matched || er.Body.Error.Id != id || er.Body.Error.ShowUser != showUser {
t.Errorf("got %#v, want Id=%d Format=%q ShowUser=%v", er, id, message, showUser)
}
Expand Down Expand Up @@ -277,7 +281,9 @@ func (c *Client) DisconnectRequest() {
// `terminateDebuggee`.
func (c *Client) DisconnectRequestWithKillOption(kill bool) {
request := &dap.DisconnectRequest{Request: *c.newRequest("disconnect")}
request.Arguments.TerminateDebuggee = kill
request.Arguments = &dap.DisconnectArguments{
TerminateDebuggee: kill,
}
c.send(request)
}

Expand Down
25 changes: 15 additions & 10 deletions service/dap/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,7 @@ func (s *Session) onDisconnectRequest(request *dap.DisconnectRequest) {
s.mu.Lock()
defer s.mu.Unlock()

if s.debugger != nil && s.config.AcceptMulti && !request.Arguments.TerminateDebuggee {
if s.debugger != nil && s.config.AcceptMulti && (request.Arguments == nil || !request.Arguments.TerminateDebuggee) {
// This is a multi-use server/debugger, so a disconnect request that doesn't
// terminate the debuggee should clean up only the client connection and pointer to debugger,
// but not the entire server.
Expand Down Expand Up @@ -1161,7 +1161,7 @@ func (s *Session) onDisconnectRequest(request *dap.DisconnectRequest) {
// In case of attach, we leave the program
// running by default, which can be
// overridden by an explicit request to terminate.
killProcess := s.debugger.AttachPid() == 0 || request.Arguments.TerminateDebuggee
killProcess := s.debugger.AttachPid() == 0 || (request.Arguments != nil && request.Arguments.TerminateDebuggee)
err = s.stopDebugSession(killProcess)
} else if s.noDebugProcess != nil {
s.stopNoDebugProcess()
Expand Down Expand Up @@ -1966,7 +1966,7 @@ func (s *Session) onStackTraceRequest(request *dap.StackTraceRequest) {
stackFrame := dap.StackFrame{Id: uniqueStackFrameID, Line: loc.Line, Name: fnName(loc), InstructionPointerReference: fmt.Sprintf("%#x", loc.PC)}
if loc.File != "<autogenerated>" {
clientPath := s.toClientPath(loc.File)
stackFrame.Source = dap.Source{Name: filepath.Base(clientPath), Path: clientPath}
stackFrame.Source = &dap.Source{Name: filepath.Base(clientPath), Path: clientPath}
}
stackFrame.Column = 0

Expand Down Expand Up @@ -3045,7 +3045,7 @@ func (s *Session) onDisassembleRequest(request *dap.DisassembleRequest) {
}
// Only set the location on the first instruction for a given line.
if instruction.Loc.File != lastFile || instruction.Loc.Line != lastLine {
instructions[i].Location = dap.Source{Path: instruction.Loc.File}
instructions[i].Location = &dap.Source{Path: instruction.Loc.File}
instructions[i].Line = instruction.Loc.Line
lastFile, lastLine = instruction.Loc.File, instruction.Loc.Line
}
Expand Down Expand Up @@ -3252,6 +3252,7 @@ func (s *Session) onExceptionInfoRequest(request *dap.ExceptionInfoRequest) {
}

if includeStackTrace {
body.Details = &dap.ExceptionDetails{}
frames, err := s.stacktrace(goroutineID, g)
if err != nil {
body.Details.StackTrace = fmt.Sprintf("Error getting stack trace: %s", err.Error())
Expand Down Expand Up @@ -3320,9 +3321,11 @@ func (s *Session) sendErrorResponseWithOpts(request dap.Request, id int, summary
er.RequestSeq = request.Seq
er.Success = false
er.Message = summary
er.Body.Error.Id = id
er.Body.Error.Format = fmt.Sprintf("%s: %s", summary, details)
er.Body.Error.ShowUser = showUser
er.Body.Error = &dap.ErrorMessage{
Id: id,
Format: fmt.Sprintf("%s: %s", summary, details),
ShowUser: showUser,
}
s.config.log.Debug(er.Body.Error.Format)
s.send(er)
}
Expand All @@ -3346,8 +3349,10 @@ func (s *Session) sendInternalErrorResponse(seq int, details string) {
er.RequestSeq = seq
er.Success = false
er.Message = "Internal Error"
er.Body.Error.Id = InternalError
er.Body.Error.Format = fmt.Sprintf("%s: %s", er.Message, details)
er.Body.Error = &dap.ErrorMessage{
Id: InternalError,
Format: fmt.Sprintf("%s: %s", er.Message, details),
}
s.config.log.Debug(er.Body.Error.Format)
s.send(er)
}
Expand Down Expand Up @@ -3667,7 +3672,7 @@ func (s *Session) logBreakpointMessage(bp *api.Breakpoint, goid int64) bool {
Body: dap.OutputEventBody{
Category: "stdout",
Output: fmt.Sprintf("> [Go %d]: %s\n", goid, msg),
Source: dap.Source{
Source: &dap.Source{
Path: s.toClientPath(bp.File),
},
Line: bp.Line,
Expand Down