Option Description: GDB Commands
Option Description: GDB Commands
Older versions use a single "-") Option --help -h --exec=file-name -e file-name --core=name-of-core-file -c name-of-core-file --command=commandfile -x command-file --directory=directory -d directory --cd=directory --nx -n List command line arguments Identify executable associated with core file. Specify core file. File listing GDB commands to perform. Good for automating set-up. Description
Run GDB using specified directory as the current working directory. Do 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 Read symbol table from file file. -s file-name --write Enable writing into executable and core files. --quiet Do not print the introductory and copyright messages. -q --tty=device Specify device for running program's standard input and output. --pid=process-id Specify process ID number to attach to. -p process-id -c process-id
GDB Commands:
Commands used within GDB: Command help help topic-classes help command apropos search-word info args i args info breakpoints info break Description List gdb command topics. List gdb command within class. Command description. Search for commands and command topics containing search-word. List program command line arguments List breakpoints List breakpoint numbers.
info break breakpoint-number info watchpoints info registers info threads info set Break and Watch break funtion-name break line-number
break ClassName::functionName
List info about specific breakpoint. List breakpoints List registers in use List threads in use List set-able option Suspend program at specified function of line number.
break +offset break -offset break filename:function break filename:line-number break *address
Set a breakpoint specified number of lines forward or back from the position at which execution stopped. Don't specify path, just the file name and function name. Don't specify path, just the file name and line number.
break Directory/Path/filename.cpp:62
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-number delete d delete breakpoint-number delete range disable breakpoint-number-orrange enable breakpoint-number-orrange Delete breakpoints as identified by command option.
Delete all breakpoints, watchpoints, or catchpoints. Delete the breakpoints, watchpoints, or catchpoints of the breakpoint ranges specified as arguments. Does not delete breakpoints. Just enables/disables them. Example: Show breakpoints: info break Disable: disable 2-9
enable breakpoint-number once Enables once continue Continue executing until next break point/watchpoint. c continue number Continue but ignore current breakpoint number times. Usefull for breakpoints within a loop. finish Continue to end of function. Line Execution
step Step to next line of code. Will step into a function. s step number-of-steps-to-perform next Execute next line of code. Will not enter functions. n next number until Continue processing until you reacha aspecified line number. Also: function until line-number name, address, filename:function or filename:line-number. stepi step/next assembly/processor instruction. si nexti ni info signals Perform the following option when signal recieved: nostop, stop, print, info handle noprint, pass/noignore or nopass/ignore handle SIGNAL-NAME option where Shows current line number and which function you are in. Stack backtrace Show trace of where you are currently. Which functions you are in. Prints bt stack backtrace. bt inner-function-nesting-depth bt -outer-function-nesting-depth backtrace full Print values of local variables. frame number Select frame number. f number up number Move up/down the specified number of frames in the stack. down number info frame List address, language, address of arguments/local variables and which registers were saved in frame. info args Info arguments of selected frame, local variables and exception handlers. info locals info catch Source Code list List source code. l list line-number list function list list start#,end# list filename:function set listsize count Number of lines listed when list command given. show listsize directory directory-name Add specified directory to front of source code path. dir directory-name show directories
directory Examine Variables print variable-name p variable-name p file-name::variable-name p 'file-name'::variable-name p *array-variable@length p/x variable p/d variable p/u variable p/o variable p/t variable x/b address x/b &variable p/c variable p/f variable p/a variable x/w address x/4b &variable GDB Modes set gdb-option value set logging on set logging off show logging set logging file log-file set print array on set print array off show print array set print array-indexes on set print array-indexes off show print array-indexes set print pretty on set print pretty off show print pretty set print union on set print union off show print union set print demangle on set print demangle off show print demangle Start and Stop
Print first # values of array specified by length. Good for pointers to dynamicaly allocated memory. Print as integer variable in hex. Print variable as a signed integer. Print variable as a un-signed integer. Print variable as a octal. Print as integer value in binary. (1 byte/8bits)
Print integer as character. Print variable as floating point number. Print as a hex address. Print binary representation of 4 bytes (1 32 bit word) of memory pointed to by address. Set a GDB option Turn on/off logging. Default name of file is gdb.txt
run r run command-line-arguments run < infile > outfile continue c kill quit q
Start program execution from the beginning of the program. The command break main will get you started. Also allows basic I/O redirection.
Continue execution to next break point. Stop program execution. Exit GDB debugger.