gdb.info: List

Go forward to Edit
Go up to Source
Go to the top op gdb

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.
   Here are the forms of the `list' command most commonly used:
`list LINENUM'
     Print lines centered around line number LINENUM in the current
     source file.
`list FUNCTION'
     Print lines centered around the beginning of function FUNCTION.
`list'
     Print more lines.  If the last lines printed were printed with a
     `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 (*note Examining the
     Stack: Stack.), this prints lines centered around that line.
`list -'
     Print lines just before the lines last printed.
   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 COUNT'
     Make the `list' command display COUNT source lines (unless the
     `list' argument explicitly specifies some other number).
`show listsize'
     Display 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 effect is always to specify some source line.
Here is a complete description of the possible arguments for `list':
`list LINESPEC'
     Print lines centered around the line specified by LINESPEC.
`list FIRST,LAST'
     Print lines from FIRST to LAST.  Both arguments are linespecs.
`list ,LAST'
     Print lines ending with LAST.
`list FIRST,'
     Print lines starting with FIRST.
`list +'
     Print lines just after the lines last printed.
`list -'
     Print lines just before the lines last printed.
`list'
     As described in the preceding table.
   Here are the ways of specifying a single source line--all the kinds
of linespec.
`NUMBER'
     Specifies line NUMBER of the current source file.  When a `list'
     command has two linespecs, this refers to the same source file as
     the first linespec.
`+OFFSET'
     Specifies the line OFFSET lines after the last line printed.  When
     used as the second linespec in a `list' command that has two, this
     specifies the line OFFSET lines down from the first linespec.
`-OFFSET'
     Specifies the line OFFSET lines before the last line printed.
`FILENAME:NUMBER'
     Specifies line NUMBER in the source file FILENAME.
`FUNCTION'
     Specifies the line that begins the body of the function FUNCTION.
     For example: in C, this is the line with the open brace.
`FILENAME:FUNCTION'
     Specifies the line of the open-brace that begins the body of the
     function FUNCTION in the file FILENAME.  You only need the file
     name with a function name to avoid ambiguity when there are
     identically named functions in different source files.
`*ADDRESS'
     Specifies the line containing the program address ADDRESS.
     ADDRESS may be any expression.