1 / 50

Unix Programming Tools

Operating Systems. 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 Systems. man pages. Operating Systems. Most unix systems have a set of on-line

shana
Download Presentation

Unix Programming Tools

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Operating Systems Unix Programming Tools

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

  3. Operating Systems man pages

  4. Operating Systems 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: 1 user commands 2 system calls 3 C library functions

  5. Operating Systems Each man page covers a specific command, utility, or system call. Individual man pages commonly are divided into the following sections: HEADER the title of this man page NAME one line summary SYNOPSIS brief description DESCRIPTION detailed description ERRORS conditions for errors FILES files used BUGS known bugs

  6. Operating Systems vi

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

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

  9. Operating Systems Leaving vi 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

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

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

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

  13. Operating Systems Some simple vi commands [n]j move the cursor down n lines [n]k move the cursor up n lines [n]h move the cursor left n characters [n]l move the cursor right n characters

  14. Operating Systems Some simple vi commands ctrl-B scroll back one page ctrl-F scroll forward one page

  15. Operating Systems Some simple vi commands g0 move to the first character on the line g$ move to the last character on the line [n]G go to line n [n]gg go to line n

  16. Operating Systems Some simple vi commands [n]w move forward n words [n]b move backwards n words

  17. Operating Systems Some simple vi commands [n]x delete n characters [n]dd delete n ines

  18. Operating Systems vi registers 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) :reg show contents of all registers

  19. Operating Systems Some simple vi commands [“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

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

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

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

  23. Operating Systems gcc

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

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

  26. Operating Systems gcc flags -ansi enforce full ansi compliance -c compile and assemble, but do not link -g create a symbol table for debugging -E stop after running the pre-processor. do not compile

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

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

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

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

  31. Operating Systems gcc examples 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. Operating Systems gcc examples compile a single source code file, link math library gcc -o power power.c -lm output will be power (no extension)

  33. Operating Systems make

  34. Operating Systems make 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. Operating Systems make 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. Operating Systems make example Consider a project that contains the following source code files: main.c studentinfo.c studentinfo.h

  37. Operating Systems make example Step One: Compile the studentinfo file the first line lists the dependecies 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

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

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

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

  41. Operating Systems make example 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. Operating Systems make example 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. Operating Systems gdb

  44. At the command prompt type gdb program_name Starting GDB 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 run run (or rerun) the program from the beginning step execute the next source instruction and return to gdb. Follow subroutine calls. step count execute count source lines next same as step, but does not step into functions finish run until the current function returns return return to calling function jump address jump to specified source line

  46. info break list all breakpoints break function set breakpoint at beginning of function break linenumber set breakpoint at this line number break filename:line set breakpoint at specified line in file break fn if expr stop at breakpoint fn if expr is true disable breaknum disable or enable breakpoint breaknum enable breaknum delete breaknum delete breakpoint breaknum command breaknum execute the commands when breaknum is reached cont continue execution Breakpoints

  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. backtrace show stackframes useful for looking at calling sequence frame framenumber look at stack frame framenumber down look at stack frame called by this one up look at stack frame calling this one info args show argument variables in the current stack frame info locals show local variables in the current stack frame Examining the Stack

  49. Source Code list linenum print 10 lines of source code, centered around linenum list function print 10 lines of source code, centered around the beginning of function list print 10 more lines of source code

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

More Related