有没有任何golang交互式调试器存在?

huangapple go评论126阅读模式
英文:

Does any golang interactive debugger exist?

问题

标题基本上概括了一切。我正在尝试使用Go语言,但我非常想念在交互环境中能够随意设置断点并进行步入/步过/步出操作的能力。我知道我可以使用gdb来调试Go语言,但与能够插入gdb进行断点设置的IDE相比,这相当麻烦。

我尝试搜索了一下,只找到了一些插件或者只有语法高亮但没有调试功能的小型IDE。

英文:

The title pretty much sums it up. I am trying out Go and I really miss being able to set breakpoints and step in/over/out as much as I want within an interactive environment. I know I can use gdb to debug Go but that is quite annoying compared to using an IDE that can plug into gdb for breakpointing.

I tried searching for one and could only find plugins or small IDEs that have syntax highlighting but no debugging.

答案1

得分: 37

更新:就个人而言,虽然GDB可以工作,但我不喜欢在Go中使用它,它会让你吐血。查看其他答案以了解好的替代方案。

是的,当然可以 有没有任何golang交互式调试器存在?

Go有一个调试器(GDB)。

这是官方教程,告诉你如何使用它。

如果你想要“图形化调试”(也就是在编辑器中设置断点),一些IDE可以让你这样做(在后台使用GDB)。

具体来说,Eclipse、LiteIDE和Zeus都可以让你设置断点并从你的编码环境中进行调试(来源)。这是一个关于如何在Zeus中进行调试的视频

英文:

Update: Personally, while GDB works I'm not a fan of using it in Go and it will make you spit some blood. Check out some of the other answers for good alternatives.


Yes, of course 有没有任何golang交互式调试器存在?

Go has a debugger (GDB)

Here is the official tutorial on how to use it.

If you'd like 'graphical debugging' (that is, setting breakpoints in the editor) some IDEs let you do that (with GDB in the background).

In specific, Eclipse, LiteIDE and Zeus all let you set breakpoints and debug from your coding environment (source). Here is a video on how to do it with Zeus.

答案2

得分: 28

GDB对Go的支持存在许多问题,这些问题不会由Go团队修复。

有关更多信息,请阅读Rob Pike的帖子

> 尽管我们将努力保持基本的gdb功能(堆栈跟踪,打印值)在支持的平台上正常工作,但使用调试器来理解Go程序的完整环境的能力可能永远无法实现,并且改进gdb的支持并不是团队的优先事项。

他们正在寻找其他调试选项,但目前没有具体计划。
文档已过时,随go 1.2一起提供的runtime-gdb.py脚本无法在使用python3支持编译的GDB上工作(例如当前的Ubuntu)。

英文:

GDB support for go has lots of issues that won't be fixed by the go team.

For more information, read the post by Rob Pike:

> Although we will endeavor to keep basic gdb functionality (stack
traces, printing values) working on supported platforms, the ability
to use the debugger to understand a Go program's full environment will
likely never work, and improving gdb support is not a priority for the
team.

They are looking for other debugging options but have no concrete plans by now.
The documentation is outdated and the runtime-gdb.pyscript coming with go 1.2
does not work for a GDB that was compiled with python3 support (current Ubuntu for example).

答案3

得分: 24

2017年更新:godebug项目已被derekparker/delve正式取代。


原始答案:

现在(2015年3月),你有另一种基于代码插装的方法。

mailgun/godebug

> godebug使用源代码生成来为你的程序插入调试调用。
go tool cover采用了类似的方法来进行代码覆盖。

> - 当你运行godebug时,它会解析你的程序,插入函数调用、变量声明和语句行,并将结果代码输出到某个地方(当前为stdout或覆盖原始文件)。

  • 当你运行这个修改过的代码时,假设你在某个地方设置了断点,你可以逐步执行并检查变量。

> 即将推出的功能:评估任意的Go表达式并写入变量。


2015年6月更新:

虽然它可能不像“某些人”希望的那样交互,但它仍然受到赞赏(并且具有“步入”功能)。
参见“Go has a debugger—and it's awesome!”(Cloudfare)

> 这里的亮点是:与其与不可移植的半打的ptrace接口纠缠不清,godebug会重写你的源代码,并在每一行插入godebug.Line函数调用,在每个变量声明处插入godebug.Declare,在断点处(即你键入_ = "breakpoint"的地方)插入godebug.SetTrace

> 我认为这个解决方案很棒。
你得到的是一个(可能是交叉编译的)启用了调试的二进制文件,你可以像普通二进制文件一样将其放在一个暂存服务器上

> 当达到断点时,程序将停在当前位置并等待你在stdin上输入。

> 这是我们喜爱的Go的单一二进制文件、零依赖的哲学应用于调试。在任何地方构建,任何地方运行,无需服务器上的工具或权限。

ifdef GODEBUG  
    GOPATH="${PWD}" go install github.com/mailgun/godebug
    GOPATH="${PWD}" ./bin/godebug build -instrument "${GODEBUG}" -o bin/rrdns rrdns

> 调试只需执行make bin/rrdns GODEBUG=rrdns/...

英文:

Update 2017: the godebug project mentions below is now official replaced by derekparker/delve.


Original answer:

You now (March 2015) have another approach, based on instrumenting the code.

mailgun/godebug:

> godebug uses source code generation to instrument your program with debugging calls.
go tool cover takes a similar approach to code coverage.

> - When you run godebug, it parses your program, instruments function calls, variable declarations, and statement lines, and outputs the resulting code somewhere (currently either stdout or in place over your original files).

  • When you run this modified code, assuming you put a breakpoint somewhere, you can step through it and inspect variables.

> Coming later: evaluate arbitrary Go expressions and write to variables.


Update June 2015:

While it might not be as interactive as "some" might hope, it is still appreciated (and has "step into" feature).
See "Go has a debugger—and it's awesome!" (Cloudfare)

> here's the cool bit: instead of wrestling with half a dozen different ptrace interfaces that would not be portable, godebug rewrites your source code and injects function calls like godebug.Line on every line, godebug.Declare at every variable declaration, and godebug.SetTrace for breakpoints (i.e. wherever you type _ = "breakpoint").

> I find this solution brilliant.
What you get out of it is a (possibly cross-compiled) debug-enabled binary that you can drop on a staging server just like you would with a regular binary.

> When a breakpoint is reached, the program will stop inline and wait for you on stdin.

> It's the single-binary, zero-dependencies philosophy of Go that we love applied to debugging. Builds everywhere, runs everywhere, with no need for tools or permissions on the server.

ifdef GODEBUG  
    GOPATH="${PWD}" go install github.com/mailgun/godebug
    GOPATH="${PWD}" ./bin/godebug build -instrument "${GODEBUG}" -o bin/rrdns rrdns

> Debugging is just a make bin/rrdns GODEBUG=rrdns/... away.

答案4

得分: 15

我已经检查过了,并且很高兴地报告说,版本:2016.1.3,构建:145.1617.8,发布日期:2016年6月5日与Delve兼容!您可以在此处下载:https://www.jetbrains.com/idea/download/。还要按照此处的Delve安装说明进行安装:https://github.com/derekparker/delve/tree/master/Documentation/installation

它有点不稳定。在我得到OSX登录提示后,交互式调试开始工作。有时,我必须调试一个简单的.go程序来启动它。但它确实可以工作,并且是我见过的最好的Go交互式调试体验。

原始帖子:

是否存在任何值得使用的golang交互式调试器?
是的。

是否存在任何值得使用的golang交互式调试器?
没有。

在Mac上配置GDB很麻烦,但是可行。

然而,一旦你开始使用它,你很快就会意识到你只是浪费了时间安装它。

你甚至可以配置IntelliJ来使用它。

IntelliJ,LiteIDE,CGDB等唯一提供的价值似乎是你可以更快地确定GDB对Go的调试支持非常差。

你可以用它来逐步执行一些Go代码,但是尝试打印除非非常简单的变量值之外的任何值,你将会浪费时间希望有一个像样的调试器。

这是一个使用CGDB打印map[string]string数据结构值时发生的情况的示例:

(gdb) print params
$1 = (github.com/go-martini/martini.Params) 0x15582 <runtime.reentersyscall+450>

...这完全没有用。

接下来,尝试这样做:

(gdb) print params["UserID"]

...你会得到“总线错误”。

Delve(https://github.com/derekparker/delve)看起来很有希望,因为它是用Go编写的,但是你是通过控制台而不是通过IDE来使用它。

我很愿意为能够在Go中进行良好的交互式调试的企业版IntelliJ(或任何其他IDE)付费。

目前,fmt.Printf("%v", variable)是最好的选择。

英文:

UPDATE:

I have checked it out and am happy to report that Version: 2016.1.3, Build: 145.1617.8, Released: June 5, 2016 works with Delve! You can download it here: https://www.jetbrains.com/idea/download/. Also follow the Delve install instructions here: https://github.com/derekparker/delve/tree/master/Documentation/installation

It's a bit flaky. Just after I got the OSX login prompt the interactive debugging started working. Sometimes, I have to debug a simple .go program to kick start it. But it does work and is the best interactive debugging experience for Go that I've seen.

ORIGINAL POST:

Does any golang interactive debugger exist?
Yes.

Does any golang interactive debugger, that is worth using, exist?
No.

Configuring GDB on the mac is tedious, but doable.

However, once you start using it you'll soon realize that you just wasted your time installing it.

You can even configure IntelliJ to use it.

The only value that IntelliJ, LiteIDE, CGDB, etc. seem to provide is that you can more quickly ascertain that GDB debugging support for Go is extremely poor.

You can use it to step through some Go code, but try to print the value of anything other than very simple variable values and you'll be wasting your time wishing for a decent debugger.

Here's an example of what happens when you try to print the value of a map[string]string data structure using CGDB:

(gdb) print params
$1 = (github.com/go-martini/martini.Params) 0x15582 &lt;runtime.reentersyscall+450&gt;

...which is completely useless.

Next, try this:

(gdb) print params[&quot;UserID&quot;]

...and you'll get "Bus error".

Delve (https://github.com/derekparker/delve) looks promising, since it is written in Go, but you drive it using the console, not via an IDE.

I would gladly pay for the enterprise version of IntelliJ (or any other IDE) that did a decent job supporting interactive debugging in Go.

As of now, fmt.Printf(&quot;%v&quot;, variable) is about as good as it gets.

答案5

得分: 9

编辑

> GO调试器现在是IntelliJ或PyCharm中的一个简单插件,不需要安装其他任何东西。只需在插件首选项中查找Go插件即可。

原始答案(2015年11月)

对于那些寻找截至2015年11月底最新信息的人:

获取delve

https://github.com/derekparker/delve

并按照构建/设置说明进行操作:

https://github.com/derekparker/delve/wiki/Building

获取最新的IntelliJ(15)或PyCharm(5)

https://www.jetbrains.com/idea/download/

并在所选IDE中获取go-lang-plugin:

Pycharm -&gt; 首选项 -&gt; 插件 -&gt; 搜索go
当前版本为Version: 0.10.749
IntelliJ -&gt; 首选项 -&gt; 插件 -&gt; 搜索go
当前版本为Version: 0.10.749
  1. 设置一个新的Go项目,或导入一个项目。
  2. 根据提示设置Go SDK。
  3. 设置Go库(通常在GOROOT/src中)。
  4. 在右上角的“播放”图标旁边设置一个“运行应用程序”配置。
  5. 编辑配置 -> 点击+ -> Go应用程序

定义要运行的包或文件。

设置完成后,播放图标和调试图标应该是活动的,您可以像往常一样设置断点、监视等。

干杯

英文:

EDIT

> The GO debugger is now a simple plugin in IntelliJ or PyCharm, no need
> to install anything else. Just look for the Go plugin in the plugin
> preferences.

Original answer (Nov 2015)

for those looking for the latest as of end of Nov 2015:

get delve

https://github.com/derekparker/delve

and follow the build / setup instructions:

https://github.com/derekparker/delve/wiki/Building

Get the latest IntelliJ (15) or PyCharm (5)

https://www.jetbrains.com/idea/download/

and get the go-lang-plugin in the IDE of your choice:

Pycharm -&gt; Preference -&gt; plugins -&gt; search for go
current version is Version: 0.10.749
IntelliJ -&gt; Preference -&gt; plugins -&gt; search for go
current version is Version: 0.10.749
  1. Setup a new Go project, or Import a project.
  2. Setup you Go SDK as prompted
  3. Setup your Go library (usually in GOROOT/src
  4. Setup a Run Application configuration top right corner by the 'play' icon:
  5. Edit Configurations -> click + -> Go Application

Define you package or file to run.

Once done with the setup, the Play icon and Debug icon should now be active, and you can set breakpoint, watches etc... as usual.

Cheers

答案6

得分: 8

我很高兴地使用CGDB,这是一个围绕GDB的小型curses包装器。

英文:

I am happily using CGDB, a little curses wrapper around GDB.

答案7

得分: 8

  1. 选项一 - GDB https://golang.org/doc/gdb

  2. Delve

  3. Visual Studio Code 与其 go 插件(仍然使用 delve)。

我个人使用选项三。为此,您需要安装 delve

此视频展示了调试的过程:https://youtu.be/uBjoTxosSys?t=16m11s(整个视频非常有趣)。

英文:
  1. Option one - GDB https://golang.org/doc/gdb

  2. Delve

  3. Visual Studio Code with its go plugin (still uses delve).

I personally use option 3. For it you will need to have delve installed.

This video shows the debugging in action: https://youtu.be/uBjoTxosSys?t=16m11s (the entire video is very interesting).

答案8

得分: 7

IDE DEBUG ON GO IS POSSIBLE (AGAIN), ACTUALLY WORKS!

Delve 在 Mac OS X 上运行得相当好,并且受到 IntelliJ IDEAGo 语言插件 的支持。

我在 Mac OSX、IntelliJ Idea 14、Go 1.5.1、Delve 0.5 上进行了测试。

我必须按照通常的步骤创建一个自签名证书,将其添加到系统环境中等等(这是在 Mac OS X 上运行调试器所必需的)。
最后,我在 IntelliJ 中设置了一个 GO 项目,并且通过恢复常规的 IDE+调试器功能来得到回报:设置断点、检查变量、单步执行。

这比打印值来调试代码要好得多。

英文:

IDE DEBUG ON GO IS POSSIBLE (AGAIN), ACTUALLY WORKS!

Delve works rather well on Mac OS X and is supported by IntelliJ IDEA Go Lang plugin.

I tested that on Mac OSX, IntelliJ Idea 14, Go 1.5.1, Delve 0.5

I had to run thru the usual loops of creating a self-signed cert, adding it to the system ring, etc (required in order to run a debugger in Mac OS X).
At the end, I set a GO project inside IntelliJ and was repaid in regaining the usual IDE+debugger features: setting breakpoints, inspecting variables, single stepping.

That's way better than printing out values in order to debug code.

答案9

得分: 0

我一直对Gogland(https://www.jetbrains.com/go/)感到非常满意,它基本上是带有Go支持的Intellij。它有一个工作中的调试器,随着他们的开发,它变得越来越好。我从2017年1月开始使用它,在2016年的MBP上它对我来说大部分时间都很稳定。

Goland是JetBrains的一个新商业IDE的代号,旨在为Go开发提供一个舒适的环境。

英文:

I've been pretty happy with Gogland (https://www.jetbrains.com/go/) which is basically Intellij with Go support. It's got a working Debugger that keeps getting better as they've been developing this. I've been using it since Jan 2017 and it's been mostly stable for me on a 2016 MBP.

> Goland is the codename for a new commercial IDE by JetBrains aimed at
> providing an ergonomic environment for Go development.

huangapple
  • 本文由 发表于 2013年5月11日 08:18:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/16492509.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定