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 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
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.