Dlv without optimization

I am trying to invoke the Go debugger dlv so that the relevant executable is not optimized, so far without success. Here is what I am doing:

I am working on a project that consists of several Go source code files, across several directories. I cd into the directory where the Go lives that contains main(). In that directory I invoke

 dlv debug --build-flags="-gcflags='-N -l'" . -- <options>

where just represents options that need to run my application.

After doing this, dlv hangs for a while, apparently building the executable, and when it is done I end up at the dlv command line. I can get the application going all right, and it runs as it should.

Now after setting a break point at some function (any function), when breaking into it dlv prints out (among other things)

Warning: debugging optimized function

I have tried variations on the dlv command above (e.g. removing the ‘=’ signs, etc.) to no avail. My code is built from a Makefile, but I understand that dlv ignores makefiles. At any rate, I changed things at the Makefile in an effort to build without optimizations, again without any success, as far as dlv is concerned. This is all with Go 1.9.2 under Linux.

Any ideas on how to proceed?

More info: I changed the command line above to read

    dlv debug --build-flags="-v -x -gcflags '-N -l'" . -- <options>

With this, I am getting copious output concerning what dlv is doing. The lines that interest me are the following:

mkdir -p $WORK/github.com/mymodule/analysis/_obj/
cd /home/abc/Go/src/github.com/mymodule/_gobuild/src/github.com/mymodule/analysis /usr/lib64/go1.9.2/go/pkg/tool/linux_amd64/compile -o $WORK/github.com/mymodule/analysis.a -trimpath $WORK -N -l -goversion go1.9.2 -p github.com/mymodule/analysis -complete -buildid 1b090ebb89235c0e56797d254c53089896e1d9bc -importmap github.com/Sirupsen/logrus=vendor/github.com/Sirupsen/logrus -importmap github.com/
go-datastructures/queue -importmap github.com/miekg/dns=vendor/github.com/miekg/
dns -importmap golang.org/x/net/idna=vendor/golang.org/x/net/idna -D _/home/abc/
Go/src/github.com/mymodule/_gobuild/src/github.com/mymodule/analysis -I $WORK -I
/home/abc/Go/src/github.com/mymodule/_gobuild/pkg/linux_amd64 -pack ./s1.go ./s2.go ./s3.go ./s4.go ./s5.go ./s6.go ./s7.go

My code is in the s1.go through s7.go files. It would seem that this code is indeed built with -N -l, meaning without optimization or inlining. However, when hitting breakpoints in any functions defined in those Go files, dlv still warns me that the function is optimized - which it is, for attempting single-stepping through it does not work properly, as is the case with optimized code.

Are there any dlv experts in this forum can enlighten me as to what is going on here?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.