refactor: move loadModuleData from runtimeTypeToDIE and expose the apis (#3741)
This commit is contained in:
parent
a8293a36f5
commit
a4196f35a9
@ -1028,7 +1028,7 @@ func (bi *BinaryInfo) AddImage(path string, addr uint64) error {
|
||||
}
|
||||
|
||||
// moduleDataToImage finds the image corresponding to the given module data object.
|
||||
func (bi *BinaryInfo) moduleDataToImage(md *moduleData) *Image {
|
||||
func (bi *BinaryInfo) moduleDataToImage(md *ModuleData) *Image {
|
||||
fn := bi.PCToFunc(md.text)
|
||||
if fn != nil {
|
||||
return bi.funcToImage(fn)
|
||||
@ -1047,7 +1047,7 @@ func (bi *BinaryInfo) moduleDataToImage(md *moduleData) *Image {
|
||||
}
|
||||
|
||||
// imageToModuleData finds the module data in mds corresponding to the given image.
|
||||
func (bi *BinaryInfo) imageToModuleData(image *Image, mds []moduleData) *moduleData {
|
||||
func (bi *BinaryInfo) imageToModuleData(image *Image, mds []ModuleData) *ModuleData {
|
||||
for _, md := range mds {
|
||||
im2 := bi.moduleDataToImage(&md)
|
||||
if im2 != nil && im2.index == image.index {
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
package proc
|
||||
|
||||
// delve counterpart to runtime.moduledata
|
||||
type moduleData struct {
|
||||
// ModuleData counterpart to runtime.moduleData
|
||||
type ModuleData struct {
|
||||
text, etext uint64
|
||||
types, etypes uint64
|
||||
typemapVar *Variable
|
||||
}
|
||||
|
||||
func loadModuleData(bi *BinaryInfo, mem MemoryReadWriter) ([]moduleData, error) {
|
||||
func LoadModuleData(bi *BinaryInfo, mem MemoryReadWriter) ([]ModuleData, error) {
|
||||
// +rtype -var firstmoduledata moduledata
|
||||
// +rtype -field moduledata.text uintptr
|
||||
// +rtype -field moduledata.types uintptr
|
||||
@ -19,7 +19,7 @@ func loadModuleData(bi *BinaryInfo, mem MemoryReadWriter) ([]moduleData, error)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
r := []moduleData{}
|
||||
r := []ModuleData{}
|
||||
|
||||
for md.Addr != 0 {
|
||||
const (
|
||||
@ -51,7 +51,7 @@ func loadModuleData(bi *BinaryInfo, mem MemoryReadWriter) ([]moduleData, error)
|
||||
return ret
|
||||
}
|
||||
|
||||
r = append(r, moduleData{
|
||||
r = append(r, ModuleData{
|
||||
types: touint(typesField), etypes: touint(etypesField),
|
||||
text: touint(textField), etext: touint(etextField),
|
||||
typemapVar: vars[typemapField],
|
||||
@ -69,7 +69,7 @@ func loadModuleData(bi *BinaryInfo, mem MemoryReadWriter) ([]moduleData, error)
|
||||
return r, nil
|
||||
}
|
||||
|
||||
func findModuleDataForType(bi *BinaryInfo, mds []moduleData, typeAddr uint64, mem MemoryReadWriter) *moduleData {
|
||||
func findModuleDataForType(bi *BinaryInfo, mds []ModuleData, typeAddr uint64, mem MemoryReadWriter) *ModuleData {
|
||||
for i := range mds {
|
||||
if typeAddr >= mds[i].types && typeAddr < mds[i].etypes {
|
||||
return &mds[i]
|
||||
|
||||
@ -89,7 +89,7 @@ func (ctxt *loadDebugInfoMapsContext) lookupAbstractOrigin(bi *BinaryInfo, off d
|
||||
return r
|
||||
}
|
||||
|
||||
// runtimeTypeToDIE returns the DIE corresponding to the runtime._type.
|
||||
// RuntimeTypeToDIE returns the DIE corresponding to the runtime._type.
|
||||
// This is done in three different ways depending on the version of go.
|
||||
// - Before go1.7 the type name is retrieved directly from the runtime._type
|
||||
// and looked up in debug_info
|
||||
@ -98,18 +98,13 @@ func (ctxt *loadDebugInfoMapsContext) lookupAbstractOrigin(bi *BinaryInfo, off d
|
||||
// debug_info
|
||||
// - After go1.11 the runtimeTypeToDIE map is used to look up the address of
|
||||
// the type and map it directly to a DIE.
|
||||
func runtimeTypeToDIE(_type *Variable, dataAddr uint64) (typ godwarf.Type, kind int64, err error) {
|
||||
func RuntimeTypeToDIE(_type *Variable, dataAddr uint64, mds []ModuleData) (typ godwarf.Type, kind int64, err error) {
|
||||
bi := _type.bi
|
||||
|
||||
_type = _type.maybeDereference()
|
||||
|
||||
// go 1.11 implementation: use extended attribute in debug_info
|
||||
|
||||
mds, err := loadModuleData(bi, _type.mem)
|
||||
if err != nil {
|
||||
return nil, 0, fmt.Errorf("error loading module data: %v", err)
|
||||
}
|
||||
|
||||
md := findModuleDataForType(bi, mds, _type.Addr, _type.mem)
|
||||
if md != nil {
|
||||
so := bi.moduleDataToImage(md)
|
||||
@ -154,7 +149,12 @@ func resolveParametricType(bi *BinaryInfo, mem MemoryReadWriter, t godwarf.Type,
|
||||
}
|
||||
_type := newVariable("", rtypeAddr, runtimeType, bi, mem)
|
||||
|
||||
typ, _, err := runtimeTypeToDIE(_type, 0)
|
||||
mds, err := LoadModuleData(bi, _type.mem)
|
||||
if err != nil {
|
||||
return ptyp.TypedefType.Type, fmt.Errorf("error loading module data: %v", err)
|
||||
}
|
||||
|
||||
typ, _, err := RuntimeTypeToDIE(_type, 0, mds)
|
||||
if err != nil {
|
||||
return ptyp.TypedefType.Type, err
|
||||
}
|
||||
@ -175,7 +175,7 @@ func dwarfToRuntimeType(bi *BinaryInfo, mem MemoryReadWriter, typ godwarf.Type)
|
||||
return 0, 0, false, nil
|
||||
}
|
||||
|
||||
mds, err := loadModuleData(bi, mem)
|
||||
mds, err := LoadModuleData(bi, mem)
|
||||
if err != nil {
|
||||
return 0, 0, false, err
|
||||
}
|
||||
|
||||
@ -2337,7 +2337,13 @@ func (v *Variable) loadInterface(recurseLevel int, loadData bool, cfg LoadConfig
|
||||
return
|
||||
}
|
||||
|
||||
typ, kind, err := runtimeTypeToDIE(_type, data.Addr)
|
||||
mds, err := LoadModuleData(_type.bi, _type.mem)
|
||||
if err != nil {
|
||||
v.Unreadable = fmt.Errorf("error loading module data: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
typ, kind, err := RuntimeTypeToDIE(_type, data.Addr, mds)
|
||||
if err != nil {
|
||||
v.Unreadable = err
|
||||
return
|
||||
|
||||
Loading…
Reference in New Issue
Block a user