GDB Command Line Arguments:: Option Description
GDB Command Line Arguments:: Option Description
GDB Command Line Arguments:: Option Description
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.)
Option Description
--help List command line arguments
-h
--exec=file-name Identify executable associated with core file.
-e file-name
--core=name-of-core- Specify core file.
file
-c name-of-core-file
--command=command- File listing GDB commands to perform. Good for
file automating set-up.
-x command-file
--directory=directory Add directory to the path to search for source files.
-d directory
--cd=directory Run GDB using specified directory as the current
working directory.
--nx Do not execute commands from ~/.gdbinit
-n 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
-q messages.
--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:
Command Description
help List gdb command topics.
help topic-classes List gdb command within class.
help command Command description.
apropos search- Search for commands and command topics
word containing search-word.
info args List program command line arguments
i args
info breakpoints List breakpoints
info break List breakpoint numbers.
info break List info about specific breakpoint.
breakpoint-number
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 Suspend program at specified function of line
break line-number number.
break ClassName::functionName
break +offset Set a breakpoint specified number of lines forward or
break -offset back from the position at which execution stopped.
break Don't specify path, just the file name and function
filename:function name.
break filename:line- Don't specify path, just the file name and line number.
number break Directory/Path/filename.cpp:62
GDB Operation:
Compile with the "-g" option (for most GNU and Intel compilers) which
generates added information in the object code so the debugger can
match a line of source code with the step of execution.
Do not use compiler optimization directive such as "-O" or "-O2" which
rearrange computing operations to gain speed as this reordering will not
match the order of execution in the source code and it may be impossible
to follow.
control+c: Stop execution. It can stop program anywhere, in your source
or a C library or anywhere.
To execute a shell command: ! command
or shell command
GDB command completion: Use TAB key
info bre + TAB will complete the command resulting in info breakpoints
Press TAB twice to see all available options if more than one option is
available or type "M-?" + RETURN.
GDB command abreviation:
info bre + RETURN will work as bre is a valid abreviation for
breakpoints