1
0
mirror of https://github.com/golang/go synced 2024-11-23 02:10:03 -07:00
go/usr/austin/ogle/goroutine.go
Austin Clements ad9c6f7700 Rudimentary command shell for Ogle. Hack to prevent linker
from inlining newprocreadylocked.  Fix type bridge's handling
of basic types.  Include interpreter's Thread in bridged
native function calls.

; load . "6.out"
Started 6.out
; BpSet("main·merge")
; ContWait()
breakpoint at 0x400800
=>   400800 main·merge /home/austin/src-go1/usr/austin/ptrace/test/sort.go:19
; bt
=>   400800 main·merge /home/austin/src-go1/usr/austin/ptrace/test/sort.go:19
     400b6a main·mergeSort+0x1be /home/austin/src-go1/usr/austin/ptrace/test/sort.go:34
     448313 goexit /home/austin/src-go1/src/pkg/runtime/proc.c:133
; main.merge.a
{1}

; load . "pid:25753"
Attached to 25753
; bt
=>   479ddf syscall·Syscall+0x24 /home/austin/src-go1/src/pkg/syscall/asm_linux_amd64.s:24
     47c011 syscall·Read+0x5d /home/austin/src-go1/src/pkg/syscall/zsyscall_linux_amd64.go:368
     4119e5 os·*File·Read+0x5f /home/austin/src-go1/src/pkg/os/file.go:122
     427bf3 bufio·*Reader·fill+0x116 /home/austin/src-go1/src/pkg/bufio/bufio.go:105
     428361 bufio·*Reader·ReadSlice+0x195 /home/austin/src-go1/src/pkg/bufio/bufio.go:244
     40204a ogle·Main+0x94 /home/austin/src-go1/usr/austin/ogle/cmd.go:226
     40080f main·main+0xf /home/austin/src-go1/usr/austin/ogle/main.go:6
     41c4b8 mainstart+0xf /home/austin/src-go1/src/pkg/runtime/amd64/asm.s:55
     41531f goexit /home/austin/src-go1/src/pkg/runtime/proc.c:133

R=rsc
APPROVED=rsc
DELTA=433  (420 added, 2 deleted, 11 changed)
OCL=34410
CL=34782
2009-09-18 09:11:19 -07:00

120 lines
2.6 KiB
Go

// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package ogle
import (
"eval";
"fmt";
"os";
"ptrace";
)
// A Goroutine represents a goroutine in a remote process.
type Goroutine struct {
g remoteStruct;
frame *Frame;
dead bool;
}
func (t *Goroutine) String() string {
if t.dead {
return "<dead thread>";
}
// TODO(austin) Give threads friendly ID's, possibly including
// the name of the entry function.
return fmt.Sprintf("thread %#x", t.g.addr().base);
}
// isG0 returns true if this thread if the internal idle thread
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) {
// TODO(austin) Reuse any live part of the current frame stack
// so existing references to Frame's keep working.
t.frame, err = newFrame(t.g);
return;
}
// Out selects the caller frame of the current frame.
func (t *Goroutine) Out() os.Error {
f, err := t.frame.Outer();
if f != nil {
t.frame = f;
}
return err;
}
// In selects the frame called by the current frame.
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();
// The new g is the only argument to this function, so the
// stack will have the return address, then the G*.
regs, err := b.osThread.Regs();
if err != nil {
return EAStop, err;
}
sp := regs.SP();
addr := sp + ptrace.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;
// Enqueue goroutine creation event
parent := b.Goroutine();
if parent.isG0() {
parent = nil;
}
p.postEvent(&GoroutineCreate{commonEvent{p, g}, parent});
// If we don't have any thread selected, select this one
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;
// Enqueue thread exit event
p.postEvent(&GoroutineExit{commonEvent{p, g}});
// If we just exited our selected goroutine, selected another
if p.curGoroutine == g {
p.selectSomeGoroutine();
}
return EADefault, nil;
}