goland remote debugging

Foreword

Written before a goland local debugging , local debugging Why can even do remote debugging?

The preferred declare that local debugging is preferred , if possible local debugging, it is naturally the most convenient local debugging.

However, the local environment and the physical environment often are not the same, it is difficult to build the machine out of line with the exact same environment, such as we want to debug database, debugging rpc, commissioning services Register found that these are readily available online but it is difficult to replicate in us the machine, then the machine such as network and our network environment is not the same line, local debugging are unable to meet our needs in these scenarios, we need to deploy the online environment to the test.

Remote debugging did not know before, I have been changing for the better program, push to the git, then pull the machine down to the wire, compile, run, look at the log. . . On the one hand, every time your program and want to test the change, it is cumbersome, on the other hand, a complete development complete feature, produced dozens commit. . .

Fortunately, goland have remote debugging feature!

With remote debugging, code is written in goland directly synchronized to the remote machine, then the button bugs debugging and breakpoint. . . Ah, it is basically the same as with local debugging convenient.

Explanation

Prior to that specific configuration instructions in mind:

1. The configuration process does not need over the wall , the configuration process will download something from github, will be very slow, but you can!

2. Local gopath and remote machine does not require the same, do not need to go the same version , if you have a go local and remote environment, without making any adjustments!

Anyway, the configuration is not high cost, very easy ~

Configuring the remote machine

Remote machine configuration instructions

My remote machine is Baidu cloud server, the system is ubuntu1604, configuration is as follows:

Ah, that is, that section of the cheapest. . .

go version is 1.12.4.

gopath follows.

Note that this only to illustrate, go and gopath version really does not matter, because later you will find it with my configuration of the machine is completely different.

Installation dlv

Let's start to hold things, in fact, only need to install a delve, What it is that it directly affixed on github profile bar.

Want to see more detailed look can go directly to github readme, link: https://github.com/go-delve/delve

Installation is according to the official, but the actual operation of the process, the need to go get found directly over the wall, then down and make install git clone also need over the wall. . . Fortunately, you can download their first package you need, so do not over the wall, using the following command:

mkdir $GOPATH/src
mkdir $GOPATH/src/golang.org
mkdir $GOPATH/src/golang.org/x
cd $GOPATH/src/golang.org/x
git clone https://github.com/golang/net.git
git clone https://github.com/golang/sys.git
git clone https://github.com/golang/arch.git
git clone https://github.com/golang/sync.git
git clone https://github.com/golang/tools.git
cd $GOPATH/src
go get -u github.com/go-delve/delve/cmd/dlv

Here reference is made to this blog https://blog.51cto.com/13740724/2318397 , lucky hit to solve my problem, at times expressed his thanks ~

After go get done, enter dlv, see the following instructions to install successfully.

 If you can not find dlv command prompt, as shown below,

Description PATH path is not installed, the need to manually add, add the following manner:

1. Locate the installed dlv command

sudo find / -name dlv

Found in both places.

Just pick a soft link to the command path go, go because the path is configured in the PATH.

ln -s /home/ubuntu/go/bin/dlv $GOROOT/bin

Then enter dlv, ah, certainly on it. 

After dlv successful installation, remote configuration of the machine will come to an end, local goland configuration below.

Local goland Configuration

The machine configuration described

macOS system, do not envy the company. . .

go version 1.13.4.

gopath follows.

Finally echoed on the description of the beginning, go and gopath do not need the same version. 

goland install remote hosts access plug

Want remote debugging, there is a need goland remote hosts access plug-in is called, I see a lot of online goland remote debugging related blog, the first step is to install the plug-in, but I like the goland comes with this plugin, so do not install . . . In short, this plugin is a must, you can go to see their goland there, if not to install a view as follows:

1. Click preference

2. Select the left side plugin, and then search the remote, if found installed, the explanation has been, if not, then install it. . .

Add Remote Server Information 

After determining With this plugin, you begin to configure the remote server information into the following steps:

1. Click tools-> deployment-> configuration

2. Click the plus sign on the left corner, select sftp, is secure ftp, linux systems are this, not ftp

3. goland is connected via ssh to your server, you need to fill in your server ip, ssh port (default 22), as well as the user name and password, remember to check the save password, or there will have to enter a password each time debugging

4. After you have entered ssh remote server information, click on the Test Connection button to test whether the connection, if this is the figure below, indicating successful connection

5. Next configure the mapping, is your local folder, which is mapped to a remote file folder

Note that I am here and became a local configuration the same path, it's not because I'm lazy direct copy, but only for this configuration path, I was debugging a success. . .

I believe that it should not be like this, but the fact is that if I changed to another folder, the breakpoint information can not be synced to the far end of this reason, there is no find, hoping to have adequate guidance. . .

Ignore this problem to continue it. . .

Click the lower right corner ok, here it is done!

Uploaded to a remote server program

 After you finish configuring the remote server information, you can put your local program uploaded to the remote file you just configured mapping in a folder

First, click on the left side of the project folder, otherwise, the default file upload current .go

Then, click tools-> deployment-> upload to ...

Then you can go look at your remote server, the file is not passed over.

goland interface configuration

It is recommended that fully use the tools provided by goland, farewell iterm, xshell these tools, and can graphically manipulate remote files.

1.点击tools->deployment->browse remote host

Then you will find, goland appeared a remote file system, where you can view, and even operating remote files!

2. goland directly below the terminal in ssh connection remote server

 Completed these two steps, you will find that remote debugging, all without goland out of this interface, just do not be too easy!

Configuring Remote Debugging

Next, configure remote debugging, follow these steps:

1. Click on the top right corner of the configuration

2. New configuration, select go remote 

3. Configure remote server information, to use the default port like

Note that command ring up the image above, it is to be performed later, this two pages to the command, which said second github.com/app/demo, I really do not know what, so use The first. . .

Here, all the configuration finished, the next time the witness went to the outcome!

Remote Debugging

Execute the following command on a development machine:

1. Enter the mapping in the configuration of the remote folder

cd /Users/dongjiaqi/testBuild/

2. Execute the command in the screenshot above, with no attention to the last argument, is that --accept-multiclient, put it, the command can not quit after the execution, I do not know why. . . Also explain that this command while completing the compile and run, if you run the program need to declare parameters, directly behind the increase in like a ~

dlv debug --headless --listen=:2345 --api-version=2

After execution, results as shown below, ah, 2345 has started listening port, waiting our operation from the present machine.

Then, on goland you can start debugging, you can set breakpoints, you can also set the program up and running again, all Oak. I'm here to run a simple little program, set breakpoints directly.

Then you can click on the upper right corner of the bugs start debugging.

Then, you will find a program such as local debugging, we stopped at a breakpoint, debugging information appears below!

Ah, there is nothing wrong, which means you're done, ha ha.

After then, like remote debugging code, only need to modify the code, upload to the remote, and then dlv command the program up and running, you can like a local debugger friends ~

Published 39 original articles · won praise 25 · views 120 000 +

Guess you like

Origin blog.csdn.net/u013536232/article/details/104123861