Skip to content

Commit d4ee246

Browse files
committed
more fixes.
1 parent 0e1d767 commit d4ee246

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

internal/gocore/type.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func (p *Process) DynamicType(t *Type, a core.Address) *Type {
111111
}
112112

113113
// Convert the address of a runtime._type to a *Type.
114-
// The "d" is the address of the second field of an interface.
114+
// The "d" is the address of the second field of an interface, used to help disambiguate types.
115115
// Guaranteed to return a non-nil *Type.
116116
func (p *Process) runtimeType2Type(a core.Address, d core.Address) *Type {
117117
if t := p.runtimeMap[a]; t != nil {
@@ -173,26 +173,30 @@ func (p *Process) runtimeType2Type(a core.Address, d core.Address) *Type {
173173
candidates = append(candidates, t)
174174
}
175175
}
176-
// There may be multiple candidates, when they are the pointers to the same struct name,
176+
// There may be multiple candidates, when they are the pointers to the same type name,
177177
// in the same package name, but in the different package paths. eg. path-1/pkg.Foo and path-2/pkg.Foo.
178178
// Match the object size may be a proper choice, just for try best, since we have no other choices.
179-
if len(candidates) > 1 && nptrs == 1 && candidates[0].Size == ptrSize {
179+
if len(candidates) > 1 {
180180
ptr := p.proc.ReadPtr(d)
181+
deref := true
181182
if ifaceIndir(a, p) {
182-
// Indirect interface: the interface introduced a new
183-
// level of indirection, not reflected in the type.
184-
// Read through it.
185-
ptr = p.proc.ReadPtr(ptr)
183+
deref = false
186184
}
187185
obj, off := p.FindObject(ptr)
188186
// only usefull while it point to the head of an object,
189-
// otherwise, the GC object size should bigger than t.Elem.Size.
187+
// otherwise, the GC object size should bigger than the size of the type.
190188
if obj != 0 && off == 0 {
191189
sz := p.Size(obj)
192190
var tmp []*Type
193191
for _, t := range candidates {
194-
if t.Elem != nil && t.Elem.Size == sz {
195-
tmp = append(tmp, t)
192+
if deref {
193+
if t.Elem != nil && t.Elem.Size == sz {
194+
tmp = append(tmp, t)
195+
}
196+
} else {
197+
if t.Size == sz {
198+
tmp = append(tmp, t)
199+
}
196200
}
197201
}
198202
if len(tmp) > 0 {

0 commit comments

Comments
 (0)