Skip to content

Commit 5698bde

Browse files
committed
For untyped objects, still recognize ptr/nonptr distinction.
1 parent 4634d5d commit 5698bde

File tree

2 files changed

+40
-12
lines changed

2 files changed

+40
-12
lines changed

gocore/object.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,29 @@ func (p *Program) isPtr(a core.Address) bool {
149149
return p.proc.ReadUint8(p.bitmapEnd.Add(-(off>>2)-1))>>uint(off&3)&1 != 0
150150
}
151151

152+
// IsPtr reports whether the inferior at address a contains a pointer.
153+
func (p *Program) IsPtr(a core.Address) bool {
154+
if a >= p.arenaStart && a < p.arenaUsed {
155+
return p.isPtr(a)
156+
}
157+
for _, m := range p.modules {
158+
for _, s := range [2]string{"data", "bss"} {
159+
min := core.Address(m.r.Field(s).Uintptr())
160+
max := core.Address(m.r.Field("e" + s).Uintptr())
161+
if a < min || a >= max {
162+
continue
163+
}
164+
gc := m.r.Field("gc" + s + "mask").Field("bytedata").Address()
165+
i := a.Sub(min)
166+
return p.proc.ReadUint8(gc.Add(i/8))>>uint(i%8) != 0
167+
}
168+
}
169+
// Everywhere is isn't a pointer. At least, not a pointer into the Go heap.
170+
// TODO: stacks?
171+
// TODO: finalizers?
172+
return false
173+
}
174+
152175
// FindObject finds the object containing a. Returns that object and the offset within
153176
// that object to which a points.
154177
// Returns 0,0 if a doesn't point to a live heap object.

html.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,25 @@ func serveHtml(c *gocore.Program) {
6666
end = n * typ.Size
6767
}
6868
for i := end; i < size; i += c.Process().PtrSize() {
69-
fmt.Fprintf(w, "<tr><td>f%d</td><td colspan=\"2\">?</td><td><pre>", i)
70-
for j := int64(0); j < c.Process().PtrSize(); j++ {
71-
fmt.Fprintf(w, "%02x ", c.Process().ReadUint8(addr.Add(i+j)))
72-
}
73-
fmt.Fprintf(w, "</pre></td><td><pre>")
74-
for j := int64(0); j < c.Process().PtrSize(); j++ {
75-
r := c.Process().ReadUint8(addr.Add(i + j))
76-
if r >= 32 && r <= 126 {
77-
fmt.Fprintf(w, "%s", html.EscapeString(string(rune(r))))
78-
} else {
79-
fmt.Fprintf(w, ".")
69+
fmt.Fprintf(w, "<tr><td>f%d</td><td colspan=\"2\">?</td>", i)
70+
if c.IsPtr(addr.Add(i)) {
71+
fmt.Fprintf(w, "<td>%s</td>", htmlPointer(c, c.Process().ReadPtr(addr.Add(i))))
72+
} else {
73+
fmt.Fprintf(w, "<td><pre>")
74+
for j := int64(0); j < c.Process().PtrSize(); j++ {
75+
fmt.Fprintf(w, "%02x ", c.Process().ReadUint8(addr.Add(i+j)))
76+
}
77+
fmt.Fprintf(w, "</pre></td><td><pre>")
78+
for j := int64(0); j < c.Process().PtrSize(); j++ {
79+
r := c.Process().ReadUint8(addr.Add(i + j))
80+
if r >= 32 && r <= 126 {
81+
fmt.Fprintf(w, "%s", html.EscapeString(string(rune(r))))
82+
} else {
83+
fmt.Fprintf(w, ".")
84+
}
8085
}
86+
fmt.Fprintf(w, "</pre></td>")
8187
}
82-
fmt.Fprintf(w, "</pre></td>")
8388
fmt.Fprintf(w, "</tr>\n")
8489
}
8590
fmt.Fprintf(w, "</table>\n")

0 commit comments

Comments
 (0)