linu develop tools 2000 summer latest update: 11/30 2000

66
Linu Linu Develop Tools Develop Tools 2000 Summer Latest update: 11/30 2000

Upload: ethelbert-watson

Post on 16-Jan-2016

223 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

LinuLinuDevelop ToolsDevelop Tools

LinuLinuDevelop ToolsDevelop Tools

2000 SummerLatest update: 11/30 2000

Page 2: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 2

OutlineOutline

GCC / G++- C / C++ compiler

MAKE - Compiler project manager

GLOBAL - Source code browse

GDB - Console debug trace tool

DDD - X-window debug trace tool

GPROF - Profile tool

CVS - Source code version control

Outline

Page 3: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 3

gcc / g++gcc / g++

What is gcc / g++?"GCC" is a common shorthand term for the GNU C compiler. This is both the most general name for the compiler, and the name used when the emphasis is on compiling C programs.

When referring to C++ compilation, it is usual to call the compiler "G++". Since there is only one compiler, it is also accurate to call it "GCC" no matter what the language context; however, the term "G++" is more useful when the emphasis is on compiling C++ programs.

gcc

Page 4: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 4

Building flowBuilding flow

Preprocessing Preprocessing CompilingCompiling AssemblyAssembly LinkingLinking

.c

.cc

.s

.S

.S .o

.o

a.out

cc1

cc1plus

as

gas

nasm

collect2

ld

ar (lib)

gcc / g++

cpp

.i

.a

Page 5: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 5

Suffixes of source file namesSuffixes of source file names.c C source; preprocess, compile, assemble.C C++ source; preprocess, compile, assemble.cc C++ source; preprocess, compile, assemble.cxx C++ source; preprocess, compile, assemble.m Objective-C source; preprocess, compile, assemble.I preprocessed C; compile, assemble.ii preprocessed C++; compile, assemble.s Assembler source; assemble.S Assembler source; preprocess, assemble.h Preprocessor file; not usually named on command line

.o Object file

.a Archive file

gcc / g++

Page 6: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 6

GCC beginningGCC beginning

% gcc –o a.out pr1.c pr2.c

% gcc –c pr1.c

% gcc –c pr2.c

% gcc –o exefile pr1.o pr2.o

gcc / g++

Page 7: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 7

GCC argumentGCC argument

-o outputfileassign Output file name

-c compiler but not linking

-Iincludepath% gcc –c –I/usr/X11R6/include pr1.c

gcc / g++

Page 8: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 8

GCC argumentGCC argument

-Ddefinename=value% gcc –c –DDEBUG pr1.c

% gcc –c –DSIZE=100 pr1.c

% gcc –c –DFILE=\”a.txt\” pr1.c

-Uundefinename% gcc –c –UDEBUG pr1.c

gcc / g++

Page 9: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 9

GCC argumentGCC argument

-Llibpath

-llibfilename

% gcc –o a.out –L/usr/X11R6/lib –lx11 pr1.o pr2.o

-g create extra inform for gnu debug

-p link with “prof” (mon.out)

-pg link with “gprof” (gmon.out)

-S make to assmberly file(*.S)

gcc / g++

Page 10: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 10

GCC argument WarningGCC argument Warning

-wNo Warning

-WWarning that Legality but maybe have some

problems

-WallWarning all

-WerrorWarning -> error

gcc / g++

Page 11: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 11

GCC argument OptimizeGCC argument Optimize

-Onoptimize, n = 0, 1, 2

-finline-functionMake simple function inline

-fno-inline-funroll-loop

Unroll loop for avoid hazard, program size will advance, maybe decrease efficiency

gcc / g++

Page 12: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 12

MakeMake

What is make?Automatically determines which pieces of a large program need to be recompiled, and issues commands to recompile them.

Keyword DefineTargetDependencyUp to date

make

Page 13: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 13

Simple project exampleSimple project example

Source files:const.hhmain.ccobject1.hh object1.ccobject2.hh object2.cc

Dependency:main.o -> main.cc const.hh object1.hh object2.hhobject1.o -> const.hh object1.hh object1.ccobject2.o -> const.hh object2.hh object2.cca.out -> main.o object1.o object2.o

make

Page 14: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 14

Build projectBuild projectBuild all

% g++ –c main.cc% g++ –c object1.cc% g++ –c object2.cc% g++ –o a.out main.o object1.o object2.o

Modify object1.cc% g++ –c object1.cc% g++ –o a.out main.o object1.o object2.o

Modify object1.hh% g++ –c main.cc% g++ –c object1.cc% g++ –o a.out main.o object1.o object2.o

make

Page 15: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 15

Make exampleMake examplea.out: main.o object1.o object2.o

g++ –o a.out main.o object1.o object2.omain.o: main.cc const.hh object1.hh object2.hh

g++ –c –O –UDEBUG main.ccobject1.o: const.hh object1.hh

g++ –c –O –UDEBUG object1.ccobject2.o: const.hh object2.hh

g++ –c –O –UDEBUG object2.cc.PHONY : clean clean:

-rm *.o-rm a.out

make

Page 16: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 16

Make Rule SyntaxMake Rule Syntax

targets : dependencies command ...

or like this:

targets : dependencies ; command command ...

TAB

TAB

make

Page 17: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 17

makemake% make will find GNUmakefile, makefile, and Makefile

% makeg++ –c –O –UDEBUG main.ccg++ –c –O –UDEBUG object1.ccg++ –c –O –UDEBUG object2.ccg++ –o a.out main.o object1.o object2.o

% make object1.og++ –c –O –UDEBUG object1.cc

% make cleanrm *.orm a.out

make

Page 18: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 18

Make example2Make example2OPT = –O –UDEBUGOBJ = main.o object1.o object2.oa.out: $(OBJ)

$(CC) –o $@ $(OBJ)main.o: main.cc object1.hh object2.hh

$(CC) –c $(OPT) main.cc object1.o: const.hh object1.hh object1.cc

$(CC) –c $(OPT) object1.ccobject2.o: const.hh object2.hh object2.cc

$(CC) –c $(OPT) object2.cc

make

Page 19: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 19

Default compilation rulesDefault compilation rules.SUFFIXS.SUFFIXS: .cc .oOPT = –O –UDEBUGOBJ = main.o object1.o object2.oa.out: $(OBJ)

g++ –o $@ $(OBJ).cc.o:

g++ –c $(OPT) $< -o [email protected]: main.cc object1.hh object2.hhobject1.o: object1.cc const.hh object1.hhobject2.o: object2.cc const.hh object2.hh

Same as $*.o

make

Page 20: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 20

GLOBALGLOBAL

What’s global ?Global can find the locations of a specified object quickly.Global can locate not only object definitions but also object

references.Global can understand POSIX 1003.2 regular expressions.

How to start ?% cd /usr/src_locate% gtags% ls G*GPATH GRTAGS GSYMS GTAGS

global

Page 21: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 21

Four databasesFour databases

GTAGS - database of function definitions

GRTAGS - database of function references

GSYMS - database of other symbols

GPATH - database of path names

global

Page 22: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 22

global Basicglobal Basic

global

% global func1../DIR1/fileB.c

% global -r func2../DIR1/fileA.c

% global 'func[1-3]'DIR1/fileB.cDIR2/fileC.c

% global func2DIR2/fileC.c

% global -x func2func2 2 DIR2/fileC.c func2() { i++; }func2 4 DIR2/fileC.c func2() { i--; }

% global -a func1/home/user/ROOT/DIR1/fileB.c

% global -xs XX 1 DIR2/fileC.c #ifdef X

% global -xg '#ifdef'#ifdef 1 DIR2/fileC.c #ifdef X

% vi `global func1`

% global -c kmemkmem_alloc_pageablekmem_alloc_waitkmem_free

relative path

be referred from

POSIX regular expressions

shows the details

absolute path

any symbols but functions

grep

complete

Page 23: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 23

Incremental updatingIncremental updating% gtags% vi tty.c modify tty.c. ...% global –vi -v means verbose. [Sun Dec 6 16:27:47 JST 1998] Gtags started Tag found in '/usr/src/sys'. Incremental update. Updating tags of 'kern/tty.c' ...GTAGS..GRTAGS..GSYMS.. Done. Global databases have been modified. [Sun Dec 6 16:28:30 JST 1998] Done.

% global –vi try again. [Sun Dec 6 16:28:48 JST 1998] Gtags started Tag found in '/usr/src/sys'. Incremental update. Global databases are up to date. do nothing. [Sun Dec 6 16:28:52 JST 1998] Done.

global

Page 24: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 24

Hypertext generatorHypertext generator% gtags <- make the tag database(GTAGS,GRTAGS,GSYMS)

% htags <- make the hypertext(HTML/)

% systags [-f] <- make the hypertext(HTML/) of the kernel (?)

[feitian@cmldb7 linux]$ ls G* -l-rw-r--r-- 2 root root 528384 Jun 16 23:04 GPATH-rw-r--r-- 2 root root 39276544 Jun 16 23:07 GRTAGS-rw-r--r-- 2 root root 46632960 Jun 16 23:13 GSYMS-rw-r--r-- 2 root root 7729152 Jun 16 23:04 GTAGS[feitian@cmldb7 linux]$ du -b HTML/156217344 HTML/S495616 HTML/I13279232 HTML/D71098368 HTML/R741376 HTML/files1740800 HTML/funcs94289920 HTML/cgi-bin337907712 HTML

global

Page 25: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 25

Page 26: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 26

Compact formatCompact format% gtags –c% htags –c% systags –c

[feitian@cmldb7 linux]$ ls -l G*-rw-r--r-- 2 root root 528384 Jun 20 01:55 GPATH-rw-r--r-- 2 root root 39276544 Jun 20 02:00 GRTAGS-rw-r--r-- 2 root root 46632960 Jun 20 02:17 GSYMS-rw-r--r-- 2 root root 7729152 Jun 20 01:55 GTAGS[feitian@cmldb7 linux]$ du -b HTML/37109760 HTML/S495616 HTML/I13033472 HTML/D54681600 HTML/R700416 HTML/files462848 HTML/funcs94294016 HTML/cgi-bin200826880 HTML

global

Page 27: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 27

gdbgdb

What’s gdb ?It’s a debugger tool, and allow you to see what is going on "inside" another program while it executes--or what another program was doing at the moment it crashed.

How to start gdb ?

% gcc –g file.c

% gdb program [ core ]

gdb

Page 28: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 28

gdb simple example 1gdb simple example 1void main( int argc, char **argv ){ int *num = NULL, i; //num = (int*) malloc(sizeof(int) *

10);

for (i=0; i<10; i++) { num[i] = rand() % 100; printf("%d ", num[i]); } printf("\n"); qsort( (void *)num, 10, sizeof(int),

compare );

/* Output sorted list: */:

}

int compare( const void *arg1, const void *arg2 )

{ return *((int*)arg1) - *((int*)arg2);}

gdb

Page 29: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 29

gdb simple example 1gdb simple example 1$ gcc -g t.cc$ ./a.outSegmentation fault (core dumped)$ gdb a.outGNU gdb 19991004Copyright 1998 Free Software

Foundation, Inc.:

(gdb) runStarting program:

/home/feitian/unix/sum/a.out

Program received signal SIGSEGV, Segmentation fault.

0x80484c7 in main (argc=1, argv=0xbffffb44) at t.cc:14

14 num[i] = rand() % 100;

(gdb) print num[i]Cannot access memory at address

0x0(gdb) print i$1 = 0(gdb) print num$2 = (int *) 0x0 got it !(gdb) quitThe program is running. Exit anyway?

(y or n) y$

gdb

Page 30: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 30

Run / quitRun / quit

(gdb) run [argument]

(gdb) set args argument(gdb) show args show now argument

(gdb) quit

gdb

Page 31: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 31

listlist

To print lines from a source file. By default, ten lines are printed.

(gdb) list line1, line2

(gdb) list routine_name

gdb

Page 32: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 32

Step / NextStep / Next

(gdb) step [count]Continue running your program until control reaches a different source line.

(gdb) stepiStep one machine instruction.

(gdb) next [count]Continue to the next source line in the current (innermost) stack frame, but function calls that appear within the line of code are executed without stopping.

(gdb) nextiNext one machine instruction.

gdb

Page 33: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 33

Break pointBreak point(gdb) break [filename:]line-number(gdb) break [filename:]routine-name(gdb) break line-or-func if condition(gdb) info breakpoints(gdb) watch condition(gdb) continue(gdb) disable breakpoint-no(gdb) enable breakpoint-no(gdb) enable once breakpoint-no(gdb) delete breakpoint-no(gdb) clear

gdb

Page 34: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 34

gdb simple example 2gdb simple example 2 7 void main( int argc, char **argv ) 8 { 9 int *num = NULL, i;10 num = (int*) malloc(sizeof(int) * 10);1112 for (i=0; i<10; i++) {13 num[i] = rand() % 100;14 printf("%d ", num[i]);15 }16 printf("\n");1718 qsort( (void *)num, 10, sizeof(int),

compare );1920 /* Output sorted list: */

:}

28 int compare29 ( const void *arg1, const void

*arg2 )30 {31 return *((int*)arg1) -

*((int*)arg2);32 }

gdb

Page 35: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 35

gdb simple example 2gdb simple example 2$ gcc -g t.cc

$ gdb a.out:

(gdb) break 10Breakpoint 1 at 0x80484af: file t.cc, line 10.(gdb) break 18Breakpoint 2 at 0x804858d: file t.cc, line 18.(gdb) info breakpointsNum Type Disp Enb Address What1 breakpoint keep y 0x080484af in main at t.cc:102 breakpoint keep y 0x0804858d in main at t.cc:18

(gdb) runStarting program: /home/feitian/unix/sum/a.out

Breakpoint 1, main (argc=1, argv=0xbffffb44) at t.cc:1010 num = (int*) malloc(sizeof(int) * 10);(gdb) continueContinuing.83 86 77 15 93 35 86 92 49 21

Breakpoint 2, main (argc=1, argv=0xbffffb44) at t.cc:1818 qsort( (void *)num, 10, sizeof(int), compare );(gdb)

gdb

Page 36: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 36

typetype

(gdb) whatis variable(gdb) ptype variable

complex v;(gdb) whatis v

type = struct complex

(gdb) ptype vtype = struct complex {

double real; double imag;}

gdb

Page 37: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 37

printprint

(gdb) print[/f] express

(gdb) print variable@count

(gdb) x/nfu addr

n : count

f : format, x c d f u o t a

u : size, b h w g

binary pointer

gdb

Page 38: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 38

Call StackCall Stack

(gdb) where / backtrace / info stack

(gdb) frame

(gdb) up [n]

(gdb) down [n]

func3

func2

func1

main

up

down

frame

where

gdb

Page 39: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 39

dddddd

What’s ddd:A graphic UI for gdb and dbx.

How to start ddd ?% gcc –g file.c

% ddd program [ core ]

ddd

Page 40: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 40

ddd

Page 41: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 41

Command ToolCommand Tool

ddd

Page 42: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 42

Tool barTool bar

ddd

Page 43: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 43

Print / Display / Looking up DefinitionsPrint / Display / Looking up Definitions

ddd

Page 44: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 44

BreakpointsBreakpoints

ddd

Page 45: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 45

DisplayDisplay

ddd

Page 46: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 46

DisplayDisplay

ddd

Page 47: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 47

PlotPlot

ddd

Page 48: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 48

GPROFGPROF

What’s gprof ?Profiling allows you to learn where your program spent its time and which functions called which other functions while it was executing. It can also tell you which functions are being called more or less often than you expected.

How to start gprof ?% gcc –o a.out –pg file.c% ./a.out It will write the profile data into file `gmon.out'

% gprof a.out > profile.txt

gprof

Page 49: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 49

Flat profile:Flat profile: % cumulative self self total

time seconds seconds calls us/call us/call name

50.00 0.02 0.02 50602 0.40 0.40 SCRDC::Putc(int, int, char)

25.00 0.03 0.01 503943 0.02 0.02 vector<basic_string<char, string_ …

25.00 0.04 0.01 336 29.76 54.92 SCRDC::Fill(RECT, char)

0.00 0.04 0.00 503936 0.00 0.02 __vc__t6vector2Zt12basic_string3Z …

0.00 0.04 0.00 13670 0.00 0.00 vector<basic_string<char, string_ …

0.00 0.04 0.00 13670 0.00 0.00 vector<basic_string<char, string_ …

0.00 0.04 0.00 13670 0.00 0.00 vector<basic_string<char, string_ …

0.00 0.04 0.00 7695 0.00 1.07 TMemo::LineLen(int)

0.00 0.04 0.00 5250 0.00 0.00 SCRDC::Print(int, int, char *,...)

0.00 0.04 0.00 3994 0.00 0.00 POS::POS(void)

0.00 0.04 0.00 3022 0.00 0.00 POS::operator=(POS const &)

:

:

gprof

Page 50: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 50

Flat profile fields explainFlat profile fields explain% Time

The percentage of the function total running time.

Cumulative secondsA running sum of the number of seconds accounted for by this function and those listed above it.

Self secondsThe number of seconds accounted for by this function alone.

CallsThe number of times this function was invoked.

Self ms/callThe average number of milliseconds spent in thisfunction per call.

Total ms/callThe average number of milliseconds spent in this function.

NameThe name of the function.

gprof

Page 51: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 51

Call graphCall graphindex % time self children called name

<spontaneous>

[1] 100.0 0.00 0.04 main [1]

0.00 0.04 1/1 CSys::Run(void) [2]

0.00 0.00 1/1 CDestop::CDestop(void) [34]

0.00 0.00 1/1 CSys::Enter(void) [120]

0.00 0.00 1/1 CDestop::Create(void) [119]

0.00 0.00 1/1 CSys::Exit(void) [121]

0.00 0.00 1/1 CDestop::~CDestop(void) [248]

-----------------------------------------------

0.00 0.04 1/1 main [1]

[2] 100.0 0.00 0.04 1 CSys::Run(void) [2]

0.00 0.02 30/30 CSys::KeySender(int) <cycle 3> [67]

0.00 0.02 22/50 CSys::Paint(void) [4]

0.00 0.00 30/1235 POS::POS(int, int) [200]

0.00 0.00 30/3022 POS::operator=(POS const &) [198]

gprof

Page 52: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 52

Call graph fields explainCall graph fields explain% Time

This is the percentage of the `total' time that was spent in this function and its children. Note that due to different viewpoints, functions excluded by options, etc, these numbers will NOT add up to 100%.

SelfThis is the total amount of time spent in this function.

ChildrenThis is the total amount of time propagated into this function by its children.

CalledThis is the number of times the function was called. If the function called itself recursively, the number only includes non-recursive calls, and is followed by a `+' and the number of recursive calls.

NameThe name of the current function.

gprof

Page 53: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 53

CVS - Concurrent Versions SystemCVS - Concurrent Versions System

What’s cvs ?It’s a front-end of RCS. It is a version control system. Using it, you can record the history of your source files.

Terminology:repository

pserver

CVSROOT

cvs

Page 54: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 54

CVS Beginning (local)CVS Beginning (local)

% CVSROOT=~/cvsroot/

% export CVSROOT

% cvs init init repository

% cd project/

% cvs import project –m “some message” vendor start

If you don’t set CVSROOT environment variable, you must add argument ‘ -d cvsroot ’ to assign repository path.

cvs

Page 55: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 55

CVS Usage ModelCVS Usage Model

CheckoutCheckout

Makes private copy in working directory

Can check out anywhere

Check out multiple copies, multiple versions

CommitCommit

Commit changes to the repository when finished

Working copies must be up to date with repository

UpdateUpdate

Brings working copy up to date with repository

cvs

Page 56: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 56

Concurrent checkoutConcurrent checkoutMaster Repository

foo.c

WorkingCopyV1.7

WorkingCopy V1.1

WorkingCopy V1.2

WorkingCopyV1.7

WorkingCopy

V1.2.2.1

checkout branch rel_1_fix checkout latest

checkout latest

checkoutV1.2

checkoutV1.1Kant

Fei-tian yichenPatrick

X XV1.8 or 1.9

V1.8 or 1.9V1.2.2.2

checkin

checkincheckin

checkin prohibited

Lulala

Checkout does not lock the files in repository

cvs

Page 57: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 57

Ideal development with CVSIdeal development with CVScheckoutupdatecheckindevelopment

repository

Developer A

Developer B

cvs

Page 58: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 58

Real development with CVSReal development with CVS

checkin

X

repository

Developer A

Developer B

updateconflict resolutioncheckin

conflict

cvs

Page 59: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 59

Common CVS commandsCommon CVS commands

% cvs [cvs-options] command [cmd-options] [files]

cvs checkout Check out source for editing.

cvs add Add new file/directory to repository.

cvs remove Remove an entry from the repository.

cvs status Show status of checked out files.

cvs log Show revision history for files.

cvs diff Compare working files to version in repository or versions inside the repository.

cvs update Bring working files into sync with repository.

cvs commit check files into the repository

cvs tag Label the sources.

cvs

Page 60: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 60

CVS exampleCVS example% cvs checkout projectcvs checkout: Updating projectU project/MakefileU project/bar.cU project/foo.cU project/main.c

% joe main.c::

% cvs commit -m “add a explaining message." main.cChecking in main.c;/class/'username'/cvsroot/project/main.c,v <-- main.cnew revision: 1.2; previous revision: 1.1done

cvs

Page 61: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 61

Conflict exampleConflict examplevoid foo(){

printf("FOO\n");}

void foo(){

printf("FOO\n"); printf("YOU\n");

}

void foo(){

printf("FOO\n"); printf("TOO\n");

}

void foo()

{

printf("FOO\n");

<<<<<<< foo.c

printf("TOO\n");

=======

printf("YOU\n");

>>>>>>> 1.2

}

Orig

ina

lV

ersio

n.

AV

ersio

n.

B

Merg

e

cvs

Page 62: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 62

Conflict exampleConflict example% cvs update foo.cRCS file: /class/'username'/cvsroot/project/foo.c,vretrieving revision 1.1.1.1retrieving revision 1.2Merging differences between 1.1.1.1 and 1.2 into foo.crcsmerge: warning: conflicts during mergecvs update: conflicts found in foo.cC foo.c

% cvs commit –m foo.c

% cvs checkout foo.c

% cvs checkout foo.c

% cvs commit foo.c

% cvs commit foo.cThis will conflict …

% cvs status foo.cFile: foo.c Status: Needs Merge Working revision: 1.1.1.1 'Some Date' Repository revision: 1.2 /class/'username'/cvsroot/project/foo.c,v

Sticky Tag: (none)

Sticky Date: (none)

Sticky Options: (none)

cvs

Page 63: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 63

The Status of a fileThe Status of a file

Up-to-date The file is identical with the latest revision in the repository.

Locally Modified You have edited the file, and not yet committed your changes.

Needing Patch Someone else has committed a newer revision to the repository.

Needs Merge Someone else has committed a newer revision to the repository, and

you have also made modifications to the file.

cvs

Page 64: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 64

Working on branchesWorking on branches

1.1 1.2 1.3

release_1

cvs tag release_1

cvs up -r rel_1_fix

1.4

release_2

cvs tag release_2

1.2.2.1 1.2.2.2

patch

rel_

1_fixcvs tag -b rel_1_fix

cvs

Page 65: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 65

Remote CVS setupRemote CVS setup/etc/services

cvspserver 2401/tcp #CVS network server

cvspserver 2401/udp #CVS network server

/etc/inetd.conf

cvspserver stream tcp nowait root /usr/bin/cvs cvs -b /usr/bin \

--allow-root=/home/cvsroot pserver

% mkdir /home/cvsroot

% cvs –d /home/cvsroot init

cvs

Page 66: Linu Develop Tools 2000 Summer Latest update: 11/30 2000

Linux Develop Tools 66

Use remote CVS serverUse remote CVS server

% CVSROOT=:pserver:[email protected]:/home/cvsroot

% export CVSROOT

% cvs login

Password: ******

Do this will create a file in your home directory:

~/.cvspass

cvs