Introduction to Linux Development Tools

The vi editor is a text editor commonly used on Linux systems.
vim is an improved version of vi, which adds a lot of extended functions, making it more suitable for editing source codes in various programming languages.
vim official: vim is not a word processing software, but a program development tool
 

Classification of Vi/vim command modes

In normal mode (the default is to enter normal mode when vi is opened)
    , you can move the cursor, delete text, and copy and paste (by command) the
    command is executed after inputting, no need to press Enter to confirm. After the execution is completed, it is still in normal mode.

     Insert (edit) mode    
     In general mode, input【a,A,I,i,o,O,rR】to enter edit mode.
     Press ESC in input mode to return to command mode.

 Bottom line command mode
     function: save the file or exit vi, you can also set the editing environment, such as searching for strings, listing line numbers, etc.
     In normal mode, input ":" or "/" as the leading command, which appears on the bottom line of the screen, and any input is regarded as a special command.
    The input command needs to be confirmed by pressing Enter before it is executed. After the execution is completed, it returns to the normal mode.

 

 

GCC toolchain

A commonly used compilation tool on GNU/Linux systems is GCC. GCC is not essentially a single program, but a collection of multiple programs, so it is often referred to as a toolchain.    

From the C language source code to the executable program, the following processing steps are generally required:
1. Preprocessing
    In this stage, all the preprocessing statements in the source code are processed, for example,
 the content of the file contained in the #include statement replaces all the preprocessed statements in the statement itself
 . The defined macros are expanded , and the     source code no longer contains any preprocessing statements after
 the corresponding partial preprocessing is performed according to whether the conditions of the #ifdef, #if and other statements are established .     The GCC preprocessing stage can generate .i files, and the compiler can stop compiling at the end of the preprocessing through the option -E. For example: gcc -E hello.c -o hello.i     2. In     this stage of compilation, the compiler performs lexical analysis, syntax analysis, optimization and other operations on the source code, and finally generates assembly code. This is the most important step in the whole process, so the whole process is often called compilation.     The option -S can be used to make GCC stop after compiling and generate .s assembler. For example: gcc -S hello.c -o hello.s     3. In     the assembly stage, the assembler is used to process the assembly code, generate machine language code, and save it in an object file with a suffix of .o.     When the program consists of multiple code files, each file must complete the assembly work first, and only after generating the .o object file can the next step of the linking work be entered.     The object file is already part of the final program, it just cannot be executed until it is linked. Object files can be generated with the -c option: gcc -c hello.c -o hello.o    











4. Link
The main content of the link is to deal with the parts of each module that refer to each other, so that the modules can be connected correctly.

    For example: the hello program calls the printf function (a function in the standard c library)

    And the printf function exists in a separate object file named printf.o.

The linker is responsible for incorporating printf.o, resulting in the hello file, making it an executable object file (or simply executable).
gcc hello.c -o hello

 

maketool

Assumption: A software project contains dozens or hundreds of files, and I only modify a few of them each time I debug. If I use a simple GCC compiler, what will be the trouble?

1 When compiling again with GCC, other unmodified files must be compiled again, which is a waste of time.
2. You have to enter a long GCC command every time, which is troublesome to use.

     Solution: Use the make tool to solve the above two problems

    The basic usage of the make tool is as follows:
make [-C dir] [-f file] [target ...]
-C dir: enter the dir directory during execution, the default is the current directory
-f file: use file as the Makefile
target: to complete The target, the target is defined in the Makefile, the default is the first target defined      

 

GDB debugging tool
GDB is a GNU debugging tool, it can trace the program being debugged, set breakpoints, single-step execution and other operations. When the program execution is suspended, you can use commands to view the variable values, CPU register values, memory values, and function call stacks and other information in the program.
     Before debugging an executable with GDB:
    The application being debugged uses the -g parameter to program debugging information into the object file at compile time:
gcc -g app.c -o app
Start debugging of the program app with the following command:
gdb app


After startup, enter the GDB interactive interface, and you can enter the GDB command to start debugging. The commonly used commands are as follows, usually just press Enter to repeat the previous command.     

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324345450&siteId=291194637