本文整理汇总了Golang中debug/proc.Word函数的典型用法代码示例。如果您正苦于以下问题:Golang Word函数的具体用法?Golang Word怎么用?Golang Word使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Word函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: String
func (f *Frame) String() string {
res := f.fn.Name
if f.pc > proc.Word(f.fn.Value) {
res += fmt.Sprintf("+%#x", f.pc-proc.Word(f.fn.Entry))
}
return res + fmt.Sprintf(" %s:%d", f.path, f.line)
}
示例2: aOuter
func (f *Frame) aOuter(a aborter) *Frame {
// Is there a cached outer frame
if f.outer != nil {
return f.outer
}
p := f.stk.r.p
sp := f.fp
if f.fn == p.sys.newproc && f.fn == p.sys.deferproc {
// TODO(rsc) The compiler inserts two push/pop's
// around calls to go and defer. Russ says this
// should get fixed in the compiler, but we account
// for it for now.
sp += proc.Word(2 * p.PtrSize())
}
pc := p.peekUintptr(a, f.fp-proc.Word(p.PtrSize()))
if pc < 0x1000 {
return nil
}
// TODO(austin) Register this frame for shoot-down.
f.outer = prepareFrame(a, pc, sp, f.stk, f)
return f.outer
}
示例3: NewProcess
// NewProcess constructs a new remote process around a traced
// process, an architecture, and a symbol table.
func NewProcess(tproc proc.Process, arch Arch, syms *gosym.Table) (*Process, os.Error) {
p := &Process{
Arch: arch,
proc: tproc,
syms: syms,
types: make(map[proc.Word]*remoteType),
breakpointHooks: make(map[proc.Word]*breakpointHook),
goroutineCreateHook: new(goroutineCreateHook),
goroutineExitHook: new(goroutineExitHook),
goroutines: make(map[proc.Word]*Goroutine),
}
// Fill in remote runtime
p.bootstrap()
switch {
case p.sys.allg.addr().base == 0:
return nil, FormatError("failed to find runtime symbol 'allg'")
case p.sys.g0.addr().base == 0:
return nil, FormatError("failed to find runtime symbol 'g0'")
case p.sys.newprocreadylocked == nil:
return nil, FormatError("failed to find runtime symbol 'newprocreadylocked'")
case p.sys.goexit == nil:
return nil, FormatError("failed to find runtime symbol 'sys.goexit'")
}
// Get current goroutines
p.goroutines[p.sys.g0.addr().base] = &Goroutine{p.sys.g0, nil, false}
err := try(func(a aborter) {
g := p.sys.allg.aGet(a)
for g != nil {
gs := g.(remoteStruct)
fmt.Printf("*** Found goroutine at %#x\n", gs.addr().base)
p.goroutines[gs.addr().base] = &Goroutine{gs, nil, false}
g = gs.field(p.f.G.Alllink).(remotePtr).aGet(a)
}
})
if err != nil {
return nil, err
}
// Create internal breakpoints to catch new and exited goroutines
p.OnBreakpoint(proc.Word(p.sys.newprocreadylocked.Entry)).(*breakpointHook).addHandler(readylockedBP, true)
p.OnBreakpoint(proc.Word(p.sys.goexit.Entry)).(*breakpointHook).addHandler(goexitBP, true)
// Select current frames
for _, g := range p.goroutines {
g.resetFrame()
}
p.selectSomeGoroutine()
return p, nil
}
示例4: bootstrap
// bootstrap constructs the runtime structure of a remote process.
func (p *Process) bootstrap() {
// Manually construct runtime types
p.runtime.String = newManualType(eval.TypeOfNative(rt1String{}), p.Arch)
p.runtime.Slice = newManualType(eval.TypeOfNative(rt1Slice{}), p.Arch)
p.runtime.Eface = newManualType(eval.TypeOfNative(rt1Eface{}), p.Arch)
p.runtime.Type = newManualType(eval.TypeOfNative(rt1Type{}), p.Arch)
p.runtime.CommonType = newManualType(eval.TypeOfNative(rt1CommonType{}), p.Arch)
p.runtime.UncommonType = newManualType(eval.TypeOfNative(rt1UncommonType{}), p.Arch)
p.runtime.StructField = newManualType(eval.TypeOfNative(rt1StructField{}), p.Arch)
p.runtime.StructType = newManualType(eval.TypeOfNative(rt1StructType{}), p.Arch)
p.runtime.PtrType = newManualType(eval.TypeOfNative(rt1PtrType{}), p.Arch)
p.runtime.ArrayType = newManualType(eval.TypeOfNative(rt1ArrayType{}), p.Arch)
p.runtime.SliceType = newManualType(eval.TypeOfNative(rt1SliceType{}), p.Arch)
p.runtime.Stktop = newManualType(eval.TypeOfNative(rt1Stktop{}), p.Arch)
p.runtime.Gobuf = newManualType(eval.TypeOfNative(rt1Gobuf{}), p.Arch)
p.runtime.G = newManualType(eval.TypeOfNative(rt1G{}), p.Arch)
// Get addresses of type.*runtime.XType for discrimination.
rtv := reflect.Indirect(reflect.NewValue(&p.runtime)).(*reflect.StructValue)
rtvt := rtv.Type().(*reflect.StructType)
for i := 0; i < rtv.NumField(); i++ {
n := rtvt.Field(i).Name
if n[0] != 'P' || n[1] < 'A' || n[1] > 'Z' {
continue
}
sym := p.syms.LookupSym("type.*runtime." + n[1:])
if sym == nil {
continue
}
rtv.Field(i).(*reflect.UintValue).Set(sym.Value)
}
// Get runtime field indexes
fillRuntimeIndexes(&p.runtime, &p.f)
// Fill G status
p.runtime.runtimeGStatus = rt1GStatus
// Get globals
p.sys.lessstack = p.syms.LookupFunc("sys.lessstack")
p.sys.goexit = p.syms.LookupFunc("goexit")
p.sys.newproc = p.syms.LookupFunc("sys.newproc")
p.sys.deferproc = p.syms.LookupFunc("sys.deferproc")
p.sys.newprocreadylocked = p.syms.LookupFunc("newprocreadylocked")
if allg := p.syms.LookupSym("allg"); allg != nil {
p.sys.allg = remotePtr{remote{proc.Word(allg.Value), p}, p.runtime.G}
}
if g0 := p.syms.LookupSym("g0"); g0 != nil {
p.sys.g0 = p.runtime.G.mk(remote{proc.Word(g0.Value), p}).(remoteStruct)
}
}
示例5: aNewFrame
func aNewFrame(a aborter, g remoteStruct) *Frame {
p := g.r.p
var pc, sp proc.Word
// Is this G alive?
switch g.field(p.f.G.Status).(remoteInt).aGet(a) {
case p.runtime.Gidle, p.runtime.Gmoribund, p.runtime.Gdead:
return nil
}
// Find the OS thread for this G
// TODO(austin) Ideally, we could look at the G's state and
// figure out if it's on an OS thread or not. However, this
// is difficult because the state isn't updated atomically
// with scheduling changes.
for _, t := range p.proc.Threads() {
regs, err := t.Regs()
if err != nil {
// TODO(austin) What to do?
continue
}
thisg := p.G(regs)
if thisg == g.addr().base {
// Found this G's OS thread
pc = regs.PC()
sp = regs.SP()
// If this thread crashed, try to recover it
if pc == 0 {
pc = p.peekUintptr(a, pc)
sp += 8
}
break
}
}
if pc == 0 && sp == 0 {
// G is not mapped to an OS thread. Use the
// scheduler's stored PC and SP.
sched := g.field(p.f.G.Sched).(remoteStruct)
pc = proc.Word(sched.field(p.f.Gobuf.Pc).(remoteUint).aGet(a))
sp = proc.Word(sched.field(p.f.Gobuf.Sp).(remoteUint).aGet(a))
}
// Get Stktop
stk := g.field(p.f.G.Stackbase).(remotePtr).aGet(a).(remoteStruct)
return prepareFrame(a, pc, sp, stk, nil)
}
示例6: aGet
func (v remotePtr) aGet(a aborter) eval.Value {
addr := proc.Word(v.r.Get(a, v.r.p.PtrSize()))
if addr == 0 {
return nil
}
return v.elemType.mk(remote{addr, v.r.p})
}
示例7: ToWord
func (ArchLSB) ToWord(data []byte) proc.Word {
var v proc.Word
for i, b := range data {
v |= proc.Word(b) << (uint(i) * 8)
}
return v
}
示例8: Set
func (v remote) Set(a aborter, size int, x uint64) {
var arr [8]byte
buf := arr[0:size]
v.p.FromWord(proc.Word(x), buf)
_, err := v.p.Poke(v.base, buf)
if err != nil {
a.Abort(err)
}
}
示例9: typeOfSym
// typeOfSym returns the type associated with a symbol. If the symbol
// has no type, returns nil.
func (p *Process) typeOfSym(s *gosym.Sym) (*remoteType, os.Error) {
if s.GoType == 0 {
return nil, nil
}
addr := proc.Word(s.GoType)
var rt *remoteType
err := try(func(a aborter) { rt = parseRemoteType(a, p.runtime.Type.mk(remote{addr, p}).(remoteStruct)) })
if err != nil {
return nil, err
}
return rt, nil
}
示例10: fnBpSet
func fnBpSet(t *eval.Thread, args []eval.Value, res []eval.Value) {
// TODO(austin) This probably shouldn't take a symbol name.
// Perhaps it should take an interface that provides PC's.
// Functions and instructions can implement that interface and
// we can have something to translate file:line pairs.
if curProc == nil {
t.Abort(NoCurrentGoroutine{})
}
name := args[0].(eval.StringValue).Get(t)
fn := curProc.syms.LookupFunc(name)
if fn == nil {
t.Abort(UsageError("no such function " + name))
}
curProc.OnBreakpoint(proc.Word(fn.Entry)).AddHandler(EventStop)
}
示例11: readylockedBP
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 + 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
// 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
}
示例12: causesToEvents
// causesToEvents translates the stop causes of the underlying process
// into an event queue.
func (p *Process) causesToEvents() ([]Event, os.Error) {
// Count causes we're interested in
nev := 0
for _, t := range p.proc.Threads() {
if c, err := t.Stopped(); err == nil {
switch c := c.(type) {
case proc.Breakpoint:
nev++
case proc.Signal:
// TODO(austin)
//nev++;
}
}
}
// Translate causes to events
events := make([]Event, nev)
i := 0
for _, t := range p.proc.Threads() {
if c, err := t.Stopped(); err == nil {
switch c := c.(type) {
case proc.Breakpoint:
gt, err := p.osThreadToGoroutine(t)
if err != nil {
return nil, err
}
events[i] = &Breakpoint{commonEvent{p, gt}, t, proc.Word(c)}
i++
case proc.Signal:
// TODO(austin)
}
}
}
return events, nil
}
示例13: prepareFrame
// prepareFrame creates a Frame from the PC and SP within that frame,
// as well as the active stack segment. This function takes care of
// traversing stack breaks and unwinding closures.
func prepareFrame(a aborter, pc, sp proc.Word, stk remoteStruct, inner *Frame) *Frame {
// Based on src/pkg/runtime/amd64/traceback.c:traceback
p := stk.r.p
top := inner == nil
// Get function
var path string
var line int
var fn *gosym.Func
for i := 0; i < 100; i++ {
// Traverse segmented stack breaks
if p.sys.lessstack != nil && pc == proc.Word(p.sys.lessstack.Value) {
// Get stk->gobuf.pc
pc = proc.Word(stk.field(p.f.Stktop.Gobuf).(remoteStruct).field(p.f.Gobuf.Pc).(remoteUint).aGet(a))
// Get stk->gobuf.sp
sp = proc.Word(stk.field(p.f.Stktop.Gobuf).(remoteStruct).field(p.f.Gobuf.Sp).(remoteUint).aGet(a))
// Get stk->stackbase
stk = stk.field(p.f.Stktop.Stackbase).(remotePtr).aGet(a).(remoteStruct)
continue
}
// Get the PC of the call instruction
callpc := pc
if !top && (p.sys.goexit == nil || pc != proc.Word(p.sys.goexit.Value)) {
callpc--
}
// Look up function
path, line, fn = p.syms.PCToLine(uint64(callpc))
if fn != nil {
break
}
// Closure?
var buf = make([]byte, p.ClosureSize())
if _, err := p.Peek(pc, buf); err != nil {
break
}
spdelta, ok := p.ParseClosure(buf)
if ok {
sp += proc.Word(spdelta)
pc = p.peekUintptr(a, sp-proc.Word(p.PtrSize()))
}
}
if fn == nil {
return nil
}
// Compute frame pointer
var fp proc.Word
if fn.FrameSize < p.PtrSize() {
fp = sp + proc.Word(p.PtrSize())
} else {
fp = sp + proc.Word(fn.FrameSize)
}
// TODO(austin) To really figure out if we're in the prologue,
// we need to disassemble the function and look for the call
// to morestack. For now, just special case the entry point.
//
// TODO(austin) What if we're in the call to morestack in the
// prologue? Then top == false.
if top && pc == proc.Word(fn.Entry) {
// We're in the function prologue, before SP
// has been adjusted for the frame.
fp -= proc.Word(fn.FrameSize - p.PtrSize())
}
return &Frame{pc, sp, fp, stk, fn, path, line, inner, nil}
}
示例14: field
func (v remoteStruct) field(i int) eval.Value {
f := &v.layout[i]
return f.fieldType.mk(v.r.plus(proc.Word(f.offset)))
}
示例15: Sub
func (v remoteArray) Sub(i int64, len int64) eval.ArrayValue {
return remoteArray{v.r.plus(proc.Word(int64(v.elemType.size) * i)), len, v.elemType}
}