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; see Specify Location, for the full list.
Here are the forms of the list
command most commonly used:
list
linenumlist
functionlist
list
command, this prints lines following the last lines
printed; however, if the last line printed was a solitary line printed
as part of displaying a stack frame (see Examining the Stack), this prints lines centered around that line.
list -
By default, gdb prints ten source lines with any of these forms of
the list
command. You can change this using set listsize
:
set listsize
countset listsize unlimited
list
command display count source lines (unless
the list
argument explicitly specifies some other number).
Setting count to unlimited
or 0 means there's no limit.
show listsize
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
locations. Locations specify source lines; there are several ways
of writing them (see Specify Location), but the effect is always
to specify some source line.
Here is a complete description of the possible arguments for list
:
list
locationlist
first,
lastlist
command has two locations, and the
source file of the second location is omitted, this refers to
the same source file as the first location.
list ,
lastlist
first,
list +
list -
list