2015-02-13 01:50
浏览 136


I wanted to know how one can enumerate the names and values of all local variables in golang. This is done with the purpose of effectively debugging go code.

Yes, I am well aware golang has limited gdb support right now.

This commonly used thread on stackoverflow has no mention of golang.

I am genuinely looking for a solution (I think others are curious as well).

Many thanks.

图片转代码服务由CSDN问答提供 功能建议

我想知道如何枚举golang中所有局部变量的名称和值。 这样做是为了有效调试go代码。

是的,我 众所周知,golang目前对gdb的支持有限。


我是真的 寻找解决方案(我想其他人也很好奇)。


  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dousi8931 2015-02-13 07:33

    There is no easy solution:

    • gotype can do static analysis of the code and print all variables (but not their value)
    • go-spew can print a variable value (deep pretty printer for Go data structures to aid in debugging), but that is like an enhanced printf, not a 'gdb' like debug session.
    解决 无用
    打赏 举报
  • douda5706 2015-02-13 13:16

    There is dlv, you can experiment with the print command, it's the closest thing to a live debugger you can get atm.

    Otherwise gotype/go-spew like @VonC mentioned are the way to go.

    解决 无用
    打赏 举报

相关推荐 更多相似问题