9

I've built my binary with: go build -gcflags "$gc_flags" -o ./bin/grafana-server ./pkg/cmd/grafana-server, where $gc_flags is '-N -l'.

When I run this file, ./bin/grafana-server, and attach to it in my debugger (Goland), not all of my symbols are loaded. Further, some breakpoints display the message:

no code at /Users/.../file.go:186

The code I'd like to debug is below:

enter image description here

The section I've added to the original project is lines 186-199. What you can see is that the execution has made it into the for _, .. loop (line 196), indicating that query has data, and we were able to pull data from the database using that query via repo.Find(query). However, query is nowhere to be found in my debugger:

enter image description here

So I'm unsure what's going on at this point. I'm really really new to golang unfortunately; this is making it incredibly difficult for me to make any progress.

MrDuk
  • 16,578
  • 18
  • 74
  • 133
  • 2
    From what I understand in https://stackoverflow.com/questions/49805029/golang-debugger-stops-on-empty-lines-why/ you are using Go 1.10+. When doing so, please use ` -gcflags="all=-N -l" ` in order to ensure that all debugged packages are properly compiled with the debug symbols on and no optimizations. – dlsniper Apr 13 '18 at 15:59
  • Thanks @dlsniper - I never came back to say this worked for me; it worked for me. – MrDuk Apr 23 '18 at 14:16
  • Happy to hear this works now. I'll add this as a proper response so it can be closed as answered. – dlsniper Apr 23 '18 at 17:29

1 Answers1

15

When using Go 1.10 or newer, in order to have a better debugging experience and remove the optimizations the compiler does, you need to build the target application using -gcflags="all=-N -l".

Before Go 1.10, you need to use -gcflags="-N -l".

The IDE adds these flags automatically when compiling an application for debugging.

dlsniper
  • 7,188
  • 1
  • 35
  • 44