Using the VS GDB expansion kit to debug C/A + + programs on Linux on VS

Source: Internet
Author: User
Tags pscp gdb debugger

On Linux, the development of A/C + + program, perhaps you will be directly (local or remote) login to Linux, open the editor after writing the code, the use of gcc/g++ to compile, encountered to debug the wrong time, you will choose to use GDB for debugging. Now, if you happen to like Visual Studio, you don't have to change your habits, write programs in Visual Studio, send them to Linux remotely, and even connect gdb to debug. This can take advantage of the powerful IDE capabilities of Visual Studio to develop programs such as embedded systems or IoT devices.

Figure: There should be a lot of developers who write programs on Linux to work like this, right?

How to do?

First of all, you must use Visual Studio 2015, you can use the free version [1] of Visual Studio Community or other higher-level version, remember to check the installation of Visual C + + and C + + cross-platform action development of these two components :

Figure: Installing Visual C + +

Then just install Visual Studio GDB Debugger This expansion suite and you'll be able to choose the project template for Makefile Project (GDB) in Visual Studio's Visual C + + > cross-platform Project type.

Figure: Establishing Makefile Project (GDB) in Visual Studio

After setting up the project, the start screen will have a simple explanation of how to connect to the far end of GDB to do the debugging, there should be no big problem. SSH-related tools can be used to download related tools to the PuTTY website.

Figure: Teaching with the VS GDB expansion Kit

First in the project right-click on the selection of content, set the debugging environment, such as the remote host address, and then authentication with the Pub/private key, as well as the way to connect (SSH or plink), and so on, it is important to note that the connection server is the use of RSA public private key way to authenticate, So you have to generate a set of RSA keys, and then put the public key on the Linux host, and then set it to authenticate with the private key (the. ppk file in the diagram).

Figure: Setting the remote host connection information

Then it is set how to upload the program to the target Linux machine on the compiler, then use the gcc/g++ on the machine to compile, switch to the NMake Settings page, set the build command:

http://roucheng.cnblogs.com/

Figure: Setting How to drop a program on a remote host and compile it

Here I set the value is:

D:\tools\pscp.exe-i $ (privatekey) "D:\Temp\Project1\Project1\main.cpp" $ (remoteusername) @$ (remotehostname): $ ( Remoteworkingdirectory)/main.cpp

$ (secureshellexecutable) $ (remoteusername) @$ (remotehostname)-I $ (privatekey) "CD $ (remoteworkingdirectory); g++-G Main.cpp-o $ (remoteexecutable) "

Here I use PSCP file on the Linux host, and then use g++ to compile, the other variables are the values set above, you can according to your tool and file location to make changes.

You can then start writing the program, and then set the breakpoint as if you were writing other programs in Visual Studio, but you can start the remote debugging by selecting remote GDB at execution time.

Figure: GDB to start the remote host to debug, but combined with Visual Studio's debug interface

It looks like it's all in Visual Studio, but this code has actually been sent to the Linux host for compilation and debugging using GdB!

Using the VS GDB expansion kit to debug C/A + + programs on Linux on VS

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.