title: Is there a way to get debugging symbols for CGO code linked into Go?
body: <p>I have some Cgo code that I'm linking into my Go binary. I've got Cgo running and building my code and wrapper. After some recent changes, I started getting a double-free in my C++ that I'm linking in. I've tried running my binary under lldb and it does trap the malloc panic, but the symbols are not especially useful.</p>
  
  <p>In vanilla C or C++ I've used <code>-g3</code> to get rich debugging symbols that includes variable names and source. This makes using lldb much more productive. However, I'm having some issues getting these symbols to show up in my go binary. I've noticed that in the backtrace my function appears as <code>main'foo</code>, where foo is the name of my function. There is no other debug info present though, all I get is a trace of assembly and memory pointers/registers.</p>
  
  <p>I've tried invoking <code>go build</code> with <code>CGO_CFLAGS="-g3" CGO_CXXFLAGS="-g3"</code> but the binary still doesn't have the symbols. I've also tried adding <code>-g3</code> to the CFLAGS/CXXFLAGS in my .go file where I set other flags (before <code>import "C"</code>) but this doesn't seem to work either. I can't think of any other way to get this debugging info added into my binary - is there some Go-specific flag or build sequence that enables this?</p>