proc/gdbserial: shut down debuggee when failing to debug (#2953)
Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
This commit is contained in:
parent
6c368b78a9
commit
0b71eeca40
@ -282,8 +282,10 @@ func TestContinue(t *testing.T) {
|
||||
|
||||
// TestChildProcessExitWhenNoDebugInfo verifies that the child process exits when dlv launch the binary without debug info
|
||||
func TestChildProcessExitWhenNoDebugInfo(t *testing.T) {
|
||||
noDebugFlags := protest.LinkStrip
|
||||
// -s doesn't strip symbols on Mac, use -w instead
|
||||
if runtime.GOOS == "darwin" {
|
||||
t.Skip("test skipped on darwin, see https://github.com/go-delve/delve/pull/2018 for details")
|
||||
noDebugFlags = protest.LinkDisableDWARF
|
||||
}
|
||||
|
||||
if _, err := exec.LookPath("ps"); err != nil {
|
||||
@ -293,7 +295,7 @@ func TestChildProcessExitWhenNoDebugInfo(t *testing.T) {
|
||||
dlvbin, tmpdir := getDlvBin(t)
|
||||
defer os.RemoveAll(tmpdir)
|
||||
|
||||
fix := protest.BuildFixture("http_server", protest.LinkStrip)
|
||||
fix := protest.BuildFixture("http_server", noDebugFlags)
|
||||
|
||||
// dlv exec the binary file and expect error.
|
||||
out, err := exec.Command(dlvbin, "exec", "--headless", "--log", fix.Path).CombinedOutput()
|
||||
@ -700,6 +702,58 @@ func TestDAPCmd(t *testing.T) {
|
||||
cmd.Wait()
|
||||
}
|
||||
|
||||
func TestDAPCmdWithNoDebugBinary(t *testing.T) {
|
||||
const listenAddr = "127.0.0.1:40579"
|
||||
|
||||
dlvbin, tmpdir := getDlvBin(t)
|
||||
defer os.RemoveAll(tmpdir)
|
||||
|
||||
cmd := exec.Command(dlvbin, "dap", "--log", "--listen", listenAddr)
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
assertNoError(err, t, "stdout pipe")
|
||||
defer stdout.Close()
|
||||
stderr, err := cmd.StderrPipe()
|
||||
assertNoError(err, t, "stderr pipe")
|
||||
defer stderr.Close()
|
||||
assertNoError(cmd.Start(), t, "start dap instance")
|
||||
|
||||
scanOut := bufio.NewScanner(stdout)
|
||||
scanErr := bufio.NewScanner(stderr)
|
||||
// Wait for the debug server to start
|
||||
scanOut.Scan()
|
||||
listening := "DAP server listening at: " + listenAddr
|
||||
if scanOut.Text() != listening {
|
||||
cmd.Process.Kill() // release the port
|
||||
t.Fatalf("Unexpected stdout:\ngot %q\nwant %q", scanOut.Text(), listening)
|
||||
}
|
||||
go func() { // Capture logging
|
||||
for scanErr.Scan() {
|
||||
t.Log(scanErr.Text())
|
||||
}
|
||||
}()
|
||||
|
||||
// Exec the stripped debuggee and expect things to fail
|
||||
noDebugFlags := protest.LinkStrip
|
||||
// -s doesn't strip symbols on Mac, use -w instead
|
||||
if runtime.GOOS == "darwin" {
|
||||
noDebugFlags = protest.LinkDisableDWARF
|
||||
}
|
||||
fixture := protest.BuildFixture("increment", noDebugFlags)
|
||||
go func() {
|
||||
for scanOut.Scan() {
|
||||
t.Errorf("Unexpected stdout: %s", scanOut.Text())
|
||||
}
|
||||
}()
|
||||
client := daptest.NewClient(listenAddr)
|
||||
client.LaunchRequest("exec", fixture.Path, false)
|
||||
client.ExpectErrorResponse(t)
|
||||
client.DisconnectRequest()
|
||||
client.ExpectDisconnectResponse(t)
|
||||
client.ExpectTerminatedEvent(t)
|
||||
client.Close()
|
||||
cmd.Wait()
|
||||
}
|
||||
|
||||
func newDAPRemoteClient(t *testing.T, addr string) *daptest.Client {
|
||||
c := daptest.NewClient(addr)
|
||||
c.AttachRequest(map[string]interface{}{"mode": "remote", "stopOnEntry": true})
|
||||
|
@ -711,7 +711,7 @@ func (p *gdbProcess) initialize(path string, debugInfoDirs []string, stopReason
|
||||
StopReason: stopReason,
|
||||
CanDump: runtime.GOOS == "darwin"})
|
||||
if err != nil {
|
||||
p.conn.conn.Close()
|
||||
p.Detach(true)
|
||||
return nil, err
|
||||
}
|
||||
return tgt, nil
|
||||
|
@ -78,6 +78,8 @@ const (
|
||||
BuildModePlugin
|
||||
BuildModeExternalLinker
|
||||
AllNonOptimized
|
||||
// LinkDisableDWARF enables '-ldflags="-w"'.
|
||||
LinkDisableDWARF
|
||||
)
|
||||
|
||||
// BuildFixture will compile the fixture 'name' using the provided build flags.
|
||||
@ -114,9 +116,14 @@ func BuildFixture(name string, flags BuildFlags) Fixture {
|
||||
// Work-around for https://github.com/golang/go/issues/13154
|
||||
buildFlags = append(buildFlags, "-ldflags=-linkmode internal")
|
||||
}
|
||||
ldflagsv := []string{}
|
||||
if flags&LinkStrip != 0 {
|
||||
buildFlags = append(buildFlags, "-ldflags=-s")
|
||||
ldflagsv = append(ldflagsv, "-s")
|
||||
}
|
||||
if flags&LinkDisableDWARF != 0 {
|
||||
ldflagsv = append(ldflagsv, "-w")
|
||||
}
|
||||
buildFlags = append(buildFlags, "-ldflags="+strings.Join(ldflagsv, " "))
|
||||
gcflagsv := []string{}
|
||||
if flags&EnableInlining == 0 {
|
||||
gcflagsv = append(gcflagsv, "-l")
|
||||
|
Loading…
Reference in New Issue
Block a user