• A
    proc: support debugging plugins (#1414) · f3b149bd
    Alessandro Arzilli 提交于
    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
    f3b149bd
stack.go 22.9 KB