You are on page 1of 2

GNU

Debugger Quick Start for ARM



Debugging Assembly Language Programs

1. Compile your assembly program using the command gcc –g –o < filename> <filename.s>

2. After a successful assembly, execute the command: gdb prog (where prog is the name of your
executable program.

3. Use breakpoints to stop the execution of your program at key points so that you can examine
registers or memory locations at that those points. You can use the command: break <line
number>. You can obtain the line numbers from the listings file (<filename>.l). You can clear a
breakpoint by using the delete <breakpoint number>.

Note: don't set a breakpoint at the first executed instruction of your program. It won't be
recognized. Start with at least the second instruction.

4. If you want the debugger to print out the contents of a specific CPU register every time there is
a breakpoint, use the command: display/f $reg command. (ie. display/x $eax). Notice that you
need to use $ to specify a register (not the % that you use in the assembly source language file).

5. Start the execution of your program (to the first breakpoint using the command: run
6. You can step through your program using the nexti or stepi commands.
7. You can continue execution to the next breakpoint by using the continue command.

GDB Command Summary


command operation
quit exit gdb
help [cmd] print description of debugger command cmd.
Without cmd prints a list of topics.
Running the program
run runs the program
Using breakpoints
info breakpoints Print a list of all breakpoints and their numbers
(the numbers are used for other breakpoint
commands)
break linenumber
set a breakpoint at line number linenumber. See
the listing file (prog.l ) for line numbers.

continue
continue the execution of the program
list <n> list 10 lines or n lines of the program source

kill
stop executing the program
delete [bpnum1] [bpnum2]
delete breakpoints bpnum1,bpnum2 or all
breakpoints if none are specified.
clear linenum
clear the breakpoint at line number linenum.

Stepping through the program

next i (or just n) step "over" the next instruction (doesn't follow
function calls)

stepi (or just i) step "into" the next instruction (follows function
calls)

finish "step out" of the current function

Examining Registers and Memory

info registers print the contents of all registers

info address <label> prints the address of label


Print the contents of register reg using format f.
print /f $reg The format can be x (hexadecimal, u (unsigned
decimal),a (address), or c (character).
Print the contents of memory address addr using
X /rsf addr repeat count r, size s, and format f. Repeat count
defaults to 1 if not specified. Size can be b (byte),
h(halfword),w(word),or g(double word). Format is
the same as print, with the additions of s (string)
and i (instruction).
Shows a numbered list of expressions set up to
info display display automatically at each break.
At each break, print the contents of register reg
display /f $reg using format f.
At each break, print the contents of memory
display/si addr address addr using size s (same options as for X
command)
Remove displaynumber from the display list.
undisplay displaynumber

You might also like