From 9d1711d37617976d576578df36ede474bf97e31d Mon Sep 17 00:00:00 2001 From: Derek Parker Date: Fri, 26 Jun 2015 09:14:21 -0500 Subject: [PATCH] dbp.Running determined by any thread running --- proc/proc.go | 11 ++++++----- proc/proc_test.go | 2 ++ proc/threads.go | 2 +- proc/threads_linux.go | 2 -- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/proc/proc.go b/proc/proc.go index 7b0e9af5..481b5899 100644 --- a/proc/proc.go +++ b/proc/proc.go @@ -51,7 +51,6 @@ type Process struct { ast *source.Searcher breakpointIDCounter int tempBreakpointIDCounter int - running bool halt bool exited bool ptraceChan chan func() @@ -130,7 +129,12 @@ func (dbp *Process) Exited() bool { // Returns whether or not Delve thinks the debugged // process is currently executing. func (dbp *Process) Running() bool { - return dbp.running + for _, th := range dbp.Threads { + if th.running { + return true + } + } + return false } // Finds the executable and then uses it @@ -212,7 +216,6 @@ func (dbp *Process) RequestManualStop() error { if err != nil { return err } - dbp.running = false return nil } @@ -643,12 +646,10 @@ func (dbp *Process) run(fn func() error) error { if dbp.exited { return fmt.Errorf("process has already exited") } - dbp.running = true dbp.halt = false for _, th := range dbp.Threads { th.CurrentBreakpoint = nil } - defer func() { dbp.running = false }() if err := fn(); err != nil { if _, ok := err.(ManualStopError); !ok { return err diff --git a/proc/proc_test.go b/proc/proc_test.go index b2813f1a..cf61c793 100644 --- a/proc/proc_test.go +++ b/proc/proc_test.go @@ -7,6 +7,7 @@ import ( "path/filepath" "runtime" "testing" + "time" protest "github.com/derekparker/delve/proc/test" ) @@ -110,6 +111,7 @@ func TestHalt(t *testing.T) { go func() { for { if p.Running() { + time.Sleep(time.Millisecond) if err := p.RequestManualStop(); err != nil { t.Fatal(err) } diff --git a/proc/threads.go b/proc/threads.go index bcc597a5..ad6f9976 100644 --- a/proc/threads.go +++ b/proc/threads.go @@ -64,8 +64,8 @@ func (thread *Thread) Continue() error { // execute the instruction, and then replace the breakpoint. // Otherwise we simply execute the next instruction. func (thread *Thread) Step() (err error) { - thread.singleStepping = true thread.running = true + thread.singleStepping = true defer func() { thread.singleStepping = false thread.running = false diff --git a/proc/threads_linux.go b/proc/threads_linux.go index 9ed0467d..e737463a 100644 --- a/proc/threads_linux.go +++ b/proc/threads_linux.go @@ -35,8 +35,6 @@ func (t *Thread) resume() (err error) { } func (t *Thread) singleStep() (err error) { - t.running = true - defer func() { t.running = false }() t.dbp.execPtraceFunc(func() { err = sys.PtraceSingleStep(t.Id) }) if err != nil { return err