You are on page 1of 4

GDB: important commands (most can be abbreviated to starting letter)

o r = run the program (can give arguments, e.g., r -f foo.txt or r < test.scri
pt)
o file filename = load in the executable filename
o s = step through code (enters function being called)
o n = next line (treats function being called as single operation)
o where = get a stack trace
o u (d) = move up (down) the stack trace
o cont = continue execution till break/end of program
o fin = finish function, i.e., run to return
o b functioname = set breakpoint for function called functioname
o b filename:lineno = set breakpoint at line lineno in file filename
o info b = print information on breakpoints
o disable 7 = disable breakpoint number 7
o cond 7 ( a == b ) = break at breakpoint 7 iff ( a == b ) is true
o watch x = break whenver x is written (rwatch, awatch for read/both)
o p varName = print variable varName
o p $ = print the current value of last variable printed
o p *X@len to print Xarray as an array of length len
o print with convenience vars: set $i = 0\n p dtab[$i++]->fv\n RET\n RET...
o disp x = print the value of x after each command
o RETURN KEY = repeat the last command
o TAB = completion, works for var/func names as well as files
o URL detailed: http://sources.redhat.com/gdb/current/onlinedocs/gdb_toc.html
o URL short: http://www.ece.utexas.edu/~adnan/gdb-refcard.pdf

GDB and EMACS


o fire up emacs (run emacs -nw if you don't have an Xsession, e.g.,
are running putty)
o get gdb running using ALT-x gdb (may have to use ESC-x gdb if you are in a v
nc session)
- run gdb exactly as above, with the added benefit of seeing where you are i
n your code
- you can also set break points directly from the source window: put the mou
se
over the line and hit CTRL-x SPACEKEY
o if you edit source in vi, it's painful to have to keep refreshing the emacs
copy;
put (global-auto-revert-mode 1) in your .emacs file to use the latest versio
n.
o open files in emacs with CTRL-x-f, save with CTRL-x-s, search with CTRL-s an
d CTRL-r,
use CTRL-x-c to quit emacs
o URL short: http://www.ece.utexas.edu/~adnan/emacs-refcard.pdf

BROWSING CODE
o run ctags *.h *.c to create a file called tags
o now in vi, hit CTRL-] to go to the definition of the function/type under the
cursor,
CTRL-t to go back (can do this iteratively)
o if your source is spread over many directories, use symbolic link to tags

GDB: smart ways to print arrays and lists


(gdb) set $index=0
(gdb) print array[$index++]
as you keep hitting return, you get the values in sequence;
it's very similar with lists:
(gdb) set $ptr=Ntk_LongNameForAPtrToListHead
(gdb) p ($tmp = $ptr, $ptr=$ptr->next, $tmp->data)

SHELL TIPS
o Useful .cshrc entries
- set host=`/bin/hostname | /bin/sed 's/\..*$//'`
- alias prmpt 'set prompt="[adnan@$host]${cwd} ! "'
- alias cd 'cd \!* ; prmpt'
- set cdpath=(. /nfs/narya /nfs/narya/src ~/ ~/narya/camcode/vis ~/papers ~
/classes)
o autocompletion
- set hosts = ( a.com b.com c.com )
- complete slogin 'p/1/$hosts/'
- complete set 'c/*=/f/' 'p/1/s/=' 'n/=/f/'
- complete vi 'n/*/f:^{core, *.dvi, *.ps, *.aux, *.bib, *.log , *.[ao]}/'
- complete make \
'n@*@`cat -s GNUmakefile Makefile makefile |& sed -n -e "/No such file/d
" -e "/^[^ #].*:/s/:.*//p"`@'
o Example .tcsh: www.opensource.apple.com/darwinsource/Current/tcsh-46/tcsh/co
mplete.tcsh
o look at stderr without it flying by (works only in bash)
[adnan@ic 100] make 2>&1 | less
o create a single pdf which lists a number of source files (for csh/tcsh)
[adnan@ic 100] for file in $(PRINT_FILES); do \
echo Enscripting $$file; \
umask 2; \
enscript -Gr2 -C -G $$file -p $(psfiledir)/`basename $$
file`.ps; \
ps2pdf $(psfiledir)/`basename $$file`.ps $(psfiledir)/`b
asename $$file`.pdf; \
ps2pdf $(psfiledir)/`basename $$file`.ps $(psfiledir)/`b
asename $$file`.pdf ; \
done
gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=$(psfiledir)/com
plete-source.pdf -dBATCH $(psfiledir)/*.pdf
VIM TIPS
o substitute :s/adnan/foo/g (does a global substitute)
- use :1,10 s/^/^ /c for inserting 2 spaces for lines 1 to 10 (with check fo
r each insertion)
o abbreviate :abb cg <FONT color=green>
- map ; $ // move to end of line
- map - 1G // move to start of file
- map \ $G // move to end of file
o split a window :sp
- ctrl-w ctrl-w to swap
o select a region (set of lines) with v
- hit d to delete it, p to paste it,
- ctrl-v to select rectangular regions, use I (note cap ) to insert from top

o tabs: http://www.jwz.org/doc/tabs-vs-spaces.html
- Standard vi interprets the tab key literally, but there are popular vi-deri
ved alternatives that are smarter, like vim. To get vim to interpret tab as an `
`indent'' command instead of an insert-a-tab command, do this:
set softtabstop=2
- To set the mod-N indentation used when you hit the tab key in vim (what Emac
s calls c-basic-offset), do this: set shiftwidth=2
- To cause the TAB file-character to be displayed as mod-N in vi and vim (what
Emacs calls tab-width), do this: set tabstop=4
- To cause TAB characters to not be used in the file for compression, and for
only spaces to be used (what emacs calls indent-tabs-mode), do this: set expandt
ab
- In vi (and vim), you can do this stuff on a per-file basis using ``modelines
,'' magic comments at the top of the file, similarly to how it works in Emacs: /
* ex: set tabstop=8 expandtab: */
o use * and # to find instances of the word under the cursor
o Syntax highlighting: http://www.fleiner.com/vim/create.html
- http://www-vlsi.stanford.edu/~jsolomon/vim/
o Indenting code: Go to 'normal mode' (not insert or command mode) and use ctrl
+V to select the lines you want reindented. Then press the equals key ('='). Th
at's it - ViM will reindent the selected code for you.

You might also like