Skip to content

Commit fe7bfbf

Browse files
committed
synthesize types for 0 size arrays in structs
1 parent f6faf77 commit fe7bfbf

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

internal/gocore/dwarf.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package gocore
77
import (
88
"debug/dwarf"
99
"fmt"
10+
"reflect"
1011
"regexp"
1112
"sort"
1213
"strings"
@@ -58,6 +59,23 @@ func (p *Process) readDWARFTypes() {
5859
t.Kind = KindStruct
5960
for _, f := range x.Field {
6061
fType := p.dwarfMap[f.Type]
62+
if fType == nil {
63+
// Weird case: arrays of size 0 in structs, like
64+
// Sysinfo_t.X_f. Synthesize a type so things later don't
65+
// get sad.
66+
if arr, ok := f.Type.(*dwarf.ArrayType); ok && arr.Count == 0 {
67+
fType = &Type{
68+
Name: f.Type.String(),
69+
Kind: KindArray,
70+
Count: arr.Count,
71+
Elem: p.dwarfMap[arr.Type],
72+
}
73+
} else {
74+
panic(fmt.Sprintf(
75+
"found a nil ftype for field %s.%s, type %s (%s) on ",
76+
x.StructName, f.Name, f.Type, reflect.TypeOf(f.Type)))
77+
}
78+
}
6179

6280
// Work around issue 21094. There's no guarantee that the
6381
// pointer type is in the DWARF, so just invent a Type.

0 commit comments

Comments
 (0)