github.com/zeebo/goof@v0.0.0-20190312211016-1ee209ef0510/troop.go (about) 1 package goof 2 3 import ( 4 "debug/dwarf" 5 "reflect" 6 "sync" 7 ) 8 9 type Troop struct { 10 once sync.Once 11 err error 12 data *dwarf.Data 13 types map[string]reflect.Type 14 globals map[string]reflect.Value 15 functions map[string]functionCacheEntry 16 } 17 18 type functionCacheEntry struct { 19 pc uint64 20 dtypes []dwarf.Type 21 } 22 23 func (t *Troop) init() { 24 t.data, t.err = openProc() 25 if t.err != nil { 26 return 27 } 28 29 t.types = make(map[string]reflect.Type) 30 t.err = t.addTypes() 31 if t.err != nil { 32 return 33 } 34 35 t.globals = make(map[string]reflect.Value) 36 t.err = t.addGlobals() 37 if t.err != nil { 38 return 39 } 40 41 t.functions = make(map[string]functionCacheEntry) 42 t.err = t.addFunctions() 43 if t.err != nil { 44 return 45 } 46 } 47 48 func (t *Troop) check() error { 49 t.once.Do(t.init) 50 return t.err 51 }