github.com/cnboonhan/delve@v0.0.0-20230908061759-363f2388c2fb/pkg/proc/moduledata.go (about) 1 package proc 2 3 // delve counterpart to runtime.moduledata 4 type moduleData struct { 5 text, etext uint64 6 types, etypes uint64 7 typemapVar *Variable 8 } 9 10 func loadModuleData(bi *BinaryInfo, mem MemoryReadWriter) ([]moduleData, error) { 11 // +rtype -var firstmoduledata moduledata 12 // +rtype -field moduledata.text uintptr 13 // +rtype -field moduledata.types uintptr 14 15 scope := globalScope(nil, bi, bi.Images[0], mem) 16 var md *Variable 17 md, err := scope.findGlobal("runtime", "firstmoduledata") 18 if err != nil { 19 return nil, err 20 } 21 22 r := []moduleData{} 23 24 for md.Addr != 0 { 25 const ( 26 typesField = "types" 27 etypesField = "etypes" 28 textField = "text" 29 etextField = "etext" 30 nextField = "next" 31 typemapField = "typemap" 32 ) 33 vars := map[string]*Variable{} 34 35 for _, fieldName := range []string{typesField, etypesField, textField, etextField, nextField, typemapField} { 36 var err error 37 vars[fieldName], err = md.structMember(fieldName) 38 if err != nil { 39 return nil, err 40 } 41 42 } 43 44 var err error 45 46 touint := func(name string) (ret uint64) { 47 if err == nil { 48 var n uint64 49 n, err = vars[name].asUint() 50 ret = n 51 } 52 return ret 53 } 54 55 r = append(r, moduleData{ 56 types: touint(typesField), etypes: touint(etypesField), 57 text: touint(textField), etext: touint(etextField), 58 typemapVar: vars[typemapField], 59 }) 60 if err != nil { 61 return nil, err 62 } 63 64 md = vars[nextField].maybeDereference() 65 if md.Unreadable != nil { 66 return nil, md.Unreadable 67 } 68 } 69 70 return r, nil 71 } 72 73 func findModuleDataForType(bi *BinaryInfo, mds []moduleData, typeAddr uint64, mem MemoryReadWriter) *moduleData { 74 for i := range mds { 75 if typeAddr >= mds[i].types && typeAddr < mds[i].etypes { 76 return &mds[i] 77 } 78 } 79 return nil 80 }