GDB - A quick reference

GDB - A quick reference

gdb program-name

gdb program-name core-file

gdb program-name process-id - GDB gets attached to the running process with its id equal to given process-id; Note that the running process pauses. Now some variable value can be set and process can be detached.

(gdb prompt) attach process-id - Attaches GDB to given process ID

(gdb prompt) detach - detaches the process attached.

gdb -q -q stands for quite; No copyright printed

b(break) main - Put a breakpoint at the beginning of the program

b(break) - Put a breakpoint at the next line ( current line makes no sense)

b(break) N - Put a breakpoint at line N

b(break) filename:N - Put a breakpoint at line N in file filename

b(break) class::func - To put a break point in C++ function

b(break) +N - Put a breakpoint N lines down from the current line

b(break) -N - Put a breakpoint N lines up from the current line

b(break) fn - Put a breakpoint at the beginning of function "fn"

b(break) if (exprsn) - Any form can take line number and break is applied if condition is satisfied

tbreak - Its similar to break but breaks temporarily. That is , it stops the program once, and the break point is removed

ignore arg1 arg2 - Skip the break point arg1; It should be skipped arg2 number of times

watch var - This is the way to set Write watch point on variable var; Watch the changes in the value of var; var should be in the context to set watch point on variable.

rwatch var - To set read watch point

awatch var - To set read/write watch point.info breakpoints - lists the breakpoints and watch points

disable N - Disables breakpoint/watchpoint number N; Where N is obtained from info breakpoints

enable N - Enables a disabled break point whose identifier is N

d(delete) N - delete breakpoint number N; Where N is a identifier obtained from info breakpoints

delete - delete with no arguments will remove all breakpoints

clear funcname - Clears the break point set at funcname

clear line-num;

clear filename:line-num;

clear addressinfo break - list breakpoints

------------------------------------------------------------------------------------------------Summary Of Breakpoints

Form 1: break linenumber Set a breakpoint at line number linenumber

Form 2: break function Set a breakpoint at function function.

Form 3: break filename:linenumber Set a breakpoint at line linenum in source file filename. Form 4: break *address Set a breakpoint at address. Use this to set breakpoints in parts of a program that doesn't have debugging information or source files.
Deleting Breakpoints

clear func - Clear any breakpoints set at the entry to the function .

clear filename:func- Clear any breakpoints set at the entry to the function defined in the source code file .

clear linenum - Clear any breakpoints set at line of the current source file. The current source file is the last file whose text was printed.

clear filename:linenum - Clear any breakpoints at line in file .

delete - Clear all breakpoints.

delete n - Each breakpoint is assigned a number starting with 1. This clears breakpoint n.

------------------------------------------------------------------------------------------------

r(run) - Run the program until a breakpoint or error

c(continues) - continue running the program until the next breakpoint or error

f(finish) - Run until the current function is finished; Also shows what values function returned

s(step) - run the next line of the program

s(step) N - run the next N lines of the program

n(next) - like s, but don't step into functions

u(until) N - run until you get N lines in front of the current line

p(print) var - print the current value of the variable "var"; Var can be arrays, or structures. GDB knows how to print them

print array[3]@5 - Prints 5 elements of the array starting from element 3. Note that bound checking of arrays is not done by GDB

set print pretty - Sets the print environment to print structures in as one structure member per line.

p $ - prints the last variable

p $31 - $31 is the variable printed previously

p (type_cast) var - Variables can be typecasted during print

bt(backtrace) - print a stack trace

u(up) - go up a level in the stack

d(down) - go down a level in the stack

q(quit) - Quit gdb

l(list) - lists code lines near crash (10 lines of code)

"list -" - lists the lines of code in the reverse order

list 5 - lists 10 lines around line number 5

list 6,9 - lists all the lines between 6 and 9 inclusive

list funcname - list the whole function

list filename:Num
list filename:funcname

list *address - address can be got by print command; Eg; gdb> print funcname

set listsize 5 - Set the list size to 5 instead of default size 10

where - equivalent backtracehelp command - gives a brief description

kill - Kills the program being debugged. But it can be re-run using run once again.

print x - Prints the values of variable x as $## = (value); $## is simply a count that keeps track of the variables ou have examined.

set x = 3 - To modify variables

call abort() - This calls the function abort(); Note: abort() dumps core.

frame N - Go to frame N; Where N is the frame number obtained using backtrace command Just frame without number gives details of current

frameinfo locals - Gives out the values of local variables in the (function)

info args - Gives out the values of the function variable in the frame(function)

info frame - Gives the information of the current frame(function)

x - x/Format ADDRESS; Format is the repeat count followed by format letter followed by size letter

x/4c s - Print 4 characters starting from address given by varialble s. See "help x" for more info

print /FMT variable - FMT can be o(octal), x(hex), d(decimal), u(unsigned decimal), t(binary), f(float), a(address), c(char)

set varname = value - Set the variable name to given valueprint varname = value - Set the variable name to given value and print the new value of the variable.

core corefile - Loads the core file to the debugger

stepi, nexti - To step through the code at instruction level

disassember func - Dump of the assembler code for function func

ptype varname - Prints the data type of the variable name

Comments

Popular posts from this blog

AWK - quick reference

SQL-QuickReference