Skip to content

Commit

Permalink
Rename core.ReadAddress to core.ReadPtr
Browse files Browse the repository at this point in the history
  • Loading branch information
randall77 committed Sep 14, 2017
1 parent 745dae7 commit 9b149ed
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 36 deletions.
6 changes: 3 additions & 3 deletions core/read.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package core

import (
"debug/elf"
"debug/elf" // TODO: use golang.org/x/debug/elf instead?
"encoding/binary"
"fmt"
"os"
Expand Down Expand Up @@ -511,8 +511,8 @@ func (p *Process) ReadInt(a Address) int64 {
return p.ReadInt64(a)
}

// ReadAddress returns a pointer loaded from address a of the inferior.
func (p *Process) ReadAddress(a Address) Address {
// ReadPtr returns a pointer loaded from address a of the inferior.
func (p *Process) ReadPtr(a Address) Address {
return Address(p.ReadUintptr(a))
}

Expand Down
24 changes: 12 additions & 12 deletions gocore/dwarf.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ func (p *Program) typeHeap() {
}

type reader interface {
ReadAddress(core.Address) core.Address
ReadPtr(core.Address) core.Address
ReadInt(core.Address) int64
}

Expand All @@ -428,11 +428,11 @@ type frameReader struct {
live map[core.Address]bool
}

func (fr *frameReader) ReadAddress(a core.Address) core.Address {
func (fr *frameReader) ReadPtr(a core.Address) core.Address {
if !fr.live[a] {
return 0
}
return fr.p.proc.ReadAddress(a)
return fr.p.proc.ReadPtr(a)
}
func (fr *frameReader) ReadInt(a core.Address) int64 {
return fr.p.proc.ReadInt(a)
Expand All @@ -450,13 +450,13 @@ func (p *Program) typeObject(a core.Address, t *Type, r reader, add func(core.Ad
case KindEface, KindIface:
// interface. Use the type word to determine the type
// of the pointed-to object.
typ := r.ReadAddress(a)
typ := r.ReadPtr(a)
if typ == 0 { // nil interface
return
}
ptr := r.ReadAddress(a.Add(ptrSize))
ptr := r.ReadPtr(a.Add(ptrSize))
if t.Kind == KindIface {
typ = p.proc.ReadAddress(typ.Add(p.rtStructs["runtime.itab"].fields["_type"].off))
typ = p.proc.ReadPtr(typ.Add(p.rtStructs["runtime.itab"].fields["_type"].off))
}
// TODO: for KindEface, type the typ pointer. It might point to the heap
// if the type was allocated with reflect.
Expand Down Expand Up @@ -485,28 +485,28 @@ func (p *Program) typeObject(a core.Address, t *Type, r reader, add func(core.Ad
}
add(ptr, dt, 1)
case KindString:
ptr := r.ReadAddress(a)
ptr := r.ReadPtr(a)
len := r.ReadInt(a.Add(ptrSize))
add(ptr, t.Elem, len)
case KindSlice:
ptr := r.ReadAddress(a)
ptr := r.ReadPtr(a)
cap := r.ReadInt(a.Add(2 * ptrSize))
add(ptr, t.Elem, cap)
case KindPtr:
if t.Elem != nil { // unsafe.Pointer has a nil Elem field.
add(r.ReadAddress(a), t.Elem, 1)
add(r.ReadPtr(a), t.Elem, 1)
}
case KindFunc:
// The referent is a closure. We don't know much about the
// type of the referent. Its first entry is a code pointer.
// The runtime._type we want exists in the binary (for all
// heap-allocated closures, anyway) but it would be hard to find
// just given the pc.
closure := r.ReadAddress(a)
closure := r.ReadPtr(a)
if closure == 0 {
break
}
pc := p.proc.ReadAddress(closure)
pc := p.proc.ReadPtr(closure)
f := p.funcTab.find(pc)
if f == nil {
panic(fmt.Sprintf("can't find func for closure pc %x", pc))
Expand Down Expand Up @@ -534,7 +534,7 @@ func (p *Program) typeObject(a core.Address, t *Type, r reader, add func(core.Ad
var n int64
for _, f := range t.Fields {
if f.Name == "buckets" {
bPtr = p.proc.ReadAddress(a.Add(f.Off))
bPtr = p.proc.ReadPtr(a.Add(f.Off))
bTyp = f.Type.Elem
}
if f.Name == "B" {
Expand Down
12 changes: 6 additions & 6 deletions gocore/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (p *Program) readObjects() {
for _, g := range p.goroutines {
for _, f := range g.frames {
for a := range f.live { // TODO: iteration order matter?
add(p.proc.ReadAddress(a))
add(p.proc.ReadPtr(a))
}
}
}
Expand All @@ -57,7 +57,7 @@ func (p *Program) readObjects() {
n := max.Sub(min) / ptrSize
for i := int64(0); i < n; i++ {
if p.proc.ReadUint8(gc.Add(i/8))>>uint(i%8)&1 != 0 {
add(p.proc.ReadAddress(min.Add(i * ptrSize)))
add(p.proc.ReadPtr(min.Add(i * ptrSize)))
}
}
}
Expand All @@ -74,7 +74,7 @@ func (p *Program) readObjects() {
// scan [obj.Addr,obj.Addr+obj.Size]
for a := obj.Addr; a < obj.Addr.Add(obj.Size); a = a.Add(ptrSize) {
if p.isPtr(a) {
add(p.proc.ReadAddress(a))
add(p.proc.ReadPtr(a))
}
}
}
Expand Down Expand Up @@ -157,7 +157,7 @@ func (p *Program) ForEachPtr(x *Object, fn func(int64, *Object, int64) bool) {
if !p.isPtr(a) {
continue
}
ptr := p.proc.ReadAddress(a)
ptr := p.proc.ReadPtr(a)
y, off := p.FindObject(ptr)
if y != nil {
if !fn(i, y, off) {
Expand All @@ -184,7 +184,7 @@ func edges1(p *Program, r *Root, off int64, t *Type, fn func(int64, *Object, int
// Types might be, though.
a := r.Addr.Add(off)
if r.Live == nil || r.Live[a] {
dst, off2 := p.FindObject(p.proc.ReadAddress(a))
dst, off2 := p.FindObject(p.proc.ReadPtr(a))
if dst != nil {
if !fn(off, dst, off2) {
return false
Expand All @@ -197,7 +197,7 @@ func edges1(p *Program, r *Root, off int64, t *Type, fn func(int64, *Object, int
case KindPtr, KindString, KindSlice, KindFunc:
a := r.Addr.Add(off)
if r.Live == nil || r.Live[a] {
dst, off2 := p.FindObject(p.proc.ReadAddress(a))
dst, off2 := p.FindObject(p.proc.ReadPtr(a))
if dst != nil {
if !fn(off, dst, off2) {
return false
Expand Down
14 changes: 7 additions & 7 deletions gocore/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func Core(proc *core.Process) (p *Program, err error) {

// Load the build version.
a := m["runtime.buildVersion"]
ptr := proc.ReadAddress(a)
ptr := proc.ReadPtr(a)
len := proc.ReadInt(a.Add(proc.PtrSize()))
b := make([]byte, len)
proc.ReadAt(b, ptr)
Expand Down Expand Up @@ -215,7 +215,7 @@ func (p *Program) readSpans() {
case spanManual:
manualSpanSize += spanSize
manualAllocSize += spanSize
for x := core.Address(s.Field("manualFreeList").Cast("uintptr").Uintptr()); x != 0; x = p.proc.ReadAddress(x) {
for x := core.Address(s.Field("manualFreeList").Cast("uintptr").Uintptr()); x != 0; x = p.proc.ReadPtr(x) {
manualAllocSize -= elemSize
manualFreeSize += elemSize
}
Expand Down Expand Up @@ -466,7 +466,7 @@ func (m *module) readFunc(r region, pcln region) *Func {
a = a.Align(r.p.proc.PtrSize())
n = r.Field("nfuncdata").Int32()
for i := int32(0); i < n; i++ {
f.funcdata = append(f.funcdata, r.p.proc.ReadAddress(a))
f.funcdata = append(f.funcdata, r.p.proc.ReadPtr(a))
a = a.Add(r.p.proc.PtrSize())
}

Expand Down Expand Up @@ -502,7 +502,7 @@ func funcdata(r region, n int64) core.Address {
x++
}
a := r.a.Add(int64(r.p.rtStructs["runtime._func"].size + 4*int64(x) + r.p.proc.PtrSize()*n))
return r.p.proc.ReadAddress(a)
return r.p.proc.ReadPtr(a)
}

func (p *Program) readMs() {
Expand Down Expand Up @@ -586,12 +586,12 @@ func (p *Program) readG(r region) *Goroutine {
if f.f.name == "runtime.sigtrampgo" {
// Continue traceback at location where the signal
// interrupted normal execution.
ctxt := p.proc.ReadAddress(sp.Add(16)) // 3rd arg
ctxt := p.proc.ReadPtr(sp.Add(16)) // 3rd arg
//ctxt is a *ucontext
mctxt := ctxt.Add(5 * 8)
// mctxt is a *mcontext
sp = p.proc.ReadAddress(mctxt.Add(15 * 8))
pc = p.proc.ReadAddress(mctxt.Add(16 * 8))
sp = p.proc.ReadPtr(mctxt.Add(15 * 8))
pc = p.proc.ReadPtr(mctxt.Add(16 * 8))
// TODO: totally arch-dependent!
} else {
sp = f.max
Expand Down
8 changes: 4 additions & 4 deletions gocore/region.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (r region) Address() core.Address {
if len(r.typ) == 0 || r.typ[0] != '*' {
panic("can't ask for the Address of a non-pointer " + r.typ)
}
return r.p.proc.ReadAddress(r.a)
return r.p.proc.ReadPtr(r.a)
}

// Int returns the int value stored in r.
Expand Down Expand Up @@ -60,7 +60,7 @@ func (r region) Deref() region {
if len(r.typ) == 0 || r.typ[0] != '*' {
panic("can't load on non-pointer: " + r.typ)
}
p := r.p.proc.ReadAddress(r.a)
p := r.p.proc.ReadPtr(r.a)
return region{p: r.p, a: p, typ: r.typ[1:]}
}

Expand Down Expand Up @@ -104,7 +104,7 @@ func (r region) String() string {
if r.typ != "string" {
panic("bad string type " + r.typ)
}
p := r.p.proc.ReadAddress(r.a)
p := r.p.proc.ReadPtr(r.a)
n := r.p.proc.ReadUintptr(r.a.Add(r.p.proc.PtrSize()))
b := make([]byte, n)
r.p.proc.ReadAt(b, p)
Expand All @@ -116,7 +116,7 @@ func (r region) SliceIndex(n int64) region {
if len(r.typ) < 2 || r.typ[:2] != "[]" {
panic("can't index a non-slice")
}
p := r.p.proc.ReadAddress(r.a)
p := r.p.proc.ReadPtr(r.a)
return region{p: r.p, a: p.Add(n * r.p.typeSize(r.typ[2:])), typ: r.typ[2:]}
}

Expand Down
8 changes: 4 additions & 4 deletions html.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ func htmlObject(w http.ResponseWriter, c *gocore.Program, name string, a core.Ad
fmt.Fprintf(w, "<tr><td>%s</td><td>%s</td><td>%s</td></tr>\n", name, html.EscapeString(t.String()), htmlPointerAt(c, a, live))
case gocore.KindFunc:
fmt.Fprintf(w, "<tr><td>%s</td><td>%s</td><td>%s</td>", name, html.EscapeString(t.String()), htmlPointerAt(c, a, live))
if fn := c.Process().ReadAddress(a); fn != 0 {
pc := c.Process().ReadAddress(fn)
if fn := c.Process().ReadPtr(a); fn != 0 {
pc := c.Process().ReadPtr(fn)
if f := c.FindFunc(pc); f != nil && f.Entry() == pc {
fmt.Fprintf(w, "<td>%s</td>", f.Name())
}
Expand All @@ -248,7 +248,7 @@ func htmlObject(w http.ResponseWriter, c *gocore.Program, name string, a core.Ad
ddd = "..."
}
b := make([]byte, n2)
c.Process().ReadAt(b, c.Process().ReadAddress(a))
c.Process().ReadAt(b, c.Process().ReadPtr(a))
fmt.Fprintf(w, "<td rowspan=\"2\">\"%s\"%s</td>", html.EscapeString(string(b)), ddd)
} else {
fmt.Fprintf(w, "<td rowspan=\"2\">\"\"</td>")
Expand Down Expand Up @@ -299,7 +299,7 @@ func htmlPointerAt(c *gocore.Program, a core.Address, live map[core.Address]bool
if live != nil && !live[a] {
return "<text style=\"color:LightGray\">dead</text>"
}
return htmlPointer(c, c.Process().ReadAddress(a))
return htmlPointer(c, c.Process().ReadPtr(a))
}

func tableStyle(w http.ResponseWriter) {
Expand Down

0 comments on commit 9b149ed

Please sign in to comment.