Segmentfault corresponding posts page: 1190000016300215
Recently has been reading OvS source code, see the user-state codes, need to debug the user-state code, a start to directly use the Linux GDB debugging, but the OvS project is too complex, from the Internet to find some articles, found that vs2017 can support the debugging of Linux C + + program , the afternoon, met some pits, finally set up the development environment.
The latest version of VS 2017 supports Linux environment programming, unlike traditional vs Windows programming, where the Linux environment required for vs2017 needs to be installed on a Linux server, vs 2017 The equivalent of a mapping between the Windows system and this Linux system, you can copy the code to the corresponding directory in Linux, and vs 2017 in the Windows system can see what's going on, even debugging the code for breakpoints.
Development environment
Window 10 operating system, vs Community version, VMware12.5.7
Installing UBUNTU14 Desktop version in VMware
VS 2017 Installation
Official website Https://visualstudio.microsoft.com/zh-hans/?rr=https%3A%2F%2Fwww.microsoft.com%2Fzh-cn%2F
Download the latest vs 2017 from the official website and be aware of the installation process, if you need to build a Linux C + + environment, you need to tick the "Linux development using C + +" toolset, see
Configuring the Ubuntu Environment
Install the C + + environment in Ubuntu, because vs 2017 needs to ssh into the Ubuntu system, so also need to install the SSH service, the command is as follows:
sudo apt-get install openssh-server g++ gdb gdbserver
To start the SSH service:
sudo service ssh start
vs2017 Creating a Linux Project
To open vs2017, proceed as follows, file--new project--cross-platform-->linux-> console Application (Linux)
After you create a new project, VS2017 automatically generates a simple Maic.cpp file
menu bar Select Debug->cross platform->add Enter the Ubuntu server user information you just established
Right-click the solution, you can see the current program's Properties page, click on the configuration properties, general-and remote build computer, select the newly created account, you can see, under this page, the default remote generation root directory under "~/projects", You will be able to see the code for the project in the corresponding directory in Ubuntu later.
menu bar Select Debug->linux console open Linux program console
You can break points in the program, click the Debug button to run, you can see the console print out the information
On Ubuntu, you can see the newly generated project folder "Test" under the ~/projects directory.
Encounter problems
The above is a simple development demonstration, in the actual work, the code may be very complex. Because these days in the learning of Linux IO multiplexing mechanism, from the Internet to find a slightly complex communication program, the code from the blog https://www.cnblogs.com/Anker/p/3261006.html, the source code has a mistake, need to add # Include <arpa/inet.h>. The function of this program is that the client sends information to the server, the server receives the output and sends it back to the client, and the client receives the output to the terminal. Some of the library files in Linux are used.
Issue 1 cannot find library file
In the blog https://www.cnblogs.com/xylc/p/6533716.html?&from=androidqq see a solution that will Ubuntu under/usr/include,/usr/local/ Directories such as include are copied to VS's Linux header path (in my machine, the address is C:\Program Files (x86) \microsoft Visual Studio\2017\community\common7\ IDE\VC\LINUX\INCLUDE\USR).
Issue 2 Gdbserver mode is not available
There are two ways to debug the vs2017, GDB and Gdb-server, which can be configured in debug mode, debugging with configuration Properties, menu bar debugging, and the official documentation for the differences between the two modes are as follows:
- In "Gdbserver" mode, GDB runs locally and connects to the Gdbserver running on the remote system. Note that this is the only mode supported by the Linux console window.
- In GDB mode, the Visual Studio debugger drives GDB on a remote system, and GDB on the remote system is more compatible if the local version of GDB is incompatible with the version installed on the target computer.
From the Internet to find a lot of information, re-update the Ubuntu gdbserver, the result is still not, because I used to be Ubuntu17 server version, helpless use UBUNTU14 desktop version, the problem is resolved immediately, Still do not know why the Gdbserver model can not be used, if there is a passing by the great God to see, hope that the comment area to leave a message.
Issue 3 Error stopped (TTY input)
When running the client in GDB mode, the client receives data from the console in the section of the code stopped (TTY input) error, by looking at the official document found that GDB mode does not support console interaction, changed to Gdbserver mode can be used normally.
Final Run Results
Finally successfully run the server and client programs, first start the server, and then run the client, respectively, the service side and the client running situation. When the client then enters information into the console, the server can receive it and send it back to the client in the console display.
Resources
Deploy, run, and debug Linux projects
Using visual Studio 2017 as a Linux C + + development tool
vs2017 Build Linux C + + development environment