Chapter 9.
Examining Source Files
gdb can print parts of your program’s source, 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 (refer to Section 8.3
Selecting a
frame
), gdb prints the line where execution in that frame has stopped. You can print other portions of
source files by explicit command.
If you use gdb through its gnu Emacs interface, you may prefer to use Emacs facilities to view source;
refer to Chapter 25
Using gdb under gnu Emacs
.
9.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.
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 (refer to Chapter 8
Examining the 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 spec-
ifies 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
:
Содержание ENTERPRISE LINUX 4 - DEVELOPER TOOLS GUIDE
Страница 1: ...Red Hat Enterprise Linux 4 Debugging with gdb ...
Страница 12: ...2 Chapter 1 Debugging with gdb ...
Страница 28: ...18 Chapter 4 Getting In and Out of gdb ...
Страница 34: ...24 Chapter 5 gdb Commands ...
Страница 44: ...34 Chapter 6 Running Programs Under gdb ...
Страница 68: ...58 Chapter 8 Examining the Stack ...
Страница 98: ...88 Chapter 10 Examining Data ...
Страница 112: ...102 Chapter 12 Tracepoints ...
Страница 118: ...108 Chapter 13 Debugging Programs That Use Overlays ...
Страница 138: ...128 Chapter 14 Using gdb with Different Languages ...
Страница 144: ...134 Chapter 15 Examining the Symbol Table ...
Страница 170: ...160 Chapter 19 Debugging remote programs ...
Страница 198: ...188 Chapter 21 Controlling gdb ...
Страница 204: ...194 Chapter 22 Canned Sequences of Commands ...
Страница 206: ...196 Chapter 23 Command Interpreters ...
Страница 216: ...206 Chapter 25 Using gdb under gnu Emacs ...
Страница 296: ...286 Chapter 27 gdb Annotations ...
Страница 300: ...290 Chapter 28 Reporting Bugs in gdb ...
Страница 322: ...312 Chapter 30 Using History Interactively ...
Страница 362: ...352 Appendix D gdb Remote Serial Protocol ...
Страница 380: ...370 Appendix F GNU GENERAL PUBLIC LICENSE ...
Страница 386: ...376 Appendix G GNU Free Documentation License ...
Страница 410: ......