Remove limitation of exit notification only for specific API calls

This commit is contained in:
Florin Patan 2017-12-19 01:24:56 +00:00 committed by Derek Parker
parent 00e473157a
commit 480fc02d50
3 changed files with 43 additions and 1 deletions

13
_fixtures/pr1055.go Normal file

@ -0,0 +1,13 @@
package main
import (
"fmt"
"go/ast"
"os"
)
func main() {
a := &ast.CompositeLit{}
fmt.Println("demo", a) // set breakpoint here and use next twice
os.Exit(2)
}

@ -526,7 +526,7 @@ func (d *Debugger) Command(command *api.DebuggerCommand) (*api.DebuggerState, er
}
if err != nil {
if exitedErr, exited := err.(proc.ProcessExitedError); (command.Name == api.Continue || command.Name == api.Rewind) && exited {
if exitedErr, exited := err.(proc.ProcessExitedError); command.Name != api.SwitchGoroutine && command.Name != api.SwitchThread && exited {
state := &api.DebuggerState{}
state.Exited = true
state.ExitStatus = exitedErr.Status

@ -1387,3 +1387,32 @@ func TestClientServer_collectBreakpointInfoError(t *testing.T) {
assertNoError(state.Err, t, "Continue()")
})
}
func TestClientServerConsistentExit(t *testing.T) {
protest.AllowRecording(t)
// This test is useful because it ensures that Next and Continue operations both
// exit with the same exit status and details when the target application terminates.
// Other program execution API calls should also behave in the same way.
// An error should be pressent in state.Err.
withTestClient2("pr1055", t, func(c service.Client) {
fp := testProgPath(t, "pr1055")
_, err := c.CreateBreakpoint(&api.Breakpoint{File: fp, Line: 12})
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
state := <-c.Continue()
if state.Err != nil {
t.Fatalf("Unexpected error: %v, state: %#v", state.Err, state)
}
state, err = c.Next()
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if !state.Exited {
t.Fatal("Process state is not exited")
}
if state.ExitStatus != 2 {
t.Fatalf("Process exit status is not 2, got: %v", state.ExitStatus)
}
})
}