Golang Remote Debug and Docker debug

Source: Internet
Author: User

Sometimes I need to remotely debug Golang programs, such as the code we write on MacOS, but sometimes run on Linux, so we need to remotely debug the code running on the Linux system. Another scenario is that we can package the goalng into a Docker image, and the code can be debugged in a container. Take Goland as an example.

Remote Debug

Remote debugging Golang code requires that you follow delve on the remote machine where the code is running, and then run the program that you want to debug with delve.

  • Compile
   export CGO_ENABLED=0 GOOS=linux GOARCH=amd64   go build -gcflags='all -N -l' main.go
  • Install Delve
   
  • Delve running the program
 dlv --listen=:2345 --headless=true --api-version=2 exec ./main
  • Goland Setting up Remote Debug
    Host IP port for remote host is the port that was just DLV set


    Screen shot 2018-07-03 pm 3.57.11.png
  • Debug
    Then debug the program on the remote host just as you would debug local code

Docker Debug

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.