Princeton University
COS 217:  Introduction to Programming System

Precept 13:  The gdb Debugger for SPARC Assembly Language


Help you learn how to use gdb to debug SPARC assembly language programs


Paul, Section 2.7


Suppose we need to debug program rect.S...

Review:  Using gdb with C Programs

Recall:  gdb with C is very powerful

To use:

gcc -g -o myprog myprog.c

"-g" option commands compiler to place debug information in object file

Generates an enhanced symbol table -- as described later in the course

Executable binary file thus also contains debug information

emacs (or xemacs)
ESC x gdb myprog

gdb uses debug information to relate executable code to source files/lines

gdb uses that file/line information to communicate with Emacs

Using gdb with Assembly Language Programs

[Refer to "The gdb Debugger for Assembly Language Programs" summary sheet]

gdb with assembly language programs is much less powerful

We don't use the compiler, and so we have no way of getting debug information into the object files or executable binary file

gdb does not have source file/line information

No point in running under Emacs

Commands (e.g. list, breakpoint) that reference files and lines will not work

gcc -o rect rect.S
gdb rect

Running the Program


Note:  Does not display lines

Using Breakpoints

Same as with C, except cannot refer to source file names or line numbers

break main

Stepping through the Program

Must use nexti (ni) and stepi (si) instead of next (n) and step (s)


Examining Registers and Memory

info registers

Print the contents of all registers

print/d $l0

Print the contents of register %l0 in decimal format

Note:  $l0, not %l0

x/i $pc

Print the contents of memory at the address contained in register %pc

display/i $pc

Add to the display list

At each program break, display the contents of memory at the address contained in register %pc

Very common/useful

Examining the Call Stack

(Same as with C)


(Same as with C)

Copyright 2002 by Robert M. Dondero, Jr.