mirror of
https://github.com/go-delve/delve.git
synced 2025-10-30 02:07:58 +08:00
thread.Halt: Remove duplication between OS implementations
Bring similar code up to top level, and keep OS dependant code in OS dependant files. DRY up code a bit.
This commit is contained in:
@ -299,3 +299,19 @@ func (thread *Thread) GetG() (g *G, err error) {
|
|||||||
func (thread *Thread) Stopped() bool {
|
func (thread *Thread) Stopped() bool {
|
||||||
return thread.stopped()
|
return thread.stopped()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stops this thread from executing. Actual
|
||||||
|
// implementation is OS dependant. Look in OS
|
||||||
|
// thread file.
|
||||||
|
func (thread *Thread) Halt() (err error) {
|
||||||
|
defer func() {
|
||||||
|
if err == nil {
|
||||||
|
thread.running = false
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
if thread.Stopped() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = thread.halt()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|||||||
@ -12,15 +12,7 @@ type OSSpecificDetails struct {
|
|||||||
registers C.x86_thread_state64_t
|
registers C.x86_thread_state64_t
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Thread) Halt() (err error) {
|
func (t *Thread) halt() (err error) {
|
||||||
defer func() {
|
|
||||||
if err == nil {
|
|
||||||
t.running = false
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
if t.Stopped() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
kret := C.thread_suspend(t.os.thread_act)
|
kret := C.thread_suspend(t.os.thread_act)
|
||||||
if kret != C.KERN_SUCCESS {
|
if kret != C.KERN_SUCCESS {
|
||||||
errStr := C.GoString(C.mach_error_string(C.mach_error_t(kret)))
|
errStr := C.GoString(C.mach_error_string(C.mach_error_t(kret)))
|
||||||
|
|||||||
@ -12,15 +12,7 @@ type OSSpecificDetails struct {
|
|||||||
registers sys.PtraceRegs
|
registers sys.PtraceRegs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Thread) Halt() (err error) {
|
func (t *Thread) halt() (err error) {
|
||||||
defer func() {
|
|
||||||
if err == nil {
|
|
||||||
t.running = false
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
if t.Stopped() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
err = sys.Tgkill(t.dbp.Pid, t.Id, sys.SIGSTOP)
|
err = sys.Tgkill(t.dbp.Pid, t.Id, sys.SIGSTOP)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("halt err %s on thread %d", err, t.Id)
|
err = fmt.Errorf("halt err %s on thread %d", err, t.Id)
|
||||||
|
|||||||
Reference in New Issue
Block a user