If you use a different directory for the project, change the directory name in the Dockerfile. Note that Dockerfile uses the debuggingTutorial directory. Save Dockerfile and main.go in $GOPATH/src/debuggingTutorial. For more information about Docker, refer to Docker.įor example purposes, you can use the following Dockerfile for this Go application. You can attach the debugger to a Go process that runs in a Docker container. Alternatively, press Alt+Shift+F9 and select the created Go Remote configuration.Īttach to a process in the Docker container Start the debugging process on the client computerįrom the list of run/debug configurations on the toolbar, select the created Go Remote configuration and click the Debug button ( ). In the Port field, type the debugger port that you configured on Step 2 (for example, 2345). In the Host field, type the host IP address (for example, 192.168.1.33). In the Run/Debug Configurations dialog, click the Add button ( ) and select Go Remote. Alternatively, click the list of run/debug configurations on the toolbar and select Edit Configurations. Create the Go Remote run/debug configuration on the client computerĬlick Edit | Run Configurations. Open the Terminal tool window ( View | Tool Windows | Terminal) and run the following command depending on your Go version:ĭlv -listen=:2345 -headless=true -api-version=2 attach Code on the client must be in the same directory ( $GOPATH/src/debuggingTutorial/). For example, if code of your application on the host is in $GOPATH/src/debuggingTutorial/. If you use the $GOPATH approach, ensure that the project is compiled with the same relative path to $GOPATH on host and client machines. Build the application on the host machine ![]() The remote debugger (Delve) must be running on the remote computer.Ĭompile Delve with the same Go version, host and target as your application because there might be slight differences between the various operating systems, which could cause the debugging session not to work as expected. You can connect to a remote computer (a host) and attach the debugger to the Go process that runs on the host. If you used the provided code example, open the link in a browser. Trigger the event at the breakpoint in your application. In the Attach with Debugger To window, select your application process and press Enter. Read more about breakpoints in Breakpoints.Ĭlick Run | Attach to Process Control+Alt+F5. For example, in the provided code example, put the breakpoint on the line 23 ( message := fmt.Sprintf("Hello %s!", r.UserAgent())). Attach to and debug the running processĬlick the gutter near the line of code to place the breakpoint. Symbolic links or symlinks are incompatible with debugging because of incompatibility between the Go toolchain, Delve, and GoLand. These flags are incompatible with debugging the application because they strip out the necessary DWARF information that is required by Delve. myApp).ĭo not use -ldflags="all=-w" or -ldflags="-w" flags. Run the compiled executable (for example. This command compiles the myApp executable and disables compiler optimizations and inlining.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |