How can I debug using GDB on IntelliJ IDEA.

1,354 views
Skip to first unread message

Harry

unread,
Nov 4, 2015, 1:34:47 AM11/4/15
to golang-nuts
Hello everyone,

I'm using IntelliJ IDEA 15 to develop golang projects. To debug golfing project, I installed GDB. But I couldn't find GDB related setting on IntelliJ IDEA. I'm trying it on macbook.

How can I debug on that??



Jason E. Aten

unread,
Nov 4, 2015, 12:51:10 PM11/4/15
to golang-nuts
Your question about how to use IntelliJ, as posed, is better directed to an IntelliJ specific forum.

For the general topic of debugging Go, I'm aware of 4 choices at the moment:

1. use fmt.Printf() to display debug information. This always works. It is currently what most Go programmers do. Yes, it is Old School. But it is also very effective. It is effective even when using Go routines. It's prime advantage is that it always works, it is very portable, and it is quite light weight. It requires no particular IDE. 

2. Jeremy Schlatter's https://github.com/mailgun/godebug does source code re-writing to give you a debugging approach that supports go-routines and is highly portable.

3. Derek Parker's https://github.com/derekparker/delve debugger is true go-native debugger. It is pre-1.0 but may still be useful. Although the blog post below discusses gdb, see the comment chain where the author notes the current recommendation of delve instead of gdb:


4. gdb (see https://golang.org/doc/gdb), while occasionally useful (for things like watchpoints), gdb support is not maintained or offered by the Go authors or project[1]. Single stepping rarely works for very long. Go 1.2.3 had the most working support for gdb. In general I would recommend one of the first three approaches first. Only fall back to gdb if nothing else works, or if you need watchpoints to track down an insidious memory corruption bug. In particular I say reserve GDB as a last resort because GDB will lie to you when you ask it to print the values of local variables in a Go routine, because GDB does not understand Go stacks. (https://github.com/golang/go/issues/6913, which is likely never going to be fixed; note the "unplanned" tag, and I don't have time to do it myself.)  Hence you'll have to combine gdb with Printf (approach #1) anyway. In summary, while sometimes useful, GDB should not be your first choice when debugging Go programs.


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, even when the program is compiled with gccgo. As a consequence, although GDB can be useful in some situations, 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. In short, the instructions below should be taken only as a guide to how to use GDB when it works, not as a guarantee of success.

Joel Eric

unread,
Nov 4, 2015, 7:08:03 PM11/4/15
to golang-nuts
I installed IntelliJ community edition out of the box with the GO plugin and debugging worked great. I have not tried it in complex situations (I.e. Goroutines) and don't expect that they will work but I plan to find out.

Give the plugin a try and good luck ...

Florin Patan

unread,
Nov 4, 2015, 8:14:42 PM11/4/15
to golang-nuts
If you are using Linux or Mac (x64) then the plugin supports Delve for debugging put of the box (there might be some small tinkering for Mac but I don't know).
As GDB doesn't understand well the Go applications and Delve is getting better and better every day, the plugin switched to it a while ago. If you do have any other questions, feel free to ask them here (I check the list once a day) or ask them in the plugin tracker on Github https://github.com/go-lang-plugin-org/go-lang-idea-plugin on on Gitter https://gitter.im/go-lang-plugin-org/go-lang-idea-plugin?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge

Harry

unread,
Nov 4, 2015, 8:48:06 PM11/4/15
to golang-nuts
Thank all of you. These are very useful for me.
I try those tips!!

Thanks again!

2015年11月4日水曜日 15時34分47秒 UTC+9 Harry:

Joel Eric

unread,
Nov 4, 2015, 9:06:23 PM11/4/15
to Harry, golang-nuts
I am on a Mac.  It works great!


Sent from Mailbox


--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/pP7n4RP5MR8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Harry

unread,
Nov 4, 2015, 9:30:36 PM11/4/15
to golang-nuts
I understand there are those who can work well.
My procedure I did is below.

I installed IntelliJ IDEA 15 and golang plugin from "https://plugins.jetbrains.com/plugins/alpha/5047".
And then installed GDB because I thought it was required to debug.
Finally I just set breakpoint on the left of source lines.

But it can't stop at breakpoints after starting Debug on IntelliJ IDEA.

What else do I need?



2015年11月4日水曜日 15時34分47秒 UTC+9 Harry:

Florin Patan

unread,
Nov 5, 2015, 3:29:25 AM11/5/15
to golang-nuts
There might be a bug in delve or in the plugin which prevent this from working correctly.
Could you please open an issue on the tracker: https://github.com/go-lang-plugin-org/go-lang-idea-plugin/issues/new including the ide version, plugin version and if possible code to reproduce the problem (or at least as much details as possible).
Thank you!

Harry

unread,
Nov 5, 2015, 7:59:55 PM11/5/15
to golang-nuts
I posted this issue on github issue as https://github.com/go-lang-plugin-org/go-lang-idea-plugin/issues/1969

Thanks for your advise!

2015年11月5日木曜日 17時29分25秒 UTC+9 Florin Patan:

Harry

unread,
Nov 5, 2015, 9:56:07 PM11/5/15
to golang-nuts
By the way I'm trying to install delve pkg for debugging.

After creating Cert using keychain access, I would have to run this command.

CERT=dlv-cert make install

But, after executing, something error occurred.

make: *** No rule to make target `install'.  Stop.


How can I install that?


2015年11月6日金曜日 9時59分55秒 UTC+9 Harry:

Florin Patan

unread,
Nov 6, 2015, 2:22:02 AM11/6/15
to golang-nuts
By the looks of the screenshot you have a backtick " ` " character before install. Can you please do a screenshot with the command you are running as well, not just the output. Cheers.

Harry

unread,
Nov 6, 2015, 4:12:11 AM11/6/15
to golang-nuts
Thanks for your help!

Command I inputed is so simple.




2015年11月6日金曜日 16時22分02秒 UTC+9 Florin Patan:

Konstantin Khomoutov

unread,
Nov 6, 2015, 5:42:05 AM11/6/15
to Florin Patan, golang-nuts
That's a GNU-ism: they like quoting words `like this' for some reason.

Harry

unread,
Nov 6, 2015, 10:17:09 PM11/6/15
to golang-nuts
Hi everyone,
This issue was solved thanks to all of your help.

I posted that issue on go lang idea plugin as the following https://github.com/go-lang-plugin-org/go-lang-idea-plugin/issues/1969

I used to try to debug project using symbolic link on IntelliJ IDEA.
It seem not to be worked well caused by symbolic link.

Thank you for your dedicated help!

2015年11月4日水曜日 15時34分47秒 UTC+9 Harry:

orig...@gmail.com

unread,
Oct 27, 2016, 11:00:50 PM10/27/16
to golang-nuts
I hate to say it, but debugging Golang sucks.   I've tried Delve and GDB with the IntelliJ Go plugin on a Mac... and I am truly disappointed.   I like Golang as a language - it ticks loads of boxes, yet it's frustrating to effectively debug / step through code at quick pace - the debugger goes AWOL and I have to rely on printing log lines for diagnostics.   I've only stuck with Golang because it's the preferred language where I work.  I've been programming for probably too long - 30 years, so I am VERY surprised that golang is as popular as it is without a proper debugger that integrates seamlessly and fault-free with any IDE.   

Come one guys, this is the 21st century!

I wish with all my heart that debugging in Go will be responsive, straightforward and glitch free as it is with other well established languages... sadly there is some way to go before that's a reality.

Anyone who says debugging is all good needs to wake up and smell the coffee.... the Golang plugin for IntelliJ is buggy ( but great work guys for getting it this far - kudos earned  but it seems like they need help.  There are many open tickets around the debugger).   The Jetbrains suite of IDE's are the go-to IDEs for many modern languages, so the reality is far from rosy.   If I were a teenager again, with time on my hands, I'd be straight in there fixing stuff up.  Having a family means I have just enough time to moan, so sorry for the rant :-)
Reply all
Reply to author
Forward
0 new messages