github.com/zeebo/goof@v0.0.0-20230907150950-e9457bc94477/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  	failures  map[string]error
    17  }
    18  
    19  type functionCacheEntry struct {
    20  	pc     uint64
    21  	dtypes []dwarf.Type
    22  }
    23  
    24  func (t *Troop) init() {
    25  	t.data, t.err = openProc()
    26  	if t.err != nil {
    27  		return
    28  	}
    29  
    30  	t.failures = make(map[string]error)
    31  
    32  	t.types = make(map[string]reflect.Type)
    33  	t.err = t.addTypes()
    34  	if t.err != nil {
    35  		return
    36  	}
    37  
    38  	t.globals = make(map[string]reflect.Value)
    39  	t.err = t.addGlobals()
    40  	if t.err != nil {
    41  		return
    42  	}
    43  
    44  	t.functions = make(map[string]functionCacheEntry)
    45  	t.err = t.addFunctions()
    46  	if t.err != nil {
    47  		return
    48  	}
    49  }
    50  
    51  func (t *Troop) check() error {
    52  	t.once.Do(t.init)
    53  	return t.err
    54  }