Q&A
-
While you’re in a gdb session, how do you set the arguments that will be passed to the program when it’s run?
A:
set args [arguments]
for setting arguments,show args
for showing arguments. -
How do you create a breakpoint? A:
break <position>
-
How do you execute the next line of C code in the program after stopping at a breakpoint? A:
next
-
If the next line of code is a function call, you’ll execute the whole function call at once if you use your answer to #3. (If not, consider a different command for #3!) How do you tell GDB that you want to debug the code inside the function (i.e. step into the function) instead? A:
step
-
How do you continue the program after stopping at a breakpoint? A:
continue
-
How can you print the value of a variable (or even an expression like 1+2) in gdb? A:
print <var>
-
How do you configure gdb so it displays the value of a variable after every step? A:
watch <var>
. List all watchpoints:info break
. Delete a watchpoint:delete 1
-
How do you show a list of all variables and their values in the current function? A:
info locals
-
How do you quit out of gdb? A:
quit
-
How to show disassemble instructions at position? A:
disass <position>
-
How to set disassembly flavor? A:
set disassembly-flavor intel|att
-
How to show register infos? A:
info registers