7 Examining Source Files

GDB can print parts of the source code of your program, since the debugging information recorded in the program tells GDB what source files were used to build it. When your program stops, GDB spontaneously prints the line where it stopped. Likewise, when you select a stack frame (see “Selecting a frame” (page 73)), GDB prints the line where execution in that frame has stopped. You can print other portions of source files by explicit command.

You can invoke GDB from its GNU Emacs interface to view the source code see Chapter 19 (page 293).

7.1 Printing source lines

To print lines from a source file, use the list command (abbreviated l). By default, ten lines are printed. There are several ways to specify what part of the file you want to print.

The following forms of the list command are used:

list linenum Prints lines centered around line number linenum in the current source file.

list function Prints lines centered around the beginning of function function.

listPrints more lines. The list command prints lines following the lines printed by a previously executed list command. If the command prior to executing a list just printed the stack frame, then the list command only prints the lines around that line.

list-

Prints lines just before the lines last printed.

By default, GDB prints ten source lines with any of these forms of the list command.

The number of lines printed by GDB can be set by the set listsize command. The following two forms are supported:

set listsize count Makes the list command display count source lines (unless the list argument explicitly specifies some other number).

show listsize

Displays the number of lines that list prints.

Repeating a list command with RET discards the argument, so it is equivalent to typing just list. This is more useful than listing the same lines again. An exception is made for an argument of '-'; that argument is preserved in repetition so that each repetition moves up in the source file.

In general, the list command expects you to supply zero, one or two linespecs.

Linespecs specify source lines. There are several ways of writing them, but the most common way is to specify some source line.

7.1 Printing source lines

77

Page 77
Image 77
HP gnu source-level debugger 5992-4701 manual Examining Source Files, Printing source lines, List, Show listsize