title: How to properly debug a binary generated by `go test -c` using GDB?
body: <p>The <code>go test</code> command has support for the <code>-c</code> flag, described as follows:</p>
  
  <pre><code>-c  Compile the test binary to pkg.test but do not run it.
      (Where pkg is the last element of the package's import path.)
  </code></pre>
  
  <p>As far as I understand, generating a binary like this is the way to run it interactively using GDB. However, since the test binary is created by combining the source and test files temporarily in some /tmp/ directory, this is what happens when I run <code>list</code> in gdb:</p>
  
  <pre><code>Loading Go Runtime support.
  (gdb) list
  42      github.com/&lt;username&gt;/&lt;project&gt;/_test/_testmain.go: No such file or directory.
  </code></pre>
  
  <p>This means I cannot happily inspect the Go source code in GDB like I'm used to. I know it is possible to force the temporary directory to stay by passing the <code>-work</code> flag to the <code>go test</code> command, but then it is still a huge hassle since the binary is not created in that directory and such. I was wondering if anyone found a clean solution to this problem.</p>