Skip to content

Commit

Permalink
service/dap: fix bugs in stdout/stderr handling
Browse files Browse the repository at this point in the history
Fixes bugs introduced in v1.21.1

* Avoid dropping the last bytes from stderr/stdout when Read returns an
  error. (Read returns n>0). And skip sending Output event if Read
  returns n==0.

* Fix the bug that drops all stdout in the existing noDebug mode.

For go-delve#3253
  • Loading branch information
hyangah committed Oct 6, 2023
1 parent b041bd8 commit 3ce4389
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions service/dap/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1050,20 +1050,22 @@ func (s *Session) onLaunchRequest(request *dap.LaunchRequest) {
var out [1024]byte
for {
n, err := reader.Read(out[:])
if n > 0 {
outs := string(out[:n])
s.send(&dap.OutputEvent{
Event: *newEvent("output"),
Body: dap.OutputEventBody{
Output: outs,
Category: category,
}})
}
if err != nil {
if err == io.EOF {
return
}
s.config.log.Errorf("failed read by %s - %v ", category, err)
return
}
outs := string(out[:n])
s.send(&dap.OutputEvent{
Event: *newEvent("output"),
Body: dap.OutputEventBody{
Output: outs,
Category: category,
}})
}
}

Expand Down Expand Up @@ -1186,7 +1188,7 @@ func (s *Session) newNoDebugProcess(program string, targetArgs []string, wd stri
return nil, err
}
} else {
cmd.Stdout, cmd.Stderr = os.Stdin, os.Stderr
cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
}

if err = cmd.Start(); err != nil {
Expand Down

0 comments on commit 3ce4389

Please sign in to comment.