Unable to debug app running in Docker 关注
Folks, I'm facing a weird problem when trying to debug my Go code running in Docker. I followed the steps documented at https://blog.jetbrains.com/go/2020/05/06/debugging-a-go-application-inside-a-docker-container/ and I can confirm that my process is up and running, I created a remote debug run configuration and it does connect to the DLV port 40000, but when I set a breakpoint in my code, it turns into a grey stop sign and I see the message "executable doesn't contain debug information". What am I missing?
Just to give you more details, here's my build command:
and this is my dlv command:
Are you using the same project from the article? It works correctly for me.
Сould you please share the project so that we can reproduce the issue?
Obviously, I'm trying to debug my own project, not the one mentioned in the article. But the steps I followed are largely the same, as you can see, I used proper gcflags and to start the app I use dlv. My question is how do I troubleshoot it? What do I need to verify? Just need some guidance here.
Please reproduce the problem with additional logging.To do that:
- add `#com.goide.dlv.DlvVm` in `Help | Debug Log Settings...`
- restart the IDE
- reproduce the problem
- provide IDE logs via the `Help | Collect logs and show in <file browser>` action
Thanks, Dmitry, I did that and I see these messages in the idea.log:
Well, the path to the main.go is correct on my local host machine - but not in the docker container where the app is deployed. Do I have to copy the source code to the docker container and make sure the path is the same as on my project?
Does the log contain the 'ListSources' command? Can you provide a full log?
It does, but the output is quite large and I don't know how to attach files to this comment. What should I look for?
Ah, ok, so MY source files are in this list, but the path is different - "/build/src/main.go" - so is there any way to map the container path to the host path?
What is the remote path to the /Users/myusr/myproj/src/main.go file? Is it a real or obfuscated name? Do you use go modules in the project?
OK, I think this is what's happening - the output of ListSources has my file at "/build/src/main.go" , which is where it was in the build container, whereas on my host machine this file is located at /Users/myusr/myproj/src/main.go . So is there some sort of mapping settings which will tell GoLand that these files are the same?
Do you have several files with the main.go name in different directories? I think that might be the reason why GoLand fails to map the file properly. Please check if changing the name from main.go to some unique name helps.
I don't have any other "main.go" files but just in case I renamed the file so that the name is for sure unique. The problem is the same though. Any other ideas?
Do you have go modules enabled in the project?
No, I don't - should I?
What's interesting, just for kicks I mounted my host /Users to the container so that the path is the same. I ran bash in the container and tried to locate the go file at the path /Users/myusr/myproj/src/main.go and it IS there.
Could you please upload the log to https://uploads.jetbrains.com, I hope it will be easier to investigate
Done - Upload id: 2020_08_31_2hte65YMbMexTDds (file: goland-logs-20200831-072440.zip)
Thank you! It looks like mapping fails because the project doesn't use go modules and also is not inside GOPATH. To match files we strip GOPATH from a local path and are trying to find a unique remote path ending with suffix we get after stripping. Since main.go is not inside a GOPATH, nothing is stripped and no corresponding remote file is found. Could you please check if adding 2 entries to GOPATH at `File | Settings | Go | GOPATH` helps? The entries should be expanded `~/go` and the directory where main.go is located on your local machine.
Ah, bingo, that did the trick!!! Now my breakpoints work as expected! Thank you very much for your help!