-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plugin support (part 2) #1414
Plugin support (part 2) #1414
Conversation
aarzilli
commented
Nov 16, 2018
•
edited
Loading
edited
7b5a93c
to
38ac8b8
Compare
c2a34d0
to
959a839
Compare
5d481c7
to
897ec55
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got through about half the review, will do another pass tomorrow or Monday.
pkg/proc/arch.go
Outdated
@@ -302,5 +304,10 @@ func (a *AMD64) GoroutineToDwarfRegisters(g *G) op.DwarfRegisters { | |||
dregs[amd64DwarfIPRegNum] = op.DwarfRegisterFromUint64(g.PC) | |||
dregs[amd64DwarfSPRegNum] = op.DwarfRegisterFromUint64(g.SP) | |||
dregs[amd64DwarfBPRegNum] = op.DwarfRegisterFromUint64(g.BP) | |||
return op.DwarfRegisters{StaticBase: g.variable.bi.staticBase, Regs: dregs, ByteOrder: binary.LittleEndian, PCRegNum: amd64DwarfIPRegNum, SPRegNum: amd64DwarfSPRegNum, BPRegNum: amd64DwarfBPRegNum} | |||
|
|||
bi := g.variable.bi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should create a helper for this to clean it up like some of the others that have been created. This should overall be more efficient than simply using the PC to find the compilation unit and thus the image because we can binary search function entries and we're doing a linear search of compilation unit PC ranges, correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the helper function.
This should overall be more efficient than simply using the PC to find the compilation unit and thus the image because we can binary search function entries and we're doing a linear search of compilation unit PC ranges, correct?
I think so. Ideally we'd just do a binary search on images but I haven't figured out how to find the end address.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree but I think this is alright for now. When (and if) we ever run into a situation where a linear search through loaded shared objects becomes a problem we can tackle it.
@@ -324,16 +326,22 @@ func (bi *BinaryInfo) LoadBinaryInfo(path string, entryPoint uint64, debugInfoDi | |||
bi.lastModified = fi.ModTime() | |||
} | |||
|
|||
bi.debugInfoDirectories = debugInfoDirs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: nothing wrong with this particular piece of code, but the comment above is incorrect and out of date, we no longer require a sync.WaitGroup
to be passed in.
pkg/proc/bininfo.go
Outdated
if !strings.HasPrefix(path, "/") { | ||
return | ||
// hasImage returns true if the shared object has already been added. | ||
func (bi *BinaryInfo) hasImage(path string, addr uint64) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only used once, let's inline it, or if you prefer to have it as a function for stylistic reasons, I'd prefer it as a function instead of a method. It doesn't really need bi
, just the list of images.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inlined is good.
pkg/proc/bininfo.go
Outdated
errs = append(errs, fmt.Errorf("closing shared object %q (split dwarf): %v", image.Path, err)) | ||
} | ||
} | ||
if image.closer != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: A refactor could possibly be to embed the closer in image so we can just call image.Close()
.
pkg/proc/bininfo.go
Outdated
} | ||
|
||
// LoadError returns any internal load error. | ||
// LoadError returns any internal error incurred while loading the last shared object. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why return just the last error specifically?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC it was the easiest way to do it at the time, because it was called from the backends. Given that now it's only called in proc.PostInitializationSetup, I've replaced it there with a loop through all the images.
pkg/proc/bininfo.go
Outdated
@@ -474,22 +566,26 @@ func (c *nilCloser) Close() error { return nil } | |||
// LoadFromData creates a new BinaryInfo object using the specified data. | |||
// This is used for debugging BinaryInfo, you should use LoadBinary instead. | |||
func (bi *BinaryInfo) LoadFromData(dwdata *dwarf.Data, debugFrameBytes, debugLineBytes, debugLocBytes []byte) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should rename this to something like LoadImageFromData
and update the comment above to reflect the intent of the new changes.
pkg/proc/bininfo.go
Outdated
// - addr is entryPoint therefore staticBase needs to be calculated by | ||
// subtracting it from the entry point specified in the executable file | ||
// - memory address of the .dynamic section needs to be recorded in | ||
// BinaryInfo so that we can find loadded libraries. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: s/loadded/loaded/
pkg/proc/bininfo.go
Outdated
if image.index == 0 { | ||
// adding executable file: | ||
// - addr is entryPoint therefore staticBase needs to be calculated by | ||
// subtracting it from the entry point specified in the executable file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: technically you're subtracting the entry point from addr.
pkg/proc/bininfo.go
Outdated
// BinaryInfo so that we can find loadded libraries. | ||
if addr != 0 { | ||
image.StaticBase = addr - elfFile.Entry | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: else if
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 go-delve#865
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 go-delve#865
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 go-delve#865