
Implements the function call injection protocol introduced in go 1.11 by https://go-review.googlesource.com/c/go/+/109699. This is only the basic support, see TODO comments in pkg/proc/fncall.go for a list of missing features. Updates #119
38 lines
624 B
Go
38 lines
624 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"runtime"
|
|
)
|
|
|
|
func callstacktrace() (stacktrace string) {
|
|
for skip := 0; ; skip++ {
|
|
pc, file, line, ok := runtime.Caller(skip)
|
|
if !ok {
|
|
break
|
|
}
|
|
fn := runtime.FuncForPC(pc)
|
|
stacktrace += fmt.Sprintf("in %s at %s:%d\n", fn.Name(), file, line)
|
|
}
|
|
return stacktrace
|
|
}
|
|
|
|
func call1(a, b int) int {
|
|
fmt.Printf("first: %d second: %d\n", a, b)
|
|
return a + b
|
|
}
|
|
|
|
func callpanic() {
|
|
fmt.Printf("about to panic\n")
|
|
panic("callpanic panicked")
|
|
}
|
|
|
|
var zero = 0
|
|
|
|
func main() {
|
|
one, two := 1, 2
|
|
runtime.Breakpoint()
|
|
call1(one, two)
|
|
fmt.Println(one, two, zero, callpanic, callstacktrace)
|
|
}
|