html5-img
1 / 49

Unix Programming Tools

Unix Programming Tools. man - on-line unix manual vi - a command line text editor make - runs make files gcc - compiler gdb - debugger. man pages. Most unix systems have a set of on-line documentation called the man pages. These are typically organized into several sections.

tamar
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. Unix Programming Tools

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

  3. man pages

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

  5. 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. vi

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

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

  9. 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. 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. vi Commands vi commands are usually of the foem [count] command [where] for example. 23x deletes 23 characters

  12. 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. 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. Some simple vi commands ctrl-B scroll back one page ctrl-F scroll forward one page

  15. 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. Some simple vi commands [n]w move forward n words [n]b move backwards n words

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

  18. 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. 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. Some simple vi commands [n]r char replace n characters with char

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

  22. gcc

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

  24. gcc flags the following are common compiler flags. See the man pages for more information.

  25. 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

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

  27. 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

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

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

  30. gcc examples compile a multiple source code files, and link gcc -c test1.c gcc -c test2.c gcc -o test.exe test1.o test2.o output will be test1.o

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

  32. make

  33. 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.

  34. 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

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

  36. make example Step One: Compile the studentinfo file the first line lists the dependencies 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

  37. 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

  38. make example Step Two: Compile main.c main.o: main.c studentinfo.h gcc -c main.c

  39. make example Step Three: Link demo.exe: main.o studentinfo.o gcc -o main.o studentinfo.o

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

  41. 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

  42. gdb

  43. 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( )

  44. 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 Program Execution

  45. 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

  46. 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.

  47. 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

  48. 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

  49. 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