I was referred here from my closed Github issue ( 
https://github.com/golang/go/issues/45467 ). I have a practical question 
about debugging in the world of Go modules.

The scenario: I am creating module mp3player, my main program. It uses 
library module mp3. While debugging I insert print statements in my main 
program. They show. Now I need to go deeper and want to insert a print 
statement in the library code. How do I do that?

I found that the code that is actually compiled is the copy of the library 
with the version specified by my go.mod file in the go mod cache (
GOPATH/pkg/mod). The file tree in the mod cache is read-only (for good 
reasons) so while changing it works, it is not the way to go.

I could create a local commit to the library or create a new debug branch 
in my local copy of the library. Then I insert my debug code and commit it. 
Then I point my main program's go.mod file at the new commit/branch, adding 
a replace along the way to use my local copy. Then when I am done debugging 
I roll everything back. This works but is very annoying for just a 
temporary print statement here and there.

I also tried temporarily vendoring my main program but then it would not 
build at all. Concretely I use GLFW <https://github.com/go-gl/glfw> which 
contains C files but they are not copied over by go mod vendor so the 
library does not compile anymore. Then even if vendoring would work 
correctly, I still consider this too much work for debugging and the go 
module reference says not to change vendored files anyway.

In GOPATH mode debugging a library was as simple as changing it, running 
the main program and see the output. Of course I see the benefits of Go 
modules and want to use them but this common use case seems hard to do now.

How do you do this?

Best Regards
gonutz

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/7727ce39-2d4b-43ca-a41e-608b196e9f47n%40googlegroups.com.

Reply via email to