mirror of
https://github.com/go-delve/delve.git
synced 2025-10-28 04:35:19 +08:00
proc: support debugging plugins (#1414)
This change splits the BinaryInfo object into a slice of Image objects containing information about the base executable and each loaded shared library (note: go plugins are shared libraries). Delve backens are supposed to call BinaryInfo.AddImage whenever they detect that a new shared library has been loaded. Member fields of BinaryInfo that are used to speed up access to dwarf (Functions, packageVars, consts, etc...) remain part of BinaryInfo and are updated to reference the correct image object. This simplifies this change. This approach has a few shortcomings: 1. Multiple shared libraries can define functions or globals with the same name and we have no way to disambiguate between them. 2. We don't have a way to handle library unloading. Both of those affect C shared libraries much more than they affect go plugins. Go plugins can't be unloaded at all and a lot of name collisions are prevented by import paths. There's only one problem that is concerning: if two plugins both import the same package they will end up with multiple definition for the same function. For example if two plugins use fmt.Printf the final in-memory image (and therefore our BinaryInfo object) will end up with two copies of fmt.Printf at different memory addresses. If a user types break fmt.Printf a breakpoint should be created at *both* locations. Allowing this is a relatively complex change that should be done in a different PR than this. For this reason I consider this approach an acceptable and sustainable stopgap. Updates #865
This commit is contained in:
committed by
Derek Parker
parent
71a7fe04d9
commit
f3b149bda7
@ -1184,9 +1184,10 @@ func (d *Debugger) ListDynamicLibraries() []api.Image {
|
||||
d.processMutex.Lock()
|
||||
defer d.processMutex.Unlock()
|
||||
bi := d.target.BinInfo()
|
||||
r := make([]api.Image, len(bi.Images))
|
||||
for i := range bi.Images {
|
||||
r[i] = api.ConvertImage(bi.Images[i])
|
||||
r := make([]api.Image, 0, len(bi.Images)-1)
|
||||
// skips the first image because it's the executable file
|
||||
for i := range bi.Images[1:] {
|
||||
r = append(r, api.ConvertImage(bi.Images[i]))
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user