Unix Debugger GDB Tips Shortcuts
Posted on March 15th, 2008
-- Sponsored Links --
GDB – important commands (most can be abbreviated to starting letter)
-- Sponsored Links --
o r = run the program (can give arguments, e.g., r -f foo.txt or r < test.script)
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 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
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 vnc session)
- run gdb exactly as above, with the added benefit of seeing where you are in your code
- you can also set break points directly from the source window: put the mouse
over the line and hit CTRL-x SPACEKEYo 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 version.o open files in emacs with CTRL-x-f, save with CTRL-x-s, search with CTRL-s and CTRL-r,
use CTRL-x-c to quit emacso 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)
Filed under Programming |
Comments are closed.
