GNU GDB Debugger Command Cheat Sheet
http://super-jiju.spaces.live.com/blog/cns!806C498DDEE76B61!565.entry
GDB Command Line Arguments:
Starting GDB:
- gdb name-of-executable
- gdb -e name-of-executable -c name-of-core-file
- gdb name-of-executable -pid process-id
(Use ps -auxw to list process id's.)
Command line options: (version 6. Older versions use a single "-")
-
Option Description --help
-hList command line arguments --exec=file-name
-e file-nameIdentify executable associated with core file. --core=name-of-core-file
-c name-of-core-fileSpecify core file. --command=command-file
-x command-fileFile listing GDB commands to perform. Good for automating set-up. --directory=directory
-d directoryAdd directory to the path to search for source files. --cd=directory Run GDB using specified directory as the current working directory. --nx
-nDo not execute commands from ~/.gdbinit initialization file. Default is to look at this file and execute the list of commands. --batch -x command-file Run in batch (not interactive) mode. Execute commands from file. Requires -x option. --symbols=file-name
-s file-nameRead symbol table from file file. --write Enable writing into executable and core files. --quiet
-qDo not print the introductory and copyright messages. --tty=device Specify device for running program's standard input and output. --pid=process-id
-p process-id
-c process-idSpecify process ID number to attach to.
GDB Commands: |
Commands used within GDB:
-
Command Description help List gdb command topics. help topic-classes List gdb command within class. help command Command description. apropos search-word Search for commands and command topics containing search-word. info args
i argsList program command line arguments info breakpoints List breakpoints info break List breakpoint numbers. info break breakpoint-number List info about specific breakpoint. info watchpoints List breakpoints info registers List registers in use info threads List threads in use info set List set-able option Break and Watch
break funtion-name
break line-numberSuspend program at specified function of line number. break +offset
break -offsetSet a breakpoint specified number of lines forward or back from the position at which execution stopped. break filename:function Don't specify path, just the file name and function name. break filename:line-number Don't specify path, just the file name and line number. break *address Suspend processing at an instruction address. Used when you do not have source. break line-number if condition Where condition is an expression. i.e. x > 5
Suspend when boolean expression is true.break line thread thread-number Break in thread at specified line number. Use info threads to display thread numbers. tbreak Temporary break. Break once only. Break is then removed. See "break" above for options. watch condition Suspend processing when condition is met. i.e. x > 5 clear
clear function
clear line-num