Skip to content

Commit

Permalink
Rename gocore.Program to gocore.Process.
Browse files Browse the repository at this point in the history
I hated the name "Program".
"Process" is the same name as core.Process.
Kind of unfortunate, but nothing better comes to mind.
  • Loading branch information
randall77 committed Oct 24, 2017
1 parent 7301434 commit 8e60c9a
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 50 deletions.
14 changes: 7 additions & 7 deletions gocore/dwarf.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

// read DWARF types from core dump.
func (p *Program) readDWARFTypes() {
func (p *Process) readDWARFTypes() {
d, _ := p.proc.DWARF()

// Make one of our own Types for each dwarf type.
Expand Down Expand Up @@ -350,7 +350,7 @@ func (c typeChunk) String() string {
}

// typeHeap tries to label all the heap objects with types.
func (p *Program) typeHeap() {
func (p *Process) typeHeap() {
// Type info for the start of each object. a.k.a. "0 offset" typings.
p.types = make([]typeInfo, p.nObj)

Expand Down Expand Up @@ -524,7 +524,7 @@ type reader interface {
}

type frameReader struct {
p *Program
p *Process
live map[core.Address]bool
}

Expand All @@ -541,7 +541,7 @@ func (fr *frameReader) ReadInt(a core.Address) int64 {
// typeObject takes an address and a type for the data at that address.
// For each pointer it finds in the memory at that address, it calls add with the pointer
// and the type + repeat count of the thing that it points to.
func (p *Program) typeObject(a core.Address, t *Type, r reader, add func(core.Address, *Type, int64)) {
func (p *Process) typeObject(a core.Address, t *Type, r reader, add func(core.Address, *Type, int64)) {
ptrSize := p.proc.PtrSize()

switch t.Kind {
Expand Down Expand Up @@ -653,7 +653,7 @@ func (p *Program) typeObject(a core.Address, t *Type, r reader, add func(core.Ad
}

// readRuntimeConstants populates the p.rtConstants map.
func (p *Program) readRuntimeConstants() {
func (p *Process) readRuntimeConstants() {
p.rtConstants = map[string]int64{}

// Hardcoded values for Go 1.8 & 1.9.
Expand Down Expand Up @@ -706,7 +706,7 @@ const (
_DW_OP_consts = 0x11
)

func (p *Program) readGlobals() {
func (p *Process) readGlobals() {
d, _ := p.proc.DWARF()
r := d.Reader()
for e, err := r.Next(); e != nil && err == nil; e, err = r.Next() {
Expand Down Expand Up @@ -744,7 +744,7 @@ func (p *Program) readGlobals() {
}
}

func (p *Program) readStackVars() {
func (p *Process) readStackVars() {
type Var struct {
name string
off int64
Expand Down
26 changes: 13 additions & 13 deletions gocore/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

// readObjects finds all the live objects in the heap and marks them
// in the p.heapInfo mark fields.
func (p *Program) readObjects() {
func (p *Process) readObjects() {
ptrSize := p.proc.PtrSize()

// number of live objects found so far
Expand Down Expand Up @@ -123,7 +123,7 @@ func (p *Program) readObjects() {

// isPtr reports whether the inferior at address a contains a pointer.
// a must be somewhere in the heap.
func (p *Program) isPtr(a core.Address) bool {
func (p *Process) isPtr(a core.Address) bool {
// Convert arena offset in words to bitmap offset in bits.
off := a.Sub(p.arenaStart)
off >>= p.proc.LogPtrSize()
Expand All @@ -134,7 +134,7 @@ func (p *Program) isPtr(a core.Address) bool {
}

// IsPtr reports whether the inferior at address a contains a pointer.
func (p *Program) IsPtr(a core.Address) bool {
func (p *Process) IsPtr(a core.Address) bool {
if a >= p.arenaStart && a < p.arenaUsed {
return p.isPtr(a)
}
Expand All @@ -159,7 +159,7 @@ func (p *Program) IsPtr(a core.Address) bool {
// FindObject finds the object containing a. Returns that object and the offset within
// that object to which a points.
// Returns 0,0 if a doesn't point to a live heap object.
func (p *Program) FindObject(a core.Address) (Object, int64) {
func (p *Process) FindObject(a core.Address) (Object, int64) {
if a < p.arenaStart || a >= p.arenaUsed {
// Not in Go heap.
return 0, 0
Expand All @@ -179,7 +179,7 @@ func (p *Program) FindObject(a core.Address) (Object, int64) {
return Object(x), a.Sub(x)
}

func (p *Program) findObjectIndex(a core.Address) (int, int64) {
func (p *Process) findObjectIndex(a core.Address) (int, int64) {
x, off := p.FindObject(a)
if x == 0 {
return -1, 0
Expand All @@ -190,7 +190,7 @@ func (p *Program) findObjectIndex(a core.Address) (int, int64) {

// ForEachObject calls fn with each object in the Go heap.
// If fn returns false, ForEachObject returns immediately.
func (p *Program) ForEachObject(fn func(x Object) bool) {
func (p *Process) ForEachObject(fn func(x Object) bool) {
for i := 0; i < len(p.heapInfo); i++ {
m := p.heapInfo[i].mark
for m != 0 {
Expand All @@ -205,7 +205,7 @@ func (p *Program) ForEachObject(fn func(x Object) bool) {

// ForEachRoot calls fn with each garbage collection root.
// If fn returns false, ForEachRoot returns immediately.
func (p *Program) ForEachRoot(fn func(r *Root) bool) {
func (p *Process) ForEachRoot(fn func(r *Root) bool) {
for _, r := range p.globals {
if !fn(r) {
return
Expand All @@ -223,19 +223,19 @@ func (p *Program) ForEachRoot(fn func(r *Root) bool) {
}

// Addr returns the starting address of x.
func (p *Program) Addr(x Object) core.Address {
func (p *Process) Addr(x Object) core.Address {
return core.Address(x)
}

// Size returns the size of x in bytes.
func (p *Program) Size(x Object) int64 {
func (p *Process) Size(x Object) int64 {
return p.heapInfo[uint64(core.Address(x).Sub(p.arenaStart))/512].size
}

// Type returns the type and repeat count for the object x.
// x contains at least repeat copies of the returned type.
// FlagTypes must have been passed to Core when p was constructed.
func (p *Program) Type(x Object) (*Type, int64) {
func (p *Process) Type(x Object) (*Type, int64) {
i, _ := p.findObjectIndex(core.Address(x))
return p.types[i].t, p.types[i].r
}
Expand All @@ -248,7 +248,7 @@ func (p *Program) Type(x Object) (*Type, int64) {
// If fn returns false, ForEachPtr returns immediately.
// For an edge from an object to its finalizer, the first argument
// passed to fn will be -1.
func (p *Program) ForEachPtr(x Object, fn func(int64, Object, int64) bool) {
func (p *Process) ForEachPtr(x Object, fn func(int64, Object, int64) bool) {
size := p.Size(x)
for i := int64(0); i < size; i += p.proc.PtrSize() {
a := core.Address(x).Add(i)
Expand All @@ -266,13 +266,13 @@ func (p *Program) ForEachPtr(x Object, fn func(int64, Object, int64) bool) {
}

// ForEachRootPtr behaves like ForEachPtr but it starts with a Root instead of an Object.
func (p *Program) ForEachRootPtr(r *Root, fn func(int64, Object, int64) bool) {
func (p *Process) ForEachRootPtr(r *Root, fn func(int64, Object, int64) bool) {
edges1(p, r, 0, r.Type, fn)
}

// edges1 calls fn for the edges found in an object of type t living at offset off in the root r.
// If fn returns false, return immediately with false.
func edges1(p *Program, r *Root, off int64, t *Type, fn func(int64, Object, int64) bool) bool {
func edges1(p *Process, r *Root, off int64, t *Type, fn func(int64, Object, int64) bool) bool {
switch t.Kind {
case KindBool, KindInt, KindUint, KindFloat, KindComplex:
// no edges here
Expand Down
20 changes: 10 additions & 10 deletions gocore/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

// Core takes a loaded core file and extracts Go information from it.
// flags is a bitmask of data that should be extracted from the core.
func Core(proc *core.Process, flags Flags) (p *Program, err error) {
func Core(proc *core.Process, flags Flags) (p *Process, err error) {
// Make sure we have DWARF info.
if _, err := proc.DWARF(); err != nil {
return nil, err
Expand All @@ -32,7 +32,7 @@ func Core(proc *core.Process, flags Flags) (p *Program, err error) {
}()
*/

p = &Program{
p = &Process{
proc: proc,
runtimeMap: map[core.Address]*Type{},
dwarfMap: map[dwarf.Type]*Type{},
Expand Down Expand Up @@ -69,7 +69,7 @@ func Core(proc *core.Process, flags Flags) (p *Program, err error) {
return p, nil
}

func (p *Program) readSpans() {
func (p *Process) readSpans() {
mheap := p.rtGlobals["mheap_"]

spanTableStart := mheap.Field("spans").SlicePtr().Address()
Expand Down Expand Up @@ -256,7 +256,7 @@ func (p *Program) readSpans() {
check(p.stats)
}

func (p *Program) readModules() {
func (p *Process) readModules() {
ms := p.rtGlobals["modulesSlice"].Cast("*[]*runtime.moduledata").Deref()
n := ms.SliceLen()
for i := int64(0); i < n; i++ {
Expand All @@ -265,7 +265,7 @@ func (p *Program) readModules() {
}
}

func (p *Program) readModule(r region) *module {
func (p *Process) readModule(r region) *module {
m := &module{r: r}
m.types = core.Address(r.Field("types").Uintptr())
m.etypes = core.Address(r.Field("etypes").Uintptr())
Expand Down Expand Up @@ -332,7 +332,7 @@ func (t *Type) ptrs1(s []int64, off int64) []int64 {

// Convert the address of a runtime._type to a *Type.
// Guaranteed to return a non-nil *Type.
func (p *Program) runtimeType2Type(a core.Address) *Type {
func (p *Process) runtimeType2Type(a core.Address) *Type {
if t := p.runtimeMap[a]; t != nil {
return t
}
Expand Down Expand Up @@ -496,7 +496,7 @@ func funcdata(r region, n int64) core.Address {
return r.p.proc.ReadPtr(a)
}

func (p *Program) readMs() {
func (p *Process) readMs() {
mp := p.rtGlobals["allm"]
for mp.Address() != 0 {
m := mp.Deref()
Expand All @@ -510,7 +510,7 @@ func (p *Program) readMs() {
}
}

func (p *Program) readGs() {
func (p *Process) readGs() {
// TODO: figure out how to "flush" running Gs.
allgs := p.rtGlobals["allgs"]
n := allgs.SliceLen()
Expand All @@ -524,7 +524,7 @@ func (p *Program) readGs() {
}
}

func (p *Program) readG(r region) *Goroutine {
func (p *Process) readG(r region) *Goroutine {
g := &Goroutine{r: r}
stk := r.Field("stack")
g.stackSize = int64(stk.Field("hi").Uintptr() - stk.Field("lo").Uintptr())
Expand Down Expand Up @@ -605,7 +605,7 @@ func (p *Program) readG(r region) *Goroutine {
return g
}

func (p *Program) readFrame(sp, pc core.Address) *Frame {
func (p *Process) readFrame(sp, pc core.Address) *Frame {
f := p.funcTab.find(pc)
if f == nil {
panic(fmt.Errorf(" pc not found %x\n", pc))
Expand Down
2 changes: 1 addition & 1 deletion gocore/region.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import "github.com/randall77/corelib/core"
// Note that it is the type of the thing in the region,
// not the type of the reference to the region.
type region struct {
p *Program // TODO: can we remove?
p *Process // TODO: can we remove?
a core.Address
typ *Type
}
Expand Down
4 changes: 2 additions & 2 deletions gocore/reverse.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/randall77/corelib/core"
)

func (p *Program) reverseEdges() {
func (p *Process) reverseEdges() {
p.reverse = make([][]core.Address, p.nObj)
p.ForEachObject(func(x Object) bool {
p.ForEachPtr(x, func(i int64, y Object, _ int64) bool {
Expand Down Expand Up @@ -40,7 +40,7 @@ func (p *Program) reverseEdges() {
// the offset j in y where the pointer points.
// If fn returns false, ForEachReversePtr returns immediately.
// FlagReverse must have been passed to Core when p was constructed.
func (p *Program) ForEachReversePtr(y Object, fn func(x Object, r *Root, i, j int64) bool) {
func (p *Process) ForEachReversePtr(y Object, fn func(x Object, r *Root, i, j int64) bool) {
idx, _ := p.findObjectIndex(p.Addr(y))
for _, a := range p.reverse[idx] {
// Read pointer, compute offset in y.
Expand Down
18 changes: 9 additions & 9 deletions gocore/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const (
FlagReverse
)

type Program struct {
type Process struct {
proc *core.Process

arenaStart core.Address
Expand Down Expand Up @@ -68,35 +68,35 @@ type Program struct {
rootIdx []*Root
}

// Process returns the core.Process used to construct this Program.
func (p *Program) Process() *core.Process {
// Process returns the core.Process used to construct this Process.
func (p *Process) Process() *core.Process {
return p.proc
}

func (p *Program) Goroutines() []*Goroutine {
func (p *Process) Goroutines() []*Goroutine {
return p.goroutines
}

// Stats returns a breakdown of the program's memory use by category.
func (p *Program) Stats() *Stats {
func (p *Process) Stats() *Stats {
return p.stats
}

// BuildVersion returns the Go version that was used to build the inferior binary.
func (p *Program) BuildVersion() string {
func (p *Process) BuildVersion() string {
return p.buildVersion
}

func (p *Program) Globals() []*Root {
func (p *Process) Globals() []*Root {
return p.globals
}

// FindFunc returns the function which contains the code at address pc, if any.
func (p *Program) FindFunc(pc core.Address) *Func {
func (p *Process) FindFunc(pc core.Address) *Func {
return p.funcTab.find(pc)
}

func (p *Program) findType(name string) *Type {
func (p *Process) findType(name string) *Type {
s := p.runtimeNameMap[name]
if len(s) == 0 {
panic("can't find type " + name)
Expand Down
12 changes: 6 additions & 6 deletions html.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/randall77/corelib/gocore"
)

func serveHtml(c *gocore.Program) {
func serveHtml(c *gocore.Process) {
http.HandleFunc("/object", func(w http.ResponseWriter, r *http.Request) {
objs, ok := r.URL.Query()["o"]
if !ok || len(objs) != 1 {
Expand Down Expand Up @@ -199,7 +199,7 @@ func serveHtml(c *gocore.Program) {
http.ListenAndServe(":8080", nil)
}

func htmlObject(w http.ResponseWriter, c *gocore.Program, name string, a core.Address, t *gocore.Type, live map[core.Address]bool) {
func htmlObject(w http.ResponseWriter, c *gocore.Process, name string, a core.Address, t *gocore.Type, live map[core.Address]bool) {
switch t.Kind {
case gocore.KindBool:
v := c.Process().ReadUint8(a) != 0
Expand Down Expand Up @@ -313,7 +313,7 @@ func htmlObject(w http.ResponseWriter, c *gocore.Program, name string, a core.Ad
}
}

func htmlPointer(c *gocore.Program, a core.Address) string {
func htmlPointer(c *gocore.Process, a core.Address) string {
if a == 0 {
return "nil"
}
Expand All @@ -337,7 +337,7 @@ func htmlPointer(c *gocore.Program, a core.Address) string {
return fmt.Sprintf("%s%s%s", s, idx, region(t, i))
}

func htmlPointerAt(c *gocore.Program, a core.Address, live map[core.Address]bool) string {
func htmlPointerAt(c *gocore.Process, a core.Address, live map[core.Address]bool) string {
if live != nil && !live[a] {
return "<text style=\"color:LightGray\">dead</text>"
}
Expand Down Expand Up @@ -406,7 +406,7 @@ func field(t *gocore.Type, off int64) string {
}

// Returns the name of the field at offset off in x.
func objField(c *gocore.Program, x gocore.Object, off int64) string {
func objField(c *gocore.Process, x gocore.Object, off int64) string {
t, r := c.Type(x)
if t == nil {
return fmt.Sprintf("f%d", off)
Expand Down Expand Up @@ -453,7 +453,7 @@ func region(t *gocore.Type, off int64) string {
}
}

func objRegion(c *gocore.Program, x gocore.Object, off int64) string {
func objRegion(c *gocore.Process, x gocore.Object, off int64) string {
t, r := c.Type(x)
if t == nil {
return fmt.Sprintf("f%d", off)
Expand Down
Loading

0 comments on commit 8e60c9a

Please sign in to comment.