delve/_fixtures/plugintest2.go
Alessandro Arzilli af1ffc8504 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
2019-03-20 10:32:51 -07:00

45 lines
765 B
Go

package main
import (
"fmt"
"github.com/go-delve/delve/_fixtures/internal/pluginsupport"
"os"
"plugin"
)
type asomething struct {
n int
}
func (a *asomething) Callback(n int) int {
return a.n + n
}
func (a *asomething) String() string {
return "success"
}
var ExeGlobal = &asomething{2}
func must(err error) {
if err != nil {
panic(err)
}
}
func main() {
plug1, err := plugin.Open(os.Args[1])
must(err)
plug2, err := plugin.Open(os.Args[2])
must(err)
fn1iface, err := plug1.Lookup("HelloFn")
must(err)
fn2iface, err := plug2.Lookup("TypesTest")
must(err)
fn1 := fn1iface.(func(int) string)
fn2 := fn2iface.(func(pluginsupport.Something) pluginsupport.SomethingElse)
a := fn1(3)
b := fn2(&asomething{2})
fmt.Println(a, b, ExeGlobal)
}