Refactor: Use thread-locked goroutine for ptrace ops

Previously either the terminal client or the debugger service would
either lock main goroutine to a thread or provide a locked goroutine to
run _all_ DebuggedProcess functions in. This is unnecessary because only
ptrace functions need to be run from the same thread that originated the
PT_ATTACH request.

Here we use a specific thread-locked goroutine to service any ptrace
request. That goroutine is also responsible for the initial spawning /
attaching of the process, since it must be responsible for the PT_ATTACH
request.
This commit is contained in:
Derek Parker
2015-06-12 23:47:30 -05:00
parent fe23036035
commit e4fc5e32c2
15 changed files with 391 additions and 459 deletions

View File

@ -2,7 +2,9 @@ package rest
import (
"net"
"os"
"path/filepath"
"runtime"
"testing"
protest "github.com/derekparker/delve/proc/test"
@ -10,6 +12,10 @@ import (
"github.com/derekparker/delve/service/api"
)
func init() {
runtime.GOMAXPROCS(2)
}
func TestMain(m *testing.M) {
protest.RunTestsWithFixtures(m)
}
@ -272,10 +278,16 @@ func TestClientServer_switchThread(t *testing.T) {
func TestClientServer_infoLocals(t *testing.T) {
withTestClient("testnextprog", t, func(c service.Client) {
fp, err := filepath.Abs("../../_fixtures/testnextprog.go")
fp, err := filepath.Abs("_fixtures/testnextprog.go")
if err != nil {
t.Fatal(err)
}
if _, err := os.Stat(fp); err != nil {
fp, err = filepath.Abs("../../_fixtures/testnextprog.go")
if err != nil {
t.Fatal(err)
}
}
_, err = c.CreateBreakpoint(&api.Breakpoint{File: fp, Line: 23})
if err != nil {
t.Fatalf("Unexpected error: %v", err)
@ -296,10 +308,16 @@ func TestClientServer_infoLocals(t *testing.T) {
func TestClientServer_infoArgs(t *testing.T) {
withTestClient("testnextprog", t, func(c service.Client) {
fp, err := filepath.Abs("../../_fixtures/testnextprog.go")
fp, err := filepath.Abs("_fixtures/testnextprog.go")
if err != nil {
t.Fatal(err)
}
if _, err := os.Stat(fp); err != nil {
fp, err = filepath.Abs("../../_fixtures/testnextprog.go")
if err != nil {
t.Fatal(err)
}
}
_, err = c.CreateBreakpoint(&api.Breakpoint{File: fp, Line: 47})
if err != nil {
t.Fatalf("Unexpected error: %v", err)