godebug icon indicating copy to clipboard operation
godebug copied to clipboard

Print stack trace

Open willfaught opened this issue 10 years ago • 7 comments

It would be helpful to print the function stack in times I forget where I am in the current goroutine.

willfaught avatar Aug 01 '15 00:08 willfaught

implementation note: debug.PrintStack() prints the stack for you.

glycerine avatar Aug 01 '15 17:08 glycerine

http://stackoverflow.com/questions/19094099/how-to-dump-goroutine-stacktraces

Also I see the docs for debug.Stack() say it is deprecated in favor of runtime.Stack(). Not sure which is called by debug.PrintStack() these days.

glycerine avatar Aug 01 '15 17:08 glycerine

The full default stack trace with arg values is probably too noisy. Perhaps even just the function names are enough, but I could see how file/line could be helpful too.

If there's ever a feature to examine other stack frames (move up/down the stack), this feature could be reused for that navigation.

willfaught avatar Aug 01 '15 17:08 willfaught

Perhaps the goroutine number would be useful too.

willfaught avatar Aug 01 '15 17:08 willfaught

Here's the stack trace you get from runtime.Stack(): http://play.golang.org/p/TzttmeRRD0

The runtime package also exports a Func type that we could use to build a cleaner trace.

jeremyschlatter avatar Aug 03 '15 18:08 jeremyschlatter

Here's an example of using runtime.Func to make a cleaner stack trace: http://play.golang.org/p/3BiuMP_ocl

jeremyschlatter avatar Aug 03 '15 18:08 jeremyschlatter

I assume that additional information is to allow those debugging the generated assembly to do so. Hence it is valuable (perhaps essential) to some. I don't find it distracting; I would leave it "uncleaned".

glycerine avatar Aug 03 '15 19:08 glycerine