Rhd256.Bowez Notes.2006-07-20.Txt Thu Jul 20 15:31
Total Page:16
File Type:pdf, Size:1020Kb
../rhd256.bowez_notes.2006-07-20.txt Thu Jul 20 15:31:29 2006 1 ==> ./01_intro/notes.txt <== ---------------------------------------------------------------------- ---------------------------------------------------------------------- 2.3 Bash Special Characaters 1.3 Prerequisates ---------------------------------------------------------------------- ---------------------------------------------------------------------- ------------------------------------------------------------------ Familiarity: Redirection (Stream Manipulation) ------------------------------------------------------------------ the classroom setup (server1, station1, etc...) the "pub" directory every process has three default file descriptors (streams): Common Tools: 0: stdin 1: stdout terminal: 2: stderr changing fonts, etc.... - by default, all are connected to the terminal. editors: - In RHL, can be accessed by /dev/std{in,out,err} emacs vi, vim, gvim < redirect descriptor input pico -w, gedit > redirect descriptor output (create or clobber) (less pager) >> redirect descriptor output (create or append) finding information: 2>&1 bind one descriptor to another (i.e., combine stderr and stdout) --help, -h >& bash shortcut for the same man pages (chapters) info pages (info, pinfo, nautilus) examples: /usr/share/doc grep root /etc/* rpm (-qf filename, -ql, -qi) grep root /etc/* > /tmp/out grep root /etc/* 2> /tmp/err ---------------------------------------------------------------------- grep root /etc/* > /tmp/out2 2> /tmp/err2 grep root /etc/* >& /tmp/all 1.4 Procedures ---------------------------------------------------------------------- ------------------------------------------------------------------ Compound Command Grouping anonymous cvs access to notes/sources: ------------------------------------------------------------------ CVSROOT=:pserver:anonymous@server:/usr/local/cvsroot | pipe cvs co gls/curricula/rhd143 rpm -qa | sort cvs export -Dnow gls/curricula/rhd143 ; execute commands in sequence && if first succeeds (return code == 0) , execute second || if first fails (return code != 0) , execute second (...) execute commands in subshell ==> ./03_bash/notes.txt <== ---------------------------------------------------------------------- examples: cd /var/tmp; date > foo; ls; pwd 2.2 Shells ls /tmp > /dev/null && echo "it exists" ls /tmpfoo > /dev/null || echo "it no exists" ---------------------------------------------------------------------- (cd /usr/share/kudzu; ls); pwd Bash Red Hat Specific Initialization ------------------------------------------------------------------ login shells: Command Line Expansions /etc/profile ------------------------------------------------------------------ /etc/profile.d/*.sh ˜/.bash_profile brace {} touch foo{a,b,c} tilde ˜ cd ˜elvis login and non-login shells: parameter $ cd $HOME ˜/.bashrc command ‘...‘, $(...) touch System-map-‘uname -r‘ /etc/bashrc arithmetic $((...)) pathname *,?,[...],[^...] ls /etc/*.conf ../rhd256.bowez_notes.2006-07-20.txt Thu Jul 20 15:31:29 2006 2 history ! !1024, !v echo ’good teacher’ else Expansions happen __before__ command is run! echo ’no apple for you’ fi Compare: find /etc -name *.conf "man test" for more conditionals touch a.conf b.conf; find /etc -name *.conf if [ x$A -eq "xapple" ]; then (set -x can be helpful in deciphering these) echo ’good teacher’ else ------------------------------------------------------------------ echo ’no apple for you’ Interactive Tricks fi ------------------------------------------------------------------ [ -x /usr/bin/foo ] && /usr/bin/foo <TAB> tab completion (CTRL-R) interactive history ESC-., ALT-. last token --------------------- loops ------------------------------------------------------------------ --------------------- Command Line Escapes (Quoting) ------------------------------------------------------------------ for _iterator_ in _list_ do Next Literal \ _command_ Weak Quoting "..." (does not protect $, ‘, or \) _command_ Strong Quoting ’...’ done ------------------------------------------------------------------ for i in dog cat mouse gerbil; do Compound Syntax echo "nice $i" ------------------------------------------------------------------ done --------------------- for i in $*; do branches echo "nice $i" --------------------- done if _command_ for i in $(users); do then echo "nice $i" _command_ done _command_ else _command_ set -x fi # vi:ts=4 if grep elvis /etc/passwd; then echo "elvis is in the house" ==> ./04_gcc/notes.txt <== else ----------------------------------------------------------------------- echo "no elvis" fi Section 3 - gcc compiler ----------------------------------------------------------------------- if grep -q elvis /etc/passwd; then echo "elvis is in the house" executable: gcc else rpm: gcc echo "no elvis" layout: /usr/lib/gcc-lib/ fi (the compiler table) if test $A -eq "apple"; then demo - hello world echo ’good teacher’ illustrate stages else link against other executables echo ’no apple for you’ fi gcc *.c gcc -o hello *.c if test x$A -eq "xapple"; then gcc -E hello.c ../rhd256.bowez_notes.2006-07-20.txt Thu Jul 20 15:31:29 2006 3 gcc -S hello.c w/o greatly increasing compilation time: gcc -c hello.c thread-jumps, defer-pop, delayed-branch -O2 all but loop unrolling, function inlining +-------------------------------------------------------------------------+ -O3 -O2 + inline functions (can be hard to debug) | Stage | utility | rpm | gcc | gcc | input | output | -Os Optomize for size | | | | switch | option | suffix | suffix | |------------+---------+----------+--------+--------+--------+------------| preprocessor options: |preprocess |cpp |cpp |-E |-Wp |.c |.i | |------------+---------+----------+--------+--------+--------+------------| -Dmacro[=def] define macro |compile |gcc |gcc |-S | |.i |.s | -Umacro undefine macro |------------+---------+----------+--------+--------+--------+------------| -M produce makefile dependency info only |assemble |as |binutils |-c |-WS |.s |.o | -MM same as -M, but don’t include system headers |------------+---------+----------+--------+--------+--------+------------| |link |ld |binutils | |-Wl |.o |executable | -include, -imacros, -idirafter, -iwithprefix, -nostdinc +-------------------------------------------------------------------------+ modify include search path documentation: linker options: man pages - examine gcc -shared generate shared object libraries (dflt) info pages - note gnome-help-browser -static generate static object libraries options: -------------------------------------------------------------------------- compilation stages: cpp options -E preprocess only -------------------------------------------------------------------------- -S preprocess and compile only -c preprocess, compile, and assemble only details: -o filename set output file to filename -ansi directory options: - disables non ANSI features and keywords (asm, -Dunix, // comments) -Idir include directory in include file search path - defines __STRICT_ANSI__ -Ldir include directory in library search path - enables trigraphs -Bdir compiler base directory (useful for cross compilations) -no-asm target options: non ANSI code not flatout rejected, use in conjunction w/ -pedantic -b arch (cross)compile for architecture arch -------------------------------------------------------------------------- language options: gcc extensions -ansi strict ansi conformance -traditional ??? -------------------------------------------------------------------------- warning options: - local (block) labels -Wall issue all warnings - nested functions -pedantic fail on non-ansi compliance -Werror promote all warnings to errors - typeof() -w disable warnings #define max(a,b) \ debugging: ({ typeof (a) _a = (a); \ typeof (b) _b = (b); \ -g produce debugging symbols _a > _b ? _a : _b; }) -ggdb produce debugging symbols w/ gdb extentions -p enable profiling with ’prof’ - int int (doubleword integers) -pg enable profiling with ’gprof’ -save-temps save temporary files - zero length arrays optimization: struct line { int length; (none) optimize compilation time and debugging consistancey char contents[0]; -O,-O1 try to reduce code size and run time, }; ../rhd256.bowez_notes.2006-07-20.txt Thu Jul 20 15:31:29 2006 4 attach to a running program: attach 3204 arugments: show args set args arg1... environment: # vi: ts=4 show environment [VARNAME] set environment VARNAME [=VALUE] ==> ./04_gdb/notes.txt <== --------------------------------------------------------------------------- forking: What gdb can do --------------------------------------------------------------------------- set follow-fork-mode parent|child|ask a) start program (w/ any args,env) threads: b) set breakpoints, conditional breakpoints c) stopped program analysis features: d) dynamic changes - new thread notification - thread specific breakpoints Supports gcc, g++ --------------------------------------------------------------------------- - thread THREAD: shift threads compiling - info threads --------------------------------------------------------------------------- - thread apply: apply cmd to all threads gcc -g -O0 --------------------------------------------------------------------------- stopping (gdb can handle optimized code, will not be ’faithful’ --------------------------------------------------------------------------- to source file) break - break at position watch - break when value changes --------------------------------------------------------------------------- catch - break on events (signals, forks, execs) invoking ---------------------------------------------------------------------------