package ogle
import (
"debug/proc"
"exp/eval"
"fmt"
"os"
)
type Goroutine struct {
g remoteStruct
frame *Frame
dead bool
}
func (t *Goroutine) String() string {
if t.dead {
return "<dead thread>"
}
return fmt.Sprintf("thread %#x", t.g.addr().base)
}
func (t *Goroutine) isG0() bool { return t.g.addr().base == t.g.r.p.sys.g0.addr().base }
func (t *Goroutine) resetFrame() (err os.Error) {
t.frame, err = newFrame(t.g)
return
}
func (t *Goroutine) Out() os.Error {
f, err := t.frame.Outer()
if f != nil {
t.frame = f
}
return err
}
func (t *Goroutine) In() os.Error {
f := t.frame.Inner()
if f != nil {
t.frame = f
}
return nil
}
func readylockedBP(ev Event) (EventAction, os.Error) {
b := ev.(*Breakpoint)
p := b.Process()
regs, err := b.osThread.Regs()
if err != nil {
return EAStop, err
}
sp := regs.SP()
addr := sp + proc.Word(p.PtrSize())
arg := remotePtr{remote{addr, p}, p.runtime.G}
var gp eval.Value
err = try(func(a aborter) { gp = arg.aGet(a) })
if err != nil {
return EAStop, err
}
if gp == nil {
return EAStop, UnknownGoroutine{b.osThread, 0}
}
gs := gp.(remoteStruct)
g := &Goroutine{gs, nil, false}
p.goroutines[gs.addr().base] = g
parent := b.Goroutine()
if parent.isG0() {
parent = nil
}
p.postEvent(&GoroutineCreate{commonEvent{p, g}, parent})
if p.curGoroutine == nil {
p.curGoroutine = g
}
return EADefault, nil
}
func goexitBP(ev Event) (EventAction, os.Error) {
b := ev.(*Breakpoint)
p := b.Process()
g := b.Goroutine()
g.dead = true
addr := g.g.addr().base
p.goroutines[addr] = nil, false
p.postEvent(&GoroutineExit{commonEvent{p, g}})
if p.curGoroutine == g {
p.selectSomeGoroutine()
}
return EADefault, nil
}