天天看點

Go IDE使用Go IDE

Go IDE使用

  • Go IDE
    • 哪種IDE使用友善
    • 為什麼不推薦eclipse

Go IDE

在學習Go語言時,可以使用的IDE或編輯軟體包括許多種。有興趣的同學的可以浏覽中文版翻譯的<< The way to Go >>。作者試用了liteide、Intellij+Go插件、Eclipse+goclipse插件。安裝過程十分簡單,網上也有很多教程說了如何安裝,這裡不再贅述,隻是介紹一下使用這些IDE遇到的問題。

哪種IDE使用友善

Go的源碼文檔(go/doc/debugging_with_gdb.html)裡面明确指出,使用Delve進行debug要好于gdb。

Note that Delve is a better alternative to GDB when debugging Go programs built with the standard toolchain. It understands the Go runtime, data structures, and expressions better than GDB. Delve currently supports Linux, OSX, and Windows on amd64. For the most up-to-date list of supported platforms, please see the Delve documentation.
GDB does not understand Go programs well. The stack management, threading, and runtime contain aspects that differ enough from the execution model GDB expects that they can confuse the debugger and cause incorrect results even when the program is compiled with gccgo. As a consequence, although GDB can be useful in some situations (e.g., debugging Cgo code, or debugging the runtime itself), it is not a reliable debugger for Go programs, particularly heavily concurrent ones. Moreover, it is not a priority for the Go project to address these issues, which are difficult.

推薦liteide或intellij,安裝友善,這兩者都支援delve debug模式。liteide的界面比較挫,不過啟動快,簡單。intellij就不用說了,功能強大,但是啟動、運作感覺慢。intellij安裝完Go插件後,進行debug會出問題:

could not launch process: decoding dwarf section info at offset 0x0: too short

  • 解決方案1

作者是通過将liteide安裝目錄下的dlv.exe替換intellij自己的dlv.exe解決了這個問題。不清楚dlv.exe位置的同學可以使用intellij debug時,檢視控制台輸出,輸出面闆的最上面是執行的指令,就可以找到dlv.exe的位置。

D:\go1.11.9.windows-amd64\go\bin\go.exe build -o C:\xxx\Temp\___go_build_main_go.exe -gcflags "all=-N -l" . #gosetup "D:\JetBrains\IntelliJ IDEA 2017.3.3\bin\runnerw.exe" C:\xx\.IntelliJIdea2017.3\config\plugins\intellij-go\lib\dlv\windows\dlv.exe --listen=localhost:52151 --headless=true --api-version=2 --backend=default exec C:\xx\Temp\___go_build_main_go.exe -- #gosetup

  • 解決方案2

idea.properties

中添加dlv位置配置:

dlv.path=D:\\\\liteide\\bin\\dlv.exe
           

為什麼不推薦eclipse

goclipse插件目前隻支援gdb。目前有人open了一個關于支援delve的issue,未來goclipse可能可以支援delve。作者的體驗是不推薦goclipse,因為可以直接運作成功,但是使用gdb進行debug時報錯:生成的可執行檔案不是正确檔案格式。可能是因為go編譯工具與目前goclipse版本提供的gdb不一緻,需要另外下載下傳gdb。