Skip to content

Commit f90ede4

Browse files
authored
service/dap: fix bugs in stdout/stderr handling (#3522)
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 #3253
1 parent b041bd8 commit f90ede4

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

service/dap/server.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,20 +1050,22 @@ func (s *Session) onLaunchRequest(request *dap.LaunchRequest) {
10501050
var out [1024]byte
10511051
for {
10521052
n, err := reader.Read(out[:])
1053+
if n > 0 {
1054+
outs := string(out[:n])
1055+
s.send(&dap.OutputEvent{
1056+
Event: *newEvent("output"),
1057+
Body: dap.OutputEventBody{
1058+
Output: outs,
1059+
Category: category,
1060+
}})
1061+
}
10531062
if err != nil {
10541063
if err == io.EOF {
10551064
return
10561065
}
10571066
s.config.log.Errorf("failed read by %s - %v ", category, err)
10581067
return
10591068
}
1060-
outs := string(out[:n])
1061-
s.send(&dap.OutputEvent{
1062-
Event: *newEvent("output"),
1063-
Body: dap.OutputEventBody{
1064-
Output: outs,
1065-
Category: category,
1066-
}})
10671069
}
10681070
}
10691071

@@ -1186,7 +1188,7 @@ func (s *Session) newNoDebugProcess(program string, targetArgs []string, wd stri
11861188
return nil, err
11871189
}
11881190
} else {
1189-
cmd.Stdout, cmd.Stderr = os.Stdin, os.Stderr
1191+
cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
11901192
}
11911193

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

0 commit comments

Comments
 (0)