@@ -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.
116116func (p * Process ) runtimeType2Type (a core.Address , d core.Address ) * Type {
117117if t := p .runtimeMap [a ]; t != nil {
@@ -173,26 +173,30 @@ func (p *Process) runtimeType2Type(a core.Address, d core.Address) *Type {
173173candidates = 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 {
180180ptr := p .proc .ReadPtr (d )
181+ deref := true
181182if 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}
187185obj , 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 .
190188if obj != 0 && off == 0 {
191189sz := p .Size (obj )
192190var tmp []* Type
193191for _ , 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}
198202if len (tmp ) > 0 {
0 commit comments