- 1. Use of Linux development tools
- Use of VIM compilation
- Use of GDB Debugging tools
- The writing of Makefile
- Linux Trace debugging
- Use of SSH
- Use of subversion
1. Use of the Linux development tool using VIM compilation
The practical technology of VIM in IBM
Http://www.ibm.com/developerworks/cn/linux/l-tip-vim1/index.html
Http://www.ibm.com/developerworks/cn/linux/l-tip-vim2/index.html
Http://www.ibm.com/developerworks/cn/linux/l-tip-vim3/index.html
L Jump command:
^,$ cursor moves to the beginning of the line, end of row
(,) The first and the last of a sentence
{,} The front and back of a paragraph
H jumps to the first line
M jumps to the middle row
L Skip to last line
GG runs to the beginning of the file
G run to end of file
Find command
/? query, s/find content/replace content
Edit command
Copy: Y copy selected content, yy copy row, Nyy copy n rows
Clip D
Paste: P; ]p Code pasting
Delete: D Delete the selected content, dd delete one line, DW delete a word
Cancel: U
Change: CW change a word at the cursor location
Delete or title a clip
DB Delete to the beginning of a word
d) Delete to the end of a statement
D (Delete to the beginning of a statement
D} Delete to the end of a paragraph
d{Delete to the beginning of a paragraph
D Delete to the end of a line =d$
Modify
CL changes the current character (equals pressing x and then I)
CW modified to end position of a word (DW again i)
CB modified to start position of a word (db again i)
<< Code moves forward
>> code moves backwards
Window commands
: Split/vsplit Separates a window
: new/vnew Create a new window
: SF file name opens in new window filename
: Only close all windows except the current window
: Ctrl-w can be switched window
: Ctrl-w h to the left window
: Ctrl-w l to the right window
: Ctrl-w J to the following window
: Ctrl-w k to the upper window
Set paste//Use this command before pasting, will not be pasted when the format of the mess, paste and then use the set Nopaste to open the Automatic Format command set complete+=k//auto-complete? setlocal omnifunc=syntaxcomplete#complete //Open the complete DW to cut words. d$, cut to the end of the line. D0, cut to the beginning of the line. [N]dd, cut one row or the following n rows. YW, copy the word. y$, copy to end of line. y0, copy to the beginning of the line. [N]yy, copy one row or the following n rows.] shortcut keys for writing code: &NBSP;]P: Similar to the function of P, but it automatically adjusts the indentation of the pasted text to fit the position of the current code. &NBSP;GD: Navigate to the local variable declaration k: Find the word in man where the cursor is currently located, display the man instruction manual for the C function under the cursor ^p/^n Auto-complete function; press c-p/n ^]: Displays the prototype of the function under the cursor in ~/.tags, ^t: Exit Function prototype Window Open another file at the same time when compiling a file: SP [filename]ctrl-w H &nbs P Skip to the left window Ctrl-w J Jump to the following window Ctrl-w K jump to the top window ctrl-w l &NBS P Jump to the right window
generate a tag file for the C standard function libraryCtags-r-F ~/.vim/systags--c-kinds=+p--fields=+s/usr/include/usr/local/include again in. VIMRC Plus Ctags+=~/.vim/systags This generates ctags cost-per-project, but it can also include standard interfaces. $ctags-R * (Generate tags for files in the current directory and subdirectories) $vi-T Find (Query the Find function in the catalog): TS find (see find function): Ta find (see find function)
Use of GDB Debugging tools
GDB Code Debugging Reference
Http://fanqiang.chinaunix.net/program/other/2005-03-23/2993.shtml 1. Set Breakpoint (GDB) b test.c:17 //means set breakpoint in line 17 (GDB) b test.c:func //indicates where the Func function starts in the test.c file set breakpoint (GDB) b test.c:21 The If RESULT==20//Breakpoint Trigger condition is result==20 (GDB) Info b //View breakpoint information (GDB) Delete, enable, Disable, clear,///Maintain breakpoints run[r]//run Continue[c]//Continue running Next[n] //Next statement; Do not enter or leave inside the function Step[s] //functions in and out of the calling function internal finish //Exit Function Note: Press two tab in input B to list all command 2 starting with B. View breakpoint variable contents backtrace[bt]//Print all the information of the current function call stack bt n //is a positive integer that represents only the stack information for the top n-tier of the stack //-n Table A negative integer that shows only the stack information of the N-tier below the stack frame (f) N //represents a view of the current stack Layer Information Info F //Print out more detailed current stack information; info args //prints out the parameter names and their values of the current function info Locals & nbsp //prints out all local variables and their values in the current function info catch //print out the exception handling information in the current function @ //operations Array (GDB) p/c *[emAil protected] //Prints the contents of the 10 characters after the array, by character view (GDB) p/x *[email protected] //According to 16 binary view (GDB) p This //view this data :: //Specifies a file, class, function variable (GDB) p "test.c":: M_test & nbsp //View the variables in the test.c file {} //An object with a memory address of type 3. View source code (GDB) L n,fun & nbsp //Display program Nth line or code around a function (GDB) L ctest::get_count //view get_count functions in CTest class
The writing of Makefile
Basic introduction to make [Makefile]
Make is a regular text file with each rule consisting of three parts: target, dependent file, command list target:dep1 dep2 dep3 ... command1 command2 ... Note: A tab in front of each command cannot be replaced with a space! Example: IPPHONE:IPPHONE.O gcc-o ipphone ipphone.oipphone.o:ipphone.c ipphone.h gcc-c IPPHONE.CCTL:CTL.O gcc-o C TL ctl.octl.o:ctrl.c ipphone.h gcc-c ctl.c There are four rules, if the make command line does not contain the rule name will check all the rules, if there is only check the rule, such as only want to build CTL file need make CTL!
pseudo Target
For example: All:ctl Ipphone//This is because all does not exist it just checks the CTL and Ipphone functions such as: clean:rm-f *.O//Because there is no dependent file so the default does not execute, can be performed by make clean
Make defines variables and uses variables
For make file editing and maintenance more convenient, can be defined in the variable, and the same shell; the variable content in the Make file is actually a string, and the definition and usage rules are similar to the shell. CC=GCC-C uses parentheses to expand the $;$ (CC) variable definition when referencing the make recursively expands to raise an error:
Make provides read-only variables:[Email protected] Target file name $< the first related file name $^ a list of related files, separated by a space? List of related files that are new to the target file $ (@D) The directory portion of the destination filename section $ (@F) The file name portion of the destination file name
Make pre-defined variables:
As assembler CCC compiler, default CCCPPC preprocessor, default value CPPRM file removal program, default Rm-f
implied rules and rule patterns
For example: Ipphone:ipphone.ogcc-o ipphone ipphone.o The rule does not indicate how IPPHONE.O got it, which is appropriate for the implied rule make automatically uses Gcc-c Ipphone.c-o The IPPHONE.O command generates the IPPHONE.O file. This rule can also be redefined by%.O:%.C, which indicates that all. o files are compiled with a. c file, or redefined as follows:%.O:%.C $ (CC)-C $<-o [email protected]//indicates the use of the first associated file name to generate Target file name
options for the Make command line:
-f Specifies that the make file name does not apply to the default-n displays all the commands to execute, but does not show commands when performing the-s command-r disable make internal rule-D display debug information-I ignore the command error of the rule, continue to do-K ignore the module compilation error, continue the following compile-compile parameter parameter information
-wall: Outputs all warning messages.
-O: Optimized at compile time.
-G: Indicates compilation of Debug version.
Basic NotationFilestat:filestat.o
GCC filestat.o-o FILESTATFILESTAT.O:
Gcc-c Filestat.cclean:
RM-FR *.o *~ *.*~ filestat
----------------------------------------------
the wording after the improvementObject = FILESTAT.O//using the target file
CC = GCC//compiler definition
Cflags =-wall-o-G//Compiler condition Filestat: $ (object)//connected to a program file by an. O file
$ (CC) $ (object)-O FILESTATFILESTAT.O://compiled from a. c file into a target file
$ (CC) $ (cflag)-C Filestat.c-o Filestat.oclean:
RM-FR *.o *.*~ *~ filestat
----------------------------------------------
optimization
CC = GCC
Cflag =-wall-o-G
TARGET =./filestat
OBJECTS = $ (patsubst%.c,%.o,$ (wildcard *.c))//Replace All. c file extensions in the current path with
Wildcard (%.C); #将目录中所有以. c suffix file name, stored in a list variable patsubst (%.c,%.O, Listvar); #表示将listvar中所有以. c as a suffix file, replace with. o as the suffix file
%.O:%.c
$ (CC) $ (cflag)-C $<-o [email protected]//Use GCC-CFLAG-C first associated file-o destination file $ (target): $ (OBJECTS)
$ (CC) $ (OBJECTS)-O $ (target)//connect the current. o file into the target program file
chmod a+x $ (TARGET)
Subsystem
CD SubDir && $ (make)//Enter sub-directory to do
Clean
RM-FR *.O $ (TARGET) *~
======================================================
Under test, create A.C and B.c2 files, and in sub directory, build sa.c and Sb.c2 files to create a simple makefilesrc=$ (wildcard *.c./sub/*.c) dir=$ (Notdir $ (src)) obj=$ (Patsubst%.c,%.o,$ (dir)) obj2=$ (DIR:%.C=%.O) All: @echo $ (SRC) @echo $ (dir) @echo $ (obj) @echo $ (OBJ2) @echo "End" first row output: W Ildcard all files that have the suffix C under the specified directory./and./sub/are expanded. A.C B.C./sub/sa.c./SUB/SB.C the second line of output: Notdir to remove the expanded file from the path information a.c B.C SA.C SB.C The third line of output: PATSUBST the variable in the $ (dir) suffix is. c all replaced by. O,A.O B.O SA.O SB.O line Fourth output: replace each value of the variable dir with an O ca.o b.o sa.o sb.o
Linux Trace debugging
-wall uses it to enable GCC to generate as many warning messages as possible 1, most functions under Linux default: The header file is placed in the/usr/include/directory and the library file is placed in the/usr/lib/directory under the-I option: Add header file directory-L option: Add library file Logging GDB Debugger 1. Display data: Print or P variable print * pointer 2. View arrays: People array: View 10 integers after the variable h in memory: print [email protected]3. Set Breakpoint: b line-or-func if Testva LUE==100 Display Breakpoint: Info B Delete breakpoint: Remove B 14. Execute: Next: Step Into the SETP: Enter an intrinsic function finish: jump out of the intrinsics list lists the following code to execute the start debugger Set variable// Assigning a value to the variable Pype displays the contents of a data structure (structure or function of c) p/x I//press 16 to display variable contents,/C by character/x///examine to X,n is the length of memory, F represents the format shown, u represents the number of bytes requested from the current address x/3u H 0x54320//represents viewing 0x54320 3 byte lengths followed by unsigned
Auto Display:displaydisplay/display/
Use of SSH
Transferring files between Linux and Linux: SCP localfile [email protected]:[path or REMOTEFILE]SCP p2p-tracker [email protected]:/usr/share/ Use of p2p-tracker/subversion installation Subversionsudo Apt-get Install Subversion subversion-tools
1. checkout files to a local directory
SVN CheckoutPath (path is a directory on the server)
Example: SVN checkout svn://
192.168.
1.1/pro/domain #表示将url中的文件checkout到本地
Shorthand: SVN Co
2 . Add a new file to the repository
SVN
AddFile
For example: SVN add test.php (add test.php) #将test. PHP is added to SVN, whose path is the SVN path where the current directory resides #add之后commit才能真正将文件加入到svn上面
3 . Submit the changed files to the repository
SVN commit -M "LogMessage"
For example: SVN commit-m "Add File" test.php #只提交test. php file
For example: SVN ci #提交当前目录所有的文件
4. Locking/unlock
SVN lock-M "Lockmessage"
[--force
]PATH
Example: SVN lock-m "lock test File" test.php
svn unlockPATH
5. Update to a version
SVN update-rM path
For example:
SVN update If there is no directory behind it, the default is to update all files in the current directory and subdirectories to the latest version.
SVN update-r test.php (Restore the file test.php in the repository to version 200)
SVN update test.php (updated, sync in Repository.) If the prompt expires at the time of submission, it is because
conflicting, need to update, modify the file, and then clear
SVN resolved, and submit a commit at the end)
Shorthand: SVN up
6. view file or directory status
1)
SVN statusPath (Status of files and subdirectories under directory, normal status not shown)
"?: not in SVN control; M: Content modified; C: conflict; A: Scheduled to be added to Repository; K: Locked"
2)
SVN status-vPath (show file and subdirectory status)
The first column remains the same, the second column shows the work version number, and the third and fourth columns show the last modified version number and the modified person.
Note: The SVN status, SVN diff, and SVN revert three commands can be executed without a network, because SVN retains the original copy of the local version in. svn.
Shorthand: SVN St
7. Delete Files
SVN DeletePath-m "Delete Test Fle"
Example: SVN delete svn://192.168.1.1/pro/domain/test.php-m "Delete test file"
Or go directly to svn delete test.php and then svn ci-m ' delete test file ', which we recommend using this
Shorthand: SVN (del, remove, RM)
8. View Logs
SVN logPath
For example: SVN log test.php shows all changes to this file, and its version number
9. View File Details
SVN infoPath
Example: SVN info test.php
10. Compare Differences
SVN diffPath (compares the modified file to the underlying version)
Example: SVN diff test.php
SVN diff-R m:n Path (difference between version m and version N)
Example: SVN diff-r 200:201 test.php
Shorthand: SVN di
11 . Merge the differences between the two versions into the current file
SVN merge-rM:n Path
For example: SVN merge-r 200:205 test.php (the difference between version 200 and 205 is merged into the current file, but generally conflicts occur and need to be addressed)
12. SVN Help
SVN Help
SVN help CI
——————————————————————————
The above is a common command, the following write a few common
——————————————————————————
13 . List of files and directories under the repository
SVN listPath
Displays all files and directories belonging to the repository under the path directory
Shorthand: SVN ls
14 . Create a new directory under version control
svn mkdir: Create a new directory under the included version control.
Usage: 1, mkdir PATH ...
2. mkdir URL ...
Create a version-controlled directory.
1. Each directory specified in the working copy PATH will be created on the local side and added
Scheduled to be submitted for the next time.
2. Each directory specified in the URL will be created by submitting it to the repository immediately.
In both cases, all intermediate directories must exist beforehand.
15. Restore Local modifications
svn revert: Restores the original unchanged working copy file (restores most of the local modifications). Revert
Usage: revert PATH ...
Note: The notebook command will not access the network and will release the conflicting condition. But it won't recover.
Directories that were deleted
16. Code Base URL Change
SVN switch (SW): updates the working copy to a different URL.
Usage: 1, switch URL [PATH]
2. Switch–relocate from to [PATH ...]
1, update your working copy, map to a new URL, its behavior is similar to "SVN update", will also
The files on the server are merged with the local files. This is the one where the working copy corresponds to a branch or tag in the same warehouse.
Method.
2, rewrite the working copy of the URL metadata to reflect the simple URL changes. When the root URL of the warehouse changes
(such as scheme name or host name change), but the working copy is still used when mapping to the same directory in the same warehouse
This command updates the correspondence between the working copy and the warehouse.
17. Conflict Resolution
SVN resolved: removes the "conflicting" status of the working Copy's directory or file.
Usage: Resolved PATH ...
Note: The book command does not resolve the conflict by syntax or remove the conflict token; it simply removes the conflicting
File, and then allow PATH to submit again.
18 . Output the contents of the specified file or URL.
SVN cat Target [@ VERSION] ... If a version is specified, the lookup starts from the specified version.
SVN cat-r PREV filename > filename (PREV is the previous version, you can also write a specific version number so that the output can be submitted)
Use of Linux development tools