Information Security system Design Fundamentals Third Week study summary-20135227 Huang

Source: Internet
Author: User
Tags set background gdb debugger

A. Vim editor

Six Modes of 1.Vim

2.Vim Three common modes of use, and the three switch. Turn on vim by default into normal mode, press I into insert mode, press ESC to exit Normal mode from insert mode, and then press: Enter command line mode.

              Normal mode downstream target movement

h

move to the next word

keys /strong>

description

l

Right (lowercase l)

j

k

on

w

b

How normal mode enters the insert mode

Command description

I edit at the current cursor

I Insert at the beginning of the line

A inserts at the end of A row

A inserts an edit after the cursor

o Insert a new row after the current line

O insert a new row before the current line

CW replaces characters from the position of the cursor to the end of a word

               How command-line mode exits:

Command

Description

: q!

Force quit, do not save

: Q

Exit

: wq!

Force Save and exit

: W < file path >

Save As

: SaveAs File path

Save As

: X

Save and exit

: Wq

Save and exit

Out of vim in normal mode

Enter SHIFT+ZZ in normal mode to save and exit vim

3.vim in normal mode delete

Command

Description

X

Delete the character that the cursor contains

X

Delete the previous character of a cursor

Delete

Same as X

Dd

Delete entire row (actually cut, can use p to paste behind)

Dw

Delete a word (not in Chinese)

d$ or D

Delete to end of line

d^

Delete to beginning of line

Dg

Delete to end of document

d1g

Delete to document header

4. Repeated execution of commands in normal mode (1) press. The last command can be pressed more than once. (2) Digital Times command: For example 8DD, delete 8 rows.

5. The quick jump (1) of the normal mode downstream target jumps (2) in a line, between the word words, or between the letters and letters.

1. Inter -row jump (Ctrl+o can return to the last position of the cursor)

Command

Description

NG (n shift+g)

Cursor moves to nth row ( If no line number is displayed by default, enter command mode first, enter: Set Nu to show line numbers)

Gg

Cursor moves to the first row

G (SHIFT+G)

To the last line

2. in-line jump

In normal mode, use the following command to jump within a line in a word

Command

Description

W

To the beginning of the next word

E

To the end of the next word

B

To the beginning of the first word

Ge

To the end of the previous word

0 or ^

to the wardrobe.

$

To end of line

f< Alphabet >

Search backwards < letters > and jump to the first matching position (very useful)

f< Alphabet >

Search forward < letters > and jump to the first matching position

t< Alphabet >

Search backwards < letters > and jump to a letter before the first matching position (not used)

t< Alphabet >

Search forward < letter > and jump to a letter after the first matching position (not used)

7. Copy and paste in normal mode, cut and paste

    • Use Y to copy in normal mode
      • In normal mode, yy copies the entire row of the cursor (3yy means copy 3 rows)
      • In normal mode, y^ is copied to the beginning of the line, or y0. Does not contain the character at which the cursor is located.
      • In normal mode, y$ is copied to the end of the line. The character where the light is contained.
      • In normal mode, yw copies a word.
      • In normal mode, y2w copies two words.
      • In normal mode, YG is copied to the end of the text.
      • In normal mode, y1g is copied to the beginning of the text.
    • Paste with P in normal mode
      • In normal mode, p (lowercase) represents pasting to the cursor (the next line)
      • In normal mode, the P (uppercase) represents the paste to the front of the cursor (the previous line)

ddThe delete command is cut , and you dd can use it p to paste each time you delete the contents of the document.

8. Replacement and revocation in normal mode

Command Description
r+< to replace letters > Replace the letter that contains the cursor with the specified letter
R Continuous replacement until you press theEsc
cc Replace the entire row, which deletes the row of the cursor and enters insert mode
cw Replace a word, delete a word, and enter insert mode
CUppercase Replace cursor later to end of line
~ Reverses the case of a cursor in the same letter
uN Undo One or N operations
UUppercase Undo all changes to the current line
Ctrl+r Redo, that is, Undo undo (undo itself) operation

9. (normal) indent, (command line) shiftwidth, (command line) text centered on right left adjustment

    • Input >> Line indent to the right in normal mode (for formatting code)
    • Normal mode input << full line left fallback
    • Normal Mode input: Enter command line mode to set the Shiftwidth value to control the number of characters to indent and rewind

In command-line mode, set Shiftwidth can draw a few cells now, set shiftwidth=12 represents a custom indent of 12 cells

Ce text the line is centered ri text The row is right le Left

10. Quick Find in normal mode

/string, carriage return down lookup

? String, enter search up

n where the next keyword appears

N the previous occurrence of the keyword

    • Normal mode input \* up to find the word where the cursor is located
    • Normal mode input \ #同上, #是向后 (bottom) find
    • Normal mode input g\* with \*, but partially conform to the word can be
    • In normal mode, enter G\ #同 \#, but partially conform to the word

11. Multi-file editing

1. use vim to edit multiple files

There are two forms of editing multiple files, one being a parameter that is used before entering Vim is multiple files. Another is to enter vim and then edit the other files. Create two new files and edit them simultaneously

$ vim 1.txt 2.txt

Default entry to 1.txt file editing interface

    • Input in command line mode: N edit 2.txt file, you can add! That is: n! force switch, the input of a file is not saved, just switch to another file
    • Command line Mode input: N edit 1.txt file, you can add! That is: n! force switch, the input in the previous file is not saved, just switch to another file

2. Open a new file after entering Vim

    • Input in command line mode: E 3.txt open new file 3.txt
    • Input in command line mode: e# back to the previous file
    • Input in command line mode: LS to list previously edited documents
    • Command line mode input: B 2.txt (or number) can be directly into the file 2.txt edit
    • Input in command line mode: BD 2.txt (or number) can delete file items from previously edited list
    • Input in command line mode: e! 4.txt, new Open file 4.txt, discard the file being edited
    • Input in command line mode: F Displays the file name being edited
    • Command line mode input: F new.txt, change the file being edited name to New.txt

3. Recover Files

If the document is not saved due to a power outage, you can use the recovery method, Vim-r Enter the document, enter: Ewcover 1.txt to restore

$ vim-r 1.txt

Visual Mode

    • Enter in normal mode v (lowercase), enter the character selection mode, you can move the cursor, where the cursor will be selected. The selection is deselected when the V-meeting is pressed again.
    • In normal mode input Shift+v (lowercase), enter the line selection mode, press V will be the entire row selection, you can move up and down the cursor select more rows, again, press once Shift+v can be deselected.
    • In normal mode Ctrl+v (lowercase), this is the area selection mode, you can select the rectangular region, and then cancel the selection by one time Ctrl+v .
    • Enter d Delete selection area in normal mode
    • Enter y Copy selection area contents in normal mode

Windows operation

In command-line mode :new , enter open a new Vim window and enter the window to edit a new file. Enter :q! exit multi-window editing in the command line mode of the different Windows respectively.

    • Input in command line mode: SP 1.txt opens new landscape window to edit 1.txt
    • Input in command line mode: VSP 2.txt Opens new portrait window to edit 1.txt
    • Ctrl-w s splits the current window into two horizontal windows in normal mode
    • Ctrl-w v in normal mode splits the current window into two vertical windows
    • In normal mode, the Ctrl-w Q is the end of the split window. If you have input in a new window, you need to use the mandatory character! namely: q!
    • Normal mode ctrl-w o opens a window and hides all previous windows
    • Ctrl-w J moves to the following window in normal mode
    • Ctrl-w K moves to the upper window in normal mode
    • Ctrl-w h moves to the left window in normal mode
    • Normal mode ctrl-w l move to the right window
    • Ctrl-w J moves the current window below in normal mode
    • Normal mode ctrl-w K moves the current window to the top
    • Normal mode ctrl-w H moves the current window to the left
    • Normal mode ctrl-w L move the current window to the right
    • Ctrl-w in normal mode-reduces the height of the window
    • Normal mode ctrl-w + increase the height of the window

14. Document Encryption

Vim-x file1

Implementation of EXTERNAL commands in vim command-line mode state

Enter in command-line mode! External shell commands can be executed

:!ls to display the contents of the current directory

:!RM filename is used to delete a file named filename

: W FILENAME to save the file you are editing in the current VIM as a filename file

View Help in Vim

    • Press F1 vim to open your own preset help document in normal mode
    • Enter :h shiftwidth shiftwidth The open Help file in command line mode

The function setting of Vim

1.vim function setting (do not move this file at this time, do not know how to change)

Can be set when editing the file function settings, such as the command line mode input :set nu (display number of lines), set value exit Vim will not be saved. To permanently save the configuration, you need to modify the Vim configuration file. Vim configuration file ~/.vimrc , you can open the file for modification, but be careful not to affect the normal use of vim

2. Get the current settings
    • Enter :set or :se display all modified configurations in command line mode
    • command-line mode input :set all displays all the SetPoint values
    • Command-line mode :set option? to enter a setting value that displays option
    • Command line mode to enter the :set nooption cancel current set value
Description of the 3.set function
    • :set autoindent(ai)automatic indentation of input settings in command line mode
    • Command line mode input :set autowrite(aw) set AutoArchive, default not open
    • Enter or in command line :set background=dark mode light , set the background style
    • Command line mode input :set backup(bk) set automatic backup, default not open
    • Command line mode input : set cindent(cin) set C language style indent

18. Supplement

Set NU Display line number

: Set AI automatically indents rows

: Set ts=4 sets a TAB key equal to several spaces

Move cursor

[[Go to Previous ' {' in first column]

]] to go to the next "{" In the first column

{Go to previous empty row

} go to the next empty line

GD goes to the definition of the local variable referred to by the current cursor

Two. GCC compilers

1.GCC supports compilation of some source file suffix names

Suffix

source file

. C

C Language Source files

. C. cc. cxx

C + + source files

. m

Object-c source File

. I

Pre-processed C source file

, i+

Pre-processed C + + source files

. S. S

assembly language Source file

. h

preprocessing files (header files)

. o

Target file

. A

Archive file

Procedures for GCC compilers

Preprocessing: Gcc–e hello.c–o hello.i;gcc–e Call CPP

Compilation: Gcc–s hello.i–o hello.s;gcc–s Call CCL

Compilation: Gcc–c hello.s–o hello.o;gcc-c Call as

Link: gcc hello.o–o hello; gcc-o call ld

The compilation process is difficult to remember, we simplify, the first three steps, GCC parameters linked to "ESc", the corresponding input file suffix is "ISO", so that memory is much easier

Attention:

    1. Linux executables, just assign x (executable) permissions to sudo chmod u+x excutefile
    2. As a Linux programmer, we can have GCC end at any stage of the compilation in order to check or use the output of that phase (which is important)

2. Experience: compile a classic hello with gcc

First use Gvim to edit the C language code, save as Hello.c

GCC file name-o name (whichever is substituted for the former name, because the former is a C language source file) compiled

./Name (just pick up the name) execution

3.GCC subdivision three steps

$ gcc-e Hello.c-o hello.i

First GCC invokes the preprocessor CPP, expanding the macros defined in the source program (example: #include <stdio.h>)

Hello.I This is a C source file that has been processed by the preprocessor

The-e parameter of GCC allows GCC to stop the compilation process at the end of preprocessing.

$ gcc-c Hello.i-o hello.o

In the second step, the HELLO.I is compiled into the target code, and GCC defaults to the. I file as the pre-preprocessed C-language source code, so it skips the preprocessing directly and begins the compilation process.

o file It is already a binary file now

Tips:

    1. Keep in mind that when GCC preprocessed the source file (first step), no syntax errors were checked
    2. The grammar check takes place in the second step, such as curly braces mismatch, no semicolon at the end of the line, keyword error ...

GCC Hello.o-o Hello

In the third step, the GCC connector links the target file to an executable file, and an approximate compilation process ends

4. gcc with function calls

Now a lot of software is the use of modular development, usually a program has a lot of source files, corresponding to the formation of a number of compilation units. GCC is able to handle these compilation units very well and eventually form an executable program

Three. Debugger GdB

1.Features of GdB

    1. Start the program, you can follow the user-defined requirements to run the program at will.
    2. Allows the program to be debugged to stop at the breakpoint specified by the user (the breakpoint can be a conditional expression).
    3. When the program stops, you can check what happens in the program at this time.
    4. Dynamically change the execution environment of the program.

There are several ways to start gdb:

    1. GDB <program> Program is the execution file, usually in the current directory.
    2. GDB <program> Core uses GDB to debug a running program and core file at the same time, and the core is the file generated after the core dump is executed illegally by the program.
    3. GDB <program> <PID> If the program is a service program, you can specify the process ID of the service program when it runs. GDB will automatically attach up and debug it. The program should be searched in the PATH environment variable. GDB start, you can add some gdb start switch, the detailed switch can be viewed with gdb-help. Here are just a few of the more commonly used parameters:-symbols <file>-S <file> reading the symbol table from the specified file. The-se file reads the symbol table information from the specified files and uses it in the executable file. -core <file>-C <file> Debug Core dump core file. -directory <directory>-D <directory> joins a search path for a source file. The default search path is the path defined by path in the environment variable.

Use gcc-g gdb.h-o testgdb to generate testgdb files that can be debugged using GDB

GDB Testgdb Open GDB Debugger

(GDB) L Type l command is equivalent to List command, starting from the first line to list the source code:

(GDB) Break <--------------------set breakpoints at line 16th of the source program.

(GDB) Break Func <--------------------set breakpoints at the entrance of function func ().

(GDB) Info Break <--------------------view breakpoint information.

(GDB) R <---------------------running program, shorthand for Run command

(GDB) n <---------------------single statement execution, next command shorthand.

(GDB) C <---------------------continue to run the program, continue command shorthand.

(GDB) P I <---------------------Print the value of the variable I, the Print command shorthand.

(GDB) bt <---------------------view the function stack.

(GDB) Finish <---------------------Exit function.

(GDB) Q <---------------------exit gdb.

GdB Programm (Start gdb)

B Set Breakpoints (4 breakpoints are set: Line breakpoint, function breakpoint, conditional breakpoint, temporary breakpoint)

Run starts running the program

BT Print function Call stack

P View variable values

C continue running from the current breakpoint to the next breakpoint

N Single Step operation

S Single Step operation

Quit Quit GDB

    • Change of display tracking variable value
    • Until jump out of the loop
    • Finish Jump function
    • Help

Four. File Manager makefile

1. The role of makefile:

There are countless source files in a project, which are placed in several directories by their type, function and module. Makefile defines a set of rules that specify which files need to be compiled first, which files need to be compiled, which files need to be recompiled, and even more complex functionality (because makefile, like a shell script, can execute operating system commands).

The advantage of makefile is that-"automated compilation", one but write, only need a make command, the entire project is fully compiled, greatly improving the development efficiency of the software. Make is a command tool that is a tool for Makefile commands in a timely manner.

The most important and basic function of make tools is to automate compiling and maintaining multiple source files according to the relationship between source programs described in the makefile file. While the makefile file needs to be written in a certain syntax, the file needs to explain how to compile the individual source files and link them to the executable file, which requires defining the dependencies between the source files.

2.use of makefile:

First VIM Makefile

makefile Content, the general wording:

test(目标文件): prog.o code.o(依赖文件列表)tab(至少一个tab的位置) gcc prog.o code.o -o test(命令).......

Cases:

TEST:PROG.O CODE.O

(Here is the TAB key) GCC PROG.O code.o-o test

PROG.O:PROG.C code.h

Gcc-c Prog.c-o PROG.O

Code.o:code.c code.h

Gcc-c Code.c-o CODE.O

Clean

Rm-f *.O Test

$ make

Perform ./test view Results

make cleanthe command will be executed to rm -f *.o test complete the clean operation.

3. makefile with a macro

Makefile can also define and use macros (also known as variables) to make them more automated and flexible, and the format for defining macros in Makefile is:

macroname = Macrotext

The format for using macros is:

$ (macroname)

Problem:

1. The use of >> in the experiment did not show that it could format the code, only to see the right to move a lot of cells.

Information Security system Design Fundamentals Third Week study summary-20135227 Huang

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.