Skip to content

Commit

Permalink
fix: type with pointer judgement (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
jayantxie authored Jul 30, 2024
1 parent 6ee797d commit bfd02d0
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions pkg/proc/reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,17 +317,14 @@ func (s *ObjRefScope) findRef(x *ReferenceVariable, idx *pprofIndex) (err error)
typ = s.specialStructTypes(typ)
for _, field := range typ.Field {
fieldAddr := x.Addr.Add(field.ByteOffset)
if isPrimitiveType(field.Type) {
continue
}
y := newReferenceVariable(fieldAddr, field.Name+". ("+field.Type.String()+")", resolveTypedef(field.Type), x.mem, x.hb)
if err = s.findRef(y, idx); errors.Is(err, errOutOfRange) {
break
}
}
case *godwarf.ArrayType:
eType := resolveTypedef(typ.Type)
if isPrimitiveType(eType) {
if !hasPtrType(eType) {
return
}
for i := int64(0); i < typ.Count; i++ {
Expand Down Expand Up @@ -395,15 +392,19 @@ func (s *ObjRefScope) specialStructTypes(st *godwarf.StructType) *godwarf.Struct
return st
}

func isPrimitiveType(typ godwarf.Type) bool {
if typ.Size() == 0 {
return true
}
typ = resolveTypedef(typ)
switch typ.(type) {
case *godwarf.BoolType, *godwarf.FloatType, *godwarf.UintType,
*godwarf.UcharType, *godwarf.CharType, *godwarf.IntType, *godwarf.ComplexType:
func hasPtrType(t godwarf.Type) bool {
switch typ := t.(type) {
case *godwarf.PtrType, *godwarf.ChanType, *godwarf.MapType, *godwarf.StringType,
*godwarf.SliceType, *godwarf.InterfaceType, *godwarf.FuncType:
return true
case *godwarf.StructType:
for _, f := range typ.Field {
if hasPtrType(resolveTypedef(f.Type)) {
return true
}
}
case *godwarf.ArrayType:
return hasPtrType(resolveTypedef(typ.Type))
}
return false
}
Expand Down

0 comments on commit bfd02d0

Please sign in to comment.