Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't my Go debugger load all symbols, causing local variables to be missing from the debugger?

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.

like image 647
MrDuk Avatar asked Apr 13 '18 15:04

MrDuk


People also ask

How do I fix No symbols have been loaded for this document?

"No Symbols have been loaded for this document"Go to the Modules window (Debug > Windows > Modules) and check whether your module is loaded. If your module is loaded, check the Symbol Status column to see whether symbols have been loaded. If symbols aren't loaded, check the symbol status to diagnose the issue.

How do I load debug symbols in Visual Studio?

In Visual Studio, open Tools > Options > Debugging > Symbols (or Debug > Options > Symbols).

How do I debug a Go program?

To debug a program, execute the dlv debug command. Attach the filename at the end of this command, and debugging will start. For example, if you want to debug the main.go file, run the command dlv debug main.go . It is also known as “delve server” because this is a running process waiting for instructions.


1 Answers

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.

like image 53
dlsniper Avatar answered Sep 24 '22 08:09

dlsniper