mirror of
https://github.com/go-delve/delve.git
synced 2025-10-29 01:27:16 +08:00
proc,proc/native,proc/gdbserial: initial plugin support (#1413)
Adds initial support for plugins, this is only the code needed to keep track of loaded plugins on linux (both native and gdbserial backend). It does not actually implement support for debugging plugins on linux. Updates #865
This commit is contained in:
committed by
Derek Parker
parent
09c92c75b9
commit
af1ffc8504
@ -26,7 +26,8 @@ import (
|
||||
"github.com/go-delve/delve/pkg/goversion"
|
||||
)
|
||||
|
||||
// BinaryInfo holds information on the binary being executed.
|
||||
// BinaryInfo holds information on the binaries being executed (this
|
||||
// includes both the executable and also any loaded libraries).
|
||||
type BinaryInfo struct {
|
||||
// Path on disk of the binary being executed.
|
||||
Path string
|
||||
@ -43,6 +44,12 @@ type BinaryInfo struct {
|
||||
// LookupFunc maps function names to a description of the function.
|
||||
LookupFunc map[string]*Function
|
||||
|
||||
// Images is a list of loaded shared libraries (also known as
|
||||
// shared objects on linux or DLLs on windws).
|
||||
Images []*Image
|
||||
|
||||
ElfDynamicSection ElfDynamicSection
|
||||
|
||||
lastModified time.Time // Time the executable of this process was last modified
|
||||
|
||||
closer io.Closer
|
||||
@ -289,6 +296,12 @@ type buildIDHeader struct {
|
||||
Type uint32
|
||||
}
|
||||
|
||||
// ElfDynamicSection describes the .dynamic section of an ELF executable.
|
||||
type ElfDynamicSection struct {
|
||||
Addr uint64 // relocated address of where the .dynamic section is mapped in memory
|
||||
Size uint64 // size of the .dynamic section of the executable
|
||||
}
|
||||
|
||||
// NewBinaryInfo returns an initialized but unloaded BinaryInfo struct.
|
||||
func NewBinaryInfo(goos, goarch string) *BinaryInfo {
|
||||
r := &BinaryInfo{GOOS: goos, nameOfRuntimeType: make(map[uintptr]nameOfRuntimeTypeEntry), typeCache: make(map[dwarf.Offset]godwarf.Type)}
|
||||
@ -412,6 +425,26 @@ func (bi *BinaryInfo) PCToFunc(pc uint64) *Function {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Image represents a loaded library file (shared object on linux, DLL on windows).
|
||||
type Image struct {
|
||||
Path string
|
||||
addr uint64
|
||||
}
|
||||
|
||||
// AddImage adds the specified image to bi.
|
||||
func (bi *BinaryInfo) AddImage(path string, addr uint64) {
|
||||
if !strings.HasPrefix(path, "/") {
|
||||
return
|
||||
}
|
||||
for _, image := range bi.Images {
|
||||
if image.Path == path && image.addr == addr {
|
||||
return
|
||||
}
|
||||
}
|
||||
//TODO(aarzilli): actually load informations about the image here
|
||||
bi.Images = append(bi.Images, &Image{Path: path, addr: addr})
|
||||
}
|
||||
|
||||
// Close closes all internal readers.
|
||||
func (bi *BinaryInfo) Close() error {
|
||||
if bi.sepDebugCloser != nil {
|
||||
@ -671,6 +704,11 @@ func (bi *BinaryInfo) LoadBinaryInfoElf(path string, entryPoint uint64, debugInf
|
||||
}
|
||||
}
|
||||
|
||||
if dynsec := elfFile.Section(".dynamic"); dynsec != nil {
|
||||
bi.ElfDynamicSection.Addr = dynsec.Addr + bi.staticBase
|
||||
bi.ElfDynamicSection.Size = dynsec.Size
|
||||
}
|
||||
|
||||
dwarfFile := elfFile
|
||||
|
||||
bi.dwarf, err = elfFile.DWARF()
|
||||
|
||||
Reference in New Issue
Block a user