title: How can I debug C code called with cgo?
body: <p><strong>Background</strong></p>
  
  <p>I'm currently in the process of writing a Go interface for this <a href="https://github.com/relic-toolkit/relic" rel="nofollow noreferrer">library</a>. </p>
  
  <p>As a first step, I'm trying to run the tests in <code>/test/test_pc.c</code> by calling them through Go wrappers. It is important to note that the tests are successful when compiled by GCC.</p>
  
  <p><em>Important Additional Details</em>: It is worth mentioning that currently I have all the C code that I want to run above <code>import "C"</code>. The reason for this is that the <code>relic_test.h</code> doesn't provide function prototypes, thus cgo does not recognize the functions through calls like <code>C.foo()</code>. Therefore, I put all the <code>test_pc.c</code> code in the following format:</p>
  
  <pre class="lang-golang prettyprint-override"><code>package main
  // #include&lt;&gt;
  /*
  void test1(){}
  void test2(){}
  .
  .
  void testN(){}
  */
  import "C"
  func main(){
    C.test1()
    C.testN()
  }
  </code></pre>
  
  <p><strong>Problem</strong></p>
  
  <p>Whenn I try running them from go, the execution gets "stuck" (i.e. the code is in execution but it just simply doesn't go to the next instruction) in one particular test. 
  How can I find out why the code gets stuck? How can I observe the execution flow of the program?</p>
  
  <p><strong>Thing I've Tried</strong></p>
  
  <p>Again, if I try using C directly (i.e. if I compile it with GCC and run it), the code works. Thus, GDB will also work.
  I've also tried  using <code>go tools cgo -debug-gcc</code>, but this only prints preprocessing directives. <code>go tools cgo -gccgo</code> doesn't output anything. finally, the Go debugger, Delve, is not able to debug the C calls.</p>