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?

 

0
Avatar
Permanently deleted user

Just to give you more details, here's my build command:

RUN /usr/local/go/bin/go build -gcflags="all=-N -l" -o bin/myapp-linux-amd64 -x src/main.go

and this is my dlv command:

CMD dlv --listen=:40000 --headless=true --api-version=2 --accept-multiclient exec /my/path/myapp-linux-amd64 -- param1 param2 ...
0

Hello,

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?

0
Avatar
Permanently deleted user

Hi Daniil,

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.

0

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

thank you

0
Avatar
Permanently deleted user

Thanks, Dmitry, I did that and I see these messages in the idea.log:

2020-08-31 06:56:22,787 [ 271163] DEBUG - #com.goide.dlv.DlvVm - IN: {"id":12,"result":{"State":{"Running":false,"Recording":false,"currentThread":{"id":15,"pc":4625315,"file":"/usr/local/go/src/runtime/sys_linux_amd64.s","line":536,"function":{"name":"runtime.futex","value":4625280,"type":0,"goType":0,"optimized":true},"goroutineID":0,"ReturnValues":null},"Threads":[{"id":15,"pc":4625315,"file":"/usr/local/go/src/runtime/sys_linux_amd64.s","line":536,"function":{"name":"runtime.futex","value":4625280,"type":0,"goType":0,"optimized":true},"goroutineID":0,"ReturnValues":null},{"id":19,"pc":4625744,"file":"/usr/local/go/src/runtime/sys_linux_amd64.s","line":673,"function":{"name":"runtime.epollwait","value":4625712,"type":0,"goType":0,"optimized":true},"goroutineID":0,"ReturnValues":null},{"id":21,"pc":4625315,"file":"/usr/local/go/src/runtime/sys_linux_amd64.s","line":536,"function":{"name":"runtime.futex","value":4625280,"type":0,"goType":0,"optimized":true},"goroutineID":0,"ReturnValues":null},{"id":22,"pc":4625315,"file":"/usr/local/go/src/runtime/sys_linux_amd64.s","line":536,"function":{"name":"runtime.futex","value":4625280,"type":0,"goType":0,"optimized":true},"goroutineID":0,"ReturnValues":null},{"id":23,"pc":4625315,"file":"/usr/local/go/src/runtime/sys_linux_amd64.s","line":536,"function":{"name":"runtime.futex","value":4625280,"type":0,"goType":0,"optimized":true},"goroutineID":6,"ReturnValues":null},{"id":18,"pc":4625315,"file":"/usr/local/go/src/runtime/sys_linux_amd64.s","line":536,"function":{"name":"runtime.futex","value":4625280,"type":0,"goType":0,"optimized":true},"goroutineID":0,"ReturnValues":null},{"id":20,"pc":4625315,"file":"/usr/local/go/src/runtime/sys_linux_amd64.s","line":536,"function":{"name":"runtime.futex","value":4625280,"type":0,"goType":0,"optimized":true},"goroutineID":7,"ReturnValues":null},{"id":24,"pc":4625315,"file":"/usr/local/go/src/runtime/sys_linux_amd64.s","line":536,"function":{"name":"runtime.futex","value":4625280,"type":0,"goType":0,"optimized":true},"goroutineID":0,"ReturnValues":null},{"id":25,"pc":4625315,"file":"/usr/local/go/src/runtime/sys_linux_amd64.s","line":536,"function":{"name":"runtime.futex","value":4625280,"type":0,"goType":0,"optimized":true},"goroutineID":0,"ReturnValues":null}],"NextInProgress":false,"exited":false,"exitStatus":0,"When":""}},"error":null} 
2020-08-31 06:56:22,788 [ 271164] DEBUG - #com.goide.dlv.DlvVm - OUT: {"method":"RPCServer.CreateBreakpoint","params":[{"Breakpoint":{"file":"/Users/myusr/myproj/src/main.go","line":96,"Cond":null}}],"id":13}
2020-08-31 06:56:22,790 [ 271166] DEBUG - #com.goide.dlv.DlvVm - IN: {"id":13,"result":null,"error":"could not find file /Users/myusr/myproj/src/main.go"}
2020-08-31 06:56:22,790 [ 271166] INFO - #com.goide.dlv.DlvVm - could not find file /Users/myusr/myproj/src/main.go
org.jetbrains.concurrency.MessageError: could not find file /Users/myusr/myproj/src/main.go
2020-08-31 06:56:22,791 [ 271167] DEBUG - #com.goide.dlv.DlvVm - OUT: {"method":"RPCServer.Command","params":[{"Name":"continue"}],"id":14}

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? 

 

0

Does the log contain the 'ListSources' command? Can you provide a full log?

0
Avatar
Permanently deleted user

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?

0
Avatar
Permanently deleted user

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?

0

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?

 

0
Avatar
Permanently deleted user

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?

 

0

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.

0
Avatar
Permanently deleted user

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?

 

0

Do you have go modules enabled in the project?

 

0
Avatar
Permanently deleted user

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. 

0

Could you please upload the log to https://uploads.jetbrains.com, I hope it will be easier to investigate

 

0
Avatar
Permanently deleted user

Done - Upload id: 2020_08_31_2hte65YMbMexTDds (file: goland-logs-20200831-072440.zip)

 

0

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.

0
Avatar
Permanently deleted user

Ah, bingo, that did the trick!!! Now my breakpoints work as expected! Thank you very much for your help!

 

0

请先登录再写评论。