Skip to content

Commit

Permalink
For untyped objects, still recognize ptr/nonptr distinction.
Browse files Browse the repository at this point in the history
  • Loading branch information
randall77 committed Oct 3, 2017
1 parent 4634d5d commit 5698bde
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 12 deletions.
23 changes: 23 additions & 0 deletions gocore/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,29 @@ func (p *Program) isPtr(a core.Address) bool {
return p.proc.ReadUint8(p.bitmapEnd.Add(-(off>>2)-1))>>uint(off&3)&1 != 0
}

// IsPtr reports whether the inferior at address a contains a pointer.
func (p *Program) IsPtr(a core.Address) bool {
if a >= p.arenaStart && a < p.arenaUsed {
return p.isPtr(a)
}
for _, m := range p.modules {
for _, s := range [2]string{"data", "bss"} {
min := core.Address(m.r.Field(s).Uintptr())
max := core.Address(m.r.Field("e" + s).Uintptr())
if a < min || a >= max {
continue
}
gc := m.r.Field("gc" + s + "mask").Field("bytedata").Address()
i := a.Sub(min)
return p.proc.ReadUint8(gc.Add(i/8))>>uint(i%8) != 0
}
}
// Everywhere is isn't a pointer. At least, not a pointer into the Go heap.
// TODO: stacks?
// TODO: finalizers?
return false
}

// 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.
Expand Down
29 changes: 17 additions & 12 deletions html.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,25 @@ func serveHtml(c *gocore.Program) {
end = n * typ.Size
}
for i := end; i < size; i += c.Process().PtrSize() {
fmt.Fprintf(w, "<tr><td>f%d</td><td colspan=\"2\">?</td><td><pre>", i)
for j := int64(0); j < c.Process().PtrSize(); j++ {
fmt.Fprintf(w, "%02x ", c.Process().ReadUint8(addr.Add(i+j)))
}
fmt.Fprintf(w, "</pre></td><td><pre>")
for j := int64(0); j < c.Process().PtrSize(); j++ {
r := c.Process().ReadUint8(addr.Add(i + j))
if r >= 32 && r <= 126 {
fmt.Fprintf(w, "%s", html.EscapeString(string(rune(r))))
} else {
fmt.Fprintf(w, ".")
fmt.Fprintf(w, "<tr><td>f%d</td><td colspan=\"2\">?</td>", i)
if c.IsPtr(addr.Add(i)) {
fmt.Fprintf(w, "<td>%s</td>", htmlPointer(c, c.Process().ReadPtr(addr.Add(i))))
} else {
fmt.Fprintf(w, "<td><pre>")
for j := int64(0); j < c.Process().PtrSize(); j++ {
fmt.Fprintf(w, "%02x ", c.Process().ReadUint8(addr.Add(i+j)))
}
fmt.Fprintf(w, "</pre></td><td><pre>")
for j := int64(0); j < c.Process().PtrSize(); j++ {
r := c.Process().ReadUint8(addr.Add(i + j))
if r >= 32 && r <= 126 {
fmt.Fprintf(w, "%s", html.EscapeString(string(rune(r))))
} else {
fmt.Fprintf(w, ".")
}
}
fmt.Fprintf(w, "</pre></td>")
}
fmt.Fprintf(w, "</pre></td>")
fmt.Fprintf(w, "</tr>\n")
}
fmt.Fprintf(w, "</table>\n")
Expand Down

0 comments on commit 5698bde

Please sign in to comment.