Chapter 9. Examining Source Files
63
9.5. Source and machine code
You can use the command
info line
to map source lines to program addresses (and vice versa),
and the command
disassemble
to display a range of addresses as machine instructions. When run
under gnu Emacs mode, the
info line
command causes the arrow to point to the line specified.
Also,
info line
prints addresses in symbolic form as well as hex.
info line
linespec
Print the starting and ending addresses of the compiled code for source line
linespec
. You can
specify source lines in any of the ways understood by the
list
command (refer to Section 9.1
Printing source lines
).
For example, we can use
info line
to discover the location of the object code for the first line of
function
m4_changequote
:
(gdb) info line m4_changequote
Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
We can also inquire (using
*
addr
as the form for
linespec
) what source line covers a particular
address:
(gdb) info line *0x63ff
Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
After
info line
, the default address for the
x
command is changed to the starting address of the
line, so that
x/i
is sufficient to begin examining the machine code (refer to Section 10.5
Examining
memory
). Also, this address is saved as the value of the convenience variable
$_
(refer to Section 10.9
Convenience variables
).
disassemble
This specialized command dumps a range of memory as machine instructions. The default mem-
ory range is the function surrounding the program counter of the selected frame. A single ar-
gument to this command is a program counter value; gdb dumps the function surrounding this
value. Two arguments specify a range of addresses (first inclusive, second exclusive) to dump.
The following example shows the disassembly of a range of addresses of HP PA-RISC 2.0 code:
(gdb) disas 0x32c4 0x32e4
Dump of assembler code from 0x32c4 to 0x32e4:
0x32c4
main+204
:
addil 0,dp
0x32c8
main+208
:
ldw 0x22c(sr0,r1),r26
0x32cc
main+212
:
ldil 0x3000,r31
0x32d0
main+216
:
ble 0x3f8(sr4,r31)
0x32d4
main+220
:
ldo 0(r31),rp
0x32d8
main+224
:
addil -0x800,dp
0x32dc
main+228
:
ldo 0x588(r1),r26
0x32e0
main+232
:
ldil 0x3000,r31
End of assembler dump.
Some architectures have more than one commonly-used set of instruction mnemonics or other syntax.
Summary of Contents for ENTERPRISE LINUX 4 - DEVELOPER TOOLS GUIDE
Page 1: ...Red Hat Enterprise Linux 4 Debugging with gdb ...
Page 12: ...2 Chapter 1 Debugging with gdb ...
Page 28: ...18 Chapter 4 Getting In and Out of gdb ...
Page 34: ...24 Chapter 5 gdb Commands ...
Page 44: ...34 Chapter 6 Running Programs Under gdb ...
Page 68: ...58 Chapter 8 Examining the Stack ...
Page 98: ...88 Chapter 10 Examining Data ...
Page 112: ...102 Chapter 12 Tracepoints ...
Page 118: ...108 Chapter 13 Debugging Programs That Use Overlays ...
Page 138: ...128 Chapter 14 Using gdb with Different Languages ...
Page 144: ...134 Chapter 15 Examining the Symbol Table ...
Page 170: ...160 Chapter 19 Debugging remote programs ...
Page 198: ...188 Chapter 21 Controlling gdb ...
Page 204: ...194 Chapter 22 Canned Sequences of Commands ...
Page 206: ...196 Chapter 23 Command Interpreters ...
Page 216: ...206 Chapter 25 Using gdb under gnu Emacs ...
Page 296: ...286 Chapter 27 gdb Annotations ...
Page 300: ...290 Chapter 28 Reporting Bugs in gdb ...
Page 322: ...312 Chapter 30 Using History Interactively ...
Page 362: ...352 Appendix D gdb Remote Serial Protocol ...
Page 380: ...370 Appendix F GNU GENERAL PUBLIC LICENSE ...
Page 386: ...376 Appendix G GNU Free Documentation License ...
Page 410: ......