proc: cache module data (#3800)

Cache module data so that we don't reload it every time we look up a
variable with a generic type.
This commit is contained in:
Alessandro Arzilli 2024-09-18 23:17:07 +02:00 committed by GitHub
parent 582305a813
commit 059f149433
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 3 deletions

@ -104,6 +104,8 @@ type BinaryInfo struct {
// dwrapUnwrapCache caches unwrapping of defer wrapper functions (dwrap)
dwrapUnwrapCache map[uint64]*Function
moduleDataCache []ModuleData
// Go 1.17 register ABI is enabled.
regabi bool

@ -260,6 +260,7 @@ func (t *Target) SupportsFunctionCalls() bool {
func (t *Target) ClearCaches() {
t.clearFakeMemory()
t.gcache.Clear()
t.BinInfo().moduleDataCache = nil
for _, thread := range t.ThreadList() {
thread.Common().g = nil
}

@ -149,9 +149,15 @@ func resolveParametricType(bi *BinaryInfo, mem MemoryReadWriter, t godwarf.Type,
}
_type := newVariable("", rtypeAddr, runtimeType, bi, mem)
mds, err := LoadModuleData(bi, _type.mem)
if err != nil {
return ptyp.TypedefType.Type, fmt.Errorf("error loading module data: %v", err)
var mds []ModuleData
if bi.moduleDataCache != nil {
mds = bi.moduleDataCache
} else {
mds, err = LoadModuleData(bi, _type.mem)
if err != nil {
return ptyp.TypedefType.Type, fmt.Errorf("error loading module data: %v", err)
}
bi.moduleDataCache = mds
}
typ, _, err := RuntimeTypeToDIE(_type, 0, mds)