3 <title>Debugging with GDB
</title>
4 <meta http-equiv=
"Content-Type" content=
"text/html">
5 <meta name=
"description" content=
"Debugging with GDB">
6 <meta name=
"generator" content=
"makeinfo 4.3">
7 <link href=
"http://www.gnu.org/software/texinfo/" rel=
"generator-home">
12 Node:
<a name=
"List">List
</a>,
13 Next:
<a rel=
"next" accesskey=
"n" href=
"Search.html#Search">Search
</a>,
14 Up:
<a rel=
"up" accesskey=
"u" href=
"Source.html#Source">Source
</a>
18 <h3 class=
"section">Printing source lines
</h3>
20 <p>To print lines from a source file, use the
<code>list
</code> command
21 (abbreviated
<code>l
</code>). By default, ten lines are printed.
22 There are several ways to specify what part of the file you want to print.
24 <p>Here are the forms of the
<code>list
</code> command most commonly used:
27 <dt><code>list
</code><var>linenum
</var><code></code>
28 <dd>Print lines centered around line number
<var>linenum
</var> in the
31 <br><dt><code>list
</code><var>function
</var><code></code>
32 <dd>Print lines centered around the beginning of function
35 <br><dt><code>list
</code>
36 <dd>Print more lines. If the last lines printed were printed with a
37 <code>list
</code> command, this prints lines following the last lines
38 printed; however, if the last line printed was a solitary line printed
39 as part of displaying a stack frame (see
<a href=
"Stack.html#Stack">Examining the Stack
</a>), this prints lines centered around that line.
41 <br><dt><code>list -
</code>
42 <dd>Print lines just before the lines last printed.
45 <p>By default, GDB prints ten source lines with any of these forms of
46 the
<code>list
</code> command. You can change this using
<code>set listsize
</code>:
49 <dt><code>set listsize
</code><var>count
</var><code></code>
50 <dd>Make the
<code>list
</code> command display
<var>count
</var> source lines (unless
51 the
<code>list
</code> argument explicitly specifies some other number).
53 <br><dt><code>show listsize
</code>
54 <dd>Display the number of lines that
<code>list
</code> prints.
57 <p>Repeating a
<code>list
</code> command with
<RET
> discards the argument,
58 so it is equivalent to typing just
<code>list
</code>. This is more useful
59 than listing the same lines again. An exception is made for an
60 argument of
<code>-
</code>; that argument is preserved in repetition so that
61 each repetition moves up in the source file.
63 <p>In general, the
<code>list
</code> command expects you to supply zero, one or two
64 <dfn>linespecs
</dfn>. Linespecs specify source lines; there are several ways
65 of writing them, but the effect is always to specify some source line.
66 Here is a complete description of the possible arguments for
<code>list
</code>:
69 <dt><code>list
</code><var>linespec
</var><code></code>
70 <dd>Print lines centered around the line specified by
<var>linespec
</var>.
72 <br><dt><code>list
</code><var>first
</var><code>,
</code><var>last
</var><code></code>
73 <dd>Print lines from
<var>first
</var> to
<var>last
</var>. Both arguments are
76 <br><dt><code>list ,
</code><var>last
</var><code></code>
77 <dd>Print lines ending with
<var>last
</var>.
79 <br><dt><code>list
</code><var>first
</var><code>,
</code>
80 <dd>Print lines starting with
<var>first
</var>.
82 <br><dt><code>list +
</code>
83 <dd>Print lines just after the lines last printed.
85 <br><dt><code>list -
</code>
86 <dd>Print lines just before the lines last printed.
88 <br><dt><code>list
</code>
89 <dd>As described in the preceding table.
92 <p>Here are the ways of specifying a single source line--all the
96 <dt><code></code><var>number
</var><code></code>
97 <dd>Specifies line
<var>number
</var> of the current source file.
98 When a
<code>list
</code> command has two linespecs, this refers to
99 the same source file as the first linespec.
101 <br><dt><code>+
</code><var>offset
</var><code></code>
102 <dd>Specifies the line
<var>offset
</var> lines after the last line printed.
103 When used as the second linespec in a
<code>list
</code> command that has
104 two, this specifies the line
<var>offset
</var> lines down from the
107 <br><dt><code>-
</code><var>offset
</var><code></code>
108 <dd>Specifies the line
<var>offset
</var> lines before the last line printed.
110 <br><dt><code></code><var>filename
</var><code>:
</code><var>number
</var><code></code>
111 <dd>Specifies line
<var>number
</var> in the source file
<var>filename
</var>.
113 <br><dt><code></code><var>function
</var><code></code>
114 <dd>Specifies the line that begins the body of the function
<var>function
</var>.
115 For example: in C, this is the line with the open brace.
117 <br><dt><code></code><var>filename
</var><code>:
</code><var>function
</var><code></code>
118 <dd>Specifies the line of the open-brace that begins the body of the
119 function
<var>function
</var> in the file
<var>filename
</var>. You only need the
120 file name with a function name to avoid ambiguity when there are
121 identically named functions in different source files.
123 <br><dt><code>*
</code><var>address
</var><code></code>
124 <dd>Specifies the line containing the program address
<var>address
</var>.
125 <var>address
</var> may be any expression.