Presentation is loading. Please wait.

Presentation is loading. Please wait.

Unix Programming Tools Operating Systems. man- on-line unix manual vi - a command line text editor make- runs make files gcc- compiler gdb- debugger Operating.

Similar presentations


Presentation on theme: "Unix Programming Tools Operating Systems. man- on-line unix manual vi - a command line text editor make- runs make files gcc- compiler gdb- debugger Operating."— Presentation transcript:

1 Unix Programming Tools Operating Systems

2 man- on-line unix manual vi - a command line text editor make- runs make files gcc- compiler gdb- debugger Operating Systems

3 man pages Operating Systems

4 Most unix systems have a set of on-line documentation called the man pages. These are typically organized into several sections. The first three are of most interest to us: 1user commands 2system calls 3C library functions Operating Systems

5 Each man page covers a specific command, utility, or system call. Individual man pages commonly are divided into the following sections: HEADERthe title of this man page NAMEone line summary SYNOPSISbrief description DESCRIPTIONdetailed description ERRORSconditions for errors FILESfiles used BUGSknown bugs Operating Systems

6 vi Operating Systems

7 Why learn a command line editor? * it’s lean and fast * always available - even from a terminal Operating Systems

8 $ vi [ filename ] if no filename is provided, vi creates a new unnamed file Starting vi Operating Systems

9 ESC - to get into command more :q to quit :q! to force a quit without saving the file :wq to save the file and then quit Leaving vi Operating Systems

10 Command mode and Insert Mode Command mode Insert Mode:press i or a Insert Mode Command Mode:press Esc key The two modes of vi Operating Systems

11 vi commands are usually of the foem [count] command [where] for example. 23x deletes 23 characters vi Commands Operating Systems

12 aenter insert mode, the characters typed will be after the current cursor position. ienter insert mode, the character types will be before the current cursor position Some simple vi commands Operating Systems

13 [n]jmove the cursor down n lines [n]kmove the cursor up n lines [n]hmove the cursor left n characters [n]lmove the cursor right n characters Some simple vi commands Operating Systems

14 ctrl-Bscroll back one page ctrl-Fscroll forward one page Some simple vi commands Operating Systems

15 g0move to the first character on the line g$move to the last character on the line [n]Ggo to line n [n]gggo to line n Some simple vi commands Operating Systems

16 [n]wmove forward n words [n]bmove backwards n words Some simple vi commands Operating Systems

17 [n]xdelete n characters [n]dddelete n ines Some simple vi commands Operating Systems

18 the un-named register (“”) numbered registers (0-9) 0 used by most recent yank command 1 used by most recent delete command named registers (a-z and A-Z) :regshow contents of all registers vi registers Operating Systems

19 [“x][n]yy yank n lines into register x [“x][n]dd delete n lines into register x [“x][n]p put register x after the cursor, n times Some simple vi commands Operating Systems

20 [n]r charreplace n characters with char Some simple vi commands Operating Systems

21 :set cindent shiftwidth=4sets auto indent for C Some simple vi commands Operating Systems

22 vi Manual Operating Systems http://vimdoc.sourceforge.net/htmldoc/usr_toc.html

23 gcc Operating Systems

24 gcc Operating Systems gcc is the gnu C compiler. It processes input file in four distinct phases: pre-processor compiler assembler linker

25 gcc flags Operating Systems the following are common compiler flags. See the man pages for more information.

26 gcc flags Operating Systems -ansienforce full ansi compliance -ccompile and assemble, but do not link -gcreate a symbol table for debugging -Estop after running the pre-processor. do not compile

27 gcc flags Operating Systems -Idiradd the directory dir to the list of directories searched for include files -llibrary link in the name library

28 gcc flags Operating Systems -Ooptimize. There are 3 levels of optimization, O1, O2, and O3 -o filename stores the resulting output in filename, most often used for linker output - Wallissue compiler warnings

29 gcc examples Operating Systems compile a single source code file, and link gcc test1.c output will be a.out

30 gcc examples Operating Systems compile a single source code file, don’t link gcc -c test1.c output will be test1.o

31 gcc examples Operating Systems compile multiple source code files, and link gcc -c test1.c gcc -c test2.c gcc -o test.exe test1.o test2.o output from the first line will be test1.o

32 gcc examples Operating Systems compile a single source code file, link math library gcc -o power power.c -lm output will be power (no extension)

33 make Operating Systems

34 make Operating Systems The unix make utility allows programmers to create “recipes” for compiling and linking multiple files in a project. These “recipes” called make files, allow for incremental re-compilation... only changed files are recompiled.

35 make Operating Systems Make files are located in the same directory as the source code files they are meant to work with. A make file is made up of a set of dependencies and rules. a dependency - defines a target file and the files required to build that target a rule - tells the system what it must do to build a target

36 make example Operating Systems Consider a project that contains the following source code files: main.c studentinfo.c studentinfo.h

37 make example Operating Systems Step One: Compile the studentinfo file studentinfo.o:studentinfo.c studentinfo.h this is the name of the target in order to build this target, we need these source code files the first line lists the dependecies

38 make example Operating Systems Step One: Compile the studentinfo file studentinfo.o:studentinfo.c studentinfo.h gcc -c studentinfo.c the second line tells the rule to build studentinfo.o the rule line must start with a tab character

39 make example Operating Systems Step Two: Compile main.c main.o:main.c studentinfo.h gcc -c main.c

40 make example Operating Systems Step Three: Link demo.exe: main.o studentinfo.o gcc -o demo.exe main.o studentinfo.o

41 make example Operating Systems The complete makefile demo.exe: main.o studentinfo.o gcc -o demo.exe main.o studentinfo.o main.o:main.c studentinfo.h gcc -c main.c studentinfo.o:studentinfo.c studentinfo.h gcc -c studentinfo.c

42 make example Operating Systems To execute the makefile, type make on the command line. This makefile should produce the following output: gcc -c studentinfo.c gcc -c main.c gcc -o demo.exe main.o studentinfo.o

43 gdb Operating Systems

44 Starting GDB At the command prompt type gdb program_name program_name is an executable, compiled with –g option the –g option creates a symbol table used by gdb the current source file is set to the file containing main and the current source line is set to the first executable statement in main( )

45 Program Execution runrun (or rerun) the program from the beginning stepexecute the next source instruction and return to gdb. Follow subroutine calls. step countexecute count source lines nextsame as step, but does not step into functions finishrun until the current function returns returnreturn to calling function jump addressjump to specified source line

46 BreakpointsBreakpoints info breaklist all breakpoints break functionset breakpoint at beginning of function break linenumberset breakpoint at this line number break filename:lineset breakpoint at specified line in file break fn if exprstop at breakpoint fn if expr is true disable breaknumdisable or enable breakpoint breaknum enable breaknum delete breaknumdelete breakpoint breaknum command breaknumexecute the commands when breaknum is reached contcontinue execution

47 The Stack Frame A stack frame is the portion of the run-time stack allocated to the currently executing function. gdb assigns numbers to stack frames, counting from zero for the currently executing function. Variable names are all relative to the current stack frame.

48 Examining the Stack backtraceshow stackframes useful for looking at calling sequence frame framenumberlook at stack frame framenumber downlook at stack frame called by this one uplook at stack frame calling this one info argsshow argument variables in the current stack frame info localsshow local variables in the current stack frame

49 Source Code list linenumprint 10 lines of source code, centered around linenum list functionprint 10 lines of source code, centered around the beginning of function listprint 10 more lines of source code

50 Examining Data print expressionprint value of expression, evaluated within the current stack frame set variable = expression assign result of expression to variable display expressionprint value of expression every time program stops ( a watch) undisplaycancels previous display requests


Download ppt "Unix Programming Tools Operating Systems. man- on-line unix manual vi - a command line text editor make- runs make files gcc- compiler gdb- debugger Operating."

Similar presentations


Ads by Google