VScode installation and code tracking and debugging under Ubuntu

Summary:

This article introduces the installation and configuration of VScode in the development environment of Ubuntu16.04, and simple debugging of the program

1. Download VScode and install and run

Download the compressed package from the official website and copy it to Ubuntu (VMtools is installed by default):

Open the terminal and type

tar -xvzf code-stable-x64-1602601238.tar.gz

Unzip

After decompression, the following files are obtained:

enter

cd VSCode-linux-x64

Enter the current directory

enter

./code

The running procedure is as follows:


Second, configure the plug-in

In view–Extensions, find the plug-in you need and download the C/C++ compiler (friends in need can also download other compilers or Chinese packages)

Below are two of the plugins I installed:

1. C/C++ is required, and C/C++ support is provided

2. Code Runner must be installed to provide a running environment for the compiled program

Of course, I think it is necessary to install these plug-ins including auto-completion


Three, configuration environment

VScode generally operates under a project file

step0: I create a folder ctest2 in advance, add the .c program I need to debug in it, and start configuration after opening the folder

step1: First, run (RUN) -> Add Configuration on the top menu bar, click C++ (GDB/LLDB) to select the environment

step2: Automatically generate the .vscode folder and launch.json file and then modify it.

lauch.json is used to set up debug and run

launch.json file (insert the meaning of the table)

Note: the boxes are the modified lines

Introduction to launch.json key:

key usefulness
name Name displayed in the sidebar of (RUN)
type Type, do not modify
request There are launch and attach options
program The path and program name of the program
args Fill in the command line parameters (formal parameters of main)
stopAtEntry When it is true, when starting to run, do not execute immediately, pause first, usually fill in false
cwd Target working directory (the folder where the project is located)
environment Temporarily add environment variables manually
MIMode Refers to gdb or lldb of the debugger

The key points of launch.json should be noted:

  • preLaunchTask: The following value needs to be the same as the label in task.json
  • externalConsole: If you want to input something, then you have to change it to true, here because I want to input a number, it is set to true

step3: Configure the task.json file

== tasks.json is used to set up compilation ==

Don't stay on the launch.json interface, click on the top menu terminal (Terminal) -> Configure Task (or directly ctrl+p, enter> task) select: Tasks: Configure Default Build Task, then select others, modify the file as follows:

Note the command line in the box

Introduction to tasks.json key:

key effect
label Need to be consistent with preLaunchTask in launch.json
tyoe Don't change the type
command Compilation instructions executed

The configuration of the environment here is just fine

Fourth, start debugging

Click the green button in the upper right corner of the debug to start debugging. I added a breakpoint on the seventh line of the program source code:

After single-step debugging during debugging, it was found that 7 was executed only once when the input was 100, so it was determined to be an error in the loop condition, and the error can be executed normally after the error is improved. (The picture below shows the input of a number during execution)


Five, summary

For the VScode configuration process, the key point is that the label of task.json must be consistent with the preLaunch of launch.json.

Visual code tracking and debugging can improve work efficiency, and the cross-platform multi-type code editor VScode is really a very good choice. VScode is a light and powerful software. Come try it out.

I would like to thank my friend ’s blog post for helping me with my studies.

Guess you like

Origin blog.csdn.net/lee_goi/article/details/109551858