Debugging Go-lang

go
debug

#1

Hi,

There is native c9 support for GO.
But there is no runner for debugging.

As a response to my previous question , (debugging c++) you have added gdb as fault .
Go also uses GDB to debug code,

Therefore i would like to ask, could you create a go (debug) runner that is there by default?

I have tried creating one myself, but i am having troubles loading the go-runtime support for GDB


{
  "cmd": [
    "sh",
    "-c",
    "go build $file -c; gdb $file_base_name"

  ],
  "info": "Compiling $file ...",
  "debugport": 15470,
  "debugger": "gdb",
  "executable": "$file_path/$file_base_name",
  "maxdepth": 50,
  "env": {},
  "selector": "source.go" 
}

#2

That’s a great idea!
The following runner seems to work for go

{
  "script": [
    "set -e",
    "if [ \"$debug\" == true ]; then ",
    "    go build -gcflags \"-N -l\" $file",
    "    gdbserver --once :15471 \"$file_path/$file_base_name\" $args",
    "else",
    "    go run $file",
    "fi"
  ],
  "info": "Running ... $file",
  "debugport": 15471,
  "debugger": "gdb",
  
  "executable": "$file_path/$file_base_name",
  "maxdepth": 50,
  "env": {},
  
  "selector": "source.go"
}

let us know if it works well, and is worth to enable by default.


#3

Hi,

This works, and when it works, it works really good.
I also like the script in the runner with the debug flag, that is something i was missing while writing runners.
But unfortunately it is not very reliable or stable.
After some runs, it does not seem to connect to the gdb server anymore, and it just says :

Listening on port 15471
and sometimes it also prints :
Remote debugging from host 127.0.0.1
(After this you should definitely expect to start debugging)

But it does not continue. all processes seem to be there.

What i think is strange, is that it spawns a ‘node’ process while running and starting the debugger, when i kill that process, the process that is being debugged, continues and the debugger and process exit as expected but consequent runs do not always work.

I also had this in my c++ debugging test… ( WIth one difference, here it seems that when you have breakpoints, it almost .never. works, and always works without breakpoints, breakpoints dont seem to make the case different for GO )

Also, after force killing gdb with kill -9 `pgrep gdb` it works a single time, but the problem persists.

So with this problem debugging with GDB is not usable as you can not reliably start debug sessions.