forked from go-delve/delve
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
proc,proc/native,proc/gdbserial: initial plugin support (go-delve#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 go-delve#865
- Loading branch information
1 parent
903ec65
commit 837fb94
Showing
19 changed files
with
484 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package pluginsupport | ||
|
||
type Something interface { | ||
Callback(int) int | ||
} | ||
|
||
type SomethingElse interface { | ||
Callback2(int, int) float64 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func Fn1() string { | ||
return "hello" | ||
} | ||
|
||
func HelloFn(n int) string { | ||
n++ | ||
s := fmt.Sprintf("hello%d", n) | ||
return s | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/go-delve/delve/_fixtures/internal/pluginsupport" | ||
) | ||
|
||
func Fn2() string { | ||
return "world" | ||
} | ||
|
||
type asomethingelse struct { | ||
x, y float64 | ||
} | ||
|
||
func (a *asomethingelse) Callback2(n, m int) float64 { | ||
r := a.x + 2*a.y | ||
r += float64(n) / float64(m) | ||
return r | ||
} | ||
|
||
func TypesTest(s pluginsupport.Something) pluginsupport.SomethingElse { | ||
if A != nil { | ||
aIsNotNil(fmt.Sprintf("%s", A)) | ||
} | ||
return &asomethingelse{1.0, float64(s.Callback(2))} | ||
} | ||
|
||
var A interface{} | ||
|
||
func aIsNotNil(str string) { | ||
// nothing here | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"plugin" | ||
"runtime" | ||
) | ||
|
||
func must(err error) { | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
func main() { | ||
plug1, err := plugin.Open(os.Args[1]) | ||
must(err) | ||
|
||
runtime.Breakpoint() | ||
|
||
plug2, err := plugin.Open(os.Args[2]) | ||
must(err) | ||
|
||
runtime.Breakpoint() | ||
|
||
fn1, err := plug1.Lookup("Fn1") | ||
must(err) | ||
fn2, err := plug2.Lookup("Fn2") | ||
must(err) | ||
|
||
a := fn1.(func() string)() | ||
b := fn2.(func() string)() | ||
|
||
fmt.Println(plug1, plug2, fn1, fn2, a, b) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.