Use the vs gdb extension package to remotely detect C/C ++ programs on Linux and gdblinux

Source: Internet
Author: User
Tags pscp gdb debugger

Use the vs gdb extension package to remotely detect C/C ++ programs on Linux and gdblinux

To develop C/C ++ programs on Linux, you may log on to Linux directly (local or remote). After opening the editor and writing the code, compile the program using gcc/g ++, when debugging is required, gdb is used for debugging. Now, if you just like Visual Studio, you don't have to change your habits. You can use Visual Studio to write programs, send remote files to Linux for compilation, and even connect gdb for debugging. Visual Studio's powerful IDE capabilities can be used to develop programs such as embedded systems or IoT devices.

Figure: Should many developers write programs on Linux do this?

How to do it?

First, you must use Visual Studio 2015. You can use the free version of [1] Visual Studio 2015 Community or other higher-level versions, remember to check Visual C ++ and C ++ for cross-platform action development during installation:

Figure: Install Visual C ++

After Visual Studio GDB Debugger is installed, you can select the Project template of Makefile Project (GDB) in Visual C ++> cross-platform projects of Visual Studio.

Figure: Create a Makefile Project (GDB) in Visual Studio)

After the project is created, the startup screen will show you how to connect to the remote GDB for debugging. There should be no major problems if you follow the instructions. SSH-related tools can be used to download tools from the PuTTY website.

Figure: How to Use the vs gdb extension package

First, right-click the project and select the content to set the debugging environment, such as the remote host address, the pub/private key used for authentication, and the connection method (ssh or plink) so, you must first generate a set of RSA keys and then place the public key on the Linux host, the private key is used for verification (as shown in the figure. ppk ).

Figure: configure remote host connection information

The next step is to set how to upload the program to the target Linux machine during program compilation, compile the program with gcc/g ++ on the machine, and switch to the NMake setting page, set the build command:

Http://roucheng.cnblogs.com/

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

Here, my setting 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 to upload files to the Linux host, and then use g ++ for compilation. Other variables are the previously set values, you can modify the file based on your tools and file location.

Next, you can start to write the program, and set the breakpoint just like writing other programs in Visual Studio. However, you can start Remote GDB for Remote detection and error.

Figure: Start gdb on the remote host to debug the error, but with the Visual Studio error detection Interface

It seems that all the debugging images are in Visual Studio, but this code has been compiled on the Linux host and detected by gdb!

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.