Hi,
Recently I need to debug an embedded Go snippet. I compiled my Go code into .so file and loaded it in my C program. However, I found that dlv seems unable to debug to Go parts.
similar issues and talk:
the above links are opened in 2017 but seem still unresolved now. Is there any progress?
go source:
package main
import "C"
import (
"sync"
"time"
"fmt"
)
func sum(a, b int) int {
return a + b
}
func gof() {
i := 0
for {
fmt.Println(sum(i+1, i+2))
i++
time.Sleep(time.Second)
}
}
//export updateHeader
func updateHeader() {
wg := sync.WaitGroup{}
wg.Add(1)
go func() {
gof()
} ()
wg.Wait()
}
func main() {}
compile command:
go build -buildmode=c-shared -gcflags "all=-N -l" -o test.so test.go
C code:
#include"test.h"
int main() {
updateHeader();
}
compiled command:
gcc -g -fno-asynchronous-unwind-tables -o main test.c test.so
After doing the above things, I tried both "dlv exec" and "dlv attach", both of them seems not work as expected, both cannot set breakpoint and list goroutines, etc.