获取“父” goroutine和“子” goroutine的堆栈

Is there a way in go, possibly with some debug flag switched on, to obtain a dump of the stack traces of all goroutines along with the stack traces of the "parent" goroutines (using "parent" here to mean the goroutine that executed the call to go foo() that launched the goroutine in question). The context for this question is that I have a connection leak and noticed there are many goroutines blocked on awaitDone (in the sql package), and these goroutines were spawned where the connections were created.

If I understand what you're asking, you can probably print/output the info you want using the runtime package.

Take a look at https://golang.org/pkg/runtime/#Caller and the skip paramter. Plus the frame docs: https://golang.org/pkg/runtime/#Frames

Is that what you're after?